Many more things done

This commit is contained in:
Ayumiwii
2016-01-11 19:59:45 +01:00
parent 3467315aef
commit 0630885d92
13 changed files with 153 additions and 37 deletions
+1
View File
@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <array>
#include "Core/Util/Logging.h" #include "Core/Util/Logging.h"
#include "Core/Util/IfDebug.h" #include "Core/Util/IfDebug.h"
-5
View File
@@ -32,11 +32,6 @@ private:
ShaderProgram* m_BasicForwardProgram; ShaderProgram* m_BasicForwardProgram;
ShaderProgram* m_CoolDeathAnimProgram; ShaderProgram* m_CoolDeathAnimProgram;
glm::vec3 Origin;
GLfloat TimeDeath = 0.f;
GLfloat EndDeath = 0.f;
}; };
#endif #endif
+10 -5
View File
@@ -67,13 +67,18 @@ struct ModelJob : RenderJob
struct CoolDeathAnimationJob : ModelJob struct CoolDeathAnimationJob : ModelJob
{ {
glm::vec3 OriginPos; glm::vec3 OriginPos;
float TimeSinceDeath = 0.f; double TimeSinceDeath = 0.f;
float EndOfDeath = 15.0f; double EndOfDeath = 2.f;
bool Gravity = true;
double GravityForce = 1.f; // Speed
double ObjectRadius = 2.f; // TODO: Change this for object radius when it's available
glm::vec4 EndColor;
bool UseRandomness = false;
std::array<float, 10> RandomNumbers;
float RandomnessScalar = 1.f;
float Acceleration = 0.f;
}; };
struct SpriteJob : RenderJob struct SpriteJob : RenderJob
{ {
unsigned int ShaderID = 0; unsigned int ShaderID = 0;
+20
View File
@@ -0,0 +1,20 @@
#include "Common.h"
#include "Core/System.h"
class CoolDeathAnimationSystem : public PureSystem
{
public:
CoolDeathAnimationSystem(EventBroker* eventBroker)
: PureSystem(eventBroker, "CoolDeathAnim")
{ }
virtual void UpdateComponent(World* world, ComponentWrapper& object, double dt) override
{
ComponentWrapper& Component = world->GetComponent(object.EntityID, "CoolDeathAnim");
if ((double)Component["TimeSinceDeath"] > (double)Component["EndOfDeath"]) {
(double)Component["TimeSinceDeath"] = 0.f;
}
(double&)Component["TimeSinceDeath"] += dt;
}
};
+1
View File
@@ -16,6 +16,7 @@
#include "Core/EntityXMLFile.h" #include "Core/EntityXMLFile.h"
#include "Core/SystemPipeline.h" #include "Core/SystemPipeline.h"
#include "RaptorCopterSystem.h" #include "RaptorCopterSystem.h"
#include "CoolDeathAnimationSystem.h"
#include "PlayerSystem.h" #include "PlayerSystem.h"
#include "Editor/EditorSystem.h" #include "Editor/EditorSystem.h"
@@ -1,5 +1,11 @@
<c:CoolDeathAnim> <c:CoolDeathAnim>
<OriginPos X="0" Y="0" Z="0"/> <OriginPos X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath> <TimeSinceDeath>0</TimeSinceDeath>
<EndOfDeath>15</EndOfDeath> <EndOfDeath>2</EndOfDeath>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<EndColor R="0" G="0" B="0" A="0"/>
<UseRandomness>0</UseRandomness>
<RandomnessScalar>1</RandomnessScalar>
</c:CoolDeathAnim> </c:CoolDeathAnim>
@@ -18,6 +18,24 @@
<xs:element name="EndOfDeath" type="t:double" minOccurs="0"> <xs:element name="EndOfDeath" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>How long the death animation should be</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>How long the death animation should be</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="Gravity" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Enable/disable gravity</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="GravityForce" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The force of the gravity</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ObjectRadius" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Object radius (TO BE REMOVED AND AUTOMATED)</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="EndColor" type="t:Color" minOccurs="0">
<xs:annotation><xs:documentation>The tint the polys end with</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="UseRandomness" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Add some randomness to the explosion</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="RandomnessScalar" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Alter the power of the randomness</xs:documentation></xs:annotation>
</xs:element>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
+7 -1
View File
@@ -75,7 +75,13 @@
<c:CoolDeathAnim> <c:CoolDeathAnim>
<OriginPos X="0" Y="0" Z="0"/> <OriginPos X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath> <TimeSinceDeath>0</TimeSinceDeath>
<EndOfDeath>15</EndOfDeath> <EndOfDeath>2</EndOfDeath>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<EndColor R="0" G="0" B="0" A="0"/>
<UseRandomness>0</UseRandomness>
<RandomnessScalar>1</RandomnessScalar>
</c:CoolDeathAnim> </c:CoolDeathAnim>
</Components> </Components>
<Children> <Children>
+2 -1
View File
@@ -11,6 +11,7 @@ in vec3 Normal;
in vec3 Position; in vec3 Position;
in vec2 TextureCoordinate; in vec2 TextureCoordinate;
in vec4 DiffuseColor; in vec4 DiffuseColor;
in vec4 ExplosionColor;
out vec4 fragmentColor; out vec4 fragmentColor;
@@ -18,5 +19,5 @@ out vec4 fragmentColor;
void main() void main()
{ {
vec4 texel = texture2D(texture0, TextureCoordinate); vec4 texel = texture2D(texture0, TextureCoordinate);
fragmentColor = texel * DiffuseColor * Color; fragmentColor = texel * DiffuseColor * Color + ExplosionColor;
} }
+50 -7
View File
@@ -6,6 +6,13 @@ uniform mat4 P;
uniform vec3 OriginPos; uniform vec3 OriginPos;
uniform float TimeSinceDeath; uniform float TimeSinceDeath;
uniform float EndOfDeath; uniform float EndOfDeath;
uniform bool Gravity;
uniform float GravityForce;
uniform float ObjectRadius;
uniform vec4 EndColor;
uniform bool UseRandomness;
uniform float RandomNumbers[10];
uniform float RandomnessScalar;
in VertexData{ in VertexData{
vec3 Position; vec3 Position;
@@ -18,6 +25,7 @@ out vec3 Normal;
out vec3 Position; out vec3 Position;
out vec2 TextureCoordinate; out vec2 TextureCoordinate;
out vec4 DiffuseColor; out vec4 DiffuseColor;
out vec4 ExplosionColor;
layout(triangles) in; layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out; layout(triangle_strip, max_vertices = 3) out;
@@ -71,24 +79,59 @@ void main()
// center position of triangle to origin // center position of triangle to origin
vec3 oriToCenterTri = normalize(centerPosS - OriginPos); vec3 oriToCenterTri = normalize(centerPosS - OriginPos);
float dist = distance(OriginPos, centerPosS);
// The distance a polygon will travel under one second.
float travelUnitS = EndOfDeath / ObjectRadius;
// The distance a polygon will travel under the current frame.
float travelUnitF = TimeSinceDeath * travelUnitS;
float randomness = 0.0f;
int randomIndex = int(mod(gl_PrimitiveIDIn, 10));
// Explosion from origin
for(int i = 0; i < gl_in.length(); i++) for(int i = 0; i < gl_in.length(); i++)
{ {
//gl_in.gl_PrimitiveIDIn;
if (UseRandomness == true)
{
switch (randomIndex)
{
case 0: randomness = RandomNumbers[0]; break;
case 1: randomness = RandomNumbers[1]; break;
case 2: randomness = RandomNumbers[2]; break;
case 3: randomness = RandomNumbers[3]; break;
case 4: randomness = RandomNumbers[4]; break;
case 5: randomness = RandomNumbers[5]; break;
case 6: randomness = RandomNumbers[6]; break;
case 7: randomness = RandomNumbers[7]; break;
case 8: randomness = RandomNumbers[8]; break;
case 9: randomness = RandomNumbers[9]; break;
}
}
float fullRandomness = dist + (randomness * RandomnessScalar);
vec4 screenPos = gl_in[i].gl_Position; vec4 screenPos = gl_in[i].gl_Position;
if (distance(OriginPos, Input[0].Position) <= TimeSinceDeath) //if (dist + fullRandomness <= travelUnitF)
if (fullRandomness <= travelUnitF)
{ {
vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * TimeSinceDeath), 1.0); //objectspace vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * travelUnitF) - (oriToCenterTri * fullRandomness), 1.0); //objectspace
changedPos = vec4(changedPos.x, changedPos.y - pow(TimeSinceDeath, 2), changedPos.z, changedPos.w); //objectspace if (Gravity == true)
{
changedPos.y = changedPos.y - pow((travelUnitF - fullRandomness) * GravityForce, 2);
}
screenPos = P*V * changedPos; //sceenspace screenPos = P*V * changedPos; //sceenspace
} }
// Explosion from origin
Normal = Input[i].Normal; Normal = Input[i].Normal;
Position = Input[i].Position; Position = Input[i].Position;
TextureCoordinate = Input[i].TextureCoordinate; TextureCoordinate = Input[i].TextureCoordinate;
DiffuseColor = vec4(Input[i].DiffuseColor.rg, Input[i].DiffuseColor.b + TimeSinceDeath, Input[i].DiffuseColor.a); DiffuseColor = Input[i].DiffuseColor;
ExplosionColor = EndColor * travelUnitF;
gl_Position = screenPos; gl_Position = screenPos;
//gl_Position = gl_in[i].gl_Position; //gl_Position = gl_in[i].gl_Position;
+12 -12
View File
@@ -33,14 +33,6 @@ void DrawScenePass::InitializeShaderPrograms()
void DrawScenePass::Draw(RenderQueueCollection& rq) void DrawScenePass::Draw(RenderQueueCollection& rq)
{ {
if (TimeDeath > 2.f) {
TimeDeath = 0.f;
}
Origin = glm::vec3(0.f, 0.0f, 0.f);
TimeDeath = TimeDeath + 0.01f;
EndDeath = EndDeath + 0.05f;
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLERROR("Renderer::Draw PickingPass"); GLERROR("Renderer::Draw PickingPass");
@@ -52,16 +44,24 @@ void DrawScenePass::Draw(RenderQueueCollection& rq)
auto coolDeathAnimationJob = std::dynamic_pointer_cast<CoolDeathAnimationJob>(job); auto coolDeathAnimationJob = std::dynamic_pointer_cast<CoolDeathAnimationJob>(job);
if (coolDeathAnimationJob) { if (coolDeathAnimationJob) {
GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //--- GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //---
//---
m_CoolDeathAnimProgram->Bind(); m_CoolDeathAnimProgram->Bind();
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color)); glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color));
glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(Origin)); glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(coolDeathAnimationJob->OriginPos));
glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), TimeDeath); glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), coolDeathAnimationJob->TimeSinceDeath);
glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), EndDeath); glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), coolDeathAnimationJob->EndOfDeath);
glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity);
glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce);
glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius);
glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(coolDeathAnimationJob->EndColor));
glUniform1i(glGetUniformLocation(ShaderHandle, "UseRandomness"), coolDeathAnimationJob->UseRandomness);
glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 10, coolDeathAnimationJob->RandomNumbers.data());
glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), coolDeathAnimationJob->RandomnessScalar);
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd //TODO: Renderer: bättre textur felhantering samt fler texturer stöd
if (coolDeathAnimationJob->DiffuseTexture != nullptr) { if (coolDeathAnimationJob->DiffuseTexture != nullptr) {
+24 -5
View File
@@ -90,8 +90,8 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
} }
for (auto texGroup : model->TextureGroups) { for (auto texGroup : model->TextureGroups) {
auto deathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim"); bool hasDeathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim");
if (!deathComp) { if (!hasDeathComp) {
ModelJob job; ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
@@ -112,9 +112,28 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
else { else {
CoolDeathAnimationJob job; CoolDeathAnimationJob job;
job.TimeSinceDeath = 1.f; auto deathComp = world->GetComponent(modelC.EntityID, "CoolDeathAnim");
job.EndOfDeath = 15.f;
job.OriginPos = glm::vec3(1000.f, 2.f, 0.f); job.OriginPos = (glm::vec3)deathComp["OriginPos"];
job.TimeSinceDeath = (double)deathComp["TimeSinceDeath"];
job.EndOfDeath = (double)deathComp["EndOfDeath"];
job.Gravity = (bool)deathComp["Gravity"];
job.GravityForce = (double)deathComp["GravityForce"];
job.ObjectRadius = (double)deathComp["ObjectRadius"];
job.EndColor = (glm::vec4)deathComp["EndColor"];
job.UseRandomness = (bool)deathComp["UseRandomness"];
job.RandomnessScalar = (double)deathComp["RandomnessScalar"];
job.RandomNumbers = {
0.3257552917701f,
0.07601508315467f,
0.57408909014151f,
0.0f,
0.8618231368539f,
0.074957156588769f,
0.39413607511396f,
0.54579346698979f,
0.83222648353885f,
0.83635707285086f };
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get(); job.DiffuseTexture = texGroup.Texture.get();
+1
View File
@@ -57,6 +57,7 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<EditorSystem>(m_Renderer); m_SystemPipeline->AddSystem<EditorSystem>(m_Renderer);
m_SystemPipeline->AddSystem<CollisionSystem>(); m_SystemPipeline->AddSystem<CollisionSystem>();
m_SystemPipeline->AddSystem<TriggerSystem>(); m_SystemPipeline->AddSystem<TriggerSystem>();
m_SystemPipeline->AddSystem<CoolDeathAnimationSystem>();
// Invoke network // Invoke network
if (m_Config->Get<bool>("Networking.StartNetwork", false)) { if (m_Config->Get<bool>("Networking.StartNetwork", false)) {