From 0e2934647c2fd212a0f0d511da8602c9715d7254 Mon Sep 17 00:00:00 2001 From: Tleety Date: Sun, 1 Jun 2014 03:01:37 +0200 Subject: [PATCH 1/4] Added a movable tree or somthing dunno lol tired-. --- assets | 2 +- src/GameWorld.cpp | 53 +++++++++++++++++++++++++++-------- src/Systems/PhysicsSystem.cpp | 8 ++++-- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/assets b/assets index d5c5a86..50ee6f8 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d5c5a867134f72ff078af1110f622647e6b7b4cd +Subproject commit 50ee6f805f9b8493450366b3a4a771da16350423 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 09e535c..6eedc97 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -324,33 +324,64 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, -10, 0); - auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/Stem/Stem.obj"; + transform->Position = glm::vec3(0, 10, 0); + auto physics = AddComponent(tree); physics->Mass = 100.f; physics->Static = false; + //physics->LinearDamping = 3.f; physics->CalculateCenterOfMass = true; + { - auto leafs = CreateEntity(tree); - auto transform = AddComponent(leafs); - auto model = AddComponent(leafs); - model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; - model->Transparent = true; - CommitEntity(leafs); + 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.f, 2.29552f); + 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); } diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 4d8b8ed..d1c5104 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 @@ -376,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); @@ -389,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); @@ -521,7 +522,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); @@ -770,6 +771,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { 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); From 00268f027ab7bb2bf6b66facd0fd256e36a65e39 Mon Sep 17 00:00:00 2001 From: Tleety Date: Mon, 2 Jun 2014 18:21:39 +0200 Subject: [PATCH 2/4] Walls are now destroyable! --- src/Components/Physics.h | 10 +- src/Components/Wall.h | 20 + src/Events/OnDead.h | 16 + src/GameWorld.cpp | 468 ++++++++++++++++-- src/GameWorld.h | 3 + src/Systems/DamageSystem.cpp | 9 +- src/Systems/DamageSystem.h | 1 + src/Systems/PhysicsSystem.cpp | 23 +- src/Systems/TankSteeringSystem.cpp | 5 +- src/Systems/WallSystem.cpp | 56 +++ src/Systems/WallSystem.h | 42 ++ vs11/Returngeance/Returngeance.vcxproj | 4 + .../Returngeance/Returngeance.vcxproj.filters | 12 + 13 files changed, 606 insertions(+), 63 deletions(-) create mode 100644 src/Components/Wall.h create mode 100644 src/Events/OnDead.h create mode 100644 src/Systems/WallSystem.cpp create mode 100644 src/Systems/WallSystem.h diff --git a/src/Components/Physics.h b/src/Components/Physics.h index 2b5065c..6925f5d 100644 --- a/src/Components/Physics.h +++ b/src/Components/Physics.h @@ -8,13 +8,19 @@ namespace Components struct Physics : Component { + 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)), + : Mass(1.f), 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 6eedc97..92626d5 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -78,7 +78,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; auto physics = AddComponent(road_base); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_base); @@ -99,7 +99,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj"; auto physics = AddComponent(road_middle); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_middle); @@ -120,7 +120,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Roads/SmallRoad.obj"; auto physics = AddComponent(road_small); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(road_small); @@ -150,7 +150,7 @@ void GameWorld::Initialize() auto physics = AddComponent(water); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; { @@ -184,7 +184,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_middle); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_middle); @@ -215,7 +215,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_small); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_small); @@ -246,7 +246,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_small_mirrored); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_small_mirrored); @@ -277,7 +277,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_base); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_base); @@ -308,7 +308,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground_base_mirrored); physics->Mass = 10; - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; auto groundshape = CreateEntity(ground_base_mirrored); @@ -328,7 +328,8 @@ void GameWorld::Initialize() auto physics = AddComponent(tree); physics->Mass = 100.f; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->CollisionEvent = false; //physics->LinearDamping = 3.f; physics->CalculateCenterOfMass = true; @@ -360,6 +361,7 @@ void GameWorld::Initialize() CommitEntity(shape); } + /*{ auto shape = CreateEntity(tree); auto transform = AddComponent(shape); @@ -385,6 +387,362 @@ void GameWorld::Initialize() 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"; + + m_WallDebrisTemplates.push_back(debri); + } +#pragma endregion Region for wall debris + +#pragma region Walls + +#pragma region Wall1 + { + auto wall = CreateEntity(); + auto transform = AddComponent(wall); + transform->Position = glm::vec3(0, -16, 0); + + 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); + } +#pragma endregion Region for wall1 + +#pragma endregion Region for all walls + + { + auto wall = CreateEntity(); + auto transform = AddComponent(wall); + transform->Position = glm::vec3(20, 10, 30); + + auto physics = AddComponent(wall); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto model = AddComponent(wall); + model->ModelFile = "Models/Wall/WallDestroyed/WallDestroyed.obj"; + + auto shape = CreateEntity(wall); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; + + CommitEntity(shape); + CommitEntity(wall); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(20, 12, 30); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris1.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris1.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(20, 10, 45); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(23, 10, 45); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris3.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris3.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(20, 12, 30); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris4.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris4.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(29, 10, 45); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris5.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris5.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + + { + auto wall_trash = CreateEntity(); + auto transform = AddComponent(wall_trash); + transform->Position = glm::vec3(32, 10, 45); + + auto physics = AddComponent(wall_trash); + physics->Mass = 100.f; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; + + auto model = AddComponent(wall_trash); + model->ModelFile = "Models/Wall/WallDestroyed/WallDebris6.obj"; + + auto shape = CreateEntity(wall_trash); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris6.obj"; + + CommitEntity(shape); + CommitEntity(wall_trash); + } + EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); @@ -464,7 +822,7 @@ void GameWorld::Initialize() model->ModelFile = "Models/Gate/Lift/Lift.obj"; auto physics = AddComponent(gateBase); - physics->Static = true; + physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; physics->CollisionLayer = 1; // Terrain-Layer { auto leftBaseShape = CreateEntity(gateBase); @@ -534,46 +892,6 @@ void GameWorld::RegisterComponents() m_ComponentFactory.Register([]() { return new Components::Flag(); }); } -void GameWorld::RegisterSystems() -{ - m_SystemFactory.Register([this]() { return new Systems::TimerSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::DamageSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::TransformSystem(this, EventBroker, ResourceManager); }); - //m_SystemFactory.Register([this]() { return new Systems::LevelGenerationSystem(this); }); - m_SystemFactory.Register([this]() { return new Systems::InputSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::DebugSystem(this, EventBroker, ResourceManager); }); - //m_SystemFactory.Register([this]() { return new Systems::CollisionSystem(this); }); - m_SystemFactory.Register([this]() { return new Systems::ParticleSystem(this, EventBroker, ResourceManager); }); - //m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); }); - m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); }); - m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); -} - -void GameWorld::AddSystems() -{ - AddSystem(); - AddSystem(); - AddSystem(); - //AddSystem(); - AddSystem(); - AddSystem(); - //AddSystem(); - AddSystem(); - //AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); - AddSystem(); -} - void GameWorld::BindKey(int keyCode, std::string command, float value) { Events::BindKey e; @@ -618,7 +936,7 @@ EntityID GameWorld::CreateTank(int playerID) //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); auto physics = AddComponent(tank); physics->Mass = 63000 - 16000; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; auto vehicle = AddComponent(tank); vehicle->MaxTorque = 36000.f; vehicle->MaxSteeringAngle = 90.f; @@ -680,7 +998,7 @@ EntityID GameWorld::CreateTank(int playerID) AddComponent(shot); auto physics = AddComponent(shot); physics->Mass = 25.f; - physics->Static = false; + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; physics->CollisionEvent = true; auto modelComponent = AddComponent(shot); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; @@ -900,7 +1218,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); AddComponent(jeep); @@ -1020,3 +1338,45 @@ EntityID GameWorld::CreateJeep(int playerID) return jeep; } + +void GameWorld::RegisterSystems() +{ + m_SystemFactory.Register([this]() { return new Systems::TimerSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::DamageSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::TransformSystem(this, EventBroker, ResourceManager); }); + //m_SystemFactory.Register([this]() { return new Systems::LevelGenerationSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::InputSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::DebugSystem(this, EventBroker, ResourceManager); }); + //m_SystemFactory.Register([this]() { return new Systems::CollisionSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::ParticleSystem(this, EventBroker, ResourceManager); }); + //m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); }); + m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); + m_SystemFactory.Register([this]() { return new Systems::WallSystem(this, EventBroker, ResourceManager); }); +} + +void GameWorld::AddSystems() +{ + AddSystem(); + AddSystem(); + AddSystem(); + //AddSystem(); + AddSystem(); + AddSystem(); + //AddSystem(); + AddSystem(); + //AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); + AddSystem(); +} diff --git a/src/GameWorld.h b/src/GameWorld.h index aae2472..a4538d4 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -21,6 +21,7 @@ #include "Systems/TimerSystem.h" #include "Systems/DamageSystem.h" #include "Systems/WheelPairSystem.h" +#include "Systems/WallSystem.h" #include "Components/Camera.h" #include "Components/DirectionalLight.h" @@ -74,6 +75,8 @@ private: EntityID CreateTank(int playerID); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); EntityID CreateJeep(int playerID); + + std::vector m_WallDebrisTemplates; }; #endif // GameWorld_h__ 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 d1c5104..01863b0 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -163,6 +163,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; @@ -227,6 +231,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; @@ -312,7 +320,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) return; } hkpShape* shape; - if(! physicsComponent->Static) // Not static + if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic) { hkArray shapeArray; for (auto &shapeData : m_Shapes[entity]) @@ -447,7 +455,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. @@ -499,7 +507,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) hkpRigidBodyCinfo rigidBodyInfo; { rigidBodyInfo.m_shape = shape; - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; + 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); @@ -816,7 +832,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 af7e41b..b5828d2 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -124,6 +124,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); @@ -155,8 +158,6 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) EventBroker->Publish(d); } - - m_World->RemoveEntity(shellEntity); } } diff --git a/src/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp new file mode 100644 index 0000000..b523611 --- /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)) * 400.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 23ff5d8..66a883a 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -122,6 +122,7 @@ + @@ -163,6 +164,7 @@ + @@ -187,6 +189,7 @@ + @@ -228,6 +231,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index d5443c9..60b8a53 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -76,6 +76,9 @@ Gameplay\Systems + + Gameplay\Systems + @@ -485,6 +488,15 @@ Rendering\Components + + Gameplay\Systems + + + Gameplay\Events + + + Gameplay\Components + From f1a9afc0976f6061171f3b58e16808283c8cdc13 Mon Sep 17 00:00:00 2001 From: Tleety Date: Mon, 2 Jun 2014 20:01:28 +0200 Subject: [PATCH 3/4] Fixed a createWall function. --- src/GameWorld.cpp | 217 +++++++------------------------------ src/GameWorld.h | 1 + src/Model.cpp | 2 +- src/Systems/WallSystem.cpp | 2 +- 4 files changed, 42 insertions(+), 180 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 92626d5..a358342 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -557,191 +557,20 @@ void GameWorld::Initialize() auto shape = CreateEntity(debri); auto shapetransform = AddComponent(shape); auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; + 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 Walls +#pragma region Wall_Regin -#pragma region Wall1 - { - auto wall = CreateEntity(); - auto transform = AddComponent(wall); - transform->Position = glm::vec3(0, -16, 0); - - 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); - } -#pragma endregion Region for wall1 - -#pragma endregion Region for all walls - - { - auto wall = CreateEntity(); - auto transform = AddComponent(wall); - transform->Position = glm::vec3(20, 10, 30); - - auto physics = AddComponent(wall); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - - auto model = AddComponent(wall); - model->ModelFile = "Models/Wall/WallDestroyed/WallDestroyed.obj"; - - auto shape = CreateEntity(wall); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDestroyed.obj"; - - CommitEntity(shape); - CommitEntity(wall); + for(int i = 0; i < 5; i++) + { + EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); } - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(20, 12, 30); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris1.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris1.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } - - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(20, 10, 45); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris2.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris2.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } - - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(23, 10, 45); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris3.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris3.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } - - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(20, 12, 30); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris4.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris4.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } - - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(29, 10, 45); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris5.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris5.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } - - { - auto wall_trash = CreateEntity(); - auto transform = AddComponent(wall_trash); - transform->Position = glm::vec3(32, 10, 45); - - auto physics = AddComponent(wall_trash); - physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Fixed; - - auto model = AddComponent(wall_trash); - model->ModelFile = "Models/Wall/WallDestroyed/WallDebris6.obj"; - - auto shape = CreateEntity(wall_trash); - auto shapetransform = AddComponent(shape); - auto shapemesh = AddComponent(shape); - shapemesh->ResourceName = "Models/Wall/WallDestroyed/WallDebris6.obj"; - - CommitEntity(shape); - CommitEntity(wall_trash); - } +#pragma endregion Region for all wall creations EntityID tank1 = CreateTank(1); { @@ -1004,7 +833,7 @@ EntityID GameWorld::CreateTank(int playerID) modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; auto tankShellComponent = AddComponent(shot); tankShellComponent->Damage = 20.f; - tankShellComponent->ExplosionRadius = 30.f; + tankShellComponent->ExplosionRadius = 5.f; tankShellComponent->ExplosionStrength = 300000.f; { auto shape = CreateEntity(shot); @@ -1101,6 +930,38 @@ EntityID GameWorld::CreateTank(int playerID) return tank; } +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; + +} + void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front) { const float separation = 1.77f; diff --git a/src/GameWorld.h b/src/GameWorld.h index a4538d4..fd061be 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -75,6 +75,7 @@ private: EntityID CreateTank(int playerID); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); EntityID CreateJeep(int playerID); + EntityID CreateWall(glm::vec3 pos, glm::quat orientation); std::vector m_WallDebrisTemplates; }; 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/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp index b523611..4f50c68 100644 --- a/src/Systems/WallSystem.cpp +++ b/src/Systems/WallSystem.cpp @@ -40,7 +40,7 @@ bool Systems::WallSystem::Damage( const Events::Damage &event ) // DO STUFF! :D float distance = glm::distance(transform->Position, transformComponent->Position); float radius = 5.f; - float strength = (1.f - pow(distance / radius, 2)) * 400.f; + float strength = (1.f - pow(distance / radius, 2)) * 500.f; glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position); Events::ApplyPointImpulse e; From f5f6a5cf3ab5c563bde97455c9ee1b59ba42eeec Mon Sep 17 00:00:00 2001 From: Tleety Date: Mon, 2 Jun 2014 22:15:52 +0200 Subject: [PATCH 4/4] Fixed transparency --- src/GameWorld.cpp | 6 +++--- src/Renderer.cpp | 32 +++++++++++++++----------------- src/Renderer.h | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index a358342..ce6cc5e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -324,11 +324,11 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, 10, 0); + transform->Position = glm::vec3(0, -10, 0); auto physics = AddComponent(tree); physics->Mass = 100.f; - physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->MotionType = Components::Physics::MotionTypeEnum::Keyframed; physics->CollisionEvent = false; //physics->LinearDamping = 3.f; physics->CalculateCenterOfMass = true; @@ -565,7 +565,7 @@ void GameWorld::Initialize() #pragma region Wall_Regin - for(int i = 0; i < 5; i++) + for(int i = 10; i < 0; i++) { EntityID Wall = CreateWall(glm::vec3(i*10.f, -15.f, 0.f), glm::quat()); } 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();