diff --git a/assets b/assets index 3c4d811..75977fd 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 3c4d81137f4f3f185080597045ec93e7ab1d6ae9 +Subproject commit 75977fd865557478a72053a93f08f10851838730 diff --git a/src/Components/Physics.h b/src/Components/Physics.h index a99cd79..e2947ab 100644 --- a/src/Components/Physics.h +++ b/src/Components/Physics.h @@ -16,13 +16,38 @@ struct Physics : Component EXPLOSION = 4, }; + enum class MotionTypeEnum + { + Dynamic, + Fixed, + Keyframed + }; + Physics() - : Mass(1.f), Static(false), Phantom(false), CalculateCenterOfMass(true), CenterOfMass(glm::vec3(0)), InitialLinearVelocity(glm::vec3(0)), InitialAngularVelocity(glm::vec3(0)), - LinearDamping(0.f), AngularDamping(0.05f), GravityFactor(1.f), Friction(0.5f), Restitution(0.4f), MaxLinearVelocity(200.f), MaxAngularVelocity(200.f), - CollisionLayer(0), CollisionSystemGroup(0), CollisionSubSystemId(0), CollisionSubSystemDontCollideWith(0), CollisionEvent(false){} + : Mass(1.f) + //, Static(false) + , MotionType(MotionTypeEnum::Fixed) + , Phantom(false) + , CalculateCenterOfMass(true) + , CenterOfMass(glm::vec3(0)) + , InitialLinearVelocity(glm::vec3(0)) + , InitialAngularVelocity(glm::vec3(0)) + , LinearDamping(0.f) + , AngularDamping(0.05f) + , GravityFactor(1.f) + , Friction(0.5f) + , Restitution(0.4f) + , MaxLinearVelocity(200.f) + , MaxAngularVelocity(200.f) + , CollisionLayer(0) + , CollisionSystemGroup(0) + , CollisionSubSystemId(0) + , CollisionSubSystemDontCollideWith(0) + , CollisionEvent(false) + { } float Mass; - bool Static; + MotionTypeEnum MotionType; bool Phantom; bool CalculateCenterOfMass; diff --git a/src/Components/Wall.h b/src/Components/Wall.h new file mode 100644 index 0000000..95ee2d7 --- /dev/null +++ b/src/Components/Wall.h @@ -0,0 +1,20 @@ +#ifndef Components_Wall_h__ +#define Components_Wall_h__ + +#include "Component.h" +#include +#include + +namespace Components +{ + + struct Wall : Component + { + std::vector Walldebris; + + virtual Wall* Clone() const override { return new Wall(*this); } + }; + +} + +#endif // Components_TankShell_h__ diff --git a/src/Events/OnDead.h b/src/Events/OnDead.h new file mode 100644 index 0000000..0149ac1 --- /dev/null +++ b/src/Events/OnDead.h @@ -0,0 +1,16 @@ +#ifndef Events_OnDead_h__ +#define Events_OnDead_h__ +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + struct OnDead : Event + { + EntityID Entity; + }; +} + + + +#endif // Events_OnDead_h__ \ No newline at end of file diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index fb3329c..2708b2e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -91,45 +91,520 @@ void GameWorld::Initialize() EventBroker->Publish(e); } + { + auto road_base = CreateEntity(); + auto transform = AddComponent(road_base); + transform->Position = glm::vec3(0, -50, 0); + auto model = AddComponent(road_base); + model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + auto physics = AddComponent(road_base); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(road_base); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + + + CommitEntity(groundshape); + CommitEntity(road_base); + } + { - auto ground = CreateEntity(); - auto transform = AddComponent(ground); + auto road_middle = CreateEntity(); + auto transform = AddComponent(road_middle); transform->Position = glm::vec3(0, -50, 0); - //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); - transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(ground); - model->ModelFile = "Models/TestScene3/testScene2.obj"; - //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; - - auto physics = AddComponent(ground); + auto model = AddComponent(road_middle); + model->ModelFile = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj"; + auto physics = AddComponent(road_middle); physics->Mass = 10; - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; - auto groundshape = CreateEntity(ground); + auto groundshape = CreateEntity(road_middle); auto transformshape = AddComponent(groundshape); auto meshShape = AddComponent(groundshape); - //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; - meshShape->ResourceName = "Models/TestScene3/testScene2.obj"; + meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj"; CommitEntity(groundshape); - CommitEntity(ground); + CommitEntity(road_middle); } + { + auto road_small = CreateEntity(); + auto transform = AddComponent(road_small); + transform->Position = glm::vec3(0, -50, 0); + auto model = AddComponent(road_small); + model->ModelFile = "Models/TerrainFiveIstles/Roads/SmallRoad.obj"; + auto physics = AddComponent(road_small); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(road_small); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/SmallRoad.obj"; + + + CommitEntity(groundshape); + CommitEntity(road_small); + } + + + { + auto water = CreateEntity(); + auto transform = AddComponent(water); + transform->Position = glm::vec3(0, -35, 0); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + transform->Scale = glm::vec3(5000.f, 10.f, 5000.f); + auto model = AddComponent(water); + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; + auto blendmap = AddComponent(water); + blendmap->TextureRed = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureGreen = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureBlue = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureRepeats = 1.f; + + auto physics = AddComponent(water); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + { + + auto groundshape = CreateEntity(water); + auto box = AddComponent(groundshape); + box->Depth = 250.f; + box->Height = 5.f; + box->Width = 250.f; + + + CommitEntity(groundshape); + } + CommitEntity(water); + } + + { + auto ground_middle = CreateEntity(); + auto transform = AddComponent(ground_middle); + transform->Position = glm::vec3(0, -50, 0); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(ground_middle); + model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; + auto blendmap = AddComponent(ground_middle); + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 30.f; + + auto physics = AddComponent(ground_middle); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(ground_middle); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Middle.obj"; + + + CommitEntity(groundshape); + CommitEntity(ground_middle); + } + + { + auto ground_small = CreateEntity(); + auto transform = AddComponent(ground_small); + transform->Position = glm::vec3(0, -50, 0); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(ground_small); + model->ModelFile = "Models/TerrainFiveIstles/Small.obj"; + auto blendmap = AddComponent(ground_small); + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 30.f; + + auto physics = AddComponent(ground_small); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(ground_small); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Small.obj"; + + + CommitEntity(groundshape); + CommitEntity(ground_small); + } + + { + auto ground_small_mirrored = CreateEntity(); + auto transform = AddComponent(ground_small_mirrored); + transform->Position = glm::vec3(0, -50, 0); + transform->Orientation = glm::angleAxis(glm::radians(180.f), glm::vec3(0, 1, 0)); + auto model = AddComponent(ground_small_mirrored); + model->ModelFile = "Models/TerrainFiveIstles/Small.obj"; + auto blendmap = AddComponent(ground_small_mirrored); + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 30.f; + + auto physics = AddComponent(ground_small_mirrored); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(ground_small_mirrored); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Small.obj"; + + + CommitEntity(groundshape); + CommitEntity(ground_small_mirrored); + } + + { + auto ground_base = CreateEntity(); + auto transform = AddComponent(ground_base); + transform->Position = glm::vec3(0, -50, 0); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(ground_base); + model->ModelFile = "Models/TerrainFiveIstles/Base.obj"; + auto blendmap = AddComponent(ground_base); + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 30.f; + + auto physics = AddComponent(ground_base); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(ground_base); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Base.obj"; + + + CommitEntity(groundshape); + CommitEntity(ground_base); + } + + { + auto ground_base_mirrored = CreateEntity(); + auto transform = AddComponent(ground_base_mirrored); + transform->Position = glm::vec3(0, -50, 0); + transform->Orientation = glm::angleAxis(glm::radians(180.f), glm::vec3(0, 1, 0)); + auto model = AddComponent(ground_base_mirrored); + model->ModelFile = "Models/TerrainFiveIstles/Base.obj"; + auto blendmap = AddComponent(ground_base_mirrored); + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 30.f; + + auto physics = AddComponent(ground_base_mirrored); + physics->Mass = 10; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(ground_base_mirrored); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Base.obj"; + + + CommitEntity(groundshape); + CommitEntity(ground_base_mirrored); + } + + { + auto tree = CreateEntity(); + auto transform = AddComponent(tree); + transform->Position = glm::vec3(0, -10, 0); + + auto physics = AddComponent(tree); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionEvent = false; + //physics->LinearDamping = 3.f; + physics->CalculateCenterOfMass = true; + + { + auto stem = CreateEntity(tree); + auto transform = AddComponent(stem); + transform->Position = glm::vec3(0, -2.40906f, 0); + auto model = AddComponent(stem); + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + } + + { + auto leafs = CreateEntity(tree); + auto transform = AddComponent(leafs); + transform->Position = glm::vec3(0, -2.45511f, 0); + auto model = AddComponent(leafs); + model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; + model->Transparent = true; + CommitEntity(leafs); + } + + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 0.f); + auto mesh = AddComponent(shape); + mesh->ResourceName = "Models/Tree/Collision/Collision.obj"; + + CommitEntity(shape); + } + + + /*{ + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto box = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0, 0.f); + box->Width = 0.296f; + box->Height = 2.511f; + box->Depth = 0.296f; + + CommitEntity(shape); + } + + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto sphere = AddComponent(shape); + transform->Position = glm::vec3(0, 2.04506f, 0.f); + sphere->Radius = 1.389f; + + CommitEntity(shape); + }*/ + + CommitEntity(tree); + } + +#pragma region Wall_Debris_Template + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(3.43f, 2.287f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris1.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris1.obj"; + + m_WallDebrisTemplates.push_back(debri); + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-3.744f, 1.508f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-3.592f, 4.664f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(-2.535f, 2.879f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris3.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris3.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.333f, 3.618f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris4.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris4.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(2.586f, 4.333f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris5.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris5.obj"; + + m_WallDebrisTemplates.push_back(debri); + + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.537f, 1.344f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris6.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris6.obj"; + + m_WallDebrisTemplates.push_back(debri); + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.f, 0.f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Wall/WallDestroyed/WallDestroyed.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->Mass = 200.f; + physics->Restitution = .004f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; //Lägg in ny collision modell + + m_WallDebrisTemplates.push_back(debri); + } +#pragma endregion Region for wall debris + +#pragma region Wall_Regin + + for(int i = 10; i < 0; i++) + { + EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); + } + +#pragma endregion Region for all wall creations + /*EntityID tank1 = CreateTank(1); { - auto transform = GetComponent(tank1); - transform->Position.z = -125.f; - transform->Position.y = -20.f; - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - Events::SetViewportCamera e; - e.CameraEntity = GetProperty(tank1, "Camera"); - e.ViewportFrame = "Viewport1"; - EventBroker->Publish(e); - }*/ + auto transform = GetComponent(tank1); + transform->Position.z = 50; - /*EntityID tank2 = CreateTank(2); + Events::SetViewportCamera e; + e.CameraEntity = GetProperty(tank1, "Camera"); + e.ViewportFrame = "Viewport1"; + EventBroker->Publish(e); + } + + EntityID tank2 = CreateTank(2); { auto transform = GetComponent(tank2); transform->Position.x = 10.f; @@ -141,6 +616,8 @@ void GameWorld::Initialize() EventBroker->Publish(e); }*/ + CreateGarage(glm::vec3(-3.93076, -49, 0), 1); + { auto flag = CreateEntity(); auto transform = AddComponent(flag); @@ -173,178 +650,6 @@ void GameWorld::Initialize() CommitEntity(flag); } - CreateGate(glm::vec3(0, -50, 150)); - glm::vec3 Position = glm::vec3(-3.93076, -49, 0); - { - auto garage = CreateEntity(); - auto transform = AddComponent(garage); - transform->Position = Position; - auto player = AddComponent(garage); - player->ID = 1; - - - - auto ElevatorBase = CreateEntity(garage); - { - auto transform = AddComponent(ElevatorBase); - auto model = AddComponent(ElevatorBase); - model->ModelFile = "Models/SpawnRamp/Main/Main.obj"; - auto physics = AddComponent(ElevatorBase); - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - - { - auto mainShape = CreateEntity(ElevatorBase); - auto transform = AddComponent(mainShape); - transform->Position = glm::vec3(0.f, 0, 0.f); - auto mesh = AddComponent(mainShape); - mesh->ResourceName = "Models/SpawnRamp/Main/CollisionShape.obj"; - CommitEntity(mainShape); - } - { - auto StairsShape = CreateEntity(ElevatorBase); - auto transform = AddComponent(StairsShape); - transform->Position = glm::vec3(-7.48639f, 0.4809f, 3.79166f); - auto box = AddComponent(StairsShape); - box->Width = 1.211f; - box->Height = 1.798f; - box->Depth = 3.229f; - CommitEntity(StairsShape); - } - } - CommitEntity(ElevatorBase); - - auto leftHatch = CreateEntity(garage); - { - auto transform = AddComponent(leftHatch); - transform->Position = glm::vec3(5.83103f, 1.3553f, -2.40268f); - auto model = AddComponent(leftHatch); - model->ModelFile = "Models/SpawnRamp/LeftHatch/LeftHatch.obj"; - auto physics = AddComponent(leftHatch); - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - auto rotate = AddComponent(leftHatch); - rotate->StartRotation = transform->Orientation; - rotate->GoalRotation = transform->Orientation * glm::angleAxis(-glm::radians(110.f),glm::vec3(0, 0, 1)); - rotate->Time = 5.f; - { - auto shape = CreateEntity(leftHatch); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(-2.79331, 0, 0); - auto box = AddComponent(shape); - box->Width = 2.317f; - box->Height = 0.183f; - box->Depth = 6.987f; - CommitEntity(shape); - } - CommitEntity(leftHatch); - } - - auto rightHatch = CreateEntity(garage); - { - auto transform = AddComponent(rightHatch); - transform->Position = glm::vec3(-4.52423f, 1.3553f, -2.40268f); - auto model = AddComponent(rightHatch); - model->ModelFile = "Models/SpawnRamp/RightHatch/RightHatch.obj"; - auto physics = AddComponent(rightHatch); - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - auto rotate = AddComponent(rightHatch); - rotate->StartRotation = transform->Orientation; - rotate->GoalRotation = transform->Orientation * glm::angleAxis(glm::radians(110.f),glm::vec3(0, 0, 1)); - rotate->Time = 5.f; - { - auto shape = CreateEntity(rightHatch); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(2.79331, 0, 0); - auto box = AddComponent(shape); - box->Width = 2.317f; - box->Height = 0.183f; - box->Depth = 6.987f; - CommitEntity(shape); - } - CommitEntity(rightHatch); - } - - auto elevator = CreateEntity(garage); - { - auto transform = AddComponent(elevator); - transform->Position = glm::vec3(0.69385f, 1.25222f, -2.39938f) + glm::vec3(0, -9.5f, 0); - auto model = AddComponent(elevator); - model->ModelFile = "Models/SpawnRamp/Elevator/Elevator.obj"; - auto physics = AddComponent(elevator); - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - auto move = AddComponent(elevator); - move->StartPosition = transform->Position; - move->GoalPosition = transform->Position + glm::vec3(0, 9.5f, 0); - move->Speed = 1.5f; - { - auto shape = CreateEntity(elevator); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(0, 0, 0); - auto box = AddComponent(shape); - box->Width = 4.754f; - box->Height = 0.141f; - box->Depth = 6.86f; - CommitEntity(shape); - } - - auto spawnPoint = CreateEntity(elevator); - { - auto transform = AddComponent(spawnPoint); - transform->Position.y = 1.f; - auto spawnPointComponent = AddComponent(spawnPoint); - } - CommitEntity(spawnPoint); - } - CommitEntity(elevator); - - auto garageComponent = AddComponent(garage); - garageComponent->DoorLeft = leftHatch; - garageComponent->DoorRight = rightHatch; - garageComponent->Elevator = elevator; - CommitEntity(garage); - - { - auto trigger = CreateEntity(garage); - SetProperty(trigger, "Name", "BoundsTrigger"); - auto transform = AddComponent(trigger); - transform->Position = glm::vec3(0, 44.87521f, 0); - auto triggerComponent = AddComponent(trigger); - { - auto shape = CreateEntity(trigger); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(0, 0, 0); - auto box = AddComponent(shape); - box->Width = 72.98f; - box->Height = 54.53f; - box->Depth = 72.98f; - CommitEntity(shape); - } - CommitEntity(trigger); - } - - { - auto trigger = CreateEntity(garage); - SetProperty(trigger, "Name", "ElevatorShaftTrigger"); - auto transform = AddComponent(trigger); - transform->Position = glm::vec3(0.69385f, -6.7997f, -2.0f); - auto triggerComponent = AddComponent(trigger); - { - auto shape = CreateEntity(trigger); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(0, 0, 0); - auto box = AddComponent(shape); - box->Width = 2.0f; - box->Height = 12.f; - box->Depth = 2.0f; - CommitEntity(shape); - } - CommitEntity(trigger); - } - } - //for (int i = 0; i < 500; i++) //{ // auto Light = CreateEntity(); @@ -359,6 +664,71 @@ void GameWorld::Initialize() // //auto model = AddComponent(Light, "Model"); // //model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; //} + + + { + auto gateBase = CreateEntity(); + auto transform = AddComponent(gateBase); + transform->Position = glm::vec3(0, -50, 150); + auto model = AddComponent(gateBase); + model->ModelFile = "Models/Gate/Lift/Lift.obj"; + + auto physics = AddComponent(gateBase); + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + physics->CollisionLayer = 1; // Terrain-Layer + { + auto leftBaseShape = CreateEntity(gateBase); + auto transform = AddComponent(leftBaseShape); + transform->Position = glm::vec3(8.5f, 3, 0); + auto box = AddComponent(leftBaseShape); + box->Width = 3.f/2; + box->Height = 6.094f/2; + box->Depth = 4.f/2; + CommitEntity(leftBaseShape); + } + { + auto RightBaseShape = CreateEntity(gateBase); + auto transform = AddComponent(RightBaseShape); + transform->Position = glm::vec3(-8.5f, 3, 0); + auto box = AddComponent(RightBaseShape); + box->Width = 3.f/2; + box->Height = 6.094f/2; + box->Depth = 4.f/2; + CommitEntity(RightBaseShape); + } + { + auto LeftTopShape = CreateEntity(gateBase); + auto transform = AddComponent(LeftTopShape); + transform->Position = glm::vec3(7.5485f, 9.385f, 0); + auto box = AddComponent(LeftTopShape); + box->Width = 1.747f/2; + box->Height = 6.851f/2; + box->Depth = 1.767f/2; + CommitEntity(LeftTopShape); + } + { + auto RightTopShape = CreateEntity(gateBase); + auto transform = AddComponent(RightTopShape); + transform->Position = glm::vec3(-7.5485f, 9.385f, 0); + auto box = AddComponent(RightTopShape); + box->Width = 1.747f/2; + box->Height = 6.851f/2; + box->Depth = 1.767f/2; + CommitEntity(RightTopShape); + } + { + auto RampShape = CreateEntity(gateBase); + auto transform = AddComponent(RampShape); + transform->Position = glm::vec3(0, 0.24f, 0); + auto box = AddComponent(RampShape); + box->Width = 14.9f/2; + box->Height = 0.38f/2; + box->Depth = 1.484f/2; + CommitEntity(RampShape); + } + CommitEntity(gateBase); + } + } void GameWorld::Update(double dt) @@ -395,6 +765,7 @@ void GameWorld::RegisterSystems() m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::FollowSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::GarageSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::WallSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); } @@ -417,6 +788,7 @@ void GameWorld::AddSystems() AddSystem(); AddSystem(); AddSystem(); + AddSystem(); AddSystem(); } @@ -465,7 +837,7 @@ void GameWorld::CreateGate(glm::vec3 Position) auto model = AddComponent(gateBase); model->ModelFile = "Models/Gate/Lift/Lift.obj"; auto physics = AddComponent(gateBase); - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; { @@ -498,6 +870,7 @@ void GameWorld::CreateGate(glm::vec3 Position) box->Depth = 1.767f/2; CommitEntity(LeftTopShape); } + { auto RightTopShape = CreateEntity(gateBase); auto transform = AddComponent(RightTopShape); @@ -526,7 +899,7 @@ void GameWorld::CreateGate(glm::vec3 Position) auto model = AddComponent(gate); model->ModelFile = "Models/Gate/Gate/Gate.obj"; auto physics = AddComponent(gate); - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; auto move = AddComponent(gate); move->Speed = 5.f; @@ -579,6 +952,38 @@ void GameWorld::CreateGate(glm::vec3 Position) } } +EntityID GameWorld::CreateWall(glm::vec3 pos, glm::quat orientation) +{ + auto wall = CreateEntity(); + auto transform = AddComponent(wall); + transform->Position = pos; + transform->Orientation = orientation; + + auto physics = AddComponent(wall); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto walldebris = AddComponent(wall); + walldebris->Walldebris = m_WallDebrisTemplates; + + auto model = AddComponent(wall); + model->ModelFile = "Models/Wall/WallWhole/Wall.obj"; + + auto health = AddComponent(wall); + health->Amount = 50.f; + + auto shape = CreateEntity(wall); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallCollision/Collision.obj"; + + CommitEntity(shape); + CommitEntity(wall); + + return wall; + +} + EntityID GameWorld::CreateJeep(int playerID) { auto jeep = CreateEntity(); @@ -587,7 +992,7 @@ EntityID GameWorld::CreateJeep(int playerID) transform->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(0, 1, 0)); auto physics = AddComponent(jeep); physics->Mass = 1800; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; auto vehicle = AddComponent(jeep); vehicle->DownshiftRPM = 3500.f; vehicle->UpshiftRPM = 6000.f; @@ -698,3 +1103,174 @@ EntityID GameWorld::CreateJeep(int playerID) return jeep; } + +EntityID GameWorld::CreateGarage(glm::vec3 Position, int playerID) +{ + auto garage = CreateEntity(); + auto transform = AddComponent(garage); + transform->Position = Position; + auto player = AddComponent(garage); + player->ID = playerID; + + auto ElevatorBase = CreateEntity(garage); + { + auto transform = AddComponent(ElevatorBase); + auto model = AddComponent(ElevatorBase); + model->ModelFile = "Models/SpawnRamp/Main/Main.obj"; + auto physics = AddComponent(ElevatorBase); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + + { + auto mainShape = CreateEntity(ElevatorBase); + auto transform = AddComponent(mainShape); + transform->Position = glm::vec3(0.f, 0, 0.f); + auto mesh = AddComponent(mainShape); + mesh->ResourceName = "Models/SpawnRamp/Main/CollisionShape.obj"; + CommitEntity(mainShape); + } + { + auto StairsShape = CreateEntity(ElevatorBase); + auto transform = AddComponent(StairsShape); + transform->Position = glm::vec3(-7.48639f, 0.4809f, 3.79166f); + auto box = AddComponent(StairsShape); + box->Width = 1.211f; + box->Height = 1.798f; + box->Depth = 3.229f; + CommitEntity(StairsShape); + } + } + CommitEntity(ElevatorBase); + + auto leftHatch = CreateEntity(garage); + { + auto transform = AddComponent(leftHatch); + transform->Position = glm::vec3(5.83103f, 1.3553f, -2.40268f); + auto model = AddComponent(leftHatch); + model->ModelFile = "Models/SpawnRamp/LeftHatch/LeftHatch.obj"; + auto physics = AddComponent(leftHatch); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto rotate = AddComponent(leftHatch); + rotate->StartRotation = transform->Orientation; + rotate->GoalRotation = transform->Orientation * glm::angleAxis(-glm::radians(110.f), glm::vec3(0, 0, 1)); + rotate->Time = 5.f; + { + auto shape = CreateEntity(leftHatch); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(-2.79331, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.317f; + box->Height = 0.183f; + box->Depth = 6.987f; + CommitEntity(shape); + } + CommitEntity(leftHatch); + } + + auto rightHatch = CreateEntity(garage); + { + auto transform = AddComponent(rightHatch); + transform->Position = glm::vec3(-4.52423f, 1.3553f, -2.40268f); + auto model = AddComponent(rightHatch); + model->ModelFile = "Models/SpawnRamp/RightHatch/RightHatch.obj"; + auto physics = AddComponent(rightHatch); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto rotate = AddComponent(rightHatch); + rotate->StartRotation = transform->Orientation; + rotate->GoalRotation = transform->Orientation * glm::angleAxis(glm::radians(110.f), glm::vec3(0, 0, 1)); + rotate->Time = 5.f; + { + auto shape = CreateEntity(rightHatch); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(2.79331, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.317f; + box->Height = 0.183f; + box->Depth = 6.987f; + CommitEntity(shape); + } + CommitEntity(rightHatch); + } + + auto elevator = CreateEntity(garage); + { + auto transform = AddComponent(elevator); + transform->Position = glm::vec3(0.69385f, 1.25222f, -2.39938f) + glm::vec3(0, -9.5f, 0); + auto model = AddComponent(elevator); + model->ModelFile = "Models/SpawnRamp/Elevator/Elevator.obj"; + auto physics = AddComponent(elevator); + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + auto move = AddComponent(elevator); + move->StartPosition = transform->Position; + move->GoalPosition = transform->Position + glm::vec3(0, 9.5f, 0); + move->Speed = 1.5f; + { + auto shape = CreateEntity(elevator); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 4.754f; + box->Height = 0.141f; + box->Depth = 6.86f; + CommitEntity(shape); + } + + auto spawnPoint = CreateEntity(elevator); + { + auto transform = AddComponent(spawnPoint); + transform->Position.y = 1.f; + auto spawnPointComponent = AddComponent(spawnPoint); + } + CommitEntity(spawnPoint); + } + CommitEntity(elevator); + + auto garageComponent = AddComponent(garage); + garageComponent->DoorLeft = leftHatch; + garageComponent->DoorRight = rightHatch; + garageComponent->Elevator = elevator; + CommitEntity(garage); + + { + auto trigger = CreateEntity(garage); + SetProperty(trigger, "Name", "BoundsTrigger"); + auto transform = AddComponent(trigger); + transform->Position = glm::vec3(0, 44.87521f, 0); + auto triggerComponent = AddComponent(trigger); + { + auto shape = CreateEntity(trigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 72.98f; + box->Height = 54.53f; + box->Depth = 72.98f; + CommitEntity(shape); + } + CommitEntity(trigger); + } + + { + auto trigger = CreateEntity(garage); + SetProperty(trigger, "Name", "ElevatorShaftTrigger"); + auto transform = AddComponent(trigger); + transform->Position = glm::vec3(0.69385f, -6.7997f, -2.0f); + auto triggerComponent = AddComponent(trigger); + { + auto shape = CreateEntity(trigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0, 0, 0); + auto box = AddComponent(shape); + box->Width = 2.0f; + box->Height = 12.f; + box->Depth = 2.0f; + CommitEntity(shape); + } + CommitEntity(trigger); + } + + return garage; +} \ No newline at end of file diff --git a/src/GameWorld.h b/src/GameWorld.h index 1ca7de7..52bdb91 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -22,6 +22,7 @@ #include "Systems/DamageSystem.h" #include "Systems/WheelPairSystem.h" #include "Systems/FollowSystem.h" +#include "Systems/WallSystem.h" #include "Systems/GarageSystem.h" #include "Components/Camera.h" @@ -77,10 +78,12 @@ private: void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value); void BindGamepadButton(Gamepad::Button button, std::string command, float value); - EntityID CreateTank(int playerID); void CreateGate(glm::vec3 Position); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); EntityID CreateJeep(int playerID); + EntityID CreateWall(glm::vec3 pos, glm::quat orientation); + EntityID CreateGarage(glm::vec3 Position, int playerID); + std::vector m_WallDebrisTemplates; }; #endif // GameWorld_h__ diff --git a/src/Model.cpp b/src/Model.cpp index dd5757c..1186671 100755 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -93,7 +93,7 @@ Model::Model(std::shared_ptr rm, OBJ &obj) if (Vertices.size() > 0) { CreateTangents(); - getSimilarVertexIndex(); + //getSimilarVertexIndex(); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); } else diff --git a/src/Renderer.cpp b/src/Renderer.cpp index ff01e67..480e3dd 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -377,9 +377,9 @@ void Renderer::DrawWorld(RenderQueuePair &rq) for(auto job : rq.Forward) { glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); - glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + glm::mat4 cameraMatrix = m_Camera->ViewMatrix(); - glm::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); + glm::vec3 spritePos = glm::vec3((cameraMatrix * job->ModelMatrix) * glm::vec4(1, 1, 1, 1)); job->Depth = spritePos.z; } rq.Forward.Jobs.sort(Renderer::DepthSort); @@ -389,7 +389,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) /* Base pass */ - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); //glViewport(0, 0, m_Width, m_Height); @@ -475,10 +475,10 @@ void Renderer::ForwardRendering(RenderQueue &rq) glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); // Clear G-buffer - GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE , GL_NONE }; glDrawBuffers(4, attachments); - glClearColor(0.f, 0.f, 0.f, 0.f); - glClear(GL_COLOR_BUFFER_BIT); + //glClearColor(0.f, 0.f, 0.f, 1.f); + //glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -512,23 +512,21 @@ void Renderer::ForwardRendering(RenderQueue &rq) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); - if (modelJob->NormalTexture != 0) + /*if (modelJob->NormalTexture != 0) { - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); } if (modelJob->SpecularTexture) { - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); - } + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); + }*/ glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); continue; } - - auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { @@ -559,9 +557,9 @@ void Renderer::ForwardRendering(RenderQueue &rq) glViewport(0, 0, m_Width, m_Height); glScissor(0, 0, m_Width, m_Height); + glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_BLEND); m_FinalForwardPassProgram.Bind(); //ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle(); @@ -947,7 +945,7 @@ void Renderer::FrameBufferTextures() //Generate and bind diffuse texture glGenTextures(1, &m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); diff --git a/src/Renderer.h b/src/Renderer.h index 7a1c214..2efdb57 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -219,7 +219,7 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth > j->Depth); } + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } GLuint CreateQuad(); void DrawDebugShadowMap(); diff --git a/src/Systems/DamageSystem.cpp b/src/Systems/DamageSystem.cpp index 55117dd..f894fd2 100644 --- a/src/Systems/DamageSystem.cpp +++ b/src/Systems/DamageSystem.cpp @@ -1,7 +1,6 @@ #include "PrecompiledHeader.h" #include "DamageSystem.h" #include "World.h" - void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf ) { cf->Register([]() { return new Components::Health(); }); @@ -15,8 +14,16 @@ void Systems::DamageSystem::Initialize() bool Systems::DamageSystem::OnDamage( const Events::Damage &event ) { + if(!m_World->ValidEntity(event.Entity)) + return false; auto health = m_World->GetComponent(event.Entity); health->Amount -= event.Amount; + if(health->Amount <= 0) + { + Events::OnDead e; + e.Entity = event.Entity; + EventBroker->Publish(e); + } LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount); return true; } \ No newline at end of file diff --git a/src/Systems/DamageSystem.h b/src/Systems/DamageSystem.h index 5b81f17..a77a600 100644 --- a/src/Systems/DamageSystem.h +++ b/src/Systems/DamageSystem.h @@ -5,6 +5,7 @@ #include "System.h" #include "Components/Health.h" #include "Events/Damage.h" +#include "Events/OnDead.h" namespace Systems { diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index d147dcd..d696b78 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -80,7 +80,7 @@ void Systems::PhysicsSystem::Initialize() worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // You must specify the size of the broad phase - objects should not be simulated outside this region - worldInfo.setBroadPhaseWorldSize(1500.0f); + worldInfo.setBroadPhaseWorldSize(500.0f); m_PhysicsWorld = new hkpWorld(worldInfo); // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks @@ -151,6 +151,10 @@ void Systems::PhysicsSystem::Update(double dt) EntityID entity = pair.first; EntityID parent = pair.second; + auto templateComponent = m_World->GetComponent(entity); + if(templateComponent) + continue; + if (m_RigidBodies.find(entity) == m_RigidBodies.end()) continue; @@ -218,6 +222,10 @@ void Systems::PhysicsSystem::Update(double dt) void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) { + auto templateComponent = m_World->GetComponent(entity); + if(templateComponent) + return; + auto transformComponent = m_World->GetComponent(entity); if (!transformComponent) return; @@ -297,14 +305,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) auto physicsComponent = m_World->GetComponent(entity); if (physicsComponent && m_Shapes[entity].size() > 0) { - if(entityParent != 0 && !physicsComponent->Static) + if(entityParent != 0 && physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic) { LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity); return; } hkpShape* shape; - if(! physicsComponent->Static) // Not static + if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic) { hkArray shapeArray; for (auto &shapeData : m_Shapes[entity]) @@ -368,6 +376,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; if(physicsComponent->CalculateCenterOfMass) physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass); + rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass); rigidBodyInfo.m_mass = massProperties.m_mass; rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity); @@ -381,7 +390,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true;; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -438,7 +447,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBody->removeReference(); } } - else // Static + else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed || physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed) { // Create the hkpStaticCompoundShape and add the instances. // "meshShape" should not be modified by the user in any way after adding it as an instance. @@ -490,7 +499,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) hkpRigidBodyCinfo rigidBodyInfo; { rigidBodyInfo.m_shape = shape; - rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED; + if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed) + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; + } + else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed) + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED; + } + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); @@ -513,7 +530,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -752,6 +769,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) { m_PhysicsWorld->markForWrite(); + m_RigidBodies[event.Entity]->activate(); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); auto transformComponent = m_World->GetComponent(event.Entity); transformComponent->Velocity = event.Velocity; @@ -795,7 +813,6 @@ void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string typ m_RigidBodies.erase(entity); m_PhysicsWorld->unmarkForWrite(); } - } diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index b142973..8c475e6 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -139,6 +139,9 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) return false; } + if(m_World->GetComponent(shellEntity)) + return false; + auto physicsComponents = m_World->GetComponentsOfType(); auto shellTransform = m_World->GetComponent(shellEntity); //auto otherTransform = m_World->GetComponent(otherEntity); @@ -205,8 +208,6 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) EventBroker->Publish(d); } - - m_World->RemoveEntity(shellEntity); } } @@ -329,7 +330,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); auto physics = m_World->AddComponent(tank); physics->Mass = 63000 - 16000; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; auto vehicle = m_World->AddComponent(tank); vehicle->MaxTorque = 8000.f; vehicle->MaxSteeringAngle = 90.f; @@ -397,7 +398,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) m_World->AddComponent(shot); auto physics = m_World->AddComponent(shot); physics->Mass = 25.f; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; physics->CollisionEvent = true; auto modelComponent = m_World->AddComponent(shot); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; diff --git a/src/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp new file mode 100644 index 0000000..4f50c68 --- /dev/null +++ b/src/Systems/WallSystem.cpp @@ -0,0 +1,56 @@ +#include "PrecompiledHeader.h" +#include "WallSystem.h" +#include "World.h" + +void Systems::WallSystem::RegisterComponents( ComponentFactory* cf ) +{ + cf->Register([]() { return new Components::Wall(); }); +} + +void Systems::WallSystem::Initialize() +{ + EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::WallSystem::Damage); +} + +bool Systems::WallSystem::Damage( const Events::Damage &event ) +{ + auto wallComponent = m_World->GetComponent(event.Entity); + if(!wallComponent) + { + return false; + } + LOG_INFO("WallSystem::Damage"); + auto wallhealthcomponent = m_World->GetComponent(event.Entity); + if(wallhealthcomponent->Amount > 0) + { + return false; + } + + + LOG_INFO("You are dead"); + auto transformComponent = m_World->GetComponent(event.Entity); + + for(auto d : wallComponent->Walldebris) + { + auto debris = m_World->CloneEntity(d); + + auto transform = m_World->GetComponent(debris); + transform->Position += transformComponent->Position; + + // DO STUFF! :D + float distance = glm::distance(transform->Position, transformComponent->Position); + float radius = 5.f; + float strength = (1.f - pow(distance / radius, 2)) * 500.f; + glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position); + + Events::ApplyPointImpulse e; + e.Entity = debris; + e.Impulse = direction * strength; + e.Position = transformComponent->Position; + EventBroker->Publish(e); + + } + + m_World->RemoveEntity(event.Entity); + return true; +} \ No newline at end of file diff --git a/src/Systems/WallSystem.h b/src/Systems/WallSystem.h new file mode 100644 index 0000000..986c7b8 --- /dev/null +++ b/src/Systems/WallSystem.h @@ -0,0 +1,42 @@ +#ifndef WallSystem_h__ +#define WallSystem_h__ + + +#include "System.h" +#include "Events/OnDead.h" +#include "Events/Damage.h" +#include "Events/ApplyPointImpulse.h" +#include "Components/Model.h" +#include "Components/Wall.h" +#include "Components/Transform.h" +#include "Components/Physics.h" +#include "Components/MeshShape.h" +#include "Components/Tankshell.h" +#include "Components/Health.h" + + + +namespace Systems +{ + class WallSystem : public System + { + public: + + WallSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + + void Initialize() override; + void RegisterComponents(ComponentFactory* cf) override; + + + + EventRelay m_eDamage; + bool Damage(const Events::Damage &event); + + private: + + }; + +} +#endif // WallSystem_h__ diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 7410589..4f89884 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -124,6 +124,7 @@ + @@ -173,6 +174,7 @@ + @@ -200,6 +202,7 @@ + @@ -249,6 +252,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 4281fd2..4afc24d 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -77,6 +77,10 @@ Game\Systems + + + + Gameplay\Systems Game\Systems @@ -521,6 +525,10 @@ Rendering\Components + + Gameplay\Systems + + Physics\Events @@ -554,9 +562,14 @@ GUI + + Gameplay\Events + Game\Events + + Game\Components Game\Components