From be90953f2280aef5ecf91976e0cc11a5d19a9a9d Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 24 Apr 2014 23:29:28 +0200 Subject: [PATCH 01/16] Rigidbody position not updating in debug FIXED --- src/Systems/PhysicsSystem.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index b275ad8..b4f8200 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -143,13 +143,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p } else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { - if(m_RigidBodies[entity]->isActive()) - { - hkVector4 position = m_RigidBodies[entity]->getPosition(); - transformComponent->Position = glm::vec3(position(0), position(1), position(2)); - hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); - transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); - } + hkVector4 position = m_RigidBodies[entity]->getPosition(); + transformComponent->Position = glm::vec3(position(0), position(1), position(2)); + hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); + transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); } @@ -271,6 +268,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) { m_PhysicsWorld->addEntity(rigidBody); m_RigidBodies[entity] = rigidBody; + shape->removeReference(); rigidBody->removeReference(); } From c4e127b154ada53860b9fd3f6f07c248e450b6ef Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Thu, 24 Apr 2014 23:30:46 +0200 Subject: [PATCH 02/16] Added VehicleSetup to Physics filter. --- vs11/Returngeance/Returngeance.vcxproj.filters | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index b8f30e6..dfd85bb 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -50,7 +50,9 @@ - + + Physics + @@ -213,7 +215,6 @@ Audio - Physics\Components @@ -226,6 +227,9 @@ Physics\Components + + Physics + From f02954a62c3dc1bf1d6ac72d48eb1fc1213694c4 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 25 Apr 2014 01:05:53 +0200 Subject: [PATCH 03/16] Box and Sphere components renamed to BoxShape and SphereShape --- src/Components/{Box.h => BoxShape.h} | 4 ++-- src/Components/{Sphere.h => SphereShape.h} | 4 ++-- src/GameWorld.cpp | 10 +++------- src/GameWorld.h | 4 ++-- src/Systems/PhysicsSystem.cpp | 12 ++++++------ src/Systems/PhysicsSystem.h | 4 ++-- vs11/Returngeance/Returngeance.vcxproj | 4 ++-- vs11/Returngeance/Returngeance.vcxproj.filters | 12 ++++++------ 8 files changed, 25 insertions(+), 29 deletions(-) rename src/Components/{Box.h => BoxShape.h} (85%) rename src/Components/{Sphere.h => SphereShape.h} (80%) diff --git a/src/Components/Box.h b/src/Components/BoxShape.h similarity index 85% rename from src/Components/Box.h rename to src/Components/BoxShape.h index b9ddea7..dc836ec 100644 --- a/src/Components/Box.h +++ b/src/Components/BoxShape.h @@ -6,9 +6,9 @@ namespace Components { -struct Box : Component +struct BoxShape : Component { - Box() + BoxShape() : Width(1.f), Height(1.f), Depth(1.f){ } float Width; diff --git a/src/Components/Sphere.h b/src/Components/SphereShape.h similarity index 80% rename from src/Components/Sphere.h rename to src/Components/SphereShape.h index 2d089dd..afc717b 100644 --- a/src/Components/Sphere.h +++ b/src/Components/SphereShape.h @@ -6,9 +6,9 @@ namespace Components { -struct Sphere : Component +struct SphereShape : Component { - Sphere() + SphereShape() : Radius(1.f){ } float Radius; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 7926dcb..da3c1c8 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -21,7 +21,7 @@ void GameWorld::Initialize() transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; - auto box = AddComponent(ground, "Box"); + auto box = AddComponent(ground, "BoxShape"); box->Width = 200; box->Height = 5; box->Depth = 200; @@ -41,7 +41,7 @@ void GameWorld::Initialize() auto physics = AddComponent(jeep, "Physics"); physics->Mass = 1200; - auto box = AddComponent(jeep, "Box"); + auto box = AddComponent(jeep, "BoxShape"); box->Width = 1.487f; box->Height = 0.727f; box->Depth = 2.594f; @@ -239,7 +239,7 @@ void GameWorld::Initialize() auto physics = AddComponent(cube, "Physics"); physics->Mass = 100; - auto box = AddComponent(cube, "Box"); + auto box = AddComponent(cube, "BoxShape"); box->Width = 0.5f; box->Height = 0.5f; box->Depth = 0.5f; @@ -266,10 +266,6 @@ void GameWorld::RegisterComponents() { m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); }); m_ComponentFactory.Register("Template", []() { return new Components::Template(); }); - m_ComponentFactory.Register("Sphere", []() { return new Components::Sphere(); }); - m_ComponentFactory.Register("Box", []() { return new Components::Box (); }); - m_ComponentFactory.Register("Vehicle", []() { return new Components::Vehicle(); }); - m_ComponentFactory.Register("Wheel", []() { return new Components::Wheel(); }); } void GameWorld::RegisterSystems() diff --git a/src/GameWorld.h b/src/GameWorld.h index 1e0f4a1..673358c 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -27,8 +27,8 @@ #include "Components/Transform.h" #include "Components/Physics.h" -#include "Components/Sphere.h" -#include "Components/Box.h" +#include "Components/SphereShape.h" +#include "Components/BoxShape.h" #include "Components/Vehicle.h" #include "Components/Wheel.h" diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index b4f8200..1f27e69 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -63,8 +63,8 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) { cf->Register("Physics", []() { return new Components::Physics(); }); - cf->Register("Box", []() { return new Components::Box(); }); - cf->Register("Sphere", []() { return new Components::Sphere(); }); + cf->Register("BoxShape", []() { return new Components::BoxShape(); }); + cf->Register("SphereShape", []() { return new Components::SphereShape(); }); cf->Register("Vehicle", []() { return new Components::Vehicle(); }); cf->Register("Wheel", []() { return new Components::Wheel(); }); } @@ -181,8 +181,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) if (!physicsComponent) return; - auto sphereComponent = m_World->GetComponent(entity, "Sphere"); - auto boxComponent = m_World->GetComponent(entity, "Box"); + auto sphereComponent = m_World->GetComponent(entity, "SphereShape"); + auto boxComponent = m_World->GetComponent(entity, "BoxShape"); hkpConvexShape* shape; @@ -285,8 +285,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent) if (!physicsComponent) return; - auto sphereComponent = m_World->GetComponent(entity, "Sphere"); - auto boxComponent = m_World->GetComponent(entity, "Box"); + auto sphereComponent = m_World->GetComponent(entity, "SphereShape"); + auto boxComponent = m_World->GetComponent(entity, "BoxShape"); hkpConvexShape* shape; diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index f5ca539..5d1af28 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -4,8 +4,8 @@ #include "System.h" #include "Components/Transform.h" #include "Components/Physics.h" -#include "Components/Sphere.h" -#include "Components/Box.h" +#include "Components/BoxShape.h" +#include "Components/SphereShape.h" #include "Components/Vehicle.h" #include "Components/Input.h" diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 65ee872..8d90c02 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -121,7 +121,7 @@ - + @@ -131,7 +131,7 @@ - + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index dfd85bb..9d5ff23 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -215,12 +215,6 @@ Audio - - Physics\Components - - - Physics\Components - Physics\Components @@ -230,6 +224,12 @@ Physics + + Physics\Components + + + Physics\Components + From cb6b0a58d8787dcb35fe2a2b797280d0752f5b85 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Sun, 27 Apr 2014 08:07:18 +0200 Subject: [PATCH 04/16] Resource manager OBJ vs Model conflict fixed --- src/Model.cpp | 2 +- src/Model.h | 2 +- src/OBJ.cpp | 2 +- src/OBJ.h | 4 +++- src/ResourceManager.cpp | 8 ++++---- src/ResourceManager.h | 9 +++++---- src/Util/UnorderedMapPair.h | 20 ++++++++++++++++++++ 7 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/Util/UnorderedMapPair.h diff --git a/src/Model.cpp b/src/Model.cpp index 547e940..753ec65 100755 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -1,7 +1,7 @@ #include "PrecompiledHeader.h" #include "Model.h" -Model::Model(OBJ &obj, ResourceManager* rm) +Model::Model(ResourceManager* rm, OBJ &obj) { OBJ::MaterialInfo* currentMaterial = nullptr; TextureGroup* currentTexGroup = nullptr; diff --git a/src/Model.h b/src/Model.h index 8d94a7d..dcf41d9 100755 --- a/src/Model.h +++ b/src/Model.h @@ -17,7 +17,7 @@ class Model : public Resource { public: - Model(OBJ &obj, ResourceManager* rm); + Model(ResourceManager* rm, OBJ &obj); struct TextureGroup { diff --git a/src/OBJ.cpp b/src/OBJ.cpp index a8b9f03..d8f91bf 100755 --- a/src/OBJ.cpp +++ b/src/OBJ.cpp @@ -9,7 +9,7 @@ bool OBJ::LoadFromFile(std::string filename) std::ifstream file(m_Path.string()); if (!file.is_open()) { - LOG_ERROR("Failed to open .obj \"%s\"", m_Path.string().c_str()); + LOG_ERROR("Failed to open .obj \"%s\": %s", m_Path.string().c_str(), strerror(errno)); return false; } diff --git a/src/OBJ.h b/src/OBJ.h index 2ef10e0..8ae9a32 100755 --- a/src/OBJ.h +++ b/src/OBJ.h @@ -12,7 +12,9 @@ #include #include -class OBJ +#include "ResourceManager.h" + +class OBJ : public Resource { public: struct MaterialInfo diff --git a/src/ResourceManager.cpp b/src/ResourceManager.cpp index 1361c11..b4ff9bd 100644 --- a/src/ResourceManager.cpp +++ b/src/ResourceManager.cpp @@ -16,7 +16,7 @@ Resource* ResourceManager::CreateResource(std::string resourceType, std::string resource->TypeID = GetTypeID(resourceType); resource->ResourceID = GetNewResourceID(resource->TypeID); // Cache - m_ResourceCache[resourceName] = resource; + m_ResourceCache[std::make_pair(resourceType, resourceName)] = resource; return resource; } @@ -28,7 +28,7 @@ void ResourceManager::RegisterType(std::string resourceType, std::function #include +#include "Util/UnorderedMapPair.h" #include "Factory.h" class Resource @@ -28,7 +29,7 @@ public: void Preload(std::string resourceType, std::string resourceName); // Checks if a resource is in cache - bool IsResourceLoaded(std::string resourceName); + bool IsResourceLoaded(std::string resourceType, std::string resourceName); template // Hot-loads a resource and caches it for future use @@ -40,7 +41,7 @@ public: private: std::unordered_map> m_FactoryFunctions; // type -> factory function - std::unordered_map m_ResourceCache; // name -> resource + std::unordered_map, Resource*> m_ResourceCache; // (type, name) -> resource // TODO: Getters for IDs unsigned int m_CurrentResourceTypeID; @@ -60,7 +61,7 @@ private: template T* ResourceManager::Load(std::string resourceType, std::string resourceName) { - auto it = m_ResourceCache.find(resourceName); + auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName)); if (it != m_ResourceCache.end()) return static_cast(it->second); @@ -79,7 +80,7 @@ T* ResourceManager::Load(std::string resourceType, std::string resourceName) template T* ResourceManager::Fetch(std::string resourceName) const { - auto it = m_ResourceCache.find(resourceName); + auto it = m_ResourceCache.find(std::make_pair(resourceType, resourceName)); if (it == m_ResourceCache.end()) { LOG_ERROR("Failed to fetch resource \"%s\": Resource not loaded!", resourceName.c_str()); diff --git a/src/Util/UnorderedMapPair.h b/src/Util/UnorderedMapPair.h new file mode 100644 index 0000000..68d2355 --- /dev/null +++ b/src/Util/UnorderedMapPair.h @@ -0,0 +1,20 @@ +#ifndef Util_UnorderedMapPair_h__ +#define Util_UnorderedMapPair_h__ + +#include + +namespace std +{ + template struct hash> + { + inline size_t operator()(const pair & v) const + { + size_t seed = 0; + boost::hash_combine(seed, v.first); + boost::hash_combine(seed, v.second); + return seed; + } + }; +} + +#endif // Util_UnorderedMapPair_h__ \ No newline at end of file From 720cf3aa8745094c917c10109f4efa126d5aeb5b Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Sun, 27 Apr 2014 08:08:00 +0200 Subject: [PATCH 05/16] Added support for HkpExtendedMeshShape. --- src/Components/MeshShape.h | 17 ++ src/Components/Vehicle.h | 2 +- src/GameWorld.cpp | 135 ++++--------- src/Systems/PhysicsSystem.cpp | 177 ++++++++---------- src/Systems/PhysicsSystem.h | 16 ++ src/Systems/RenderSystem.cpp | 3 +- vs11/Returngeance/Returngeance.vcxproj | 4 +- .../Returngeance/Returngeance.vcxproj.filters | 6 + 8 files changed, 153 insertions(+), 207 deletions(-) create mode 100644 src/Components/MeshShape.h diff --git a/src/Components/MeshShape.h b/src/Components/MeshShape.h new file mode 100644 index 0000000..64084ab --- /dev/null +++ b/src/Components/MeshShape.h @@ -0,0 +1,17 @@ +#ifndef Components_MeshShape_h__ +#define Components_MeshShape_h__ + +#include + +#include "Component.h" + +namespace Components +{ + +struct MeshShape : Component +{ + std::string ResourceName; +}; + +} +#endif // !Components_MeshShape_h__ \ No newline at end of file diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index e61c713..9e4a59e 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -10,7 +10,7 @@ namespace Components struct Vehicle : Component { Vehicle() - : MaxTorque(500.0f), MinRPM(1000.0f), OptimalRPM(5500.0f), MaxRPM(7500.0f), MaxSteeringAngle(35), TopSpeed(50.0f) { } + : MaxTorque(500.0f), MinRPM(800.0f), OptimalRPM(4000.0f), MaxRPM(6000.0f), MaxSteeringAngle(35), TopSpeed(50.0f) { } float MaxTorque; float MinRPM; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 7926dcb..4ca0ac7 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -16,15 +16,14 @@ void GameWorld::Initialize() { auto ground = CreateEntity(); auto transform = AddComponent(ground, "Transform"); - transform->Position = glm::vec3(0, -5, 0); - transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); + transform->Position = glm::vec3(0, 0, 0); + //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; - auto box = AddComponent(ground, "Box"); - box->Width = 200; - box->Height = 5; - box->Depth = 200; + model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; + auto meshShape = AddComponent(ground, "MeshShape"); + meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; @@ -37,16 +36,28 @@ void GameWorld::Initialize() { auto jeep = CreateEntity(); auto transform = AddComponent(jeep, "Transform"); - transform->Position = glm::vec3(0, 2, 0); + transform->Position = glm::vec3(0, 10, 0); auto physics = AddComponent(jeep, "Physics"); - physics->Mass = 1200; - auto box = AddComponent(jeep, "Box"); - box->Width = 1.487f; - box->Height = 0.727f; - box->Depth = 2.594f; + physics->Mass = 800; + + +// auto box = AddComponent(jeep, "Box"); +// box->Width = 1.487f; +// box->Height = 0.727f; +// box->Depth = 2.594f; + + auto meshShape = AddComponent(jeep, "MeshShape"); + meshShape->ResourceName = "Models/JeepV2/Chassi/chassi.OBJ"; + auto vehicle = AddComponent(jeep, "Vehicle"); + auto light = AddComponent(jeep, "PointLight"); + light->Diffuse = glm::vec3(0, 1, 0); + light->constantAttenuation = 0.0005f; + light->linearAttenuation = 0.001f; + light->quadraticAttenuation = 0.001f; + AddComponent(jeep, "Input"); @@ -69,7 +80,6 @@ void GameWorld::Initialize() transform->Position = glm::vec3(0, -0.6577f, 0); auto model = AddComponent(chassis, "Model"); model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ"; - } { @@ -86,7 +96,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.837f; Wheel->Steering = true; Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 4.0f; + Wheel->Friction = 3.0f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -106,7 +116,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.837f; Wheel->Steering = true; Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 4.0f; + Wheel->Friction = 3.0f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -123,8 +133,9 @@ void GameWorld::Initialize() Wheel->Mass = 10; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 4.0f; + Wheel->SuspensionStrength = 20.f; + Wheel->Friction = 3.0f; + Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -141,93 +152,15 @@ void GameWorld::Initialize() Wheel->Mass = 10; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 4.0f; + Wheel->SuspensionStrength = 20.f; + Wheel->Friction = 3.0f; + Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } CommitEntity(jeep); } -/* - - { - // Front Right Wheel - auto ent = CreateEntity(car); - auto transform = AddComponent(ent, "Transform"); - transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5); - transform->Position = glm::vec3(1.1f, -1.5f, -1.3f); - auto Wheel = AddComponent(ent, "Wheel"); - Wheel->Hardpoint = glm::vec3(1.1f, 0.f, -1.3f);// HACK: make into component - Wheel->AxleID = 0; - Wheel->Mass = 10; - Wheel->Radius = 0.5f; - Wheel->Steering = true; - Wheel->SuspensionStrength = 20.f; - auto model = AddComponent(ent, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - CommitEntity(ent); - } - { - // Front Left Wheel - auto ent = CreateEntity(car); - auto transform = AddComponent(ent, "Transform"); - transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5); - transform->Position = glm::vec3(-1.1f, -1.5f, -1.3f); - auto Wheel = AddComponent(ent, "Wheel"); - Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, -1.3f); - Wheel->AxleID = 0; - Wheel->Mass = 10; - Wheel->Radius = 0.5f; - Wheel->Steering = true; - Wheel->SuspensionStrength = 20.f; - auto model = AddComponent(ent, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - CommitEntity(ent); - } - { - // Back Right Wheel - auto ent = CreateEntity(car); - auto transform = AddComponent(ent, "Transform"); - transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5); - transform->Position = glm::vec3(1.1f, -1.5f, 1.3f); - auto Wheel = AddComponent(ent, "Wheel"); - Wheel->Hardpoint = glm::vec3(1.1f, 0.f, 1.3f); - Wheel->AxleID = 1; - Wheel->Mass = 10; - Wheel->Radius = 0.5f; - Wheel->Steering = false; - Wheel->ConnectedToHandbrake = true; - Wheel->SuspensionStrength = 20.f; - auto model = AddComponent(ent, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - CommitEntity(ent); - } - { - // Back Left Wheel - auto ent = CreateEntity(car); - auto transform = AddComponent(ent, "Transform"); - transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5); - transform->Position = glm::vec3(-1.1f, -1.5f, 1.3f); - auto Wheel = AddComponent(ent, "Wheel"); - Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, 1.3f); - Wheel->AxleID = 1; - Wheel->Mass = 10; - Wheel->Radius = 0.5f; - Wheel->Steering = false; - Wheel->ConnectedToHandbrake = true; - Wheel->SuspensionStrength = 20.f; - auto model = AddComponent(ent, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; - CommitEntity(ent); - } - - CommitEntity(car); - } -*/ - - - - for(int i = 0; i < 10; i++) + for(int i = 0; i < 0; i++) { auto cube = CreateEntity(); auto transform = AddComponent(cube, "Transform"); @@ -235,7 +168,7 @@ void GameWorld::Initialize() transform->Scale = glm::vec3(1); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(cube, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; + model->ModelFile = "Models/cardboardBox/BoxFixed.obj"; auto physics = AddComponent(cube, "Physics"); physics->Mass = 100; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index b4f8200..059629c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -67,6 +67,7 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) cf->Register("Sphere", []() { return new Components::Sphere(); }); cf->Register("Vehicle", []() { return new Components::Vehicle(); }); cf->Register("Wheel", []() { return new Components::Wheel(); }); + cf->Register("MeshShape", []() { return new Components::MeshShape(); }); } void Systems::PhysicsSystem::Update(double dt) @@ -183,11 +184,12 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) auto sphereComponent = m_World->GetComponent(entity, "Sphere"); auto boxComponent = m_World->GetComponent(entity, "Box"); + auto meshShapeComponent = m_World->GetComponent(entity, "MeshShape"); - - hkpConvexShape* shape; + hkpShape* shape = nullptr; hkpRigidBodyCinfo rigidBodyInfo; hkMassProperties massProperties; + if (sphereComponent) { @@ -220,16 +222,83 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; } hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties); + + } + else if(meshShapeComponent) + { + std::vector* vertices = new std::vector; + std::vector* vertexIndices = new std::vector; + auto meshShape = m_World->GetResourceManager()->Load("OBJ", meshShapeComponent->ResourceName); + + for (auto &vertex : meshShape->Vertices) + { + hkReal x, y, z; + std::tie(x, y, z) = vertex; + vertices->push_back(x); + vertices->push_back(y); + vertices->push_back(z); + } + + int i = 0; + for (auto &face : meshShape->Faces) + { + for (auto &faceDef : face.Definitions) + { + /*hkReal x, y, z; + std::tie(x, y, z) = meshShape->Vertices.at(faceDef.VertexIndex - 1); + vertices.push_back(x); + vertices.push_back(y); + vertices.push_back(z);*/ + vertexIndices->push_back(faceDef.VertexIndex - 1); + //vertexIndices.push_back(i++); + } + } + + hkpExtendedMeshShape* mesh = new hkpExtendedMeshShape(); + mesh->setRadius( 0.05f); + { + hkpExtendedMeshShape::TrianglesSubpart part; + part.m_numTriangleShapes = meshShape->Faces.size(); + part.m_indexBase = vertexIndices->data(); + part.m_indexStriding = sizeof(hkUint16) * 3; + + part.m_numVertices = vertices->size() / 3; + part.m_vertexBase = vertices->data(); + part.m_vertexStriding = sizeof(hkReal) * 3; + + part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16; + + + + mesh->addTrianglesSubpart(part); + } + + if (physicsComponent->Static) + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; + } + else + { + rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; + } + hkpInertiaTensorComputer::computeShapeVolumeMassProperties(mesh, physicsComponent->Mass, massProperties); + rigidBodyInfo.m_shape = mesh; + m_hkpExtendedMeshShapes[entity].ExtendedMeshShape = mesh; + m_hkpExtendedMeshShapes[entity].VertexIndices = vertexIndices; + m_hkpExtendedMeshShapes[entity].Vertices = vertices; + shape = mesh; } else { return; } + rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; - rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; + //rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; rigidBodyInfo.m_mass = massProperties.m_mass; + // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -271,108 +340,10 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) shape->removeReference(); rigidBody->removeReference(); + + } } -/* - -void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent) -{ - auto transformComponent = m_World->GetComponent(entity, "Transform"); - if (!transformComponent) - return; - - auto physicsComponent = m_World->GetComponent(entity, "Physics"); - if (!physicsComponent) - return; - - auto sphereComponent = m_World->GetComponent(entity, "Sphere"); - auto boxComponent = m_World->GetComponent(entity, "Box"); - - - hkpConvexShape* shape; - hkpRigidBodyCinfo rigidBodyInfo; - hkMassProperties massProperties; - - - if (sphereComponent) - { - shape = new hkpSphereShape(sphereComponent->Radius); - rigidBodyInfo.m_shape = shape; - - if (physicsComponent->Static) - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - } - else - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA; - } - - hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties); - - } - else if (boxComponent) - { - hkReal thickness = 0.05; - shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness)); - rigidBodyInfo.m_shape = shape; - if (physicsComponent->Static) - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - } - else - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; - } - hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties); - } - else - { - return; - } - - rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); - rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; - rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; - rigidBodyInfo.m_mass = massProperties.m_mass; - - // Create RigidBody - hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); - - - auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); - if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end()) - { - VehicleSetup vehicleSetup; - - // Create the basic vehicle. - m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); - vehicleSetup.buildVehicle(m_PhysicsWorld, *m_Vehicles[entity]); - // Add the vehicle's entities and phantoms to the world - m_Vehicles[entity]->addToWorld(m_PhysicsWorld); - - m_RigidBodies[entity] = rigidBody; - - // The vehicle is an action - m_PhysicsWorld->addAction(m_Vehicles[entity]); - - //m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here - - shape->removeReference(); - rigidBody->removeReference(); - } - else - { - m_PhysicsWorld->addEntity(rigidBody); - m_RigidBodies[entity] = rigidBody; - shape->removeReference(); - rigidBody->removeReference(); - } -} -*/ - - - void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent) { diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index f5ca539..e69a38c 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -8,6 +8,8 @@ #include "Components/Box.h" #include "Components/Vehicle.h" #include "Components/Input.h" +#include "Components/MeshShape.h" +#include "OBJ.h" // Math and base include #include @@ -34,6 +36,8 @@ #include #include +#include + #include "Physics/VehicleSetup.h" #include @@ -66,10 +70,22 @@ private: void SetupPhysics(hkpWorld* physicsWorld); std::unordered_map m_RigidBodies; + + std::unordered_map m_Vehicles; std::vector m_Wheels; hkpVehicleInstance* Systems::PhysicsSystem::createVehicle(VehicleSetup& vehicleSetup, hkpRigidBody* chassis); + + + + struct ExtendedShapeData + { + hkpExtendedMeshShape* ExtendedMeshShape; + std::vector* Vertices; + std::vector* VertexIndices; + }; + std::unordered_map m_hkpExtendedMeshShapes; }; } diff --git a/src/Systems/RenderSystem.cpp b/src/Systems/RenderSystem.cpp index fe254f4..60044f8 100755 --- a/src/Systems/RenderSystem.cpp +++ b/src/Systems/RenderSystem.cpp @@ -72,7 +72,8 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf) void Systems::RenderSystem::RegisterResourceTypes(ResourceManager* rm) { - rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(OBJ(resourceName), rm); }); + rm->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load("OBJ", resourceName)); }); + rm->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); }); rm->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); }); } diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 65ee872..3702a27 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -80,7 +80,7 @@ true true true - _CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;_MBCS;HK_CONFIG_SIMD=1;%(PreprocessorDefinitions) Create PrecompiledHeader.h StreamingSIMDExtensions2 @@ -126,6 +126,7 @@ + @@ -162,6 +163,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index dfd85bb..5117384 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -230,6 +230,12 @@ Physics + + Physics\Components + + + Util + From 00d27f0058cbb6873a41d66ebfe89501651cc792 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Mon, 28 Apr 2014 02:06:08 +0200 Subject: [PATCH 06/16] Physics now running on multiple threads --- src/GameWorld.cpp | 86 +++++++++++++--------- src/Systems/PhysicsSystem.cpp | 130 ++++++++++++++++++++++++---------- src/Systems/PhysicsSystem.h | 8 +++ 3 files changed, 156 insertions(+), 68 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index fe71de6..bdf3f29 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -32,6 +32,18 @@ void GameWorld::Initialize() CommitEntity(ground); } + { + auto camera = CreateEntity(); + auto transform = AddComponent(camera, "Transform"); + transform->Position.z = 20.f; + transform->Position.y = 10.f; + transform->Orientation = glm::quat(glm::vec3(-glm::pi() / 8.f, 0.f, 0.f)); + auto cameraComp = AddComponent(camera, "Camera"); + cameraComp->FarClip = 2000.f; + AddComponent(camera, "Input"); + auto freeSteering = AddComponent(camera, "FreeSteering"); + CommitEntity(camera); + } { auto jeep = CreateEntity(); @@ -60,20 +72,6 @@ void GameWorld::Initialize() AddComponent(jeep, "Input"); - - { - auto camera = CreateEntity(); - auto transform = AddComponent(camera, "Transform"); - transform->Position.z = 20.f; - transform->Position.y = 10.f; - transform->Orientation = glm::quat(glm::vec3(-glm::pi() / 8.f, 0.f, 0.f)); - auto cameraComp = AddComponent(camera, "Camera"); - cameraComp->FarClip = 2000.f; - AddComponent(camera, "Input"); - auto freeSteering = AddComponent(camera, "FreeSteering"); - CommitEntity(camera); - } - { auto chassis = CreateEntity(jeep); auto transform = AddComponent(chassis, "Transform"); @@ -160,24 +158,48 @@ void GameWorld::Initialize() CommitEntity(jeep); } - for(int i = 0; i < 0; i++) - { - auto cube = CreateEntity(); - auto transform = AddComponent(cube, "Transform"); - transform->Position = glm::vec3(20, 10 + i*2, 0); - transform->Scale = glm::vec3(1); - transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(cube, "Model"); - model->ModelFile = "Models/cardboardBox/BoxFixed.obj"; - - auto physics = AddComponent(cube, "Physics"); - physics->Mass = 100; - auto box = AddComponent(cube, "BoxShape"); - box->Width = 0.5f; - box->Height = 0.5f; - box->Depth = 0.5f; - CommitEntity(cube); - } + + for (int x = 0; x < 5; x++) + for (int y = 0; y < 5; y++) + { + auto cube = CreateEntity(); + auto transform = AddComponent(cube, "Transform"); + transform->Position = glm::vec3(3 * x + 0.1f + 20.f, 3 * y + 0.1f + 1.f, 0); + transform->Scale = glm::vec3(3); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(cube, "Model"); + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; + + auto physics = AddComponent(cube, "Physics"); + physics->Mass = 100; + auto box = AddComponent(cube, "BoxShape"); + box->Width = 1.5f; + box->Height = 1.5f; + box->Depth = 1.5f; + CommitEntity(cube); + } + + /*for (int x = 0; x < 5; x++) + for (int y = 0; y < 5; y++) + { + auto cube = CreateEntity(); + auto transform = AddComponent(cube, "Transform"); + transform->Position = glm::vec3(3 * x + 0.1f + -20.f, 3 * y + 0.1f + 1.f, 0); + transform->Scale = glm::vec3(3); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(cube, "Model"); + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; + + auto physics = AddComponent(cube, "Physics"); + physics->Mass = 100; + auto box = AddComponent(cube, "BoxShape"); + box->Width = 1.5f; + box->Height = 1.5f; + box->Depth = 1.5f; + CommitEntity(cube); + } +*/ + /*{ auto entity = CreateEntity(); diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 2554d1d..ab19101 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -28,36 +28,81 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) { m_Accumulator = 0; + + hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer + hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); + hkBaseSystem::init(memoryRouter, HavokErrorReport); + + + // Get the number of physical threads available on the system + hkHardwareInfo hwInfo; + hkGetHardwareInfo(hwInfo); + m_TotalNumThreadsUsed = hwInfo.m_numThreads; + + // We use one less than this for our thread pool, because we must also use this thread for our simulation + hkCpuJobThreadPoolCinfo threadPoolCinfo; + threadPoolCinfo.m_numThreads = m_TotalNumThreadsUsed - 1; + + // This line enables timers collection, by allocating 200 Kb per thread. If you leave this at its default (0), + // timer collection will not be enabled. + threadPoolCinfo.m_timerBufferPerThreadAllocation = 200000; + m_ThreadPool = new hkCpuJobThreadPool(threadPoolCinfo); + + hkJobQueueCinfo info; + info.m_jobQueueHwSetup.m_numCpuThreads = m_TotalNumThreadsUsed; + m_JobQueue = new hkJobQueue(info); + + // + // Enable monitors for this thread. + // + + // Monitors have been enabled for thread pool threads already (see above comment). + hkMonitorStream::getInstance().resize(200000); + { - hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer - hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); - hkBaseSystem::init(memoryRouter, HavokErrorReport); - - hkpWorldCinfo worldInfo; + + // Set the simulation type of the world to multi-threaded. + worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED; + worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); - worldInfo.m_gravity = hkVector4(0.0f, -9.8f, 0.0f); - worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far + worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f); + worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY; // just fix the entity if the object falls off too far // You must specify the size of the broad phase - objects should not be simulated outside this region worldInfo.setBroadPhaseWorldSize(1000.0f); m_PhysicsWorld = new hkpWorld(worldInfo); - } - // Register all collision agents, even though only box - box will be used in this particular example. - // It's important to register collision agents before adding any entities to the world. - hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher()); - - // - // Initialize the visual debugger so we can connect remotely to the simulation - // The context must exist beyond the use of the VDB instance, and you can make - // whatever contexts you like for your own viewer types. - // - hkpPhysicsContext* context = new hkpPhysicsContext; - hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers - context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it - SetupVisualDebugger(context); - //SetupPhysics(m_PhysicsWorld); + + + + // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks + // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread + // must call markForRead / markForWrite before it modifies the world to enable these checks. + m_PhysicsWorld->markForWrite(); + + // Register all collision agents, even though only box - box will be used in this particular example. + // It's important to register collision agents before adding any entities to the world. + hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher()); + + // We need to register all modules we will be running multi-threaded with the job queue + m_PhysicsWorld->registerWithJobQueue(m_JobQueue); + + + // + // Initialize the visual debugger so we can connect remotely to the simulation + // The context must exist beyond the use of the VDB instance, and you can make + // whatever contexts you like for your own viewer types. + // + m_Context = new hkpPhysicsContext; + hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers + m_Context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it + + SetupVisualDebugger(m_Context); + + m_PhysicsWorld->unmarkForWrite(); + } + } void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) @@ -86,9 +131,11 @@ void Systems::PhysicsSystem::Update(double dt) if(m_RigidBodies[entity]->isActive()) { + m_PhysicsWorld->markForWrite(); hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); hkQuaternion rotation(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); + m_PhysicsWorld->unmarkForWrite(); } } @@ -100,12 +147,18 @@ void Systems::PhysicsSystem::Update(double dt) m_Accumulator += dt; while (m_Accumulator >= timestep) { - m_PhysicsWorld->stepDeltaTime(timestep); + m_PhysicsWorld->stepMultithreaded(m_JobQueue, m_ThreadPool, timestep); m_Accumulator -= timestep; - } - // Step the visual debugger - StepVisualDebugger(); + m_Context->syncTimers(m_ThreadPool); + // Step the visual debugger + StepVisualDebugger(); + } + + + // Clear accumulated timer data in this thread and all slave threads + hkMonitorStream::getInstance().reset(); + m_ThreadPool->clearTimerData(); } void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -120,6 +173,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p EntityID car = m_World->GetEntityParent(entity); if(m_Vehicles.find(car) != m_Vehicles.end()) { + m_PhysicsWorld->markForWrite(); m_Vehicles[car]->getChassis()->activate(); hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace; @@ -132,22 +186,26 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle; glm::quat orientation = glm::quat(steeringOrientation(3), steeringOrientation(0), steeringOrientation(1), steeringOrientation(2)) * glm::angleAxis(spinAngle, glm::vec3(1, 0, 0)); transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation; + m_PhysicsWorld->unmarkForWrite(); } } else if(m_Vehicles.find(entity) != m_Vehicles.end()) { + m_PhysicsWorld->markForWrite(); hkVector4 position = m_RigidBodies[entity]->getPosition(); transformComponent->Position = glm::vec3(position(0), position(1), position(2)); hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); - transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); - + transformComponent->Orientation = glm::quat(orientation(3), orientation(0), orientation(1), orientation(2)); + m_PhysicsWorld->unmarkForWrite(); } else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { + m_PhysicsWorld->markForWrite(); hkVector4 position = m_RigidBodies[entity]->getPosition(); transformComponent->Position = glm::vec3(position(0), position(1), position(2)); hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); + m_PhysicsWorld->unmarkForWrite(); } @@ -156,10 +214,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p auto inputComponent = m_World->GetComponent(entity, "Input"); if (vehicleComponent && inputComponent) { + m_PhysicsWorld->markForWrite(); hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; deviceStatus->m_positionY = inputComponent->KeyState[GLFW_KEY_UP] * -1 + inputComponent->KeyState[GLFW_KEY_DOWN] * 1; deviceStatus->m_positionX = inputComponent->KeyState[GLFW_KEY_LEFT] * -1 + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1; deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; + m_PhysicsWorld->unmarkForWrite(); } } @@ -244,13 +304,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) { for (auto &faceDef : face.Definitions) { - /*hkReal x, y, z; - std::tie(x, y, z) = meshShape->Vertices.at(faceDef.VertexIndex - 1); - vertices.push_back(x); - vertices.push_back(y); - vertices.push_back(z);*/ vertexIndices->push_back(faceDef.VertexIndex - 1); - //vertexIndices.push_back(i++); } } @@ -315,8 +369,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) i--; } } - VehicleSetup vehicleSetup; + m_PhysicsWorld->markForWrite(); + VehicleSetup vehicleSetup; // Create the basic vehicle. m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels); @@ -327,6 +382,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) // The vehicle is an action m_PhysicsWorld->addAction(m_Vehicles[entity]); + m_PhysicsWorld->unmarkForWrite(); //m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here m_Wheels.clear(); @@ -335,9 +391,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } else { + m_PhysicsWorld->markForWrite(); m_PhysicsWorld->addEntity(rigidBody); m_RigidBodies[entity] = rigidBody; - + m_PhysicsWorld->unmarkForWrite(); + shape->removeReference(); rigidBody->removeReference(); diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index cd02d1d..82a0222 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -38,6 +38,10 @@ #include +#include +#include +#include + #include "Physics/VehicleSetup.h" #include @@ -71,6 +75,10 @@ private: std::unordered_map m_RigidBodies; + hkJobThreadPool* m_ThreadPool; + hkJobQueue* m_JobQueue; + int m_TotalNumThreadsUsed; + hkpPhysicsContext* m_Context; std::unordered_map m_Vehicles; std::vector m_Wheels; From 7e32946173f0151eb912a69cc7d234754e3f7ae8 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Apr 2014 04:00:53 +0200 Subject: [PATCH 07/16] Optimizations --- src/Systems/RenderSystem.cpp | 7 ++++--- src/Systems/TransformSystem.cpp | 31 +++++++++++++++++++++++++++++++ src/Systems/TransformSystem.h | 3 ++- src/World.cpp | 9 +++------ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Systems/RenderSystem.cpp b/src/Systems/RenderSystem.cpp index 60044f8..23c8274 100755 --- a/src/Systems/RenderSystem.cpp +++ b/src/Systems/RenderSystem.cpp @@ -23,10 +23,11 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa auto model = m_World->GetResourceManager()->Load("Model", modelComponent->ModelFile); if (model != nullptr) { - glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); + /*glm::vec3 position = m_TransformSystem->AbsolutePosition(entity); glm::quat orientation = m_TransformSystem->AbsoluteOrientation(entity); - glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity); - m_Renderer->AddModelToDraw(model, position, orientation, scale, modelComponent->Visible, modelComponent->ShadowCaster); + glm::vec3 scale = m_TransformSystem->AbsoluteScale(entity);*/ + Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity); + m_Renderer->AddModelToDraw(model, absoluteTransform.Position, absoluteTransform.Orientation, absoluteTransform.Scale, modelComponent->Visible, modelComponent->ShadowCaster); } } diff --git a/src/Systems/TransformSystem.cpp b/src/Systems/TransformSystem.cpp index 494acd0..383c123 100755 --- a/src/Systems/TransformSystem.cpp +++ b/src/Systems/TransformSystem.cpp @@ -60,3 +60,34 @@ glm::vec3 Systems::TransformSystem::AbsoluteScale(EntityID entity) return absScale; } + +Components::Transform Systems::TransformSystem::AbsoluteTransform(EntityID entity) +{ + glm::vec3 absPosition; + glm::quat absOrientation; + glm::vec3 absScale(1); + + do + { + auto transform = m_World->GetComponent(entity, "Transform"); + entity = m_World->GetEntityParent(entity); + auto transform2 = m_World->GetComponent(entity, "Transform"); + + // Position + if (entity != 0) + absPosition += transform2->Orientation * transform->Position; + else + absPosition += transform->Position; + // Orientation + absOrientation = transform->Orientation * absOrientation; + // Scale + absScale *= transform->Scale; + } while (entity != 0); + + Components::Transform transform; + transform.Position = absPosition; + transform.Orientation = absOrientation; + transform.Scale = absScale; + + return transform; +} diff --git a/src/Systems/TransformSystem.h b/src/Systems/TransformSystem.h index 542000d..754a567 100755 --- a/src/Systems/TransformSystem.h +++ b/src/Systems/TransformSystem.h @@ -15,7 +15,8 @@ public: //void Update(double dt) override; //void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - + + Components::Transform AbsoluteTransform(EntityID entity); glm::vec3 AbsolutePosition(EntityID entity); glm::quat AbsoluteOrientation(EntityID entity); glm::vec3 AbsoluteScale(EntityID entity); diff --git a/src/World.cpp b/src/World.cpp index 0b6a245..6e168c2 100755 --- a/src/World.cpp +++ b/src/World.cpp @@ -22,16 +22,13 @@ EntityID World::GenerateEntityID() void World::RecursiveUpdate(std::shared_ptr system, double dt, EntityID parentEntity) { - for (auto pair : m_EntityParents) + for (auto &pair : m_EntityParents) { EntityID child = pair.first; EntityID parent = pair.second; - if (parent == parentEntity) - { - system->UpdateEntity(dt, child, parent); - RecursiveUpdate(system, dt, child); - } + system->UpdateEntity(dt, child, parent); + //RecursiveUpdate(system, dt, child); } } From 55059c05fed94c1140cde989bca9d1ecb5282960 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 28 Apr 2014 04:56:37 +0200 Subject: [PATCH 08/16] Debugging Optimizations Removed Basic Runtime Checks flag /RTC1 Added Maximize Speed flag /O2 Changed Debug Information Format flag /ZI -> /Zi Added Enable Intrinsic Functions flag /Oi --- vs11/Returngeance/Returngeance.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 77e653e..b78075c 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -53,15 +53,15 @@ Level3 - Disabled - true _WINDOWS;WIN32;_WIN32;_DEBUG;HK_DEBUG;HK_DEBUG_SLOW;_XT_STATICLINK;_CONSOLE;_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH;HK_CONFIG_SIMD=1;DEBUG;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions) Create PrecompiledHeader.h - true MultiThreadedDebugDLL - StreamingSIMDExtensions2 false + Default + ProgramDatabase + MaxSpeed + true true From ed1df6dc60edb0378f6e84e85c83ed4c9879089d Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Mon, 28 Apr 2014 19:51:13 +0200 Subject: [PATCH 09/16] Proper rotation of child physics objects --- src/Components/Vehicle.h | 4 +- src/GameWorld.cpp | 123 +++++++++++++++++++++++----------- src/Physics/VehicleSetup.cpp | 8 +-- src/Renderer.cpp | 2 +- src/Systems/PhysicsSystem.cpp | 89 ++++++++++++++++++------ src/Systems/PhysicsSystem.h | 1 + src/Texture.cpp | 3 + vs11/Returngeance.sln | 3 + 8 files changed, 166 insertions(+), 67 deletions(-) diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 9e4a59e..3892e8f 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -10,7 +10,8 @@ namespace Components struct Vehicle : Component { Vehicle() - : MaxTorque(500.0f), MinRPM(800.0f), OptimalRPM(4000.0f), MaxRPM(6000.0f), MaxSteeringAngle(35), TopSpeed(50.0f) { } + : MaxTorque(1000.0f), MinRPM(1000.0f), OptimalRPM(3000.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(130.0f), + MaxSpeedFullSteeringAngle(40.0f){ } float MaxTorque; float MinRPM; @@ -19,6 +20,7 @@ struct Vehicle : Component // Degrees float MaxSteeringAngle; float TopSpeed; + float MaxSpeedFullSteeringAngle; }; } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index bdf3f29..a120fb8 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -64,37 +64,46 @@ void GameWorld::Initialize() auto vehicle = AddComponent(jeep, "Vehicle"); - auto light = AddComponent(jeep, "PointLight"); - light->Diffuse = glm::vec3(0, 1, 0); - light->constantAttenuation = 0.0005f; - light->linearAttenuation = 0.001f; - light->quadraticAttenuation = 0.001f; - AddComponent(jeep, "Input"); { auto chassis = CreateEntity(jeep); auto transform = AddComponent(chassis, "Transform"); - transform->Position = glm::vec3(0, -0.6577f, 0); + transform->Position = glm::vec3(0, 0, 0); // 0.6577f auto model = AddComponent(chassis, "Model"); model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ"; } + { + auto lightentity = CreateEntity(jeep); + auto transform = AddComponent(lightentity, "Transform"); + transform->Position = glm::vec3(0, 15, 0); + auto light = AddComponent(lightentity, "PointLight"); + light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f); + light->Specular = glm::vec3(1.f); + light->constantAttenuation = 0.3f; + light->linearAttenuation = 0.003f; + light->quadraticAttenuation = 0.002f; + } + + float wheelOffset = -0.2f; + float hardPointOffset = 0.0f; + { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f); + transform->Position = glm::vec3(1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.0f; + Wheel->SuspensionStrength = 50.f; + Wheel->Friction = 3.5f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -102,19 +111,19 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f); + transform->Position = glm::vec3(-1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.0f; + Wheel->SuspensionStrength = 50.f; + Wheel->Friction = 3.5f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -122,17 +131,17 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f); + transform->Position = glm::vec3(0.2726f, 0.2805f + wheelOffset, 1.9307f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); Wheel->AxleID = 1; - Wheel->Mass = 10; + Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 20.f; - Wheel->Friction = 3.0f; + Wheel->SuspensionStrength = 40.f; + Wheel->Friction = 3.5f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -140,44 +149,78 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f); + transform->Position = glm::vec3(-0.2726f, 0.2805f + wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); Wheel->AxleID = 1; - Wheel->Mass = 10; + Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 20.f; - Wheel->Friction = 3.0f; + Wheel->SuspensionStrength = 40.f; + Wheel->Friction = 3.5f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } CommitEntity(jeep); } - - for (int x = 0; x < 5; x++) - for (int y = 0; y < 5; y++) + /* + for(int i = 0; i < 10; i++) { - auto cube = CreateEntity(); - auto transform = AddComponent(cube, "Transform"); - transform->Position = glm::vec3(3 * x + 0.1f + 20.f, 3 * y + 0.1f + 1.f, 0); - transform->Scale = glm::vec3(3); + auto entity = CreateEntity(); + auto transform = AddComponent(entity, "Transform"); + transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f); + transform->Scale = glm::vec3(0); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - auto model = AddComponent(cube, "Model"); - model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; + + std::stringstream ss; + ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj"; - auto physics = AddComponent(cube, "Physics"); + auto model = AddComponent(entity, "Model"); + model->ModelFile = ss.str(); + + auto physics = AddComponent(entity, "Physics"); physics->Mass = 100; - auto box = AddComponent(cube, "BoxShape"); - box->Width = 1.5f; - box->Height = 1.5f; - box->Depth = 1.5f; - CommitEntity(cube); + physics->Static = true; + auto meshShape = AddComponent(entity, "MeshShape"); + meshShape->ResourceName = ss.str(); + + CommitEntity(entity); + }*/ + + { + auto wall = CreateEntity(); + auto transform = AddComponent(wall, "Transform"); + transform->Position = glm::vec3(10, 0, -20); + transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); + + for (int y = 0; y < 10; y++) + { + for (int x = -5; x < 5; x++) + { + auto brick = CreateEntity(wall); + auto transform = AddComponent(brick, "Transform"); + transform->Position = glm::vec3(x + 0.01f, y*0.3f + 0.01f, 0); + transform->Position.x += (y % 2)*0.5f; + transform->Scale = glm::vec3(1, 0.3f, 0.6f); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + auto model = AddComponent(brick, "Model"); + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; + + auto physics = AddComponent(brick, "Physics"); + physics->Mass = 1; + auto box = AddComponent(brick, "BoxShape"); + box->Width = 0.5f; + box->Height = 0.15f; + box->Depth = 0.3f; + CommitEntity(brick); + } } + CommitEntity(wall); + } /*for (int x = 0; x < 5; x++) for (int y = 0; y < 5; y++) diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 1768b1e..5041b9d 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -165,7 +165,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultS // [mph/h] The steering angle decreases linearly // based on your overall max speed of the vehicle. - steering.m_maxSpeedFullSteeringAngle = 70.0f * (1.605f / 3.6f); //MPH???! + steering.m_maxSpeedFullSteeringAngle = vehicleComponent.MaxSpeedFullSteeringAngle; // * (1.605f / 3.6f); //MPH???! for (int i = 0; i < m_Wheels.size(); i++) { @@ -198,8 +198,8 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_gearsRatio.setSize(numberOfGears); transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels); - transmission.m_downshiftRPM = 3500.0f; - transmission.m_upshiftRPM = 6500.0f; + transmission.m_downshiftRPM = 1500.0f; + transmission.m_upshiftRPM = 3500.0f; transmission.m_clutchDelayTime = 0.0f; transmission.m_reverseGearRatio = 1.0f; @@ -267,7 +267,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultA aerodynamics.m_liftCoefficient = -0.3f; // Extra gavity applies in world space (independent of m_chassisCoordinateSystem). - aerodynamics.m_extraGravityws.set(0.0f, -5.0f, 0.0f); + aerodynamics.m_extraGravityws.set(0.0f, -0.982f, 0.0f); // fuck this shit } void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index e7dfed6..6cc7dc2 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -191,7 +191,7 @@ void Renderer::DrawSkybox() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_ShaderProgramSkybox.Bind(); - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(m_Camera->Orientation()); + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(glm::inverse(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(); diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index ab19101..1b8bc81 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -129,21 +129,21 @@ void Systems::PhysicsSystem::Update(double dt) continue; - if(m_RigidBodies[entity]->isActive()) + /*if(m_RigidBodies[entity]->isActive()) { m_PhysicsWorld->markForWrite(); hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); hkQuaternion rotation(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); m_PhysicsWorld->unmarkForWrite(); - } + }*/ } - static const double timestep = 1 / 30.0; + static const double timestep = 1 / 60.0; m_Accumulator += dt; while (m_Accumulator >= timestep) { @@ -189,36 +189,84 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p m_PhysicsWorld->unmarkForWrite(); } } - else if(m_Vehicles.find(entity) != m_Vehicles.end()) - { - m_PhysicsWorld->markForWrite(); - hkVector4 position = m_RigidBodies[entity]->getPosition(); - transformComponent->Position = glm::vec3(position(0), position(1), position(2)); - hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); - transformComponent->Orientation = glm::quat(orientation(3), orientation(0), orientation(1), orientation(2)); - m_PhysicsWorld->unmarkForWrite(); - } else if(m_RigidBodies.find(entity) != m_RigidBodies.end()) { - m_PhysicsWorld->markForWrite(); + auto transformComponentParent = m_World->GetComponent(parent, "Transform"); + //m_PhysicsWorld->markForWrite(); hkVector4 position = m_RigidBodies[entity]->getPosition(); transformComponent->Position = glm::vec3(position(0), position(1), position(2)); + if (transformComponentParent) + { + transformComponent->Position -= transformComponentParent->Position; + transformComponent->Position = transformComponent->Position * transformComponentParent->Orientation; + } hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); - m_PhysicsWorld->unmarkForWrite(); + if (transformComponentParent) + { + transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation); + } + //m_PhysicsWorld->unmarkForWrite(); } // HACK: Vehicle test-controls auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); auto inputComponent = m_World->GetComponent(entity, "Input"); - if (vehicleComponent && inputComponent) + if (vehicleComponent && inputComponent && m_Vehicles.find(entity) != m_Vehicles.end() && m_RigidBodies.find(entity) != m_RigidBodies.end()) { m_PhysicsWorld->markForWrite(); hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; - deviceStatus->m_positionY = inputComponent->KeyState[GLFW_KEY_UP] * -1 + inputComponent->KeyState[GLFW_KEY_DOWN] * 1; - deviceStatus->m_positionX = inputComponent->KeyState[GLFW_KEY_LEFT] * -1 + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1; + + + if(inputComponent->KeyState[GLFW_KEY_UP] != 0 || inputComponent->KeyState[GLFW_KEY_DOWN] != 0) + { + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.05f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.05f; + } + else + { + deviceStatus->m_positionY = 0; + } + + if(deviceStatus->m_positionY > 1) + deviceStatus->m_positionY = 1; + else if(deviceStatus->m_positionY < -1) + deviceStatus->m_positionY = -1; + + + + if(inputComponent->KeyState[GLFW_KEY_LEFT] != 0 || inputComponent->KeyState[GLFW_KEY_RIGHT] != 0) + { + deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * 0.01f + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * 0.01f; + } + else + { + if(deviceStatus->m_positionX > 0) + { + deviceStatus->m_positionX += -1 * 0.01f; + } + else if(deviceStatus->m_positionX < 0) + { + deviceStatus->m_positionX += 1 * 0.01f; + } + } + + if(deviceStatus->m_positionX > 1) + deviceStatus->m_positionX = 1; + else if(deviceStatus->m_positionX < -1) + deviceStatus->m_positionX = -1; + + deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; + + if(inputComponent->KeyState[GLFW_KEY_R]) + { + transformComponent->Position = glm::vec3(0, 10, 0); + transformComponent->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + m_RigidBodies[entity]->setLinearVelocity(hkVector4(0, 0, 0)); + m_RigidBodies[entity]->setAngularVelocity(hkVector4(0, 0, 0)); + } + m_PhysicsWorld->unmarkForWrite(); } } @@ -322,8 +370,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16; - - mesh->addTrianglesSubpart(part); } @@ -347,8 +393,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) return; } - - rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); + auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + rigidBodyInfo.m_position.set(absoluteTransform.Position.x, absoluteTransform.Position.y, absoluteTransform.Position.z); + rigidBodyInfo.m_rotation.set(absoluteTransform.Orientation.x, absoluteTransform.Orientation.y, absoluteTransform.Orientation.z, absoluteTransform.Orientation.w); rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; //rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; rigidBodyInfo.m_mass = massProperties.m_mass; diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 82a0222..bee1039 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -2,6 +2,7 @@ #define PhysicsSystem_h__ #include "System.h" +#include "Systems/TransformSystem.h" #include "Components/Transform.h" #include "Components/Physics.h" #include "Components/BoxShape.h" diff --git a/src/Texture.cpp b/src/Texture.cpp index 49256da..373db0d 100755 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -15,6 +15,9 @@ void Texture::Load(std::string path) } m_Texture = m_TextureCache[path]; + glBindTexture(GL_TEXTURE_2D, m_Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } void Texture::Bind() diff --git a/vs11/Returngeance.sln b/vs11/Returngeance.sln index 10ce52b..8daf9b5 100644 --- a/vs11/Returngeance.sln +++ b/vs11/Returngeance.sln @@ -39,4 +39,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(Performance) = preSolution + HasPerformanceSessions = true + EndGlobalSection EndGlobal From f471d7732f541cc9746ed931cab4f5506ffec3b1 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Tue, 29 Apr 2014 03:47:09 +0200 Subject: [PATCH 10/16] Vehicle tuning --- src/Components/Vehicle.h | 1 + src/GameWorld.cpp | 58 +++++++++++++++++++---------------- src/Physics/VehicleSetup.cpp | 2 +- src/Systems/PhysicsSystem.cpp | 28 ++++++++++------- vs11/Returngeance.sln | 4 ++- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 3892e8f..388d9f2 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -19,6 +19,7 @@ struct Vehicle : Component float MaxRPM; // Degrees float MaxSteeringAngle; + //TopSpeed not working fully yet float TopSpeed; float MaxSpeedFullSteeringAngle; }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index a120fb8..3388729 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -20,10 +20,11 @@ void GameWorld::Initialize() //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground, "Model"); - model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; + model->ModelFile = "Models/TestScene/testScene.obj"; + //model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; auto meshShape = AddComponent(ground, "MeshShape"); - meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; - + //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + meshShape->ResourceName = "Models/TestScene/testScene.obj"; auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; @@ -86,24 +87,26 @@ void GameWorld::Initialize() light->quadraticAttenuation = 0.002f; } - float wheelOffset = -0.2f; - float hardPointOffset = 0.0f; + //Create wheels + float wheelOffset = 0.4f; + float springLength = 0.3f; + float suspensionStrength = 20.f; { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); + transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -111,19 +114,19 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); + transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -131,17 +134,17 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(0.2726f, 0.2805f + wheelOffset, 1.9307f); + transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -149,18 +152,18 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-0.2726f, 0.2805f + wheelOffset, 1.9307f); + transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -191,27 +194,28 @@ void GameWorld::Initialize() CommitEntity(entity); }*/ + for(int i = 0; i < 0; i++) { auto wall = CreateEntity(); auto transform = AddComponent(wall, "Transform"); - transform->Position = glm::vec3(10, 0, -20); - transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); + transform->Position = glm::vec3(10, 0, -20 + (-10 * i)); + //transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); - for (int y = 0; y < 10; y++) + for (int y = 0; y < 15; y++) { for (int x = -5; x < 5; x++) { auto brick = CreateEntity(wall); auto transform = AddComponent(brick, "Transform"); - transform->Position = glm::vec3(x + 0.01f, y*0.3f + 0.01f, 0); + transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, 0); transform->Position.x += (y % 2)*0.5f; - transform->Scale = glm::vec3(1, 0.3f, 0.6f); + transform->Scale = glm::vec3(1, 0.3f, 0.4f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(brick, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; auto physics = AddComponent(brick, "Physics"); - physics->Mass = 1; + physics->Mass = 3; auto box = AddComponent(brick, "BoxShape"); box->Width = 0.5f; box->Height = 0.15f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 5041b9d..2995fd1 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -267,7 +267,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultA aerodynamics.m_liftCoefficient = -0.3f; // Extra gavity applies in world space (independent of m_chassisCoordinateSystem). - aerodynamics.m_extraGravityws.set(0.0f, -0.982f, 0.0f); // fuck this shit + aerodynamics.m_extraGravityws.set(0.0f, -8.0f, 0.0f); // fuck this shit } void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent) diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 1b8bc81..b1d93cd 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -29,7 +29,7 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) { m_Accumulator = 0; - hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer + hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); hkBaseSystem::init(memoryRouter, HavokErrorReport); @@ -143,7 +143,7 @@ void Systems::PhysicsSystem::Update(double dt) - static const double timestep = 1 / 60.0; + static const double timestep = 1 / 30.0; m_Accumulator += dt; while (m_Accumulator >= timestep) { @@ -153,12 +153,14 @@ void Systems::PhysicsSystem::Update(double dt) m_Context->syncTimers(m_ThreadPool); // Step the visual debugger StepVisualDebugger(); + + // Clear accumulated timer data in this thread and all slave threads + hkMonitorStream::getInstance().reset(); + m_ThreadPool->clearTimerData(); } - // Clear accumulated timer data in this thread and all slave threads - hkMonitorStream::getInstance().reset(); - m_ThreadPool->clearTimerData(); + } void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -218,10 +220,9 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p m_PhysicsWorld->markForWrite(); hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; - if(inputComponent->KeyState[GLFW_KEY_UP] != 0 || inputComponent->KeyState[GLFW_KEY_DOWN] != 0) { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.05f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.05f; + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.1f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.1f; } else { @@ -233,21 +234,26 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(deviceStatus->m_positionY < -1) deviceStatus->m_positionY = -1; - + float turningSpeed = 0.02f; if(inputComponent->KeyState[GLFW_KEY_LEFT] != 0 || inputComponent->KeyState[GLFW_KEY_RIGHT] != 0) { - deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * 0.01f + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * 0.01f; + deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * turningSpeed + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * turningSpeed; } else { if(deviceStatus->m_positionX > 0) { - deviceStatus->m_positionX += -1 * 0.01f; + deviceStatus->m_positionX += -1 * turningSpeed; } else if(deviceStatus->m_positionX < 0) { - deviceStatus->m_positionX += 1 * 0.01f; + deviceStatus->m_positionX += 1 * turningSpeed; + } + + if (deviceStatus->m_positionX > -turningSpeed && deviceStatus->m_positionX < turningSpeed) + { + deviceStatus->m_positionX = 0.f; } } diff --git a/vs11/Returngeance.sln b/vs11/Returngeance.sln index 8daf9b5..f834d6d 100644 --- a/vs11/Returngeance.sln +++ b/vs11/Returngeance.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}" EndProject Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}" From dc32316bd744faf8a1fe45ed21ce9f45eea50736 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Tue, 29 Apr 2014 14:21:14 +0200 Subject: [PATCH 11/16] Fixing suspension and car collision shape --- src/GameWorld.cpp | 18 +++++------ src/Systems/PhysicsSystem.cpp | 60 ++++++++++++++++++++++++----------- src/Systems/PhysicsSystem.h | 6 +++- vs11/Returngeance.sln | 7 +--- 4 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 3388729..fc83950 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -20,11 +20,11 @@ void GameWorld::Initialize() //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground, "Model"); - model->ModelFile = "Models/TestScene/testScene.obj"; - //model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; + //model->ModelFile = "Models/TestScene/testScene.obj"; + model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; auto meshShape = AddComponent(ground, "MeshShape"); - //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; - meshShape->ResourceName = "Models/TestScene/testScene.obj"; + meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + //meshShape->ResourceName = "Models/TestScene/testScene.obj"; auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; @@ -49,7 +49,7 @@ void GameWorld::Initialize() { auto jeep = CreateEntity(); auto transform = AddComponent(jeep, "Transform"); - transform->Position = glm::vec3(0, 10, 0); + transform->Position = glm::vec3(0, 15, 0); auto physics = AddComponent(jeep, "Physics"); physics->Mass = 800; @@ -61,7 +61,7 @@ void GameWorld::Initialize() // box->Depth = 2.594f; auto meshShape = AddComponent(jeep, "MeshShape"); - meshShape->ResourceName = "Models/JeepV2/Chassi/chassi.OBJ"; + meshShape->ResourceName = "Models/JeepV2/Chassi/ChassiCollision.obj"; auto vehicle = AddComponent(jeep, "Vehicle"); @@ -72,7 +72,7 @@ void GameWorld::Initialize() auto transform = AddComponent(chassis, "Transform"); transform->Position = glm::vec3(0, 0, 0); // 0.6577f auto model = AddComponent(chassis, "Model"); - model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ"; + model->ModelFile = "Models/JeepV2/Chassi/ChassiCollision.obj"; } { @@ -91,7 +91,7 @@ void GameWorld::Initialize() //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; - float suspensionStrength = 20.f; + float suspensionStrength = 35.f; { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); @@ -194,7 +194,7 @@ void GameWorld::Initialize() CommitEntity(entity); }*/ - for(int i = 0; i < 0; i++) + for(int i = 0; i < 5; i++) { auto wall = CreateEntity(); auto transform = AddComponent(wall, "Transform"); diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index b1d93cd..d59e09d 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -120,6 +120,7 @@ void Systems::PhysicsSystem::Update(double dt) for (auto pair : *m_World->GetEntities()) { EntityID entity = pair.first; + EntityID parent = pair.second; if (m_RigidBodies.find(entity) == m_RigidBodies.end()) continue; @@ -128,22 +129,35 @@ void Systems::PhysicsSystem::Update(double dt) if (!transformComponent) continue; - - /*if(m_RigidBodies[entity]->isActive()) + if(m_RigidBodies[entity]->isActive()) { + + hkVector4 position; + hkQuaternion rotation; + + if (parent) + { + auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + position = hkVector4(absoluteTransform.Position.x, absoluteTransform.Position.y, absoluteTransform.Position.z); + rotation = hkQuaternion(absoluteTransform.Orientation.x, absoluteTransform.Orientation.y, absoluteTransform.Orientation.z, absoluteTransform.Orientation.w); + } + else + { + position = hkVector4(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); + rotation = hkQuaternion(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w); + } m_PhysicsWorld->markForWrite(); - hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); - hkQuaternion rotation(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); m_PhysicsWorld->unmarkForWrite(); - }*/ + + } } - static const double timestep = 1 / 30.0; + static const double timestep = 1 / 60.0; m_Accumulator += dt; while (m_Accumulator >= timestep) { @@ -222,7 +236,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p if(inputComponent->KeyState[GLFW_KEY_UP] != 0 || inputComponent->KeyState[GLFW_KEY_DOWN] != 0) { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.1f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.1f; + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 1.f * dt + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 1.f * dt; } else { @@ -234,24 +248,24 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(deviceStatus->m_positionY < -1) deviceStatus->m_positionY = -1; - float turningSpeed = 0.02f; + float turningSpeed = 3.f; if(inputComponent->KeyState[GLFW_KEY_LEFT] != 0 || inputComponent->KeyState[GLFW_KEY_RIGHT] != 0) { - deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * turningSpeed + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * turningSpeed; + deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * turningSpeed * dt + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * turningSpeed * dt; } else { if(deviceStatus->m_positionX > 0) { - deviceStatus->m_positionX += -1 * turningSpeed; + deviceStatus->m_positionX += -1 * (turningSpeed*2) *dt; } else if(deviceStatus->m_positionX < 0) { - deviceStatus->m_positionX += 1 * turningSpeed; + deviceStatus->m_positionX += 1 * (turningSpeed*2) * dt; } - if (deviceStatus->m_positionX > -turningSpeed && deviceStatus->m_positionX < turningSpeed) + if (deviceStatus->m_positionX > -0.1 && deviceStatus->m_positionX < 0.1) { deviceStatus->m_positionX = 0.f; } @@ -265,9 +279,9 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; - if(inputComponent->KeyState[GLFW_KEY_R]) + if(inputComponent->KeyState[GLFW_KEY_R] && !inputComponent->LastKeyState[GLFW_KEY_R]) { - transformComponent->Position = glm::vec3(0, 10, 0); + transformComponent->Position = transformComponent->Position + glm::vec3(0, 5, 0); transformComponent->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); m_RigidBodies[entity]->setLinearVelocity(hkVector4(0, 0, 0)); m_RigidBodies[entity]->setAngularVelocity(hkVector4(0, 0, 0)); @@ -389,9 +403,18 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } hkpInertiaTensorComputer::computeShapeVolumeMassProperties(mesh, physicsComponent->Mass, massProperties); rigidBodyInfo.m_shape = mesh; - m_hkpExtendedMeshShapes[entity].ExtendedMeshShape = mesh; - m_hkpExtendedMeshShapes[entity].VertexIndices = vertexIndices; - m_hkpExtendedMeshShapes[entity].Vertices = vertices; + m_ExtendedMeshShapes[entity].ExtendedMeshShape = mesh; + m_ExtendedMeshShapes[entity].VertexIndices = vertexIndices; + m_ExtendedMeshShapes[entity].Vertices = vertices; + + hkpMoppCompilerInput mci; + hkpMoppCode* code = hkpMoppUtility::buildCode( mesh, mci ); + hkpMoppBvTreeShape* moppShape = new hkpMoppBvTreeShape(mesh, code); + + m_ExtendedMeshShapes[entity].Code = code; + m_ExtendedMeshShapes[entity].MoppShape = moppShape; + shape = moppShape; + shape = mesh; } else @@ -422,11 +445,12 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) i--; } } - m_PhysicsWorld->markForWrite(); + VehicleSetup vehicleSetup; // Create the basic vehicle. m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); + 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 m_Vehicles[entity]->addToWorld(m_PhysicsWorld); diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index bee1039..6981f3a 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -38,6 +38,8 @@ #include #include +#include +#include #include #include @@ -93,8 +95,10 @@ private: hkpExtendedMeshShape* ExtendedMeshShape; std::vector* Vertices; std::vector* VertexIndices; + hkpMoppCode* Code; + hkpMoppBvTreeShape* MoppShape; }; - std::unordered_map m_hkpExtendedMeshShapes; + std::unordered_map m_ExtendedMeshShapes; }; } diff --git a/vs11/Returngeance.sln b/vs11/Returngeance.sln index f834d6d..10ce52b 100644 --- a/vs11/Returngeance.sln +++ b/vs11/Returngeance.sln @@ -1,8 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 -MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2012 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}" EndProject Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}" @@ -41,7 +39,4 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(Performance) = preSolution - HasPerformanceSessions = true - EndGlobalSection EndGlobal From 469b53c14d18422cbade43fafd50f2484e09e4da Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 6 May 2014 04:46:22 +0200 Subject: [PATCH 12/16] Updated model paths --- src/GameWorld.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index fc83950..8b56f75 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -61,7 +61,7 @@ void GameWorld::Initialize() // box->Depth = 2.594f; auto meshShape = AddComponent(jeep, "MeshShape"); - meshShape->ResourceName = "Models/JeepV2/Chassi/ChassiCollision.obj"; + meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; auto vehicle = AddComponent(jeep, "Vehicle"); @@ -72,7 +72,7 @@ void GameWorld::Initialize() auto transform = AddComponent(chassis, "Transform"); transform->Position = glm::vec3(0, 0, 0); // 0.6577f auto model = AddComponent(chassis, "Model"); - model->ModelFile = "Models/JeepV2/Chassi/ChassiCollision.obj"; + model->ModelFile = "Models/Jeep/Chassi/ChassiCollision.obj"; } { @@ -98,7 +98,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; + model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; @@ -118,7 +118,7 @@ void GameWorld::Initialize() transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; + model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; @@ -136,7 +136,7 @@ void GameWorld::Initialize() auto transform = AddComponent(wheel, "Transform"); transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; + model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; @@ -155,7 +155,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; + model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; From ea69a9345d0230184d23ee45e8ef77f1229de30e Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 7 May 2014 16:21:47 +0200 Subject: [PATCH 13/16] PhysicsSystem redesigned, more work is needed. --- src/Components/ExtendedMeshShape.h | 0 src/Components/HingeConstraint.h | 18 + src/GameWorld.cpp | 46 +- src/GameWorld.h | 1 + src/Physics/VehicleSetup.cpp | 4 +- src/Systems/PhysicsSystem.cpp | 408 ++++++++++-------- src/Systems/PhysicsSystem.h | 34 +- vs11/Returngeance/Returngeance.vcxproj | 2 + .../Returngeance/Returngeance.vcxproj.filters | 6 + 9 files changed, 325 insertions(+), 194 deletions(-) create mode 100644 src/Components/ExtendedMeshShape.h create mode 100644 src/Components/HingeConstraint.h diff --git a/src/Components/ExtendedMeshShape.h b/src/Components/ExtendedMeshShape.h new file mode 100644 index 0000000..e69de29 diff --git a/src/Components/HingeConstraint.h b/src/Components/HingeConstraint.h new file mode 100644 index 0000000..96f0db3 --- /dev/null +++ b/src/Components/HingeConstraint.h @@ -0,0 +1,18 @@ +#ifndef Components_HingeConstraint_h__ +#define Components_HingeConstraint_h__ + +#include "Component.h" + +namespace Components +{ + + struct HingeConstraint : Component + { + EntityID LinkedEntity; + glm::vec3 Pivot; + glm::vec3 Axis; + }; + +} + +#endif // Components_HingeConstraint_h__ diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index fc83950..8c36206 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -22,14 +22,20 @@ void GameWorld::Initialize() auto model = AddComponent(ground, "Model"); //model->ModelFile = "Models/TestScene/testScene.obj"; model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; - auto meshShape = AddComponent(ground, "MeshShape"); - meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; - //meshShape->ResourceName = "Models/TestScene/testScene.obj"; - + auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; physics->Static = true; + + auto groundshape = CreateEntity(ground); + auto transformshape = AddComponent(groundshape, "Transform"); + auto meshShape = AddComponent(groundshape, "MeshShape"); + meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + //meshShape->ResourceName = "Models/TestScene/testScene.obj"; + + + CommitEntity(groundshape); CommitEntity(ground); } @@ -49,11 +55,10 @@ void GameWorld::Initialize() { auto jeep = CreateEntity(); auto transform = AddComponent(jeep, "Transform"); - transform->Position = glm::vec3(0, 15, 0); - + transform->Position = glm::vec3(0, 5, 0); + transform->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(0, 1, 0)); auto physics = AddComponent(jeep, "Physics"); - physics->Mass = 800; - + physics->Mass = 1800; // auto box = AddComponent(jeep, "Box"); // box->Width = 1.487f; @@ -61,7 +66,7 @@ void GameWorld::Initialize() // box->Depth = 2.594f; auto meshShape = AddComponent(jeep, "MeshShape"); - meshShape->ResourceName = "Models/JeepV2/Chassi/ChassiCollision.obj"; + meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; auto vehicle = AddComponent(jeep, "Vehicle"); @@ -72,7 +77,7 @@ void GameWorld::Initialize() auto transform = AddComponent(chassis, "Transform"); transform->Position = glm::vec3(0, 0, 0); // 0.6577f auto model = AddComponent(chassis, "Model"); - model->ModelFile = "Models/JeepV2/Chassi/ChassiCollision.obj"; + model->ModelFile = "Models/Jeep/Chassi/chassi.obj"; } { @@ -98,7 +103,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; + model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; @@ -118,7 +123,7 @@ void GameWorld::Initialize() transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; + model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; @@ -136,7 +141,7 @@ void GameWorld::Initialize() auto transform = AddComponent(wheel, "Transform"); transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; + model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; @@ -155,7 +160,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); - model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; + model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; @@ -167,6 +172,7 @@ void GameWorld::Initialize() Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } + CommitEntity(jeep); } @@ -194,7 +200,7 @@ void GameWorld::Initialize() CommitEntity(entity); }*/ - for(int i = 0; i < 5; i++) + for(int i = 0; i < 1; i++) { auto wall = CreateEntity(); auto transform = AddComponent(wall, "Transform"); @@ -205,7 +211,7 @@ void GameWorld::Initialize() { for (int x = -5; x < 5; x++) { - auto brick = CreateEntity(wall); + auto brick = CreateEntity(); auto transform = AddComponent(brick, "Transform"); transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, 0); transform->Position.x += (y % 2)*0.5f; @@ -216,10 +222,16 @@ void GameWorld::Initialize() auto physics = AddComponent(brick, "Physics"); physics->Mass = 3; - auto box = AddComponent(brick, "BoxShape"); + + + + auto shape = CreateEntity(brick); + auto transformshape = AddComponent(shape, "Transform"); + auto box = AddComponent(shape, "BoxShape"); box->Width = 0.5f; box->Height = 0.15f; box->Depth = 0.3f; + CommitEntity(shape); CommitEntity(brick); } } diff --git a/src/GameWorld.h b/src/GameWorld.h index 673358c..cda5836 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -31,6 +31,7 @@ #include "Components/BoxShape.h" #include "Components/Vehicle.h" #include "Components/Wheel.h" +#include "Components/HingeConstraint.h" class GameWorld : public World { diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 2995fd1..a309824 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -48,7 +48,6 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpV setupWheelCollide(physicsWorld, vehicle, *static_cast(vehicle.m_wheelCollide)); - // // Check that all components are present. // @@ -212,6 +211,9 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_wheelsTorqueRatio[2] = 0.3f; transmission.m_wheelsTorqueRatio[3] = 0.3f; + //transmission.m_wheelsTorqueRatio[4] = 0.1f; + //transmission.m_wheelsTorqueRatio[5] = 0.1f; + // HACK: fix support for more than 4 wheels, m_wheelsTorqueRatio must equal 1 for all wheels transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio( vehicleComponent.TopSpeed, diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index d59e09d..fb54b87 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -67,15 +67,12 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM); worldInfo.m_gravity = hkVector4(0.0f, -9.82f, 0.0f); - worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY; // just fix the entity if the object falls off too far + worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far // You must specify the size of the broad phase - objects should not be simulated outside this region worldInfo.setBroadPhaseWorldSize(1000.0f); m_PhysicsWorld = new hkpWorld(worldInfo); - - - // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread // must call markForRead / markForWrite before it modifies the world to enable these checks. @@ -113,6 +110,7 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) cf->Register("Vehicle", []() { return new Components::Vehicle(); }); cf->Register("Wheel", []() { return new Components::Wheel(); }); cf->Register("MeshShape", []() { return new Components::MeshShape(); }); + cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); }); } void Systems::PhysicsSystem::Update(double dt) @@ -131,20 +129,19 @@ void Systems::PhysicsSystem::Update(double dt) if(m_RigidBodies[entity]->isActive()) { - hkVector4 position; hkQuaternion rotation; if (parent) { auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); - position = hkVector4(absoluteTransform.Position.x, absoluteTransform.Position.y, absoluteTransform.Position.z); - rotation = hkQuaternion(absoluteTransform.Orientation.x, absoluteTransform.Orientation.y, absoluteTransform.Orientation.z, absoluteTransform.Orientation.w); + position = ConvertPosition(absoluteTransform.Position); + rotation = ConvertRotation(absoluteTransform.Orientation); } else { - position = hkVector4(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z); - rotation = hkQuaternion(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w); + position = ConvertPosition(transformComponent->Position); + rotation = ConvertRotation(transformComponent->Orientation); } m_PhysicsWorld->markForWrite(); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); @@ -154,14 +151,13 @@ void Systems::PhysicsSystem::Update(double dt) } - - - static const double timestep = 1 / 60.0; m_Accumulator += dt; while (m_Accumulator >= timestep) { m_PhysicsWorld->stepMultithreaded(m_JobQueue, m_ThreadPool, timestep); + //m_PhysicsWorld->stepDeltaTime(timestep); + m_Accumulator -= timestep; m_Context->syncTimers(m_ThreadPool); @@ -200,7 +196,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace; hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle; - glm::quat orientation = glm::quat(steeringOrientation(3), steeringOrientation(0), steeringOrientation(1), steeringOrientation(2)) * glm::angleAxis(spinAngle, glm::vec3(1, 0, 0)); + glm::quat orientation = ConvertRotation(steeringOrientation) * glm::angleAxis(spinAngle, glm::vec3(1, 0, 0)); transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation; m_PhysicsWorld->unmarkForWrite(); } @@ -208,23 +204,18 @@ 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, "Transform"); - //m_PhysicsWorld->markForWrite(); - hkVector4 position = m_RigidBodies[entity]->getPosition(); - transformComponent->Position = glm::vec3(position(0), position(1), position(2)); + + transformComponent->Position = ConvertPosition(m_RigidBodies[entity]->getPosition()); + transformComponent->Orientation = ConvertRotation(m_RigidBodies[entity]->getRotation()); + // TODO: No support for Scale, MIGHT be possible + if (transformComponentParent) { transformComponent->Position -= transformComponentParent->Position; transformComponent->Position = transformComponent->Position * transformComponentParent->Orientation; - } - hkQuaternion orientation = m_RigidBodies[entity]->getRotation(); - transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); - if (transformComponentParent) - { transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation); } - //m_PhysicsWorld->unmarkForWrite(); } - // HACK: Vehicle test-controls auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); @@ -276,7 +267,6 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(deviceStatus->m_positionX < -1) deviceStatus->m_positionX = -1; - deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; if(inputComponent->KeyState[GLFW_KEY_R] && !inputComponent->LastKeyState[GLFW_KEY_R]) @@ -297,7 +287,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) if (!transformComponent) return; - auto wheelComponent = m_World->GetComponent(entity, "Wheel"); if (wheelComponent) { @@ -306,178 +295,216 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) m_Wheels.push_back(entity); } - auto physicsComponent = m_World->GetComponent(entity, "Physics"); - if (!physicsComponent) - return; + EntityID entityParent = m_World->GetEntityBaseParent(entity); auto sphereComponent = m_World->GetComponent(entity, "SphereShape"); auto boxComponent = m_World->GetComponent(entity, "BoxShape"); auto meshShapeComponent = m_World->GetComponent(entity, "MeshShape"); - - hkpShape* shape = nullptr; - hkpRigidBodyCinfo rigidBodyInfo; - hkMassProperties massProperties; - - if (sphereComponent) - { - shape = new hkpSphereShape(sphereComponent->Radius); - rigidBodyInfo.m_shape = shape; - - if (physicsComponent->Static) - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - } - else - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA; - } - - hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties); - - } - else if (boxComponent) - { - hkReal thickness = 0.05; - shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness)); - rigidBodyInfo.m_shape = shape; - if (physicsComponent->Static) - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - } - else - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; - } - hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties); - - } - else if(meshShapeComponent) - { - std::vector* vertices = new std::vector; - std::vector* vertexIndices = new std::vector; - auto meshShape = m_World->GetResourceManager()->Load("OBJ", meshShapeComponent->ResourceName); - - for (auto &vertex : meshShape->Vertices) - { - hkReal x, y, z; - std::tie(x, y, z) = vertex; - vertices->push_back(x); - vertices->push_back(y); - vertices->push_back(z); - } - - int i = 0; - for (auto &face : meshShape->Faces) - { - for (auto &faceDef : face.Definitions) - { - vertexIndices->push_back(faceDef.VertexIndex - 1); - } - } - - hkpExtendedMeshShape* mesh = new hkpExtendedMeshShape(); - mesh->setRadius( 0.05f); - { - hkpExtendedMeshShape::TrianglesSubpart part; - part.m_numTriangleShapes = meshShape->Faces.size(); - part.m_indexBase = vertexIndices->data(); - part.m_indexStriding = sizeof(hkUint16) * 3; - - part.m_numVertices = vertices->size() / 3; - part.m_vertexBase = vertices->data(); - part.m_vertexStriding = sizeof(hkReal) * 3; - - part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16; - - mesh->addTrianglesSubpart(part); - } - - if (physicsComponent->Static) - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; - } - else - { - rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; - } - hkpInertiaTensorComputer::computeShapeVolumeMassProperties(mesh, physicsComponent->Mass, massProperties); - rigidBodyInfo.m_shape = mesh; - m_ExtendedMeshShapes[entity].ExtendedMeshShape = mesh; - m_ExtendedMeshShapes[entity].VertexIndices = vertexIndices; - m_ExtendedMeshShapes[entity].Vertices = vertices; - - hkpMoppCompilerInput mci; - hkpMoppCode* code = hkpMoppUtility::buildCode( mesh, mci ); - hkpMoppBvTreeShape* moppShape = new hkpMoppBvTreeShape(mesh, code); - - m_ExtendedMeshShapes[entity].Code = code; - m_ExtendedMeshShapes[entity].MoppShape = moppShape; - shape = moppShape; - - shape = mesh; - } - else + if(entityParent == entity && (sphereComponent || boxComponent || meshShapeComponent)) { + LOG_ERROR("Entity: %i , Only the children can have a shapeComponent", entity); return; } - auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); - rigidBodyInfo.m_position.set(absoluteTransform.Position.x, absoluteTransform.Position.y, absoluteTransform.Position.z); - rigidBodyInfo.m_rotation.set(absoluteTransform.Orientation.x, absoluteTransform.Orientation.y, absoluteTransform.Orientation.z, absoluteTransform.Orientation.w); - rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; - //rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; - rigidBodyInfo.m_mass = massProperties.m_mass; - - - // Create RigidBody - hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); - - - auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); - if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end()) + auto physicsComponent = m_World->GetComponent(entity, "Physics"); + if (physicsComponent) { - for (int i = 0; i < m_Wheels.size(); i++) - { - if(m_World->GetEntityParent(m_Wheels[i]) != entity) - { - m_Wheels.erase(m_Wheels.begin() + i); - i--; - } - } + if(entityParent != entity) + { + LOG_ERROR("Entity: %i , Only the baseparent can have a PhysicsComponent", entity); + return; + } - VehicleSetup vehicleSetup; - // Create the basic vehicle. - m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); - 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 - m_Vehicles[entity]->addToWorld(m_PhysicsWorld); + if(! physicsComponent->Static) // Not static + { + hkArray shapeArray; + for (auto &shapeData : m_Shapes[entity]) + { + shapeArray.pushBack(shapeData.Shape); + } - m_RigidBodies[entity] = rigidBody; - // The vehicle is an action - m_PhysicsWorld->addAction(m_Vehicles[entity]); - m_PhysicsWorld->unmarkForWrite(); + // 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 + m_ListShapes[entity] = listShape; + + + ////////////////////////////////// + //******************************// + // Add a hkpBvShape // + //******************************// + ////////////////////////////////// + + // Clean up for less memory usage + m_Shapes.erase(entity); + + hkMassProperties massProperties; + hkpInertiaTensorComputer::computeShapeVolumeMassProperties(listShape, physicsComponent->Mass, massProperties); + + hkpRigidBodyCinfo rigidBodyInfo; + { + rigidBodyInfo.m_shape = listShape; + rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC; + auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + hkVector4 position = ConvertPosition(absoluteTransform.Position); + hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); + rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); + rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3)); + + rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; + //rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER + rigidBodyInfo.m_mass = massProperties.m_mass; + } + // Create RigidBody + hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); + + m_PhysicsWorld->markForWrite(); + m_PhysicsWorld->addEntity(rigidBody); + m_RigidBodies[entity] = rigidBody; + m_PhysicsWorld->unmarkForWrite(); + + listShape->removeReference(); + rigidBody->removeReference(); + } + else // Static + { + // Create the hkpStaticCompoundShape and add the instances. + // "meshShape" should not be modified by the user in any way after adding it as an instance. + hkpStaticCompoundShape* staticCompoundShape = new hkpStaticCompoundShape(); + + for (auto &shapeData : m_Shapes[entity]) + { + + auto childTransformComponent = m_World->GetComponent(shapeData.Entity, "Transform"); + + hkVector4 position = ConvertPosition(childTransformComponent->Position); + hkQuaternion rotation = ConvertRotation(childTransformComponent->Orientation); + hkVector4 scale = ConvertScale(childTransformComponent->Scale); + hkQsTransform transform(position, rotation, scale); + + staticCompoundShape->addInstance(shapeData.Shape, transform); + } + + // This must be called after adding the instances and before using the shape. + staticCompoundShape->bake(); + + m_Shapes.erase(entity); + hkMassProperties massProperties; + hkpInertiaTensorComputer::computeShapeVolumeMassProperties(staticCompoundShape, physicsComponent->Mass, massProperties); + + hkpRigidBodyCinfo rigidBodyInfo; + { + rigidBodyInfo.m_shape = staticCompoundShape; + rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; + auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); + hkVector4 position = ConvertPosition(absoluteTransform.Position); + hkQuaternion rotation = ConvertRotation(absoluteTransform.Orientation); + rigidBodyInfo.m_position.set(position(0), position(1), position(2), position(3)); + rigidBodyInfo.m_rotation.set(rotation(0), rotation(1), rotation(2), rotation(3)); + + rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; + //rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass; //HACK: CENTER OF MASS ALWAYS IN THE CENTER + rigidBodyInfo.m_mass = massProperties.m_mass; + } + // Create RigidBody + hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); + + m_PhysicsWorld->markForWrite(); + m_PhysicsWorld->addEntity(rigidBody); + m_RigidBodies[entity] = rigidBody; + m_PhysicsWorld->unmarkForWrite(); + + staticCompoundShape->removeReference(); + rigidBody->removeReference(); + } - //m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here - m_Wheels.clear(); - shape->removeReference(); - rigidBody->removeReference(); } else { - m_PhysicsWorld->markForWrite(); - m_PhysicsWorld->addEntity(rigidBody); - m_RigidBodies[entity] = rigidBody; - m_PhysicsWorld->unmarkForWrite(); + + //TODO: COMMENT THIS SECTION + if(sphereComponent) + { + hkpSphereShape* sphereShape = new hkpSphereShape(sphereComponent->Radius); + + hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale)); + hkpConvexTransformShape* transformedSphereShape = new hkpConvexTransformShape( sphereShape, transform ); + + m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedSphereShape)); - shape->removeReference(); - rigidBody->removeReference(); + sphereShape->removeReference(); + } + //TODO: COMMENT THIS SECTION + else if(boxComponent) + { + hkReal thickness = 0.05; + hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width, boxComponent->Height, boxComponent->Depth), thickness); + + hkpShapeShrinker* shapeShrinker = new hkpShapeShrinker(); + boxShape = shapeShrinker->shrinkBoxShape(boxShape, thickness, 0); // HACK: Unsure about the 3rd argument + delete shapeShrinker; + + hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale)); + hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform ); + m_Shapes[entityParent].push_back(ShapeArrayData(entity, transformedBoxShape)); + boxShape->removeReference(); + } + else if(meshShapeComponent) + { + std::vector* vertices = new std::vector; + std::vector* vertexIndices = new std::vector; + auto meshShape = m_World->GetResourceManager()->Load("OBJ", meshShapeComponent->ResourceName); + for (auto &vertex : meshShape->Vertices) + { + hkReal x, y, z; + std::tie(x, y, z) = vertex; + vertices->push_back(x); + vertices->push_back(y); + vertices->push_back(z); + } + int i = 0; + for (auto &face : meshShape->Faces) + { + for (auto &faceDef : face.Definitions) + { + vertexIndices->push_back(faceDef.VertexIndex - 1); + } + } + + hkpExtendedMeshShape* mesh = new hkpExtendedMeshShape(); + hkReal thickness = 0.00f; // HACK: Convex radius should be 0 for static shapes and 0.05 for dynamic shapes. + mesh->setRadius(thickness); + { + hkpExtendedMeshShape::TrianglesSubpart part; + part.m_numTriangleShapes = meshShape->Faces.size(); + part.m_indexBase = vertexIndices->data(); + part.m_indexStriding = sizeof(hkUint16) * 3; + + part.m_numVertices = vertices->size() / 3; + part.m_vertexBase = vertices->data(); + part.m_vertexStriding = sizeof(hkReal) * 3; + + part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16; + + mesh->addTrianglesSubpart(part); + } + hkpMoppCompilerInput mci; + hkpMoppCode* code = hkpMoppUtility::buildCode( mesh, mci ); + hkpMoppBvTreeShape* moppShape = new hkpMoppBvTreeShape(mesh, code); + + m_ExtendedMeshShapes[entity].Code = code; + m_ExtendedMeshShapes[entity].MoppShape = moppShape; + m_Shapes[entityParent].push_back(ShapeArrayData(entity, moppShape)); //HACK: Should maybe have transform, not sure yet + } } + + + } void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent) @@ -527,3 +554,34 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*) LOG_INFO("%s", msg); } + +glm::vec3 Systems::PhysicsSystem::ConvertPosition(const hkVector4 &hkPosition) +{ + return glm::vec3(hkPosition(0), hkPosition(1), hkPosition(2)); +} + +const hkVector4& Systems::PhysicsSystem::ConvertPosition(glm::vec3 glmPosition) +{ + return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z ); +} + +glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation) +{ + return glm::quat(hkRotation(3), hkRotation(0), hkRotation(1), hkRotation(2)); +} + +const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation) +{ + return hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w ); +} + +glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale) +{ + return glm::vec3(hkScale(0), hkScale(1), hkScale(2)); +} + +const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale) +{ + return hkVector4(glmScale.x, glmScale.y, glmScale.z); +} + diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 6981f3a..c74a5ec 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -10,6 +10,7 @@ #include "Components/Vehicle.h" #include "Components/Input.h" #include "Components/MeshShape.h" +#include "Components/HingeConstraint.h" #include "OBJ.h" // Math and base include @@ -44,6 +45,13 @@ #include #include #include +#include +#include + +#include +#include +#include +#include #include "Physics/VehicleSetup.h" @@ -75,6 +83,16 @@ private: void StepVisualDebugger(); static void HK_CALL HavokErrorReport(const char* msg, void*); void SetupPhysics(hkpWorld* physicsWorld); + + // Converterfunctions + glm::vec3 ConvertPosition(const hkVector4 &hkPosition); + const hkVector4& ConvertPosition(glm::vec3 glmPosition); + + glm::quat ConvertRotation(const hkQuaternion &hkRotation); + const hkQuaternion& ConvertRotation(glm::quat glmRotation); + + glm::vec3 ConvertScale(const hkVector4 &hkScale); + const hkVector4&ConvertScale(glm::vec3 glmScale); std::unordered_map m_RigidBodies; @@ -88,7 +106,21 @@ private: hkpVehicleInstance* Systems::PhysicsSystem::createVehicle(VehicleSetup& vehicleSetup, hkpRigidBody* chassis); - + + struct ShapeArrayData + { + ShapeArrayData(EntityID entity, hkpShape* shape) + { + Entity = entity; + Shape = shape; + } + EntityID Entity; + hkpShape* Shape; + }; + std::unordered_map> m_Shapes; + std::unordered_map m_ListShapes; + + struct ExtendedShapeData { diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index b78075c..6e66309 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -124,7 +124,9 @@ + + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 4e41278..cf6f009 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -236,6 +236,12 @@ Util + + Physics\Components + + + Physics\Components + From 4c0b465c7f3b9f6287d62179ab0ab2a68ea81aa3 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sat, 10 May 2014 19:13:41 +0200 Subject: [PATCH 14/16] Assets now as Git submodule! (cherry picked from commit 6e6a115ac3ad18184b6bb8d5e0b87ade9e0cd39f) --- .gitignore | 1 - .gitmodules | 4 ++++ assets | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 assets diff --git a/.gitignore b/.gitignore index 4f30c2a..c1454f6 100755 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,4 @@ ipch/ [Rr]elease*/ Ankh.NoLoad -assets/ !libs/*.lib \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..185a1f9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "assets"] + path = assets + url = returngeance@shard.imon.nu:Assets + branch = master diff --git a/assets b/assets new file mode 160000 index 0000000..672e8a2 --- /dev/null +++ b/assets @@ -0,0 +1 @@ +Subproject commit 672e8a2b11ecaafc95a5b0286b5ec310c62438ad From d7e5630f1b3d09386b0221905e4ab5c703696bea Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Sun, 11 May 2014 01:52:00 +0200 Subject: [PATCH 15/16] Tank with 8 wheels --- assets | 2 +- src/Components/Wheel.h | 4 +- src/Components/WheelPair.h | 16 ++ src/GameWorld.cpp | 269 ++++++++++++++++-- src/Physics/VehicleSetup.cpp | 30 +- src/Physics/VehicleSetup.h | 4 +- src/Systems/PhysicsSystem.cpp | 91 ++++-- src/Systems/PhysicsSystem.h | 1 + vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 3 + 10 files changed, 357 insertions(+), 64 deletions(-) create mode 100644 src/Components/WheelPair.h diff --git a/assets b/assets index 672e8a2..8b6c48b 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 672e8a2b11ecaafc95a5b0286b5ec310c62438ad +Subproject commit 8b6c48b26b3bbc10f5e66c1f59fec6ca935f641b diff --git a/src/Components/Wheel.h b/src/Components/Wheel.h index d4917db..533d193 100644 --- a/src/Components/Wheel.h +++ b/src/Components/Wheel.h @@ -14,7 +14,7 @@ struct Wheel : Component Wheel() : AxleID(0), Radius(0), Width(0), Mass(0), Steering(false), DownDirection(glm::vec3(0, -1, 0)), Friction(1.5f), SlipAngle(0.0f), - MaxBreakingTorque(1500.0f), ConnectedToHandbrake(false), SuspensionStrength(50.0f) { } + MaxBreakingTorque(1500.0f), ConnectedToHandbrake(false), SuspensionStrength(50.0f), TorqueRatio(0.25f) { } // The Hardpoint MUST be positioned INSIDE the chassis. glm::vec3 Hardpoint; @@ -30,6 +30,8 @@ struct Wheel : Component float SlipAngle; float MaxBreakingTorque; bool ConnectedToHandbrake; + // The wheels total TorqueRatio must be equal to 1 + float TorqueRatio; private: int ID; diff --git a/src/Components/WheelPair.h b/src/Components/WheelPair.h new file mode 100644 index 0000000..0173e30 --- /dev/null +++ b/src/Components/WheelPair.h @@ -0,0 +1,16 @@ +#ifndef Components_WheelPair_h__ +#define Components_WheelPair_h__ + +#include "Component.h" + +namespace Components +{ + + struct WheelPair : Component + { + // Flag for pair wheels + }; + +} + +#endif // Components_WheelPair_h__ diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 8c36206..ad840a9 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -21,7 +21,7 @@ void GameWorld::Initialize() transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground, "Model"); //model->ModelFile = "Models/TestScene/testScene.obj"; - model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; + model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; @@ -31,7 +31,7 @@ void GameWorld::Initialize() auto groundshape = CreateEntity(ground); auto transformshape = AddComponent(groundshape, "Transform"); auto meshShape = AddComponent(groundshape, "MeshShape"); - meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; //meshShape->ResourceName = "Models/TestScene/testScene.obj"; @@ -52,26 +52,31 @@ void GameWorld::Initialize() CommitEntity(camera); } - { + /*{ auto jeep = CreateEntity(); auto transform = AddComponent(jeep, "Transform"); transform->Position = glm::vec3(0, 5, 0); transform->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(0, 1, 0)); auto physics = AddComponent(jeep, "Physics"); physics->Mass = 1800; - -// auto box = AddComponent(jeep, "Box"); -// box->Width = 1.487f; -// box->Height = 0.727f; -// box->Depth = 2.594f; - - auto meshShape = AddComponent(jeep, "MeshShape"); - meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; - + physics->Static = false; auto vehicle = AddComponent(jeep, "Vehicle"); - AddComponent(jeep, "Input"); + { + auto shape = CreateEntity(jeep); + auto transform = AddComponent(shape, "Transform"); + auto meshShape = AddComponent(shape, "MeshShape"); + meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; + CommitEntity(shape); + + // auto box = AddComponent(jeep, "Box"); + // box->Width = 1.487f; + // box->Height = 0.727f; + // box->Depth = 2.594f; + + } + { auto chassis = CreateEntity(jeep); auto transform = AddComponent(chassis, "Transform"); @@ -174,6 +179,236 @@ void GameWorld::Initialize() } CommitEntity(jeep); + }*/ + + + { + auto tank = CreateEntity(); + auto transform = AddComponent(tank, "Transform"); + transform->Position = glm::vec3(0, 5, 0); + transform->Orientation = glm::angleAxis(glm::pi()/2, glm::vec3(0, 1, 0)); + auto physics = AddComponent(tank, "Physics"); + physics->Mass = 45000; + physics->Static = false; + auto vehicle = AddComponent(tank, "Vehicle"); + vehicle->MaxTorque = 5200.f; + + AddComponent(tank, "Input"); + + { + auto shape = CreateEntity(tank); + auto transform = AddComponent(shape, "Transform"); + auto meshShape = AddComponent(shape, "MeshShape"); + meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj"; + CommitEntity(shape); + + // auto box = AddComponent(jeep, "Box"); + // box->Width = 1.487f; + // box->Height = 0.727f; + // box->Depth = 2.594f; + + } + + { + auto chassis = CreateEntity(tank); + auto transform = AddComponent(chassis, "Transform"); + transform->Position = glm::vec3(0, 0, 0); // 0.6577f + auto model = AddComponent(chassis, "Model"); + model->ModelFile = "Models/Tank/Fix/Chassi.obj"; + } + { + auto top = CreateEntity(tank); + auto transform = AddComponent(top, "Transform"); + transform->Position = glm::vec3(0, 1.2, 1.95); // 0.6577f + auto model = AddComponent(top, "Model"); + model->ModelFile = "Models/Tank/Fix/Top.obj"; + + { + auto top = CreateEntity(tank); + auto transform = AddComponent(top, "Transform"); + transform->Position = glm::vec3(0, 1, 0.5); // 0.6577f + auto model = AddComponent(top, "Model"); + model->ModelFile = "Models/Tank/Fix/Barrel.obj"; + } + } + + { + auto lightentity = CreateEntity(tank); + auto transform = AddComponent(lightentity, "Transform"); + transform->Position = glm::vec3(0, 15, 0); + auto light = AddComponent(lightentity, "PointLight"); + light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f); + light->Specular = glm::vec3(1.f); + light->constantAttenuation = 0.3f; + light->linearAttenuation = 0.003f; + light->quadraticAttenuation = 0.002f; + } + +// auto wheelpair = CreateEntity(tank); +// SetProperty(wheelpair, "Name", "WheelPair"); +// AddComponent(wheelpair, "WheelPairThingy"); + + //Create wheels + float wheelOffset = 0.4f; + float springLength = 0.3f; + float suspensionStrength = 25.f; + + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -2.6f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -0.83f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -2.6f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -0.83f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + + + //Back + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 1.f); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 2.95f); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 1.f); + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + { + auto wheel = CreateEntity(tank); + auto transform = AddComponent(wheel, "Transform"); + transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 2.95f); + auto model = AddComponent(wheel, "Model"); + model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; + auto Wheel = AddComponent(wheel, "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; + CommitEntity(wheel); + } + + CommitEntity(tank); } /* @@ -202,18 +437,13 @@ void GameWorld::Initialize() for(int i = 0; i < 1; i++) { - auto wall = CreateEntity(); - auto transform = AddComponent(wall, "Transform"); - transform->Position = glm::vec3(10, 0, -20 + (-10 * i)); - //transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); - for (int y = 0; y < 15; y++) { for (int x = -5; x < 5; x++) { auto brick = CreateEntity(); auto transform = AddComponent(brick, "Transform"); - transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, 0); + transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, -20); transform->Position.x += (y % 2)*0.5f; transform->Scale = glm::vec3(1, 0.3f, 0.4f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); @@ -235,7 +465,6 @@ void GameWorld::Initialize() CommitEntity(brick); } } - CommitEntity(wall); } /*for (int x = 0; x < 5; x++) diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index a309824..1babfcb 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -197,23 +197,21 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_gearsRatio.setSize(numberOfGears); transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels); - transmission.m_downshiftRPM = 1500.0f; - transmission.m_upshiftRPM = 3500.0f; + transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent + transmission.m_upshiftRPM = 7000.0f; transmission.m_clutchDelayTime = 0.0f; - transmission.m_reverseGearRatio = 1.0f; - transmission.m_gearsRatio[0] = 2.0f; - transmission.m_gearsRatio[1] = 1.5f; - transmission.m_gearsRatio[2] = 1.0f; - transmission.m_gearsRatio[3] = 0.75f; - transmission.m_wheelsTorqueRatio[0] = 0.2f; - transmission.m_wheelsTorqueRatio[1] = 0.2f; - transmission.m_wheelsTorqueRatio[2] = 0.3f; - transmission.m_wheelsTorqueRatio[3] = 0.3f; - - //transmission.m_wheelsTorqueRatio[4] = 0.1f; - //transmission.m_wheelsTorqueRatio[5] = 0.1f; - // HACK: fix support for more than 4 wheels, m_wheelsTorqueRatio must equal 1 for all wheels + transmission.m_reverseGearRatio = 1.2f; + transmission.m_gearsRatio[0] = 3.0f; + transmission.m_gearsRatio[1] = 2.25f; + transmission.m_gearsRatio[2] = 1.5f; + transmission.m_gearsRatio[3] = 1.0f; + + for(int i = 0; i < m_Wheels.size(); i++) + { + // The wheels total TorqueRatio must be equal to 1 + transmission.m_wheelsTorqueRatio[i] = m_Wheels[i].WheelComponent->TorqueRatio; + } transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio( vehicleComponent.TopSpeed, @@ -287,7 +285,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultV // The threshold in m/s at which the algorithm switches from // using the normalSpinDamping to the collisionSpinDamping. - velocityDamper.m_collisionThreshold = 1.0f; + velocityDamper.m_collisionThreshold = 100.0f; } void VehicleSetup::setupWheelCollide(const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide) diff --git a/src/Physics/VehicleSetup.h b/src/Physics/VehicleSetup.h index b54adbd..83647bb 100644 --- a/src/Physics/VehicleSetup.h +++ b/src/Physics/VehicleSetup.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ public: Components::Wheel* WheelComponent; Components::Transform* TransformComponent; }; - + std::vector m_Wheels; virtual void setupVehicleData(const hkpWorld* world, hkpVehicleData& data); @@ -58,6 +59,7 @@ public: virtual void setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent); virtual void setupWheelCollide(const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide); + }; #endif // Physics_Vehicle_h__ diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index fb54b87..9e14054 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -111,6 +111,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) cf->Register("Wheel", []() { return new Components::Wheel(); }); cf->Register("MeshShape", []() { return new Components::MeshShape(); }); cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); }); + cf->Register("WheelPair", []() { return new Components::WheelPair(); }); + } void Systems::PhysicsSystem::Update(double dt) @@ -225,9 +227,14 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p m_PhysicsWorld->markForWrite(); hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; - if(inputComponent->KeyState[GLFW_KEY_UP] != 0 || inputComponent->KeyState[GLFW_KEY_DOWN] != 0) + if(inputComponent->KeyState[GLFW_KEY_UP] != 0) { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 1.f * dt + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 1.f * dt; + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 1.f * dt; + } + else if (inputComponent->KeyState[GLFW_KEY_DOWN] != 0) + { + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 1.f * dt; + deviceStatus->m_reverseButtonPressed = true; } else { @@ -310,7 +317,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) auto physicsComponent = m_World->GetComponent(entity, "Physics"); if (physicsComponent) { - + hkpShape* shape; if(entityParent != entity) { LOG_ERROR("Entity: %i , Only the baseparent can have a PhysicsComponent", entity); @@ -330,7 +337,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT); // Save the listShape for further use m_ListShapes[entity] = listShape; - + shape = listShape; ////////////////////////////////// //******************************// @@ -342,11 +349,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) m_Shapes.erase(entity); hkMassProperties massProperties; - hkpInertiaTensorComputer::computeShapeVolumeMassProperties(listShape, physicsComponent->Mass, massProperties); + hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties); hkpRigidBodyCinfo rigidBodyInfo; { - rigidBodyInfo.m_shape = listShape; + rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_motionType = hkpMotion::MOTION_DYNAMIC; auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); hkVector4 position = ConvertPosition(absoluteTransform.Position); @@ -361,13 +368,48 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); - m_PhysicsWorld->markForWrite(); - m_PhysicsWorld->addEntity(rigidBody); - m_RigidBodies[entity] = rigidBody; - m_PhysicsWorld->unmarkForWrite(); + auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); + if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end()) + { + for (int i = 0; i < m_Wheels.size(); i++) + { + if(m_World->GetEntityParent(m_Wheels[i]) != entity) + { + m_Wheels.erase(m_Wheels.begin() + i); + i--; + } + } - listShape->removeReference(); - rigidBody->removeReference(); + + VehicleSetup vehicleSetup; + // Create the basic vehicle. + m_Vehicles[entity] = new hkpVehicleInstance(rigidBody); + 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 + m_Vehicles[entity]->addToWorld(m_PhysicsWorld); + + m_RigidBodies[entity] = rigidBody; + + // The vehicle is an action + m_PhysicsWorld->addAction(m_Vehicles[entity]); + m_PhysicsWorld->unmarkForWrite(); + + //m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here + m_Wheels.clear(); + shape->removeReference(); + rigidBody->removeReference(); + } + else + { + m_PhysicsWorld->markForWrite(); + m_PhysicsWorld->addEntity(rigidBody); + m_RigidBodies[entity] = rigidBody; + m_PhysicsWorld->unmarkForWrite(); + + shape->removeReference(); + rigidBody->removeReference(); + } } else // Static { @@ -390,14 +432,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) // This must be called after adding the instances and before using the shape. staticCompoundShape->bake(); - + shape = staticCompoundShape; m_Shapes.erase(entity); hkMassProperties massProperties; - hkpInertiaTensorComputer::computeShapeVolumeMassProperties(staticCompoundShape, physicsComponent->Mass, massProperties); + hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, physicsComponent->Mass, massProperties); hkpRigidBodyCinfo rigidBodyInfo; { - rigidBodyInfo.m_shape = staticCompoundShape; + rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; auto absoluteTransform = m_World->GetSystem("TransformSystem")->AbsoluteTransform(entity); hkVector4 position = ConvertPosition(absoluteTransform.Position); @@ -417,8 +459,10 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) m_RigidBodies[entity] = rigidBody; m_PhysicsWorld->unmarkForWrite(); - staticCompoundShape->removeReference(); + shape->removeReference(); rigidBody->removeReference(); + + } } @@ -441,11 +485,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) else if(boxComponent) { hkReal thickness = 0.05; - hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width, boxComponent->Height, boxComponent->Depth), thickness); - - hkpShapeShrinker* shapeShrinker = new hkpShapeShrinker(); - boxShape = shapeShrinker->shrinkBoxShape(boxShape, thickness, 0); // HACK: Unsure about the 3rd argument - delete shapeShrinker; + hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(boxComponent->Width- thickness, boxComponent->Height -thickness, boxComponent->Depth - thickness), thickness); hkQsTransform transform( ConvertPosition(transformComponent->Position), ConvertRotation(transformComponent->Orientation), ConvertScale(transformComponent->Scale)); hkpConvexTransformShape* transformedBoxShape = new hkpConvexTransformShape( boxShape, transform ); @@ -477,7 +517,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) } hkpExtendedMeshShape* mesh = new hkpExtendedMeshShape(); - hkReal thickness = 0.00f; // HACK: Convex radius should be 0 for static shapes and 0.05 for dynamic shapes. + hkReal thickness = 0.05f; // HACK: Convex radius should be 0 for static shapes and 0.05 for dynamic shapes. mesh->setRadius(thickness); { hkpExtendedMeshShape::TrianglesSubpart part; @@ -527,8 +567,9 @@ void Systems::PhysicsSystem::SetupVisualDebugger(hkpPhysicsContext* worlds) { // Setup the visual debugger hkArray contexts; + contexts.pushBack(worlds); - + m_VisualDebugger = new hkVisualDebugger(contexts); m_VisualDebugger->serve(); @@ -562,7 +603,7 @@ glm::vec3 Systems::PhysicsSystem::ConvertPosition(const hkVector4 &hkPosition) const hkVector4& Systems::PhysicsSystem::ConvertPosition(glm::vec3 glmPosition) { - return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z ); + return hkVector4( glmPosition.x, glmPosition.y, glmPosition.z); } glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation) @@ -572,7 +613,7 @@ glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation) { - return hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w ); + return hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w); } glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale) diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index c74a5ec..9ef1260 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -11,6 +11,7 @@ #include "Components/Input.h" #include "Components/MeshShape.h" #include "Components/HingeConstraint.h" +#include "Components/WheelPair.h" #include "OBJ.h" // Math and base include diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 6e66309..bae6084 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -140,6 +140,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index cf6f009..6f29356 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -242,6 +242,9 @@ Physics\Components + + Physics\Components + From 2aa51c3e90a7dcdeeb7071df5d50307050a7dd47 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Mon, 12 May 2014 14:04:55 +0200 Subject: [PATCH 16/16] Tank sterring event-based --- src/Components/TankSteering.h | 14 +++ src/Events/TankSteer.h | 19 ++++ src/GameWorld.cpp | 21 +++-- src/GameWorld.h | 1 + src/Systems/FreeSteeringSystem.cpp | 16 ++-- src/Systems/InputSystem.cpp | 11 +-- src/Systems/InputSystem.h | 2 +- src/Systems/PhysicsSystem.cpp | 88 +++++-------------- src/Systems/PhysicsSystem.h | 5 ++ src/Systems/TankSteeringSystem.cpp | 87 ++++++++++++++++++ src/Systems/TankSteeringSystem.h | 45 ++++++++++ vs11/Returngeance/Returngeance.vcxproj | 4 + .../Returngeance/Returngeance.vcxproj.filters | 19 +++- 13 files changed, 244 insertions(+), 88 deletions(-) create mode 100644 src/Components/TankSteering.h create mode 100644 src/Events/TankSteer.h create mode 100644 src/Systems/TankSteeringSystem.cpp create mode 100644 src/Systems/TankSteeringSystem.h diff --git a/src/Components/TankSteering.h b/src/Components/TankSteering.h new file mode 100644 index 0000000..963d81c --- /dev/null +++ b/src/Components/TankSteering.h @@ -0,0 +1,14 @@ +#ifndef TankSteering_h__ +#define TankSteering_h__ + +#include "Component.h" + +namespace Components +{ + struct TankSteering : Component + { + + }; +} + +#endif // TankSteering_h__ \ No newline at end of file diff --git a/src/Events/TankSteer.h b/src/Events/TankSteer.h new file mode 100644 index 0000000..3ee6dc9 --- /dev/null +++ b/src/Events/TankSteer.h @@ -0,0 +1,19 @@ +#ifndef Events_TankSteer_h__ +#define Events_TankSteer_h__ +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + +struct TankSteer : Event +{ + EntityID Entity; + float PositionX; + float PositionY; + bool Handbrake; +}; + +} + +#endif // Events_TankSteer_h__ \ No newline at end of file diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 4744912..979376b 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -12,7 +12,9 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_S, "+backward"); BindKey(GLFW_KEY_A, "+left"); BindKey(GLFW_KEY_D, "+right"); - BindKey(GLFW_KEY_SPACE, "+up"); + BindKey(GLFW_KEY_SPACE, "+handbrake"); + + BindKey(GLFW_KEY_Q, "+up"); BindKey(GLFW_KEY_LEFT_CONTROL, "+down"); BindKey(GLFW_KEY_LEFT_ALT, "+slow"); BindKey(GLFW_KEY_LEFT_SHIFT, "+fast"); @@ -20,6 +22,12 @@ void GameWorld::Initialize() BindMouseButton(GLFW_MOUSE_BUTTON_2, "+attack2"); BindMouseButton(GLFW_MOUSE_BUTTON_3, "+attack3"); + + BindKey(GLFW_KEY_UP, "+cam_forward"); + BindKey(GLFW_KEY_DOWN, "+cam_backward"); + BindKey(GLFW_KEY_LEFT, "+cam_right"); + BindKey(GLFW_KEY_RIGHT, "+cam_left"); + RegisterComponents(); { @@ -214,7 +222,7 @@ void GameWorld::Initialize() physics->Static = false; auto vehicle = AddComponent(tank, "Vehicle"); vehicle->MaxTorque = 5200.f; - + AddComponent(tank, "TankSteering"); AddComponent(tank, "Input"); { @@ -542,11 +550,11 @@ void GameWorld::RegisterSystems() //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); ////m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); //m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); - m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this); }); - m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); - m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this); }); - m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); }); m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); }); + m_SystemFactory.Register("TankSteeringSystem", [this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); }); + m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this, m_EventBroker); }); + m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this, m_EventBroker); }); + m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); }); } void GameWorld::AddSystems() @@ -559,6 +567,7 @@ void GameWorld::AddSystems() ////AddSystem("ParticleSystem"); //AddSystem("PlayerSystem"); AddSystem("FreeSteeringSystem"); + AddSystem("TankSteeringSystem"); AddSystem("SoundSystem"); AddSystem("PhysicsSystem"); AddSystem("RenderSystem"); diff --git a/src/GameWorld.h b/src/GameWorld.h index 6c03eb7..6e9c9e4 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -12,6 +12,7 @@ //#include "Systems/ParticleSystem.h" //#include "Systems/PlayerSystem.h" #include "Systems/FreeSteeringSystem.h" +#include "Systems/TankSteeringSystem.h" #include "Systems/RenderSystem.h" #include "Systems/SoundSystem.h" #include "Systems/PhysicsSystem.h" diff --git a/src/Systems/FreeSteeringSystem.cpp b/src/Systems/FreeSteeringSystem.cpp index b382b23..8373c80 100755 --- a/src/Systems/FreeSteeringSystem.cpp +++ b/src/Systems/FreeSteeringSystem.cpp @@ -38,35 +38,35 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event) { // Movement - if (event.Command == "+forward") + if (event.Command == "+cam_forward") { Movement.z += -1.f; } - else if (event.Command == "-forward") + else if (event.Command == "-cam_forward") { Movement.z -= -1.f; } - else if (event.Command == "+backward") + else if (event.Command == "+cam_backward") { Movement.z += 1.f; } - else if (event.Command == "-backward") + else if (event.Command == "-cam_backward") { Movement.z -= 1.f; } - else if (event.Command == "+right") + else if (event.Command == "+cam_right") { Movement.x += 1.f; } - else if (event.Command == "-right") + else if (event.Command == "-cam_right") { Movement.x -= 1.f; } - else if (event.Command == "+left") + else if (event.Command == "+cam_left") { Movement.x += -1.f; } - else if (event.Command == "-left") + else if (event.Command == "-cam_left") { Movement.x -= -1.f; } diff --git a/src/Systems/InputSystem.cpp b/src/Systems/InputSystem.cpp index 3c9fdfd..18a21aa 100755 --- a/src/Systems/InputSystem.cpp +++ b/src/Systems/InputSystem.cpp @@ -44,7 +44,7 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event) auto bindingIt = m_KeyBindings.find(event.KeyCode); if (bindingIt != m_KeyBindings.end()) { - PublishCommand(0, bindingIt->second, false); + PublishCommand(0, bindingIt->second, 1.f, false); } return true; @@ -55,7 +55,7 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event) auto bindingIt = m_KeyBindings.find(event.KeyCode); if (bindingIt != m_KeyBindings.end()) { - PublishCommand(0, bindingIt->second, true); + PublishCommand(0, bindingIt->second, 1.f, true); } return true; @@ -66,7 +66,7 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event) auto bindingIt = m_MouseButtonBindings.find(event.Button); if (bindingIt != m_MouseButtonBindings.end()) { - PublishCommand(0, bindingIt->second, false); + PublishCommand(0, bindingIt->second, 1.f, false); } return true; @@ -77,7 +77,7 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event) auto bindingIt = m_MouseButtonBindings.find(event.Button); if (bindingIt != m_MouseButtonBindings.end()) { - PublishCommand(0, bindingIt->second, true); + PublishCommand(0, bindingIt->second, 1.f, true); } return true; @@ -113,7 +113,7 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even return true; } -void Systems::InputSystem::PublishCommand(int playerID, std::string command, bool release /*= false*/) +void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value, bool release /*= false*/) { if (release && command.at(0) == '+') { @@ -123,6 +123,7 @@ void Systems::InputSystem::PublishCommand(int playerID, std::string command, boo Events::InputCommand e; e.PlayerID = playerID; e.Command = command; + e.Value = value; EventBroker->Publish(e); LOG_DEBUG("Input: Published command %s for player %i", e.Command.c_str(), playerID); diff --git a/src/Systems/InputSystem.h b/src/Systems/InputSystem.h index c56cccf..f912de0 100755 --- a/src/Systems/InputSystem.h +++ b/src/Systems/InputSystem.h @@ -48,7 +48,7 @@ private: EventRelay m_EBindMouseButton; bool OnBindMouseButton(const Events::BindMouseButton &event); - void PublishCommand(int playerID, std::string command, bool release = false); + void PublishCommand(int playerID, std::string command, float value, bool release = false); }; } diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 2000a3c..5fad34c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -28,6 +28,9 @@ void Systems::PhysicsSystem::Initialize() { m_Accumulator = 0; + + // Events + EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer); hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); @@ -219,73 +222,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p } } - // HACK: Vehicle test-controls - auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); - auto inputComponent = m_World->GetComponent(entity, "Input"); - if (vehicleComponent && inputComponent && m_Vehicles.find(entity) != m_Vehicles.end() && m_RigidBodies.find(entity) != m_RigidBodies.end()) - { - m_PhysicsWorld->markForWrite(); - hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; - - if(inputComponent->KeyState[GLFW_KEY_UP] != 0) - { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 1.f * dt; - } - else if (inputComponent->KeyState[GLFW_KEY_DOWN] != 0) - { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 1.f * dt; - deviceStatus->m_reverseButtonPressed = true; - } - else - { - deviceStatus->m_positionY = 0; - } - - if(deviceStatus->m_positionY > 1) - deviceStatus->m_positionY = 1; - else if(deviceStatus->m_positionY < -1) - deviceStatus->m_positionY = -1; - - float turningSpeed = 3.f; - - if(inputComponent->KeyState[GLFW_KEY_LEFT] != 0 || inputComponent->KeyState[GLFW_KEY_RIGHT] != 0) - { - deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * turningSpeed * dt + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * turningSpeed * dt; - } - else - { - if(deviceStatus->m_positionX > 0) - { - deviceStatus->m_positionX += -1 * (turningSpeed*2) *dt; - } - else if(deviceStatus->m_positionX < 0) - { - deviceStatus->m_positionX += 1 * (turningSpeed*2) * dt; - } - - if (deviceStatus->m_positionX > -0.1 && deviceStatus->m_positionX < 0.1) - { - deviceStatus->m_positionX = 0.f; - } - } - - if(deviceStatus->m_positionX > 1) - deviceStatus->m_positionX = 1; - else if(deviceStatus->m_positionX < -1) - deviceStatus->m_positionX = -1; - - deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; - - if(inputComponent->KeyState[GLFW_KEY_R] && !inputComponent->LastKeyState[GLFW_KEY_R]) - { - transformComponent->Position = transformComponent->Position + glm::vec3(0, 5, 0); - transformComponent->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - m_RigidBodies[entity]->setLinearVelocity(hkVector4(0, 0, 0)); - m_RigidBodies[entity]->setAngularVelocity(hkVector4(0, 0, 0)); - } - - m_PhysicsWorld->unmarkForWrite(); - } + } void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) @@ -626,3 +563,20 @@ const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale) return hkVector4(glmScale.x, glmScale.y, glmScale.z); } +bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) +{ + auto vehicleComponent = m_World->GetComponent(event.Entity, "Vehicle"); + auto inputComponent = m_World->GetComponent(event.Entity, "Input"); + if (vehicleComponent && inputComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) + { + m_PhysicsWorld->markForWrite(); + hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus; + deviceStatus->m_positionX = event.PositionX; + deviceStatus->m_positionY = event.PositionY; + deviceStatus->m_handbrakeButtonPressed = event.Handbrake; + m_PhysicsWorld->unmarkForWrite(); + } + + return true; +} + diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 7592a7b..b8fc262 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -12,6 +12,7 @@ #include "Components/MeshShape.h" #include "Components/HingeConstraint.h" #include "Components/WheelPair.h" +#include "Events/TankSteer.h" #include "OBJ.h" // Math and base include @@ -79,6 +80,10 @@ private: double m_Accumulator; hkpWorld* m_PhysicsWorld; + // Events + EventRelay m_ETankSteer; + bool OnTankSteer(const Events::TankSteer &event); + void SetUpPhysicsState(EntityID entity, EntityID parent); void TearDownPhysicsState(EntityID entity, EntityID parent); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp new file mode 100644 index 0000000..f0a4e30 --- /dev/null +++ b/src/Systems/TankSteeringSystem.cpp @@ -0,0 +1,87 @@ +#include "PrecompiledHeader.h" +#include "TankSteeringSystem.h" +#include "World.h" + +void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf ) +{ + cf->Register("TankSteering", []() { return new Components::TankSteering(); }); +} + +void Systems::TankSteeringSystem::Initialize() +{ + m_InputController = std::unique_ptr(new TankSteeringInputController(EventBroker)); + m_InputController->PositionX = 0; + m_InputController->PositionY = 0; + m_InputController->Handbrake = false; +} + +void Systems::TankSteeringSystem::Update(double dt) +{ + +} + +void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + auto tankSteeringComponent = m_World->GetComponent(entity, "TankSteering"); + if(tankSteeringComponent) + { + Events::TankSteer e; + e.Entity = entity; + e.PositionX = m_InputController->PositionX; + e.PositionY = m_InputController->PositionY; + e.Handbrake = m_InputController->Handbrake; + EventBroker->Publish(e); + } +} + +bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event) +{ + float val = boost::any_cast(event.Value); + if (event.Command == "+right") + { + PositionX += val; + } + else if (event.Command == "-right") + { + PositionX -= val; + } + else if (event.Command == "+left") + { + PositionX += -val; + } + else if (event.Command == "-left") + { + PositionX -= -val; + } + else if (event.Command == "+forward") + { + PositionY += -val; + } + else if (event.Command == "-forward") + { + PositionY -= -val; + } + else if (event.Command == "+backward") + { + PositionY += val; + } + else if (event.Command == "-backward") + { + PositionY -= val; + } + + else if (event.Command == "+handbrake") + { + Handbrake = true; + } + else if (event.Command == "-handbrake") + { + Handbrake = false; + } + return true; +} + +bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event ) +{ + return false; +} diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h new file mode 100644 index 0000000..5c7a02e --- /dev/null +++ b/src/Systems/TankSteeringSystem.h @@ -0,0 +1,45 @@ +#include + +#include "System.h" +#include "Events/TankSteer.h" +#include "Components/Transform.h" +#include "Components/TankSteering.h" +#include "Components/Vehicle.h" +#include "InputController.h" + +namespace Systems +{ + + class TankSteeringSystem : public System + { + public: + TankSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker) + : System(world, eventBroker) { } + + void RegisterComponents(ComponentFactory* cf) override; + void Initialize() override; + + void Update(double dt) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + + private: + class TankSteeringInputController; + std::unique_ptr m_InputController; + }; + + class TankSteeringSystem::TankSteeringInputController : InputController + { + public: + TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) + : InputController(eventBroker) { } + + float PositionY; + float PositionX; + bool Handbrake; + + protected: + virtual bool OnCommand(const Events::InputCommand &event); + virtual bool OnMouseMove(const Events::MouseMove &event); + }; + +} \ No newline at end of file diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index ac4c36b..47fff50 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -115,6 +115,7 @@ + @@ -138,6 +139,7 @@ + @@ -155,6 +157,7 @@ + @@ -179,6 +182,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 169f797..8b1f1a3 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -57,6 +57,9 @@ Input + + Physics\Systems + @@ -128,6 +131,9 @@ {ee125b77-b275-4841-abc9-374957a89916} + + {42ae084f-ade8-402c-87ba-f03f6b846bc8} + @@ -228,7 +234,6 @@ Audio - Physics\Components @@ -305,6 +310,18 @@ GUI + + Physics + + + Physics\Components + + + Physics\Events + + + Physics\Systems +