From 133473b00e7fe3c81582c88c598982279ab69428 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 28 May 2014 20:28:48 +0200 Subject: [PATCH 01/15] Tanksteering improved --- src/Systems/PhysicsSystem.cpp | 45 +++++++++++++++++++++++++----- src/Systems/TankSteeringSystem.cpp | 3 +- src/Systems/TankSteeringSystem.h | 1 + 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index fa23048..612355c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -138,6 +138,7 @@ void Systems::PhysicsSystem::Initialize() e.Layer2 = EXPLOSION_LAYER; EventBroker->Publish(e); }*/ + } void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) @@ -377,6 +378,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); + m_RigidBodies[entity] = rigidBody; + m_RigidBodyEntities[rigidBody] = entity; auto vehicleComponent = m_World->GetComponent(entity); if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end()) @@ -393,7 +396,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) VehicleSetup vehicleSetup; // Create the basic vehicle. - m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); + m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]); m_PhysicsWorld->markForWrite(); vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels); // Add the vehicle's entities and phantoms to the world @@ -402,8 +405,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBody->addContactListener( m_collisionResolution ); } m_Vehicles[entity]->addToWorld(m_PhysicsWorld); - m_RigidBodies[entity] = rigidBody; - m_RigidBodyEntities[rigidBody] = entity; // The vehicle is an action @@ -423,8 +424,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBody->addContactListener( m_collisionResolution ); } m_PhysicsWorld->addEntity(rigidBody); - m_RigidBodies[entity] = rigidBody; - m_RigidBodyEntities[rigidBody] = entity; + m_PhysicsWorld->unmarkForWrite(); shape->removeReference(); @@ -707,11 +707,42 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*) bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) { auto vehicleComponent = m_World->GetComponent(event.Entity); + if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus; - deviceStatus->m_positionX = event.PositionX; - deviceStatus->m_positionY = event.PositionY; + auto transformComponent = m_World->GetComponent(event.Entity); + + float steeringX = event.PositionX; + + glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity())); + glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1)); + float dotProduct = glm::dot(forward, velocityNormalized); + + + + if(dotProduct < 0) + { + steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX; + } + + + if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180)) + { + deviceStatus->m_positionY = -0.4f; + deviceStatus->m_positionX = steeringX; + } +// else if(m_Vehicles[event.Entity]->calcKMPH() > -2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180)) +// { +// deviceStatus->m_positionY = 0.4f;; +// deviceStatus->m_positionX = -steeringX; +// } + else + { + deviceStatus->m_positionX = steeringX; + deviceStatus->m_positionY = event.PositionY; + } + if(event.PositionY > 0) { deviceStatus->m_reverseButtonPressed = true; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 5b5e34d..bbe6948 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -257,13 +257,12 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E if (event.Command == "horizontal") { m_Horizontal = val; - m_Vertical = -0.4f; } else if (event.Command == "vertical") { m_Vertical = -val; } - + else if (event.Command == "handbrake") { Handbrake = val > 0; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index aba3047..1ccb056 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -29,6 +29,7 @@ #include "Components/FrameTimer.h" #include "Events/Damage.h" +#include "Components/Vehicle.h" namespace Systems { From 651e62ba942bbd3a7d59af87fed4eb19dcee59d6 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 28 May 2014 20:40:15 +0200 Subject: [PATCH 02/15] Camera on tank barrel --- src/GameWorld.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index d2a591c..d25c813 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -379,6 +379,20 @@ EntityID GameWorld::CreateTank(int playerID) } CommitEntity(shot); barrelSteering->ShotTemplate = shot; + + + auto cameraTower = CreateEntity(barrel); + { + auto transform = AddComponent(cameraTower); + transform->Position.z = 16.f; + transform->Position.y = 4.f; + transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f)); + auto cameraComp = AddComponent(cameraTower); + cameraComp->FarClip = 2000.f; + //auto freeSteering = AddComponent(cameraTower); + } + + SetProperty(tank, "Camera", cameraTower); } CommitEntity(barrel); tankSteering->Barrel = barrel; @@ -387,18 +401,7 @@ EntityID GameWorld::CreateTank(int playerID) tankSteering->Turret = tower; - auto cameraTower = CreateEntity(tower); - { - auto transform = AddComponent(cameraTower); - transform->Position.z = 16.f; - transform->Position.y = 4.f; - //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); - auto cameraComp = AddComponent(cameraTower); - cameraComp->FarClip = 2000.f; - //auto freeSteering = AddComponent(cameraTower); - } - - SetProperty(tank, "Camera", cameraTower); + } //{ From ef0ff5a99b9c98ca50179c4a885b8992610a6bbc Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 28 May 2014 22:05:17 +0200 Subject: [PATCH 03/15] WIP Awesometastic debugging --- src/GUI/Frame.h | 18 +++++++++++++++++- src/GUI/GameFrame.h | 26 +++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index a2acb8e..e502fea 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -32,12 +32,14 @@ public: , Rectangle() , m_Name("UIParent") , m_Layer(0) + , m_Hidden(false) { } // Create a frame as a child Frame(Frame* parent, std::string name) : m_Name(name) , m_Layer(0) + , m_Hidden(false) { SetParent(std::shared_ptr(parent)); } ::RenderQueue RenderQueue; @@ -74,6 +76,9 @@ public: std::string Name() const { return m_Name; } void SetName(std::string val) { m_Name = val; } int Layer() const { return m_Layer; } + bool Hidden() const { return m_Hidden; } + void Hide() { m_Hidden = true; } + void Show() { m_Hidden = false; } int Left() const override { @@ -105,6 +110,9 @@ public: void UpdateLayered(double dt) { + if (this->Hidden()) + return; + // Update ourselves this->Update(dt); @@ -115,6 +123,8 @@ public: for (auto &pairChild : children) { auto child = pairChild.second; + if (child->Hidden()) + continue; child->Update(dt); } } @@ -123,6 +133,9 @@ public: void DrawLayered(std::shared_ptr renderer) { + if (this->Hidden()) + return; + // Draw ourselves renderer->SetViewport(AbsoluteRectangle()); this->Draw(renderer); @@ -134,6 +147,8 @@ public: for (auto &pairChild : children) { auto child = pairChild.second; + if (child->Hidden()) + continue; Rectangle rect = child->AbsoluteRectangle(); renderer->SetViewport(rect); child->Draw(renderer); @@ -149,7 +164,8 @@ protected: std::string m_Name; int m_Layer; - + bool m_Hidden; + std::shared_ptr m_Parent; typedef std::multimap> Children_t; // name -> frame std::map m_Children; // layer -> Children_t diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 8286997..078a687 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -18,32 +18,48 @@ public: GameFrame(Frame* parent, std::string name) : Frame(parent, name) { + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &GameFrame::OnCommand); + m_World = std::make_shared(EventBroker, ResourceManager); auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World); { vp1 = new Viewport(worldFrame, "Viewport1", m_World); vp1->X = 0; vp1->Width = 640; - vp1->Height = 720 / 2; new PlayerHUD(vp1, "PlayerHUD", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); vp2->Width = 640; - vp2->Height = 720 / 2; new PlayerHUD(vp2, "PlayerHUD", m_World, 2); - auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World); - vpc->Y = 720 / 2; - vpc->Height = 720 / 2; + m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); + m_FreeCamViewport->Show(); } m_World->Initialize(); } private: + EventRelay m_EInputCommand; + std::shared_ptr m_World; Viewport* vp1; Viewport* vp2; + Viewport* m_FreeCamViewport; + + bool OnCommand(const Events::InputCommand &event) + { + if (event.Command == "cam_vertical" || event.Command == "cam_horizontal" || event.Command == "cam_normal" || event.Command == "cam_lock") + { + m_FreeCamViewport->Show(); + } + else + { + m_FreeCamViewport->Hide(); + } + + return true; + } }; } From fd188fded6b3a9de6fece26a2de061bacbaeb902 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 28 May 2014 22:09:54 +0200 Subject: [PATCH 04/15] Velocity now updating in transformcomponent --- src/Components/TankSteering.h | 1 - src/GameWorld.cpp | 32 +++++++++++++++++++++++------- src/Physics/VehicleSetup.cpp | 3 +-- src/Systems/PhysicsSystem.cpp | 22 +++++++++++++++----- src/Systems/TankSteeringSystem.cpp | 2 +- src/Systems/TankSteeringSystem.h | 1 + 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Components/TankSteering.h b/src/Components/TankSteering.h index 2c4b123..c47c5c8 100644 --- a/src/Components/TankSteering.h +++ b/src/Components/TankSteering.h @@ -7,7 +7,6 @@ namespace Components { struct TankSteering : Component { - EntityID Player; EntityID Turret; EntityID Barrel; TankSteering* Clone() const override { return new TankSteering(*this); } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index d25c813..659e628 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -194,6 +194,31 @@ void GameWorld::Initialize() //} + /*{ + auto gate = CreateEntity(); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(0, -50, 100); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/FishingRod/FishingRod.obj"; + + + { + //shape + } + + + { + auto fish = CreateEntity(flag); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(-1.3f, 1.0, 0); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/LeFish/Salmon.obj"; + CommitEntity(fish); + } + + CommitEntity(gate); + }*/ + } void GameWorld::Update(double dt) @@ -285,12 +310,6 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f EntityID GameWorld::CreateTank(int playerID) { - auto playerEnt = CreateEntity(); - { - auto player = AddComponent(playerEnt); - player->ID = playerID; - } - auto tank = CreateEntity(); auto transform = AddComponent(tank); transform->Position = glm::vec3(0, 5, 0); @@ -305,7 +324,6 @@ EntityID GameWorld::CreateTank(int playerID) auto player = AddComponent(tank); player->ID = playerID; auto tankSteering = AddComponent(tank); - tankSteering->Player = playerEnt; AddComponent(tank); auto health = AddComponent(tank); health->Amount = 100.f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index e319834..3568a26 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -183,7 +183,6 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultE engine.m_maxRPM = vehicleComponent.MaxRPM; - engine.m_torqueFactorAtMinRPM = 0.8f; engine.m_torqueFactorAtMaxRPM = 0.8f; engine.m_resistanceFactorAtMinRPM = 0.05f; @@ -200,7 +199,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent transmission.m_upshiftRPM = 7000.0f; - transmission.m_clutchDelayTime = 0.0f; + transmission.m_clutchDelayTime = 1.5f; transmission.m_reverseGearRatio = 1.0f; transmission.m_gearsRatio[0] = 3.0f; transmission.m_gearsRatio[1] = 2.25f; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index a9d4e76..13f136c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -156,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) void Systems::PhysicsSystem::Update(double dt) { + + for (auto pair : *m_World->GetEntities()) { EntityID entity = pair.first; @@ -172,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt) { hkVector4 position; hkQuaternion rotation; + hkVector4 velocity; if (parent) { auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity); } else { position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position); rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity); } m_PhysicsWorld->markForWrite(); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); + m_RigidBodies[entity]->setLinearVelocity(velocity); m_PhysicsWorld->unmarkForWrite(); } +/* + + glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition()); + pos1 += glm::vec3(1, 1, 1)*(float)dt; + hkVector4 pos = GLMVEC3_TO_HKVECTOR4(pos1); + + m_PhysicsWorld->markForWrite(); + m_RigidBodies[m_World->m_Terrain]->setPositionAndRotation(pos, GLMQUAT_TO_HKQUATERNION(glm::quat())); + m_PhysicsWorld->unmarkForWrite();*/ } static const double timestep = 1 / 60.0; @@ -241,11 +256,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { auto transformComponentParent = m_World->GetComponent(parent); - transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition()); transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation()); + transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity()); // TODO: No support for Scale, MIGHT be possible + // HACK: WTF IS THIS? if (transformComponentParent) { transformComponent->Position -= transformComponentParent->Position; @@ -320,7 +336,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } - // Create a hkpListShape* of all the childEntities collected in m_ShapeArrays hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT); // Save the listShape for further use @@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) if(triggerComponent) { auto parentTransformComponent = m_World->GetComponent(entityParent); - PhantomCallbackShape* phantom = new PhantomCallbackShape(this); hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom); @@ -719,8 +733,6 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1)); float dotProduct = glm::dot(forward, velocityNormalized); - - if(dotProduct < 0) { steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 2def044..1d028d9 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit if(!tankSteeringComponent) return; - auto playerComponent = m_World->GetComponent(tankSteeringComponent->Player); + auto playerComponent = m_World->GetComponent(entity); if (!playerComponent) return; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 9a08e59..01fc27a 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -30,6 +30,7 @@ #include "Events/Damage.h" #include "Components/Vehicle.h" +#include "Components/Player.h" namespace Systems { From b8ec7e1dbd1cdc938c8339aed1b2c444f2d77262 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 29 May 2014 17:40:48 +0200 Subject: [PATCH 05/15] Gate half done --- src/GameWorld.cpp | 76 ++++++++++++++++++++++++++--------- src/Systems/PhysicsSystem.cpp | 3 ++ src/Systems/TriggerSystem.cpp | 2 +- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 659e628..d9ffd16 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -194,30 +194,68 @@ void GameWorld::Initialize() //} - /*{ - auto gate = CreateEntity(); - auto transform = AddComponent(gate); - transform->Position = glm::vec3(0, -50, 100); - auto model = AddComponent(gate); - model->ModelFile = "Models/Flag/FishingRod/FishingRod.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->Static = true; + physics->CollisionLayer = 1; // Terrain-Layer { - //shape + 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 fish = CreateEntity(flag); - auto transform = AddComponent(gate); - transform->Position = glm::vec3(-1.3f, 1.0, 0); - auto model = AddComponent(gate); - model->ModelFile = "Models/Flag/LeFish/Salmon.obj"; - CommitEntity(fish); + 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); } - - CommitEntity(gate); - }*/ + { + 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); + } } diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 13f136c..4d8b8ed 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -771,6 +771,9 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) { m_PhysicsWorld->markForWrite(); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); + + auto transformComponent = m_World->GetComponent(event.Entity); + transformComponent->Velocity = event.Velocity; m_PhysicsWorld->unmarkForWrite(); } return true; diff --git a/src/Systems/TriggerSystem.cpp b/src/Systems/TriggerSystem.cpp index 41ea333..166a509 100644 --- a/src/Systems/TriggerSystem.cpp +++ b/src/Systems/TriggerSystem.cpp @@ -82,7 +82,7 @@ void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity ) m_World->RemoveComponent(phantomEntity); m_World->SetEntityParent(phantomEntity, entity); auto phantomTransform = m_World->GetComponent(phantomEntity); - phantomTransform->Position = glm::vec3(1.f, 0.1f, 2.f); + phantomTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f); } From 04b15fe92a7286305550effd8a38c1e83ef5702e Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 28 May 2014 22:09:54 +0200 Subject: [PATCH 06/15] Velocity now updating in transformcomponent --- src/Components/TankSteering.h | 1 - src/GameWorld.cpp | 32 +++++++++++++++++++++++------- src/Physics/VehicleSetup.cpp | 3 +-- src/Systems/PhysicsSystem.cpp | 22 +++++++++++++++----- src/Systems/TankSteeringSystem.cpp | 2 +- src/Systems/TankSteeringSystem.h | 1 + 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/Components/TankSteering.h b/src/Components/TankSteering.h index 2c4b123..c47c5c8 100644 --- a/src/Components/TankSteering.h +++ b/src/Components/TankSteering.h @@ -7,7 +7,6 @@ namespace Components { struct TankSteering : Component { - EntityID Player; EntityID Turret; EntityID Barrel; TankSteering* Clone() const override { return new TankSteering(*this); } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index d25c813..659e628 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -194,6 +194,31 @@ void GameWorld::Initialize() //} + /*{ + auto gate = CreateEntity(); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(0, -50, 100); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/FishingRod/FishingRod.obj"; + + + { + //shape + } + + + { + auto fish = CreateEntity(flag); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(-1.3f, 1.0, 0); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/LeFish/Salmon.obj"; + CommitEntity(fish); + } + + CommitEntity(gate); + }*/ + } void GameWorld::Update(double dt) @@ -285,12 +310,6 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f EntityID GameWorld::CreateTank(int playerID) { - auto playerEnt = CreateEntity(); - { - auto player = AddComponent(playerEnt); - player->ID = playerID; - } - auto tank = CreateEntity(); auto transform = AddComponent(tank); transform->Position = glm::vec3(0, 5, 0); @@ -305,7 +324,6 @@ EntityID GameWorld::CreateTank(int playerID) auto player = AddComponent(tank); player->ID = playerID; auto tankSteering = AddComponent(tank); - tankSteering->Player = playerEnt; AddComponent(tank); auto health = AddComponent(tank); health->Amount = 100.f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index e319834..3568a26 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -183,7 +183,6 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultE engine.m_maxRPM = vehicleComponent.MaxRPM; - engine.m_torqueFactorAtMinRPM = 0.8f; engine.m_torqueFactorAtMaxRPM = 0.8f; engine.m_resistanceFactorAtMinRPM = 0.05f; @@ -200,7 +199,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent transmission.m_upshiftRPM = 7000.0f; - transmission.m_clutchDelayTime = 0.0f; + transmission.m_clutchDelayTime = 1.5f; transmission.m_reverseGearRatio = 1.0f; transmission.m_gearsRatio[0] = 3.0f; transmission.m_gearsRatio[1] = 2.25f; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index a9d4e76..13f136c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -156,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) void Systems::PhysicsSystem::Update(double dt) { + + for (auto pair : *m_World->GetEntities()) { EntityID entity = pair.first; @@ -172,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt) { hkVector4 position; hkQuaternion rotation; + hkVector4 velocity; if (parent) { auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity); } else { position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position); rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity); } m_PhysicsWorld->markForWrite(); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); + m_RigidBodies[entity]->setLinearVelocity(velocity); m_PhysicsWorld->unmarkForWrite(); } +/* + + glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition()); + pos1 += glm::vec3(1, 1, 1)*(float)dt; + hkVector4 pos = GLMVEC3_TO_HKVECTOR4(pos1); + + m_PhysicsWorld->markForWrite(); + m_RigidBodies[m_World->m_Terrain]->setPositionAndRotation(pos, GLMQUAT_TO_HKQUATERNION(glm::quat())); + m_PhysicsWorld->unmarkForWrite();*/ } static const double timestep = 1 / 60.0; @@ -241,11 +256,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { auto transformComponentParent = m_World->GetComponent(parent); - transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition()); transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation()); + transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity()); // TODO: No support for Scale, MIGHT be possible + // HACK: WTF IS THIS? if (transformComponentParent) { transformComponent->Position -= transformComponentParent->Position; @@ -320,7 +336,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } - // Create a hkpListShape* of all the childEntities collected in m_ShapeArrays hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT); // Save the listShape for further use @@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) if(triggerComponent) { auto parentTransformComponent = m_World->GetComponent(entityParent); - PhantomCallbackShape* phantom = new PhantomCallbackShape(this); hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom); @@ -719,8 +733,6 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1)); float dotProduct = glm::dot(forward, velocityNormalized); - - if(dotProduct < 0) { steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 2def044..1d028d9 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit if(!tankSteeringComponent) return; - auto playerComponent = m_World->GetComponent(tankSteeringComponent->Player); + auto playerComponent = m_World->GetComponent(entity); if (!playerComponent) return; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 9a08e59..01fc27a 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -30,6 +30,7 @@ #include "Events/Damage.h" #include "Components/Vehicle.h" +#include "Components/Player.h" namespace Systems { From 0db4ebea95ac4607dbf2d792d0147d83648ec521 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 29 May 2014 17:45:15 +0200 Subject: [PATCH 07/15] WIP WheelPair --- src/Components/WheelPair.h | 3 +- src/GameWorld.cpp | 134 ++++++++++-------- src/GameWorld.h | 2 + src/Systems/WheelPairSystem.cpp | 35 +++++ src/Systems/WheelPairSystem.h | 22 +++ vs11/Returngeance/Returngeance.vcxproj | 2 + .../Returngeance/Returngeance.vcxproj.filters | 4 + 7 files changed, 144 insertions(+), 58 deletions(-) create mode 100644 src/Systems/WheelPairSystem.cpp create mode 100644 src/Systems/WheelPairSystem.h diff --git a/src/Components/WheelPair.h b/src/Components/WheelPair.h index 4e74a82..973b5b5 100644 --- a/src/Components/WheelPair.h +++ b/src/Components/WheelPair.h @@ -8,7 +8,8 @@ namespace Components struct WheelPair : Component { - // Flag for pair wheels + EntityID FakeWheel1; + EntityID FakeWheel2; virtual WheelPair* Clone() const override { return new WheelPair(*this); } }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 659e628..0cf3e5e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -247,6 +247,7 @@ void GameWorld::RegisterSystems() //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); }); @@ -266,6 +267,7 @@ void GameWorld::AddSystems() //AddSystem(); AddSystem(); AddSystem(); + AddSystem(); AddSystem(); AddSystem(); AddSystem(); @@ -444,67 +446,82 @@ EntityID GameWorld::CreateTank(int playerID) float springLength = 0.3f; float suspensionStrength = 15.f; +#pragma region Pair R1 { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = true; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; + auto wheel1 = CreateEntity(tank); { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); + auto transform = AddComponent(wheel1); + transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel1); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel1); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = 0; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = true; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 3.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel1); + auto shapetransform = AddComponent(shape); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } + CommitEntity(wheel1); } - CommitEntity(wheel); - } - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; + auto wheel2 = CreateEntity(tank); { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); + auto transform = AddComponent(wheel2); + transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel2); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel2); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = 0; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = false; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 3.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel2); + auto shapetransform = AddComponent(shape); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } + CommitEntity(wheel2); } - CommitEntity(wheel); - } + auto wheelPair = CreateEntity(tank); + { + auto transform = AddComponent(wheelPair); + transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -1.715f); + auto pair = AddComponent(wheelPair); + pair->FakeWheel1 = wheel1; + pair->FakeWheel2 = wheel2; + auto model = AddComponent(wheel2); + model->ModelFile = "Models/Tank/tankWheel.obj"; + } + } +#pragma endregion +#pragma region Pair L1 { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); @@ -566,7 +583,8 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(wheel); } - +#pragma endregion +#pragma region Pair R2 //Back { auto wheel = CreateEntity(tank); @@ -650,7 +668,8 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(particleEntity); } - +#pragma endregion +#pragma region Pair L2 { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); @@ -709,6 +728,7 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(shape); } CommitEntity(wheel); +#pragma endregion #pragma endregion auto entity = CreateEntity(tank); diff --git a/src/GameWorld.h b/src/GameWorld.h index b777975..faf7ec4 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -20,6 +20,7 @@ #include "Systems/TriggerSystem.h" #include "Systems/TimerSystem.h" #include "Systems/DamageSystem.h" +#include "Systems/WheelPairSystem.h" #include "Components/Camera.h" #include "Components/DirectionalLight.h" @@ -47,6 +48,7 @@ #include "Components/Health.h" #include "Components/Trigger.h" #include "Components/Flag.h" +#include "Components/WheelPair.h" class GameWorld : public World { diff --git a/src/Systems/WheelPairSystem.cpp b/src/Systems/WheelPairSystem.cpp new file mode 100644 index 0000000..f0cea10 --- /dev/null +++ b/src/Systems/WheelPairSystem.cpp @@ -0,0 +1,35 @@ +#include "PrecompiledHeader.h" +#include "WheelPairSystem.h" +#include "World.h" + +void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf) +{ + cf->Register([]() { return new Components::WheelPair(); }); +} + +void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + auto wheelPair = m_World->GetComponent(entity); + if (!wheelPair) + return; + + auto transform = m_World->GetComponent(entity); + if (!transform) + return; + auto transformFake1 = m_World->GetComponent(wheelPair->FakeWheel1); + if (!transformFake1) + return; + auto transformFake2 = m_World->GetComponent(wheelPair->FakeWheel2); + if (!transformFake2) + return; + + glm::vec3 thing = transformFake2->Position - transformFake1->Position; + glm::vec3 forward = glm::normalize(glm::vec3(thing.x, 0, thing.z)); + glm::vec3 up = glm::vec3(0, 1, 0); + + float angle = glm::acos(glm::dot(glm::normalize(thing), forward)); + float height = (thing / 2.f).y; + + transform->Position.y = height; + //transform->Orientation = glm::quat(glm::vec3()) +} \ No newline at end of file diff --git a/src/Systems/WheelPairSystem.h b/src/Systems/WheelPairSystem.h new file mode 100644 index 0000000..a2bd224 --- /dev/null +++ b/src/Systems/WheelPairSystem.h @@ -0,0 +1,22 @@ +#ifndef Systems_WheelPairSystem_h__ +#define Systems_WheelPairSystem_h__ + +#include "World.h" +#include "System.h" +#include "Components/Transform.h" +#include "Components/WheelPair.h" + +namespace Systems +{ + class WheelPairSystem : public System + { + public: + + WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + void RegisterComponents(ComponentFactory* cf) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + }; +} +#endif // Systems_WheelPairSystem_h__ diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 21e0951..137e26e 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -122,6 +122,7 @@ + @@ -226,6 +227,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 2430d0c..7238a0e 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -75,6 +75,7 @@ Gameplay\Systems + @@ -478,6 +479,9 @@ GUI + + Physics\Systems + From 04a2642f85f2b1bd080aea7e114a8a712d060dcb Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 30 May 2014 01:00:22 +0200 Subject: [PATCH 08/15] Tank shell inheriting velocity --- src/Systems/TankSteeringSystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 1d028d9..cc1008b 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -62,6 +62,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit if(barrelSteeringComponent) { + auto tankTransform = m_World->GetComponent(entity); auto transformComponent = m_World->GetComponent(tankSteeringComponent->Barrel); auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(tankSteeringComponent->Barrel); glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); @@ -76,7 +77,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation; Events::SetVelocity eSetVelocity; eSetVelocity.Entity = clone; - eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed); + eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed); EventBroker->Publish(eSetVelocity); m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0; From 701ca06a6570efb868188ef9c56b5c46a049ee8a Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 30 May 2014 01:03:59 +0200 Subject: [PATCH 09/15] Crosshair --- assets | 2 +- src/GUI/PlayerHUD.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/assets b/assets index bc811a1..fe035e7 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit bc811a1b392782213d0823e418bc1d773e1a9641 +Subproject commit fe035e74bd086cfa924003349711f31133337812 diff --git a/src/GUI/PlayerHUD.h b/src/GUI/PlayerHUD.h index 648230a..b094d4c 100644 --- a/src/GUI/PlayerHUD.h +++ b/src/GUI/PlayerHUD.h @@ -16,6 +16,13 @@ namespace GUI , m_PlayerID(playerID) { m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID); + m_Crosshair = new TextureFrame(this, "Crosshair"); + m_Crosshair->Width = 45; + m_Crosshair->Height = 45; + m_Crosshair->X = this->Width / 2.f - m_Crosshair->Width / 2.f; + m_Crosshair->Y = this->Height / 2.f - m_Crosshair->Height / 2.f; + m_Crosshair->SetTexture("Textures/GUI/crosshair.png"); + m_Crosshair->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.75f)); } protected: @@ -23,6 +30,7 @@ namespace GUI int m_PlayerID; HealthOverlay* m_HealthOverlay; + TextureFrame* m_Crosshair; }; } From 235a03ab4cc84fc8680a973f94a193dedbf360ce Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 30 May 2014 01:04:09 +0200 Subject: [PATCH 10/15] Tank wheel pair! --- src/Components/WheelPair.h | 4 +- src/GUI/GameFrame.h | 17 +- src/GameWorld.cpp | 411 ++++++++++---------------------- src/GameWorld.h | 7 +- src/Systems/WheelPairSystem.cpp | 18 +- 5 files changed, 143 insertions(+), 314 deletions(-) diff --git a/src/Components/WheelPair.h b/src/Components/WheelPair.h index 973b5b5..24bc598 100644 --- a/src/Components/WheelPair.h +++ b/src/Components/WheelPair.h @@ -8,8 +8,8 @@ namespace Components struct WheelPair : Component { - EntityID FakeWheel1; - EntityID FakeWheel2; + EntityID FakeWheelFront; + EntityID FakeWheelBack; virtual WheelPair* Clone() const override { return new WheelPair(*this); } }; diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 078a687..19f66ac 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -18,7 +18,7 @@ public: GameFrame(Frame* parent, std::string name) : Frame(parent, name) { - EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &GameFrame::OnCommand); + EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &GameFrame::OnKeyUp); m_World = std::make_shared(EventBroker, ResourceManager); auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World); @@ -40,22 +40,21 @@ public: } private: - EventRelay m_EInputCommand; + EventRelay m_EKeyUp; std::shared_ptr m_World; Viewport* vp1; Viewport* vp2; Viewport* m_FreeCamViewport; - bool OnCommand(const Events::InputCommand &event) + bool OnKeyUp(const Events::KeyUp &event) { - if (event.Command == "cam_vertical" || event.Command == "cam_horizontal" || event.Command == "cam_normal" || event.Command == "cam_lock") + if (event.KeyCode == GLFW_KEY_1) { - m_FreeCamViewport->Show(); - } - else - { - m_FreeCamViewport->Hide(); + if (m_FreeCamViewport->Hidden()) + m_FreeCamViewport->Show(); + else + m_FreeCamViewport->Hide(); } return true; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index e19e914..6a7e51a 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -56,8 +56,8 @@ void GameWorld::Initialize() auto camera = CreateEntity(); { auto transform = AddComponent(camera); - transform->Position.z = 20.f; - transform->Position.y = 20.f; + transform->Position.z = 150.f; + transform->Position.y = 10.f; //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); auto cameraComp = AddComponent(camera); cameraComp->FarClip = 2000.f; @@ -126,7 +126,7 @@ void GameWorld::Initialize() EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); - transform->Position.z = 50.f; + transform->Position.z = 145.f; Events::SetViewportCamera e; e.CameraEntity = GetProperty(tank1, "Camera"); @@ -480,295 +480,17 @@ EntityID GameWorld::CreateTank(int playerID) #pragma region Wheels //Create wheels - float wheelOffset = 0.4f; - float springLength = 0.3f; - float suspensionStrength = 15.f; - -#pragma region Pair R1 - { - auto wheel1 = CreateEntity(tank); - { - auto transform = AddComponent(wheel1); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel1); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel1); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = true; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel1); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel1); - } - auto wheel2 = CreateEntity(tank); - { - auto transform = AddComponent(wheel2); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel2); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel2); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel2); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel2); - } - - auto wheelPair = CreateEntity(tank); - { - auto transform = AddComponent(wheelPair); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -1.715f); - auto pair = AddComponent(wheelPair); - pair->FakeWheel1 = wheel1; - pair->FakeWheel2 = wheel2; - auto model = AddComponent(wheel2); - model->ModelFile = "Models/Tank/tankWheel.obj"; - } - } -#pragma endregion -#pragma region Pair L1 - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = true; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); - } - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 0; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = true; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); - } - -#pragma endregion -#pragma region Pair R2 - //Back - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 1; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); - } - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 1; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); - - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); - } -#pragma endregion -#pragma region Pair L2 - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f); - transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 1; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); - } - { - auto wheel = CreateEntity(tank); - auto transform = AddComponent(wheel); - transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f); - auto model = AddComponent(wheel); - model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; - auto Wheel = AddComponent(wheel); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); - Wheel->AxleID = 1; - Wheel->Mass = 2000; - Wheel->Radius = 0.6f; - Wheel->Steering = false; - Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; - Wheel->ConnectedToHandbrake = true; - Wheel->TorqueRatio = 0.125f; - Wheel->Width = 0.6f; - { - auto shape = CreateEntity(wheel); - auto shapetransform = AddComponent(shape); - shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; - auto boxShape = AddComponent(shape); - boxShape->Width = 0.7f; - boxShape->Height = 0.34f; - boxShape->Depth = 0.7f; - CommitEntity(shape); - } - CommitEntity(wheel); -#pragma endregion + float wheelOffset = -0.83f; + const float suspensionStrength = 15.f; + const float springLength = 0.3f; + + AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, -1.715f), 0, true); + AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, -1.715f), 0, true); + AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, 2.375), 1, false); + AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false); #pragma endregion + { auto entity = CreateEntity(tank); auto transformComponent = AddComponent(entity); transformComponent->Position = glm::vec3(-2, -1.7, 2.0); @@ -799,6 +521,115 @@ EntityID GameWorld::CreateTank(int playerID) return tank; } +void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front) +{ + const float separation = 1.77f; + const float suspensionStrength = 15.f; + const float springLength = 0.3f; + + bool steering = front; + + auto wheelFront = CreateEntity(tankEntity); + { + auto transform = AddComponent(wheelFront); + transform->Position = position - glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); + //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); +#ifdef DEBUG + auto model = AddComponent(wheelFront); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; +#endif + auto Wheel = AddComponent(wheelFront); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = axleID; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = steering; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 3.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheelFront); + auto shapetransform = AddComponent(shape); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } + CommitEntity(wheelFront); + } + + auto wheelBack = CreateEntity(tankEntity); + { + auto transform = AddComponent(wheelBack); + transform->Position = position + glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); + //transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); +#ifdef DEBUG + auto model = AddComponent(wheelBack); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; +#endif + auto Wheel = AddComponent(wheelBack); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); + Wheel->AxleID = axleID; + Wheel->Mass = 2000; + Wheel->Radius = 0.6f; + Wheel->Steering = steering; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 3.f; + Wheel->ConnectedToHandbrake = true; + Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheelBack); + auto shapetransform = AddComponent(shape); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } + CommitEntity(wheelBack); + } + + auto wheelPair = CreateEntity(tankEntity); + { + { + auto transform = AddComponent(wheelPair); + transform->Position = position; + //transform->Orientation = glm::quat(glm::vec3(0, glm::pi() / 4.f, 0)); + + auto pair = AddComponent(wheelPair); + pair->FakeWheelFront = wheelFront; + pair->FakeWheelBack = wheelBack; + } + + auto modelEntity = CreateEntity(wheelPair); + { + auto transform = AddComponent(modelEntity); + //transform->Position = glm::vec3(0.f, 0.35f, 0.f); + if (front) + { + transform->Position = glm::vec3(0.f, 0.03f, 0.f); + transform->Orientation = glm::quat(glm::vec3(0, glm::pi(), 0)); + } + else + { + transform->Position = glm::vec3(0.f, 0.17f, 0.f); + transform->Scale = glm::vec3(1.f, 1.2f, 1.2f); + } + + auto model = AddComponent(modelEntity); + model->ModelFile = "Models/Tank/tankWheel.obj"; + } + CommitEntity(modelEntity); + } + CommitEntity(wheelPair); +} + EntityID GameWorld::CreateJeep(int playerID) { auto jeep = CreateEntity(); diff --git a/src/GameWorld.h b/src/GameWorld.h index faf7ec4..aae2472 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -59,9 +59,6 @@ public: void Initialize(); - EntityID CreateTank(int playerID); - EntityID CreateJeep(int playerID); - void RegisterSystems() override; void AddSystems() override; void RegisterComponents() override; @@ -73,6 +70,10 @@ private: void BindMouseButton(int button, std::string command, float value); 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 AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); + EntityID CreateJeep(int playerID); }; #endif // GameWorld_h__ diff --git a/src/Systems/WheelPairSystem.cpp b/src/Systems/WheelPairSystem.cpp index f0cea10..b8b6c4a 100644 --- a/src/Systems/WheelPairSystem.cpp +++ b/src/Systems/WheelPairSystem.cpp @@ -16,20 +16,18 @@ void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID auto transform = m_World->GetComponent(entity); if (!transform) return; - auto transformFake1 = m_World->GetComponent(wheelPair->FakeWheel1); - if (!transformFake1) + auto transformFakeFront = m_World->GetComponent(wheelPair->FakeWheelFront); + if (!transformFakeFront) return; - auto transformFake2 = m_World->GetComponent(wheelPair->FakeWheel2); - if (!transformFake2) + auto transformFakeBack = m_World->GetComponent(wheelPair->FakeWheelBack); + if (!transformFakeBack) return; - glm::vec3 thing = transformFake2->Position - transformFake1->Position; - glm::vec3 forward = glm::normalize(glm::vec3(thing.x, 0, thing.z)); - glm::vec3 up = glm::vec3(0, 1, 0); + glm::vec3 thing = transformFakeBack->Position - transformFakeFront->Position; - float angle = glm::acos(glm::dot(glm::normalize(thing), forward)); - float height = (thing / 2.f).y; + float height = ((transformFakeFront->Position + transformFakeBack->Position) / 2.f).y; + float angle = std::atan2f(thing.y, thing.z); transform->Position.y = height; - //transform->Orientation = glm::quat(glm::vec3()) + transform->Orientation = glm::quat(glm::eulerAngles(transform->Orientation) * glm::vec3(0, 1, 1) + glm::vec3(-angle, 0, 0)); } \ No newline at end of file From ee2f7fcecf8d22189cb6f78b73af9431dd3dfbfd Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 01:11:14 +0200 Subject: [PATCH 11/15] Added some water to see how it looks --- assets | 2 +- src/GameWorld.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/assets b/assets index 74035fa..e7ff07b 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 74035fae2626e2e62f803cd7d9817d1e47353f69 +Subproject commit e7ff07be10092507ff1aff17a3041d4c00aa46e1 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 27fa9fd..c752f4e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -98,6 +98,41 @@ void GameWorld::Initialize() // CommitEntity(ground); //} + { + 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/Ground/WaterPlain0017_6_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/WaterPlain0017_6_S.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 400.f; + + auto physics = AddComponent(water); + physics->Mass = 10; + physics->Static = true; + 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); @@ -107,9 +142,9 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; auto blendmap = AddComponent(ground_middle); blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; - blendmap->TextureBlueNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; - blendmap->TextureBlueNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; blendmap->TextureRepeats = 30.f; From a459a1c69b7099f82b30d5a710fe345a7fe0feba Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 02:03:50 +0200 Subject: [PATCH 12/15] Skybox bugfix --- src/Renderer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index e6aa0ad..f9dbe01 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -392,6 +392,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); + DrawSkybox(); DrawFBOScene(rq.Deferred); /* @@ -593,12 +594,16 @@ void Renderer::Swap() void Renderer::DrawSkybox() { //glBindFramebuffer(GL_FRAMEBUFFER, 0); - //glViewport(0, 0, m_Width, m_Height); - //glScissor(0, 0, m_Width, m_Height); + glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_ShaderProgramSkybox.Bind(); - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * glm::toMat4(glm::inverse(m_Camera->Orientation())); + + //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->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height) * glm::inverse(glm::toMat4(m_Camera->Orientation())); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix)); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_Skybox->Draw(); From ad075f185ee77f7182e0a1cf5204094170b38477 Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 17:12:31 +0200 Subject: [PATCH 13/15] untracked files on deffered_rendering: a459a1c Skybox bugfix --- src/Systems/WheelPairSystem.cpp | 33 +++++++++++++++++++++++++++++++++ src/Systems/WheelPairSystem.h | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/Systems/WheelPairSystem.cpp create mode 100644 src/Systems/WheelPairSystem.h diff --git a/src/Systems/WheelPairSystem.cpp b/src/Systems/WheelPairSystem.cpp new file mode 100644 index 0000000..b8b6c4a --- /dev/null +++ b/src/Systems/WheelPairSystem.cpp @@ -0,0 +1,33 @@ +#include "PrecompiledHeader.h" +#include "WheelPairSystem.h" +#include "World.h" + +void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf) +{ + cf->Register([]() { return new Components::WheelPair(); }); +} + +void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + auto wheelPair = m_World->GetComponent(entity); + if (!wheelPair) + return; + + auto transform = m_World->GetComponent(entity); + if (!transform) + return; + auto transformFakeFront = m_World->GetComponent(wheelPair->FakeWheelFront); + if (!transformFakeFront) + return; + auto transformFakeBack = m_World->GetComponent(wheelPair->FakeWheelBack); + if (!transformFakeBack) + return; + + glm::vec3 thing = transformFakeBack->Position - transformFakeFront->Position; + + float height = ((transformFakeFront->Position + transformFakeBack->Position) / 2.f).y; + float angle = std::atan2f(thing.y, thing.z); + + transform->Position.y = height; + transform->Orientation = glm::quat(glm::eulerAngles(transform->Orientation) * glm::vec3(0, 1, 1) + glm::vec3(-angle, 0, 0)); +} \ No newline at end of file diff --git a/src/Systems/WheelPairSystem.h b/src/Systems/WheelPairSystem.h new file mode 100644 index 0000000..a2bd224 --- /dev/null +++ b/src/Systems/WheelPairSystem.h @@ -0,0 +1,22 @@ +#ifndef Systems_WheelPairSystem_h__ +#define Systems_WheelPairSystem_h__ + +#include "World.h" +#include "System.h" +#include "Components/Transform.h" +#include "Components/WheelPair.h" + +namespace Systems +{ + class WheelPairSystem : public System + { + public: + + WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + void RegisterComponents(ComponentFactory* cf) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + }; +} +#endif // Systems_WheelPairSystem_h__ From 1b252c95e08c87e7135b33dff03bd160153aa33b Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 17:12:31 +0200 Subject: [PATCH 14/15] index on deffered_rendering: a459a1c Skybox bugfix From 2d1d4f02f30938df35b41e9423f9006b129072af Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 23:14:33 +0200 Subject: [PATCH 15/15] Fixed some things in gameworld and added a new skymap. --- src/GameWorld.cpp | 77 +++++++++++++++++++----------- src/GameWorld.h | 1 - src/RenderQueue.h | 18 +++---- src/Renderer.cpp | 19 ++++++-- src/Renderer.h | 3 +- src/Systems/TankSteeringSystem.cpp | 2 +- 6 files changed, 76 insertions(+), 44 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index e3d86ea..09e535c 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -70,26 +70,26 @@ 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->Static = true; - 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 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->Static = true; + 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 road_middle = CreateEntity(); @@ -143,13 +143,10 @@ void GameWorld::Initialize() auto model = AddComponent(water); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; auto blendmap = AddComponent(water); - blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; - blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg"; - blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; - blendmap->TextureBlue = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; - blendmap->TextureRepeats = 400.f; + 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; @@ -327,11 +324,33 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, -15, 0); + transform->Position = glm::vec3(0, -10, 0); auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/leafs/Leafs.obj"; + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + auto physics = AddComponent(tree); + physics->Mass = 100.f; + physics->Static = false; + 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 shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto box = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 2.29552f); + box->Width = 0.296f; + box->Height = 2.511f; + box->Depth = 0.296f; + + CommitEntity(shape); + } CommitEntity(tree); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 3837c77..aae2472 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -34,7 +34,6 @@ #include "Components/Template.h" #include "Components/Transform.h" #include "Components/Viewport.h" -#include "Components/BlendMap.h" #include "Components/Physics.h" #include "Components/SphereShape.h" diff --git a/src/RenderQueue.h b/src/RenderQueue.h index 932dd69..2636f84 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -14,6 +14,9 @@ struct RenderJob { friend class RenderQueue; + glm::mat4 ModelMatrix; + float Depth; + protected: uint64_t Hash; @@ -37,7 +40,6 @@ struct ModelJob : RenderJob GLuint VAO; unsigned int StartIndex; unsigned int EndIndex; - glm::mat4 ModelMatrix; float Transparent; void CalculateHash() override @@ -67,7 +69,6 @@ struct SpriteJob : RenderJob GLuint Texture; glm::vec4 Color; - glm::mat4 ModelMatrix; void CalculateHash() override { @@ -82,31 +83,30 @@ public: void Add(T &job) { job.CalculateHash(); - m_Jobs.push_front(std::shared_ptr(new T(job))); + Jobs.push_front(std::shared_ptr(new T(job))); } void Sort() { - m_Jobs.sort(); + Jobs.sort(); } void Clear() { - m_Jobs.clear(); + Jobs.clear(); } std::forward_list>::const_iterator begin() { - return m_Jobs.begin(); + return Jobs.begin(); } std::forward_list>::const_iterator end() { - return m_Jobs.end(); + return Jobs.end(); } -private: - std::forward_list> m_Jobs; + std::forward_list> Jobs; }; struct RenderQueuePair diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 62626b7..142f7ec 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -18,7 +18,7 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager) CAtt = 1.0f; LAtt = 0.0f; QAtt = 3.0f; - m_ShadowMapRes = 2048*2; + m_ShadowMapRes = 1; m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f); m_SunTarget = glm::vec3(0, 0, 0); m_SunProjection_height = glm::vec2(-40.f, 40.f); @@ -163,7 +163,7 @@ void Renderer::LoadContent() FrameBufferTextures(); m_sphereModel = ResourceManager->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"); - m_Skybox = std::make_shared("Textures/Skybox/Sky34", "jpg"); + m_Skybox = std::make_shared("Textures/Skybox/sky36", "jpg"); } void Renderer::Draw(double dt) @@ -369,6 +369,17 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glDepthMask(GL_TRUE); glEnable(GL_SCISSOR_TEST); + //Sort forward rendering items by z value. + 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::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); + job->Depth = spritePos.z; + } + rq.Forward.Jobs.sort(Renderer::DepthSort); + //DrawShadowMap(rq.Deferred); /* @@ -392,7 +403,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); - //DrawSkybox(); + DrawSkybox(); DrawFBOScene(rq.Deferred); /* @@ -512,6 +523,8 @@ void Renderer::ForwardRendering(RenderQueue &rq) continue; } + + auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { diff --git a/src/Renderer.h b/src/Renderer.h index 445601f..dacc6db 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -201,7 +201,8 @@ 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); } + GLuint CreateQuad(); void DrawDebugShadowMap(); GLuint CreateAABB(); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index cc1008b..af7e41b 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -88,7 +88,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit Events::ApplyPointImpulse ePointImpulse ; ePointImpulse.Entity = entity; ePointImpulse.Position = absoluteTransform.Position; - ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f; + ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f; EventBroker->Publish(ePointImpulse); }