Merge remote-tracking branch 'origin/master' into Physics
Conflicts: include/Core/Engine.h src/game/Game/PadSystem.cpp src/game/Physics/PhysicsSystem.cpp
@@ -0,0 +1,22 @@
|
||||
# Blender MTL File: 'octopus.blend'
|
||||
# Material Count: 2
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd octotex.png
|
||||
|
||||
newmtl Material.001_NONE
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd octotex.png
|
||||
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd Brick_d.png
|
||||
map_Bump Brick_n.png
|
||||
map_Ks Brick_s.png
|
||||
@@ -0,0 +1,46 @@
|
||||
# Blender v2.75 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib Brick.mtl
|
||||
o Cube
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.499999
|
||||
v 0.499999 0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
vt 0.566439 0.503009
|
||||
vt 0.567048 0.728848
|
||||
vt 0.341210 0.729457
|
||||
vt 0.339992 0.277781
|
||||
vt 0.339383 0.051943
|
||||
vt 0.565221 0.051334
|
||||
vt 0.793495 0.954077
|
||||
vt 0.567657 0.954686
|
||||
vt 0.341819 0.955295
|
||||
vt 0.115981 0.955904
|
||||
vt 0.115372 0.730066
|
||||
vt 0.340601 0.503618
|
||||
vt 0.565830 0.277172
|
||||
vt 0.792886 0.728239
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -0.000000 0.000000 1.000000
|
||||
vn -1.000000 -0.000000 -0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
usemtl Material
|
||||
s off
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
f 8/4/2 7/5/2 6/6/2
|
||||
f 5/7/3 6/8/3 2/2/3
|
||||
f 6/8/4 7/9/4 3/3/4
|
||||
f 7/9/5 8/10/5 4/11/5
|
||||
f 1/1/6 4/12/6 8/4/6
|
||||
f 4/12/1 1/1/1 3/3/1
|
||||
f 5/13/2 8/4/2 6/6/2
|
||||
f 1/14/3 5/7/3 2/2/3
|
||||
f 2/2/4 6/8/4 3/3/4
|
||||
f 3/3/5 7/9/5 4/11/5
|
||||
f 5/13/6 1/1/6 8/4/6
|
||||
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 2.1 MiB |
@@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'Brick.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Brick
|
||||
Ns 17.647059
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.154050 0.039202
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 1
|
||||
map_Kd Brick_d.png
|
||||
map_Bump Brick_n.png
|
||||
map_Ks Brick_s.png
|
||||
|
After Width: | Height: | Size: 774 KiB |
|
After Width: | Height: | Size: 773 KiB |
|
After Width: | Height: | Size: 433 KiB |
@@ -0,0 +1,14 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material.001
|
||||
Ns 96.078431
|
||||
Ka 0.000000 0.000000 0.000000
|
||||
Kd 0.640000 0.640000 0.640000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ni 1.000000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd Brick_Diffuse.png
|
||||
map_Bump Brick_Normal.png
|
||||
map_Ks Brick_Specular.png
|
||||
@@ -0,0 +1,124 @@
|
||||
# Blender v2.75 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib Halfpipe.mtl
|
||||
o Cylinder
|
||||
v 0.000000 -2.908792 -1.000000
|
||||
v 0.000000 2.908792 -1.000000
|
||||
v 0.195090 -2.908792 -0.980785
|
||||
v 0.195090 2.908792 -0.980785
|
||||
v 0.382683 -2.908792 -0.923880
|
||||
v 0.382683 2.908792 -0.923880
|
||||
v 0.555570 -2.908792 -0.831470
|
||||
v 0.555570 2.908792 -0.831470
|
||||
v 0.707107 -2.908792 -0.707107
|
||||
v 0.707107 2.908792 -0.707107
|
||||
v 0.831470 -2.908792 -0.555570
|
||||
v 0.831470 2.908792 -0.555570
|
||||
v 0.923880 -2.908792 -0.382683
|
||||
v 0.923880 2.908792 -0.382683
|
||||
v 0.980785 -2.908792 -0.195090
|
||||
v 0.980785 2.908792 -0.195090
|
||||
v 1.000000 -2.908792 -0.000000
|
||||
v 1.000000 2.908792 -0.000000
|
||||
v -1.000000 -2.908792 -0.000001
|
||||
v -1.000000 2.908792 -0.000001
|
||||
v -0.980785 -2.908792 -0.195091
|
||||
v -0.980785 2.908792 -0.195091
|
||||
v -0.923879 -2.908792 -0.382684
|
||||
v -0.923879 2.908792 -0.382684
|
||||
v -0.831469 -2.908792 -0.555571
|
||||
v -0.831469 2.908792 -0.555571
|
||||
v -0.707106 -2.908792 -0.707108
|
||||
v -0.707106 2.908792 -0.707108
|
||||
v -0.555569 -2.908792 -0.831470
|
||||
v -0.555569 2.908792 -0.831470
|
||||
v -0.382682 -2.908792 -0.923880
|
||||
v -0.382682 2.908792 -0.923880
|
||||
v -0.195089 -2.908792 -0.980786
|
||||
v -0.195089 2.908792 -0.980786
|
||||
vt -1.156714 -1.419990
|
||||
vt -1.158346 2.336063
|
||||
vt -1.031779 2.336118
|
||||
vt -1.283288 -1.420045
|
||||
vt -1.284913 2.336008
|
||||
vt -1.409862 -1.420100
|
||||
vt -1.411480 2.335954
|
||||
vt -1.536436 -1.420155
|
||||
vt -1.538048 2.335899
|
||||
vt 2.387354 -1.418355
|
||||
vt 2.385534 2.337692
|
||||
vt 2.512101 2.337753
|
||||
vt 2.260782 -1.418416
|
||||
vt 2.258967 2.337631
|
||||
vt 2.134208 -1.418478
|
||||
vt 2.132400 2.337570
|
||||
vt 2.007634 -1.418538
|
||||
vt 2.005832 2.337510
|
||||
vt -0.144122 -1.419541
|
||||
vt -0.145809 2.336510
|
||||
vt -0.019241 2.336567
|
||||
vt -0.270696 -1.419598
|
||||
vt -0.272376 2.336454
|
||||
vt -0.397270 -1.419654
|
||||
vt -0.398943 2.336397
|
||||
vt -0.523844 -1.419711
|
||||
vt -0.525511 2.336341
|
||||
vt -0.650418 -1.419767
|
||||
vt -0.652078 2.336285
|
||||
vt -0.776992 -1.419823
|
||||
vt -0.778645 2.336229
|
||||
vt -1.030140 -1.419935
|
||||
vt -0.905212 2.336174
|
||||
vt -0.903566 -1.419879
|
||||
vt 2.513929 -1.418293
|
||||
vt -0.017548 -1.419484
|
||||
vn -0.098000 0.000000 0.995200
|
||||
vn -0.290300 0.000000 0.956900
|
||||
vn -0.471400 0.000000 0.881900
|
||||
vn -0.634400 0.000000 0.773000
|
||||
vn -0.773000 0.000000 0.634400
|
||||
vn -0.881900 0.000000 0.471400
|
||||
vn -0.956900 0.000000 0.290300
|
||||
vn -0.995200 0.000000 0.098000
|
||||
vn 0.995200 0.000000 0.098000
|
||||
vn 0.956900 0.000000 0.290300
|
||||
vn 0.881900 0.000000 0.471400
|
||||
vn 0.773000 0.000000 0.634400
|
||||
vn 0.634400 0.000000 0.773000
|
||||
vn 0.471400 0.000000 0.881900
|
||||
vn 0.098000 0.000000 0.995200
|
||||
vn 0.290300 0.000000 0.956900
|
||||
usemtl Material.001
|
||||
s off
|
||||
f 3/1/1 4/2/1 2/3/1
|
||||
f 5/4/2 6/5/2 4/2/2
|
||||
f 7/6/3 8/7/3 6/5/3
|
||||
f 9/8/4 10/9/4 8/7/4
|
||||
f 11/10/5 12/11/5 10/12/5
|
||||
f 13/13/6 14/14/6 12/11/6
|
||||
f 15/15/7 16/16/7 14/14/7
|
||||
f 17/17/8 18/18/8 16/16/8
|
||||
f 21/19/9 22/20/9 20/21/9
|
||||
f 23/22/10 24/23/10 22/20/10
|
||||
f 25/24/11 26/25/11 24/23/11
|
||||
f 27/26/12 28/27/12 26/25/12
|
||||
f 29/28/13 30/29/13 28/27/13
|
||||
f 31/30/14 32/31/14 30/29/14
|
||||
f 1/32/15 2/3/15 34/33/15
|
||||
f 33/34/16 34/33/16 32/31/16
|
||||
f 1/32/1 3/1/1 2/3/1
|
||||
f 3/1/2 5/4/2 4/2/2
|
||||
f 5/4/3 7/6/3 6/5/3
|
||||
f 7/6/4 9/8/4 8/7/4
|
||||
f 9/35/5 11/10/5 10/12/5
|
||||
f 11/10/6 13/13/6 12/11/6
|
||||
f 13/13/7 15/15/7 14/14/7
|
||||
f 15/15/8 17/17/8 16/16/8
|
||||
f 19/36/9 21/19/9 20/21/9
|
||||
f 21/19/10 23/22/10 22/20/10
|
||||
f 23/22/11 25/24/11 24/23/11
|
||||
f 25/24/12 27/26/12 26/25/12
|
||||
f 27/26/13 29/28/13 28/27/13
|
||||
f 29/28/14 31/30/14 30/29/14
|
||||
f 33/34/15 1/32/15 34/33/15
|
||||
f 31/30/16 33/34/16 32/31/16
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 4.0 MiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -72,9 +72,6 @@ public:
|
||||
m_World->SystemFactory.Register<Systems::TransformSystem>(
|
||||
[this]() { return new Systems::TransformSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::TransformSystem>();
|
||||
// m_World->ComponentFactory.Register<Components::Model>();
|
||||
// m_World->ComponentFactory.Register<Components::Template>();
|
||||
|
||||
|
||||
m_World->ComponentFactory.Register<Components::Sprite>();
|
||||
|
||||
@@ -83,6 +80,7 @@ public:
|
||||
m_World->ComponentFactory.Register<Components::Ball>();
|
||||
m_World->ComponentFactory.Register<Components::Brick>();
|
||||
m_World->ComponentFactory.Register<Components::Pad>();
|
||||
m_World->ComponentFactory.Register<Components::Life>();
|
||||
m_World->SystemFactory.Register<Systems::PhysicsSystem>(
|
||||
[this]() { return new Systems::PhysicsSystem(m_World.get(), m_EventBroker); });
|
||||
m_World->AddSystem<Systems::PhysicsSystem>();
|
||||
@@ -101,18 +99,10 @@ public:
|
||||
|
||||
|
||||
//TODO: Remove tobias light-test code.
|
||||
{
|
||||
auto t_BrickWall = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
|
||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
|
||||
//TODO: Rename SpriteFile to DiffuseTexture or similar.
|
||||
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
|
||||
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
|
||||
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
|
||||
}
|
||||
|
||||
/*{
|
||||
}*/
|
||||
|
||||
//OctoBall
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
@@ -120,8 +110,8 @@ public:
|
||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||
transform->Velocity = glm::vec3(-1.0f, -5.f, 0.f);
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
sprite->SpriteFile = "Textures/Ball.png";
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||
@@ -137,10 +127,40 @@ public:
|
||||
|
||||
}
|
||||
|
||||
//PointLightTest
|
||||
{
|
||||
auto t_Light = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
|
||||
transform->Position = glm::vec3(2.f, 1.5f, -9.f);
|
||||
auto pl = m_World->AddComponent<Components::PointLight>(t_Light);
|
||||
pl->Radius = 8.f;
|
||||
}
|
||||
|
||||
//Halfpipe background test model.
|
||||
{
|
||||
auto t_halfPipe = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_halfPipe);
|
||||
transform->Position = glm::vec3(0.f, 0.f, -15.f);
|
||||
transform->Scale = glm::vec3(15.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(t_halfPipe);
|
||||
model->ModelFile = "Models/Test/halfpipe/Halfpipe.obj";
|
||||
}
|
||||
|
||||
//Brick test model
|
||||
{
|
||||
auto t_Brick = m_World->CreateEntity();
|
||||
auto transform = m_World->AddComponent<Components::Transform>(t_Brick);
|
||||
transform->Position = glm::vec3(0.f, 0.f, -12.f);
|
||||
transform->Orientation = glm::rotate(glm::quat(), 0.5f, glm::vec3(0,-1,-1));
|
||||
auto model = m_World->AddComponent<Components::Model>(t_Brick);
|
||||
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
auto topWall = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
|
||||
transform->Position = glm::vec3(0.f, 5.f, -10.f);
|
||||
transform->Position = glm::vec3(0.f, 6.f, -10.f);
|
||||
transform->Scale = glm::vec3(20.f, 0.5f, 1.f);
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(topWall);
|
||||
@@ -186,25 +206,6 @@ public:
|
||||
m_World->CommitEntity(rightWall);
|
||||
}
|
||||
|
||||
|
||||
/*{
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(0.f, -3.f, -10.f);
|
||||
transform->Scale = glm::vec3(8.f, 0.5f, 1.f);
|
||||
transform->Orientation = glm::rotate(transform->Orientation, glm::radians(25.f), glm::vec3(0, 0, -1));
|
||||
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = true;
|
||||
|
||||
m_World->CommitEntity(ent);
|
||||
}*/
|
||||
|
||||
{
|
||||
auto ent = m_World->CreateEntity();
|
||||
m_World->SetProperty(ent, "Name", "Pad");
|
||||
@@ -304,7 +305,7 @@ public:
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
|
||||
* glm::toMat4(absoluteTransform.Orientation)
|
||||
* glm::scale(absoluteTransform.Scale);
|
||||
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
|
||||
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color, modelComponent->ModelFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +345,7 @@ public:
|
||||
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
|
||||
* glm::toMat4(orientation2D)
|
||||
* glm::scale(absoluteTransform.Scale);
|
||||
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color);
|
||||
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +353,7 @@ public:
|
||||
}
|
||||
|
||||
//TODO: Get this out of engine.h
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
|
||||
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color, std::string fileName)
|
||||
{
|
||||
for (auto texGroup : model->TextureGroups)
|
||||
{
|
||||
@@ -367,13 +368,14 @@ public:
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Color = color;
|
||||
job.fileName = fileName;
|
||||
|
||||
m_RendererQueue.Deferred.Add(job);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Get this out of engine.h
|
||||
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color)
|
||||
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth)
|
||||
{
|
||||
SpriteJob job;
|
||||
job.TextureID = texture->ResourceID;
|
||||
@@ -382,8 +384,10 @@ public:
|
||||
job.SpecularTexture = *specularTexture;
|
||||
job.ModelMatrix = modelMatrix;
|
||||
job.Color = color;
|
||||
job.Depth = depth;
|
||||
|
||||
m_RendererQueue.Deferred.Add(job);
|
||||
|
||||
m_RendererQueue.Forward.Add(job);
|
||||
}
|
||||
|
||||
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
|
||||
|
||||
@@ -121,8 +121,6 @@ public:
|
||||
int Process(std::string contextTypeName);
|
||||
void Clear();
|
||||
void Unsubscribe(BaseEventRelay &relay);
|
||||
template <typename ContextType>
|
||||
void UnsubscribeAll();
|
||||
|
||||
private:
|
||||
typedef std::string ContextTypeName_t; // typeid(ContextType).name()
|
||||
@@ -156,13 +154,6 @@ int EventBroker::Process()
|
||||
return Process(contextTypeName);
|
||||
}
|
||||
|
||||
template <typename ContextType>
|
||||
void EventBroker::UnsubscribeAll()
|
||||
{
|
||||
const std::string contextTypeName = typeid(ContextType).name();
|
||||
m_ContextRelays.erase(contextTypeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // MessageRelay_h__
|
||||
|
||||
@@ -52,6 +52,8 @@ struct ModelJob : RenderJob
|
||||
unsigned int ShaderID;
|
||||
unsigned int TextureID;
|
||||
|
||||
std::string fileName;
|
||||
|
||||
glm::mat4 ModelMatrix;
|
||||
GLuint DiffuseTexture;
|
||||
GLuint NormalTexture;
|
||||
|
||||
@@ -76,6 +76,8 @@ private:
|
||||
GLuint m_ScreenQuad = 0;
|
||||
Model* m_UnitSphere = nullptr;
|
||||
Model* m_UnitQuad = nullptr;
|
||||
Texture* m_StandardNormal;
|
||||
Texture* m_StandardSpecular;
|
||||
|
||||
GLuint m_rbDepthBuffer = 0;
|
||||
GLuint m_fbDeferred1 = 0;
|
||||
@@ -93,6 +95,8 @@ private:
|
||||
void CreateBuffers();
|
||||
GLuint CreateQuad();
|
||||
|
||||
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
|
||||
|
||||
void DrawDeferred(RenderQueue &objects, RenderQueue &lights);
|
||||
void DrawForward(RenderQueue &objects, RenderQueue &lights);
|
||||
void DrawScene(RenderQueue &objects, ShaderProgram &program);
|
||||
|
||||
@@ -194,7 +194,7 @@ public:
|
||||
|
||||
// Triggers commit events in systems
|
||||
// TODO: Replace completely by EComponentCreated?
|
||||
void CommitEntity(EntityID entity);
|
||||
int CommitEntity(EntityID entity);
|
||||
|
||||
/** Get all components of a specific type.
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Components
|
||||
|
||||
struct Ball : Component
|
||||
{
|
||||
|
||||
int Number = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ struct Brick : Component
|
||||
{
|
||||
int Points = 10;
|
||||
int Hits = 1;
|
||||
int Score = 50;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-15.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_CLIFE_H
|
||||
#define DAYDREAM_CLIFE_H
|
||||
|
||||
#include "Core/Component.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Life : Component {
|
||||
|
||||
int Number = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CLIFE_H
|
||||
@@ -19,6 +19,10 @@ struct Pad : Component
|
||||
{
|
||||
int Lives;
|
||||
int Points;
|
||||
|
||||
float SlowdownModifier = 5.f;
|
||||
float AccelerationSpeed = 80.f;
|
||||
float MaxSpeed = 40.f;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-15.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ELIFELOST_H
|
||||
#define DAYDREAM_ELIFELOST_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct LifeLost : Event
|
||||
{
|
||||
EntityID Entity;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ELIFELOST_H
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-15.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ERESETBALL_H
|
||||
#define DAYDREAM_ERESETBALL_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ResetBall : Event
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ERESETBALL_H
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Adniklastrator on 2015-09-15.
|
||||
//
|
||||
|
||||
#ifndef DAYDREAM_ESCOREEVENT_H
|
||||
#define DAYDREAM_ESCOREEVENT_H
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
namespace dd
|
||||
{
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ScoreEvent : Event
|
||||
{
|
||||
int Score = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_ESCOREEVENT_H
|
||||
@@ -8,14 +8,21 @@
|
||||
#include "Core/System.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Game/CBrick.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/CLife.h"
|
||||
#include "Game/EStageCleared.h"
|
||||
#include "Game/ELifeLost.h"
|
||||
#include "Game/EResetBall.h"
|
||||
#include "Game/EScoreEvent.h"
|
||||
#include "Physics/CBoxShape.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <intrin.h>
|
||||
@@ -47,6 +54,7 @@ public:
|
||||
void Initialize() override;
|
||||
|
||||
void CreateBasicLevel(int, int, glm::vec2, int);
|
||||
void CreateLife(int);
|
||||
void SaveLevel(int, int, glm::vec2, int); // Shouldn't be here, but I'm experimenting.
|
||||
void LoadLevel(char[20]);
|
||||
void CreateBrick(int, int, glm::vec2, int, int);
|
||||
@@ -56,20 +64,47 @@ public:
|
||||
|
||||
void EndLevel();
|
||||
|
||||
void Update(double dt);
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
bool Initialized() const { return m_Initialized; }
|
||||
void SetInitialized(const bool& initialized) { m_Initialized = initialized; }
|
||||
int& Lives() { return m_Lives; }
|
||||
void SetLives(const int& lives) { m_Lives = lives; }
|
||||
int& PastLives() { return m_PastLives; }
|
||||
void SetPastLives(const int& pastLives) { m_PastLives = pastLives; }
|
||||
int& Score() { return m_Score; }
|
||||
void SetScore(const int& score) { m_Score = score; }
|
||||
int& NumberOfBricks() { return m_NumberOfBricks; }
|
||||
void SetNumberOfBricks(const int& numberOfBricks) { m_NumberOfBricks = numberOfBricks; }
|
||||
int& Rows() { return m_Rows; }
|
||||
void SetRows(const int& rows) { m_Rows = rows; }
|
||||
int& Lines() { return m_Lines; }
|
||||
void SetLines(const int& lines) { m_Lines = lines; }
|
||||
int& SpaceToEdge() { return m_SpaceToEdge; }
|
||||
void SetSpaceToEdge(const int& spaceToEdge) { m_SpaceToEdge = spaceToEdge; }
|
||||
|
||||
glm::vec2& SpaceBetweenBricks() { return m_SpaceBetweenBricks; }
|
||||
void SetSpaceBetweenBricks(const glm::vec2& spaceBetweenBricks) { m_SpaceBetweenBricks = spaceBetweenBricks; }
|
||||
|
||||
private:
|
||||
bool m_Initialized = false;
|
||||
int m_Lives = 3;
|
||||
int m_PastLives = 3;
|
||||
int m_Score = 0;
|
||||
int m_NumberOfBricks;
|
||||
int m_Rows = 7;
|
||||
int m_Lines = 8;
|
||||
int m_SpaceToEdge = 0;
|
||||
glm::vec2 m_SpaceBetweenBricks = glm::vec2(2, 0.5);
|
||||
|
||||
dd::EventRelay<LevelSystem, dd::Events::Contact> m_EContact;
|
||||
dd::EventRelay<LevelSystem, dd::Events::LifeLost> m_ELifeLost;
|
||||
dd::EventRelay<LevelSystem, dd::Events::ScoreEvent> m_EScoreEvent;
|
||||
|
||||
bool OnContact(const dd::Events::Contact &event);
|
||||
|
||||
bool m_Initialized = false;
|
||||
|
||||
int numberOfBricks;
|
||||
int tRows = 7;
|
||||
int tLines = 8;
|
||||
glm::vec2 tSpaceBetweenBricks = glm::vec2(2, 0.5);
|
||||
int tSpaceToEdge = 0;
|
||||
bool LifeLost(const dd::Events::LifeLost &event);
|
||||
bool ScoreEvent(const dd::Events::ScoreEvent &event);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,19 +7,22 @@
|
||||
|
||||
#include "Core/InputController.h"
|
||||
#include "Core/System.h"
|
||||
#include "Core/Component.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
#include "Input/EBindKey.h"
|
||||
#include "Physics/EContact.h"
|
||||
#include "Core/CTransform.h"
|
||||
#include "Physics/CBoxShape.h"
|
||||
#include "Physics/CPhysics.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Core/Component.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Physics/CCircleShape.h"
|
||||
#include "Physics/ESetImpulse.h"
|
||||
#include "Rendering/CSprite.h"
|
||||
#include "Rendering/CModel.h"
|
||||
#include "Game/CBall.h"
|
||||
#include "Game/EResetBall.h"
|
||||
#include "CPad.h"
|
||||
|
||||
|
||||
namespace dd
|
||||
@@ -32,34 +35,49 @@ class PadSystem : public System
|
||||
{
|
||||
public:
|
||||
PadSystem(World* world, std::shared_ptr<dd::EventBroker> eventBroker)
|
||||
: System(world, eventBroker)
|
||||
{ }
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
void Initialize() override;
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
EntityID& Entity() { return m_Entity; }
|
||||
void SetEntity(const EntityID& ent) { m_Entity = ent; }
|
||||
glm::vec3 Acceleration() const { return m_Acceleration; }
|
||||
void SetAcceleration(const glm::vec3& acceleration) { m_Acceleration = acceleration; }
|
||||
|
||||
bool Left() const { return m_Left; }
|
||||
void SetLeft(const bool& left) { m_Left = left; }
|
||||
bool Right() const { return m_Right; }
|
||||
void SetRight(const bool& right) { m_Right = right; }
|
||||
bool ReplaceBall() const { return m_ReplaceBall; }
|
||||
void SetReplaceBall(const bool& replaceBall) { m_ReplaceBall = replaceBall; }
|
||||
|
||||
Components::Transform* Transform() const { return m_Transform; }
|
||||
void SetTransform(const Components::Transform* transform) { m_Transform = transform; }
|
||||
Components::Pad* Pad() const { return m_Pad; }
|
||||
void SetPad(const Components::Pad* pad) { m_Pad = pad; }
|
||||
|
||||
private:
|
||||
EntityID m_Entity = 0;
|
||||
glm::vec3 m_Acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||
bool m_Left = false, m_Right = false, m_ReplaceBall = false;
|
||||
Components::Transform* m_Transform;
|
||||
Components::Pad* m_Pad;
|
||||
|
||||
dd::EventRelay<PadSystem, dd::Events::KeyDown> m_EKeyDown;
|
||||
dd::EventRelay<PadSystem, dd::Events::KeyUp> m_EKeyUp;
|
||||
dd::EventRelay<PadSystem, dd::Events::Contact> m_EContact;
|
||||
dd::EventRelay<PadSystem, dd::Events::ResetBall> m_EResetBall;
|
||||
|
||||
bool OnKeyDown(const dd::Events::KeyDown &event);
|
||||
bool OnKeyUp(const dd::Events::KeyUp &event);
|
||||
|
||||
|
||||
bool OnContact(const dd::Events::Contact &event);
|
||||
|
||||
|
||||
|
||||
|
||||
bool ResetBall(const dd::Events::ResetBall &event);
|
||||
|
||||
class PadSteeringInputController;
|
||||
std::array<std::shared_ptr<PadSteeringInputController>, 4> m_PadInputControllers;
|
||||
|
||||
EntityID ent = 0;
|
||||
Components::Transform* transform;
|
||||
glm::vec3 acceleration = glm::vec3(0.f, 0.f, 0.f);
|
||||
bool left = false, right = false;
|
||||
};
|
||||
|
||||
class PadSystem::PadSteeringInputController : InputController<PadSystem>
|
||||
|
||||
@@ -75,8 +75,7 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_Rendering}
|
||||
${SOURCE_FILES_Transform}
|
||||
${SOURCE_FILES_Physics}
|
||||
${SOURCE_FILES_Game}
|
||||
)
|
||||
${SOURCE_FILES_Game})
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
|
||||
@@ -77,20 +77,20 @@ void dd::Camera::SetOrientation(glm::quat val)
|
||||
|
||||
void dd::Camera::UpdateProjectionMatrix()
|
||||
{
|
||||
m_ProjectionMatrix = glm::ortho(
|
||||
-16.f,
|
||||
16.f,
|
||||
-9.f,
|
||||
9.f,
|
||||
m_NearClip,
|
||||
m_FarClip
|
||||
);
|
||||
// m_ProjectionMatrix = glm::perspective(
|
||||
// m_FOV,
|
||||
// m_AspectRatio,
|
||||
// m_ProjectionMatrix = glm::ortho(
|
||||
// -16.f,
|
||||
// 16.f,
|
||||
// -9.f,
|
||||
// 9.f,
|
||||
// m_NearClip,
|
||||
// m_FarClip
|
||||
// );
|
||||
m_ProjectionMatrix = glm::perspective(
|
||||
m_FOV,
|
||||
m_AspectRatio,
|
||||
m_NearClip,
|
||||
m_FarClip
|
||||
);
|
||||
}
|
||||
|
||||
void dd::Camera::UpdateViewMatrix()
|
||||
|
||||
@@ -40,6 +40,7 @@ void dd::EventBroker::Unsubscribe(BaseEventRelay &relay) // ?
|
||||
{
|
||||
if (it->second == &relay)
|
||||
{
|
||||
relay.m_Broker = nullptr;
|
||||
eventRelays.erase(it);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ void dd::Renderer::CreateBuffers()
|
||||
m_ScreenQuad = CreateQuad();
|
||||
m_UnitQuad = ResourceManager::Load<Model>("Models/Core/UnitQuad.obj");
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
m_StandardNormal = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||
m_StandardSpecular = ResourceManager::Load<Texture>("Textures/Core/NeutralSpecularMap.png");
|
||||
|
||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_rbDepthBuffer);
|
||||
@@ -207,7 +209,9 @@ void dd::Renderer::CreateBuffers()
|
||||
|
||||
void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
|
||||
DrawDeferred(rq.Deferred, rq.Lights);
|
||||
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
|
||||
DrawForward(rq.Forward, rq.Lights);
|
||||
|
||||
// Finally: Draw the deferred+forward combined texture to the screen
|
||||
@@ -276,14 +280,20 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
|
||||
void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
|
||||
{
|
||||
|
||||
// Forward-render semi-transparent objects on top of the current framebuffer
|
||||
glDisable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
|
||||
// glClearColor(1, 0.9, 0.8f, 1);
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
m_spForward->Bind();
|
||||
DrawScene(objects, *m_spForward);
|
||||
}
|
||||
@@ -304,21 +314,32 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
||||
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightPosition"), 1, glm::value_ptr(glm::vec3(0.f,0.f,-9.f)));
|
||||
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightSpecular"), 1, glm::value_ptr(glm::vec3(1.f)));
|
||||
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightDiffuse"), 1, glm::value_ptr(glm::vec3(1.f)));
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
|
||||
|
||||
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
|
||||
|
||||
//TODO: Make sure that a normal/specular is loaded in.
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
|
||||
if (modelJob->NormalTexture != 0) {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardNormal);
|
||||
}
|
||||
|
||||
if (modelJob->SpecularTexture != 0) {
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, *m_StandardSpecular);
|
||||
}
|
||||
|
||||
|
||||
glBindVertexArray(modelJob->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
@@ -38,7 +38,8 @@ void main()
|
||||
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
||||
frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
|
||||
//frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
|
||||
frag_Diffuse = DiffuseTexel + LightingTexel;
|
||||
//frag_Diffuse = DiffuseTexel;
|
||||
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ in VertexData
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 FragmentColor;
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
@@ -83,7 +83,8 @@ void main()
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
|
||||
FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
//FragmentColor = diffuseTexel;
|
||||
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
//frag_Diffuse = light;
|
||||
frag_Diffuse = diffuseTexel;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D NormalMap;
|
||||
layout (binding=2) uniform sampler2D SpecularMap;
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec3 LightPosition;
|
||||
uniform float LightRadius;
|
||||
uniform vec3 LightSpecular;
|
||||
uniform vec3 LightDiffuse;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
|
||||
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
|
||||
{
|
||||
// Diffuse
|
||||
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
|
||||
vec3 distanceToLight = lightPos - position;
|
||||
vec3 directionToLight = normalize(distanceToLight);
|
||||
float dotProd = dot(directionToLight, normal);
|
||||
dotProd = max(dotProd, 0.0);
|
||||
vec3 Idiffuse = LightDiffuse * dotProd;
|
||||
|
||||
// Specular
|
||||
//vec3 reflection = reflect(-directionToLight, normal);
|
||||
vec3 surfaceToViewer = normalize(-position);
|
||||
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
|
||||
float dotSpecular = max(dot(halfWay, normal), 0.0);
|
||||
float specularFactor = pow(dotSpecular, specularExponent);
|
||||
vec3 Ispecular = specular * LightSpecular * specularFactor;
|
||||
|
||||
//Attenuation
|
||||
float dist = distance(lightPos, position);
|
||||
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
|
||||
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
|
||||
|
||||
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
|
||||
|
||||
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
|
||||
|
||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||
|
||||
//frag_Diffuse = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||
frag_Diffuse = diffuseTexel;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Daydream Engine.
|
||||
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
|
||||
|
||||
Daydream Engine is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Daydream Engine is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 440
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 Bones[100];
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec3 Tangent;
|
||||
layout (location = 3) in vec3 BiTangent;
|
||||
layout (location = 4) in vec2 TextureCoord;
|
||||
layout (location = 5) in vec4 DiffuseColor;
|
||||
layout (location = 6) in vec4 SpecularColor;
|
||||
layout (location = 7) in vec4 BoneIndices1;
|
||||
layout (location = 8) in vec4 BoneIndices2;
|
||||
layout (location = 9) in vec4 BoneWeights1;
|
||||
layout (location = 10) in vec4 BoneWeights2;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoord;
|
||||
vec4 DiffuseColor;
|
||||
vec4 SpecularColor;
|
||||
vec4 BoneIndices1;
|
||||
vec4 BoneIndices2;
|
||||
vec4 BoneWeights1;
|
||||
vec4 BoneWeights2;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 boneTransform = mat4(1);
|
||||
if (length(BoneWeights1 + BoneWeights2) > 0) {
|
||||
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
|
||||
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
|
||||
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
|
||||
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
|
||||
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
|
||||
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
|
||||
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
|
||||
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
|
||||
}
|
||||
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
Output.BiTangent = BiTangent;
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.DiffuseColor = DiffuseColor;
|
||||
Output.SpecularColor = SpecularColor;
|
||||
Output.BoneIndices1 = BoneIndices1;
|
||||
Output.BoneIndices2 = BoneIndices2;
|
||||
Output.BoneWeights1 = BoneWeights1;
|
||||
Output.BoneWeights2 = BoneWeights2;
|
||||
}
|
||||
@@ -161,7 +161,7 @@ void dd::World::Initialize()
|
||||
}
|
||||
}
|
||||
|
||||
void dd::World::CommitEntity(EntityID entity)
|
||||
int dd::World::CommitEntity(EntityID entity)
|
||||
{
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
|
||||
@@ -10,26 +10,79 @@
|
||||
void dd::Systems::LevelSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, LevelSystem::OnContact);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ELifeLost, LevelSystem::LifeLost);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EScoreEvent, LevelSystem::ScoreEvent);
|
||||
|
||||
for (int i = 0; i < Lives(); i++) {
|
||||
CreateLife(i);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::Update(double dt) {
|
||||
void dd::Systems::LevelSystem::CreateLife(int number)
|
||||
{
|
||||
auto life = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(life);
|
||||
transform->Position = glm::vec3(-4.f + number * 0.5f, -2.f, -5.f);
|
||||
transform->Scale = glm::vec3(0.25f, 0.25f, 0.25f);
|
||||
|
||||
std::shared_ptr<Components::Life> lifeNr = m_World->AddComponent<Components::Life>(life);
|
||||
lifeNr->Number = number;
|
||||
|
||||
auto model = m_World->AddComponent<Components::Model>(life);
|
||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||
|
||||
/*std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(life);
|
||||
sprite->SpriteFile = "Textures/Ball.png";*/
|
||||
|
||||
m_World->CommitEntity(life);
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::Update(double dt)
|
||||
{
|
||||
if (!m_Initialized) {
|
||||
CreateBasicLevel(tRows, tLines, tSpaceBetweenBricks, tSpaceToEdge);
|
||||
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
|
||||
m_Initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
||||
|
||||
if (ball != NULL) {
|
||||
auto transformBall = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (transformBall->Position.y < -10) {
|
||||
if (Lives() == PastLives()) {
|
||||
Events::LifeLost e;
|
||||
e.Entity = entity;
|
||||
EventBroker->Publish(e);
|
||||
Events::ResetBall be;
|
||||
EventBroker->Publish(be);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Lives() != PastLives()) {
|
||||
auto life = m_World->GetComponent<Components::Life>(entity);
|
||||
if (life != NULL) {
|
||||
if (life->Number + 1 == PastLives()) {
|
||||
m_World->RemoveEntity(entity);
|
||||
SetPastLives(Lives());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::CreateBasicLevel(int rows, int lines, glm::vec2 spacesBetweenBricks, int spaceToEdge)
|
||||
{
|
||||
int num = 0;
|
||||
numberOfBricks = rows * lines;
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
SetNumberOfBricks(rows * lines);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
num++;
|
||||
for (int j = 0; j < lines; j++)
|
||||
{
|
||||
for (int j = 0; j < Lines(); j++) {
|
||||
CreateBrick(i, j, spacesBetweenBricks, spaceToEdge, num);
|
||||
}
|
||||
if (num == 7)
|
||||
@@ -43,19 +96,21 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
|
||||
{
|
||||
auto brick = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(brick);
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
|
||||
//std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(brick);
|
||||
auto model = m_World->AddComponent<Components::Model>(brick);
|
||||
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
|
||||
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
|
||||
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
|
||||
std::string fileName = "Textures/Bricks/";
|
||||
fileName.append(std::to_string(num));
|
||||
fileName.append(".png");
|
||||
sprite->SpriteFile = fileName;
|
||||
//sprite->SpriteFile = fileName;
|
||||
model->ModelFile = "Models/Test/Brick/Brick.obj";
|
||||
float x = spaceToEdge + line * spacesBetweenBricks.x;
|
||||
float y = spaceToEdge + row * spacesBetweenBricks.y;
|
||||
transform->Scale = glm::vec3(1.6, 0.4, 0.);
|
||||
transform->Scale = glm::vec3(1.6, 0.35, 0.5);
|
||||
transform->Position = glm::vec3(x - 7, y + 1, -10.f);
|
||||
//sprite->Color = glm::vec4(1.f, 1.f, 1.f, 1.f);
|
||||
cBrick->Score = 10 * num;
|
||||
m_World->CommitEntity(brick);
|
||||
return;
|
||||
}
|
||||
@@ -68,72 +123,57 @@ void dd::Systems::LevelSystem::ProcessCollision()
|
||||
|
||||
void dd::Systems::LevelSystem::OnEntityRemoved(EntityID entity)
|
||||
{
|
||||
auto brick = m_World->GetComponent<Components::Brick>(entity);
|
||||
if (brick != NULL)
|
||||
{
|
||||
/*auto brick = m_World->GetComponent<Components::Brick>(entity);
|
||||
if (brick != NULL) {
|
||||
numberOfBricks--;
|
||||
if (numberOfBricks < 1)
|
||||
{
|
||||
if (numberOfBricks < 1) {
|
||||
EndLevel();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return;
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::OnContact(const dd::Events::Contact &event)
|
||||
{
|
||||
/*event.Entity1 - Vi vet inte vilken som.
|
||||
event.Entity2 - */
|
||||
EntityID entityBrick = event.Entity1;
|
||||
auto brick = m_World->GetComponent<Components::Brick>(entityBrick);
|
||||
if (brick == NULL)
|
||||
{
|
||||
if (brick == NULL) {
|
||||
return false;
|
||||
}
|
||||
EntityID entityBall = event.Entity2;
|
||||
//EntityID entity1 = event.Entity1;
|
||||
//EntityID entity2 = event.Entity2;
|
||||
|
||||
//auto brick = m_World->GetComponent<Components::Brick>(entity1);
|
||||
//auto ball = m_World->GetComponent<Components::Ball>(entity2);
|
||||
//std::cout << brick << std::endl;
|
||||
//std::cout << ball << std::endl;
|
||||
/*if (brick != NULL)
|
||||
{
|
||||
std::cout << "Entity1 is a brick!" << std::endl;
|
||||
entityBrick = entity1;
|
||||
if (ball != NULL)
|
||||
{
|
||||
std::cout << "Entity2 is a ball!" << std::endl;
|
||||
entityBall = entity2;
|
||||
}
|
||||
m_World->RemoveEntity(entityBrick);
|
||||
|
||||
SetNumberOfBricks(NumberOfBricks() - 1);
|
||||
if (NumberOfBricks() == 0) {
|
||||
Events::ScoreEvent es;
|
||||
es.Score = 500;
|
||||
EventBroker->Publish(es);
|
||||
Events::ResetBall e;
|
||||
EventBroker->Publish(e);
|
||||
CreateBasicLevel(Rows(), Lines(), SpaceBetweenBricks(), SpaceToEdge());
|
||||
}
|
||||
else
|
||||
{
|
||||
brick = m_World->GetComponent<Components::Brick>(entity2);
|
||||
if (brick != NULL)
|
||||
{
|
||||
std::cout << "Entity2 is a brick!" << std::endl;
|
||||
entityBrick = entity2;
|
||||
}
|
||||
Events::ScoreEvent es;
|
||||
es.Score = brick->Score;
|
||||
EventBroker->Publish(es);
|
||||
|
||||
ball = m_World->GetComponent<Components::Ball>(entity1);
|
||||
if (ball != NULL)
|
||||
{
|
||||
std::cout << "Entity1 is a ball!" << std::endl;
|
||||
entityBall = entity1;
|
||||
}
|
||||
}
|
||||
std::cout << "Score: " << Score() << std::endl;
|
||||
|
||||
if (entityBrick != NULL && entityBall != NULL)
|
||||
{*/
|
||||
//std::cout << "We're destroying!" << std::endl;
|
||||
m_World->RemoveEntity(entityBrick);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
//}
|
||||
bool dd::Systems::LevelSystem::LifeLost(const dd::Events::LifeLost &event)
|
||||
{
|
||||
SetLives(Lives() - 1);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::LevelSystem::ScoreEvent(const dd::Events::ScoreEvent &event)
|
||||
{
|
||||
SetScore(Score() += event.Score);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void dd::Systems::LevelSystem::EndLevel()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Core/World.h"
|
||||
#include <iostream>
|
||||
#include <Game/CPad.h>
|
||||
#include <Rendering/CPointLight.h>
|
||||
|
||||
|
||||
void dd::Systems::PadSystem::Initialize()
|
||||
@@ -24,74 +25,118 @@ void dd::Systems::PadSystem::Initialize()
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, PadSystem::OnKeyDown);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, PadSystem::OnKeyUp);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, PadSystem::OnContact);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResetBall, PadSystem::ResetBall);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void dd::Systems::PadSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto ball = m_World->GetComponent<Components::Ball>(entity);
|
||||
if (ball != NULL) {
|
||||
if (ReplaceBall() == true) {
|
||||
SetReplaceBall(false);
|
||||
|
||||
auto transformEntity = m_World->GetComponent<Components::Transform>(entity);
|
||||
transformEntity->Position = glm::vec3(20, 20, -10);
|
||||
|
||||
//Temporary. Create new ball.
|
||||
/*auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||
sprite->SpriteFile = "Textures/Ball.png";
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;*/
|
||||
|
||||
auto ent = m_World->CreateEntity();
|
||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||
auto model = m_World->AddComponent<Components::Model>(ent);
|
||||
model->ModelFile = "Models/Test/Ball/Ballopus.obj";
|
||||
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
|
||||
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
|
||||
m_World->RemoveEntity(entity);
|
||||
m_World->CommitEntity(ent);
|
||||
|
||||
Events::SetImpulse e;
|
||||
e.Entity = ent;
|
||||
e.Impulse = glm::vec2(0.f, -7.f);
|
||||
e.Point = glm::vec2(transform->Position.x, transform->Position.y);
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PadSystem::Update(double dt)
|
||||
{
|
||||
if (ent == 0) {
|
||||
if (Entity() == 0) {
|
||||
for (auto it = m_World->GetEntities()->begin(); it != m_World->GetEntities()->end(); it++) {
|
||||
if (m_World->GetProperty<std::string>(it->first, "Name") == "Pad") {
|
||||
ent = it->first;
|
||||
transform = m_World->GetComponent<Components::Transform>(ent);
|
||||
SetEntity(it->first);
|
||||
SetTransform(m_World->GetComponent<Components::Transform>(Entity()));
|
||||
SetPad(m_World->GetComponent<Components::Pad>(Entity()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (transform->Velocity.x < -400.f)
|
||||
{
|
||||
transform->Velocity.x = -400.f;
|
||||
auto transform = Transform();
|
||||
auto pad = Pad();
|
||||
auto acceleration = Acceleration();
|
||||
|
||||
if (transform->Velocity.x < -pad->MaxSpeed) {
|
||||
transform->Velocity.x = -pad->MaxSpeed;
|
||||
}
|
||||
else if (transform->Velocity.x > 400.f)
|
||||
{
|
||||
transform->Velocity.x = 400.f;
|
||||
else if (transform->Velocity.x > pad->MaxSpeed) {
|
||||
transform->Velocity.x = pad->MaxSpeed;
|
||||
}
|
||||
transform->Position += transform->Velocity * (float)dt;
|
||||
transform->Velocity += acceleration * (float)dt;
|
||||
transform->Velocity -= transform->Velocity * (0.9f * (float)dt);
|
||||
transform->Velocity -= transform->Velocity * pad->SlowdownModifier * (float)dt;
|
||||
|
||||
|
||||
|
||||
if (left)
|
||||
{
|
||||
acceleration.x = -20.f;
|
||||
if (Left()) {
|
||||
acceleration.x = -pad->AccelerationSpeed;
|
||||
}
|
||||
else if (right)
|
||||
{
|
||||
acceleration.x = 20.f;
|
||||
else if (Right()) {
|
||||
acceleration.x = pad->AccelerationSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
acceleration.x = 0.f;
|
||||
}
|
||||
|
||||
SetTransform(transform);
|
||||
SetPad(pad);
|
||||
SetAcceleration(acceleration);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||
{
|
||||
int val = event.KeyCode;
|
||||
if (val == 265)
|
||||
{
|
||||
if (val == GLFW_KEY_UP) {
|
||||
//std::cout << "Up!" << std::endl;
|
||||
}
|
||||
else if (val == 264)
|
||||
{
|
||||
} else if (val == GLFW_KEY_DOWN) {
|
||||
//std::cout << "Down!" << std::endl;
|
||||
}
|
||||
else if (val == 263)
|
||||
{
|
||||
} else if (val == GLFW_KEY_LEFT) {
|
||||
//std::cout << "Left!" << std::endl;
|
||||
//acceleration.x = -0.01f;
|
||||
left = true;
|
||||
}
|
||||
else if (val = 262)
|
||||
{
|
||||
SetLeft(true);
|
||||
} else if (val == GLFW_KEY_RIGHT) {
|
||||
//std::cout << "Right!" << std::endl;
|
||||
//acceleration.x = 0.01f;
|
||||
right = true;
|
||||
SetRight(true);
|
||||
} else if (val == GLFW_KEY_R) {
|
||||
SetReplaceBall(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -99,21 +144,14 @@ bool dd::Systems::PadSystem::OnKeyDown(const dd::Events::KeyDown &event)
|
||||
bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
||||
{
|
||||
int val = event.KeyCode;
|
||||
if (val == 265)
|
||||
{
|
||||
if (val == GLFW_KEY_UP) {
|
||||
|
||||
}
|
||||
else if (val == 264)
|
||||
{
|
||||
} else if (val == GLFW_KEY_DOWN) {
|
||||
|
||||
}
|
||||
else if (val == 263)
|
||||
{
|
||||
left = false;
|
||||
}
|
||||
else if (val = 262)
|
||||
{
|
||||
right = false;
|
||||
} else if (val == GLFW_KEY_LEFT) {
|
||||
SetLeft(false);
|
||||
} else if (val == GLFW_KEY_RIGHT) {
|
||||
SetRight(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -123,27 +161,38 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||
/*
|
||||
EntityID entityBall = event.Entity2;
|
||||
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
||||
if (ball == NULL)
|
||||
{
|
||||
if (ball == NULL) {
|
||||
return false;
|
||||
}
|
||||
EntityID entityPad = event.Entity1;
|
||||
auto pad = m_World->GetComponent<Components::Pad>(entityPad);
|
||||
if (pad == NULL)
|
||||
{
|
||||
if (pad == NULL) {
|
||||
return false;
|
||||
}
|
||||
auto transformBall = m_World->GetComponent<Components::Transform>(entityBall);
|
||||
auto transformPad = m_World->GetComponent<Components::Transform>(entityPad);
|
||||
|
||||
float movementMultiplier = 2.f;
|
||||
float movementMultiplier = 4.f;
|
||||
|
||||
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||
//float movementY = glm::cos((abs(movementX) / (3.2f * movementMultiplier)) * 3.14159265359f / 2) * 2.f;
|
||||
if (whatX > 0) {
|
||||
movementX = movementMultiplier * whatX;
|
||||
//std::cout << "Right!" << std::endl;
|
||||
} else {
|
||||
movementX = movementMultiplier * whatX;
|
||||
//std::cout << "Left!" << std::endl;
|
||||
}
|
||||
|
||||
// std::cout << movementX << " " << movementY << std::endl;
|
||||
|
||||
//float movementX = (event.ContactPoint.x - transformPad->Position.x) * movementMultiplier;
|
||||
float movementY = glm::cos((abs(movementX) / ((1.6f) * movementMultiplier)) * 3.14159265359f / 2) + 1;
|
||||
|
||||
//std::cout << movementX << " " << movementY << std::endl;
|
||||
|
||||
float len = glm::length<float>(transformBall->Velocity);
|
||||
//auto pointlight = m_World->AddComponent<Components::PointLight>(ent);
|
||||
|
||||
transformBall->Velocity += glm::vec3(transformPad->Velocity.x, 0, 0);
|
||||
transformBall->Velocity = glm::normalize(transformBall->Velocity) * len;
|
||||
@@ -153,18 +202,21 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||
*/
|
||||
}
|
||||
|
||||
bool dd::Systems::PadSystem::ResetBall(const dd::Events::ResetBall &event)
|
||||
{
|
||||
SetReplaceBall(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
std::string command = event.Command;
|
||||
|
||||
std::cout << "Command!" << std::endl;
|
||||
|
||||
if (command == "right")
|
||||
{
|
||||
if (command == "right") {
|
||||
std::cout << "Right!" << std::endl;
|
||||
}
|
||||
else if (command == "left")
|
||||
{
|
||||
} else if (command == "left") {
|
||||
std::cout << "Left!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,13 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
b2Body* body = i.second;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (! transformComponent)
|
||||
continue;
|
||||
|
||||
if (body == nullptr) {
|
||||
//LOG_ERROR("This body should not exist");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
|
||||
b2Vec2 position;
|
||||
@@ -66,7 +72,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
body->SetTransform(position, angle);
|
||||
|
||||
|
||||
body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y));
|
||||
|
||||
|
||||
@@ -91,8 +96,14 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
EntityID entity = i.first;
|
||||
b2Body* body = i.second;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (body == nullptr) {
|
||||
//LOG_ERROR("This body should not exist");
|
||||
continue;
|
||||
}
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (! transformComponent)
|
||||
continue;
|
||||
if (m_World->GetEntityParent(entity) == 0) {
|
||||
b2Vec2 position = body->GetPosition();
|
||||
transformComponent->Position.x = position.x;
|
||||
@@ -103,7 +114,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
||||
|
||||
//TODO: Fix this back for real bodies
|
||||
b2Vec2 velocity = body->GetLinearVelocity();
|
||||
transformComponent->Velocity.x = velocity.x;
|
||||
transformComponent->Velocity.y = velocity.y;
|
||||
@@ -131,10 +141,13 @@ void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
{
|
||||
b2Body* body = m_EntitiesToBodies[entity];
|
||||
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
m_BodiesToEntities.erase(body);
|
||||
if (body != nullptr) {
|
||||
m_EntitiesToBodies.erase(entity);
|
||||
m_BodiesToEntities.erase(body);
|
||||
|
||||
m_PhysicsWorld->DestroyBody(body);
|
||||
}
|
||||
|
||||
m_PhysicsWorld->DestroyBody(body);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ include_directories(
|
||||
set(SOURCE_FILES
|
||||
main.cpp
|
||||
FileWatcherTest.cpp
|
||||
EventTest.cpp
|
||||
ComponentCopyTest.cpp
|
||||
EntityCloneTest.cpp
|
||||
)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/World.h"
|
||||
#include "Core/CTemplate.h"
|
||||
using namespace dd;
|
||||
|
||||
struct TestComponent : public Component
|
||||
{
|
||||
int Int = 5;
|
||||
float Float = 1.33333f;
|
||||
double Double = 1.33333;
|
||||
std::string String = "Hello World";
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EntityCloneTest)
|
||||
{
|
||||
// Setup world
|
||||
std::shared_ptr<EventBroker> eventBroker = std::make_shared<EventBroker>();
|
||||
World world(eventBroker);
|
||||
world.ComponentFactory.Register<Components::Template>();
|
||||
world.ComponentFactory.Register<TestComponent>();
|
||||
|
||||
// Create our original entity
|
||||
EntityID entOriginal = world.CreateEntity();
|
||||
world.AddComponent<Components::Template>(entOriginal);
|
||||
world.AddComponent<TestComponent>(entOriginal);
|
||||
|
||||
// Clone it
|
||||
EntityID entClone = world.CloneEntity(entOriginal);
|
||||
|
||||
// Check
|
||||
// EntityID of clone should not be same as original (obviously)
|
||||
BOOST_CHECK(entOriginal != entClone);
|
||||
// Template component SHOULD be in clone
|
||||
auto templateComponentClone = world.GetComponent<Components::Template>(entClone);
|
||||
BOOST_REQUIRE(templateComponentClone != nullptr);
|
||||
// Values should be the same across the clone
|
||||
auto testComponentOriginal = world.GetComponent<TestComponent>(entOriginal);
|
||||
BOOST_REQUIRE(testComponentOriginal != nullptr);
|
||||
auto testComponentClone = world.GetComponent<TestComponent>(entClone);
|
||||
BOOST_REQUIRE(testComponentClone != nullptr);
|
||||
BOOST_CHECK(testComponentClone->Int == testComponentOriginal->Int);
|
||||
BOOST_CHECK(testComponentClone->Float == testComponentOriginal->Float);
|
||||
BOOST_CHECK(testComponentClone->Double == testComponentOriginal->Double);
|
||||
BOOST_CHECK(testComponentClone->String == testComponentOriginal->String);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef EVENTFIXTURE_H
|
||||
#define EVENTFIXTURE_H
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "Core/EventBroker.h"
|
||||
|
||||
template <typename EventType>
|
||||
struct EventFixture
|
||||
{
|
||||
EventFixture()
|
||||
{
|
||||
this->EventBroker = new dd::EventBroker();
|
||||
m_EEventType = decltype(m_EEventType)(std::bind(&OnEvent, this, std::placeholders::_1));
|
||||
this->EventBroker->Subscribe(m_EEventType);
|
||||
Run();
|
||||
Check();
|
||||
}
|
||||
~EventFixture()
|
||||
{
|
||||
this->EventBroker->Unsubscribe(m_EEventType);
|
||||
delete this->EventBroker;
|
||||
}
|
||||
|
||||
dd::EventBroker* EventBroker = nullptr;
|
||||
dd::EventRelay<EventFixture, EventType> m_EEventType;
|
||||
bool m_EventRecieved = false;
|
||||
EventType Before;
|
||||
EventType After;
|
||||
|
||||
bool OnEvent(const EventType& event)
|
||||
{
|
||||
m_EventRecieved = true;
|
||||
After = event;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Run()
|
||||
{
|
||||
// Publish the event
|
||||
this->EventBroker->Publish(Before);
|
||||
// Clear to swap buffers
|
||||
this->EventBroker->Clear();
|
||||
// Process the event
|
||||
this->EventBroker->template Process<EventFixture>();
|
||||
}
|
||||
|
||||
void Check()
|
||||
{
|
||||
BOOST_CHECK(m_EventRecieved);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "EventFixture.h"
|
||||
|
||||
using namespace dd;
|
||||
|
||||
struct ETestEvent : public Event
|
||||
{
|
||||
int Int = 5;
|
||||
float Float = 1.33333f;
|
||||
double Double = 1.33333;
|
||||
std::string String = "Hello World";
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(EventBrokerTest)
|
||||
{
|
||||
EventFixture<ETestEvent> f;
|
||||
BOOST_CHECK(f.Before.Int == f.After.Int);
|
||||
BOOST_CHECK_CLOSE(f.Before.Float, f.After.Float, 0.00001f);
|
||||
BOOST_CHECK_CLOSE(f.Before.Double, f.After.Double, 0.00001f);
|
||||
BOOST_CHECK(f.Before.String == f.After.String);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef FILENAME_H__
|
||||
#define FILENAME_H__
|
||||
#ifndef NAMESPACE_FILENAME_H__
|
||||
#define NAMESPACE_FILENAME_H__
|
||||
|
||||
namespace dd
|
||||
{
|
||||
@@ -62,8 +62,7 @@ private:
|
||||
// Private member function
|
||||
bool privateMemberFunction()
|
||||
{
|
||||
switch (m_PrivateMember1)
|
||||
{
|
||||
switch (m_PrivateMember1) {
|
||||
case 1:
|
||||
m_PrivateMember2 = new ClassName(2);
|
||||
break;
|
||||
|
||||