Fixing suspension and car collision shape
This commit is contained in:
+9
-9
@@ -20,11 +20,11 @@ void GameWorld::Initialize()
|
|||||||
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
|
//transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
auto model = AddComponent<Components::Model>(ground, "Model");
|
auto model = AddComponent<Components::Model>(ground, "Model");
|
||||||
model->ModelFile = "Models/TestScene/testScene.obj";
|
//model->ModelFile = "Models/TestScene/testScene.obj";
|
||||||
//model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj";
|
model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj";
|
||||||
auto meshShape = AddComponent<Components::MeshShape>(ground, "MeshShape");
|
auto meshShape = AddComponent<Components::MeshShape>(ground, "MeshShape");
|
||||||
//meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj";
|
meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj";
|
||||||
meshShape->ResourceName = "Models/TestScene/testScene.obj";
|
//meshShape->ResourceName = "Models/TestScene/testScene.obj";
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
||||||
physics->Mass = 10;
|
physics->Mass = 10;
|
||||||
@@ -49,7 +49,7 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto jeep = CreateEntity();
|
auto jeep = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
||||||
transform->Position = glm::vec3(0, 10, 0);
|
transform->Position = glm::vec3(0, 15, 0);
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
|
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
|
||||||
physics->Mass = 800;
|
physics->Mass = 800;
|
||||||
@@ -61,7 +61,7 @@ void GameWorld::Initialize()
|
|||||||
// box->Depth = 2.594f;
|
// box->Depth = 2.594f;
|
||||||
|
|
||||||
auto meshShape = AddComponent<Components::MeshShape>(jeep, "MeshShape");
|
auto meshShape = AddComponent<Components::MeshShape>(jeep, "MeshShape");
|
||||||
meshShape->ResourceName = "Models/JeepV2/Chassi/chassi.OBJ";
|
meshShape->ResourceName = "Models/JeepV2/Chassi/ChassiCollision.obj";
|
||||||
|
|
||||||
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ void GameWorld::Initialize()
|
|||||||
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
||||||
transform->Position = glm::vec3(0, 0, 0); // 0.6577f
|
transform->Position = glm::vec3(0, 0, 0); // 0.6577f
|
||||||
auto model = AddComponent<Components::Model>(chassis, "Model");
|
auto model = AddComponent<Components::Model>(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
|
//Create wheels
|
||||||
float wheelOffset = 0.4f;
|
float wheelOffset = 0.4f;
|
||||||
float springLength = 0.3f;
|
float springLength = 0.3f;
|
||||||
float suspensionStrength = 20.f;
|
float suspensionStrength = 35.f;
|
||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
||||||
@@ -194,7 +194,7 @@ void GameWorld::Initialize()
|
|||||||
CommitEntity(entity);
|
CommitEntity(entity);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
for(int i = 0; i < 0; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
auto wall = CreateEntity();
|
auto wall = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(wall, "Transform");
|
auto transform = AddComponent<Components::Transform>(wall, "Transform");
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
for (auto pair : *m_World->GetEntities())
|
for (auto pair : *m_World->GetEntities())
|
||||||
{
|
{
|
||||||
EntityID entity = pair.first;
|
EntityID entity = pair.first;
|
||||||
|
EntityID parent = pair.second;
|
||||||
|
|
||||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
||||||
continue;
|
continue;
|
||||||
@@ -128,22 +129,35 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
if (!transformComponent)
|
if (!transformComponent)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if(m_RigidBodies[entity]->isActive())
|
||||||
/*if(m_RigidBodies[entity]->isActive())
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
hkVector4 position;
|
||||||
|
hkQuaternion rotation;
|
||||||
|
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("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();
|
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_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
||||||
m_PhysicsWorld->unmarkForWrite();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
}*/
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const double timestep = 1 / 30.0;
|
static const double timestep = 1 / 60.0;
|
||||||
m_Accumulator += dt;
|
m_Accumulator += dt;
|
||||||
while (m_Accumulator >= timestep)
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -234,24 +248,24 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
else if(deviceStatus->m_positionY < -1)
|
else if(deviceStatus->m_positionY < -1)
|
||||||
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
if(deviceStatus->m_positionX > 0)
|
if(deviceStatus->m_positionX > 0)
|
||||||
{
|
{
|
||||||
deviceStatus->m_positionX += -1 * turningSpeed;
|
deviceStatus->m_positionX += -1 * (turningSpeed*2) *dt;
|
||||||
}
|
}
|
||||||
else if(deviceStatus->m_positionX < 0)
|
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;
|
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];
|
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));
|
transformComponent->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
||||||
m_RigidBodies[entity]->setLinearVelocity(hkVector4(0, 0, 0));
|
m_RigidBodies[entity]->setLinearVelocity(hkVector4(0, 0, 0));
|
||||||
m_RigidBodies[entity]->setAngularVelocity(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);
|
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(mesh, physicsComponent->Mass, massProperties);
|
||||||
rigidBodyInfo.m_shape = mesh;
|
rigidBodyInfo.m_shape = mesh;
|
||||||
m_hkpExtendedMeshShapes[entity].ExtendedMeshShape = mesh;
|
m_ExtendedMeshShapes[entity].ExtendedMeshShape = mesh;
|
||||||
m_hkpExtendedMeshShapes[entity].VertexIndices = vertexIndices;
|
m_ExtendedMeshShapes[entity].VertexIndices = vertexIndices;
|
||||||
m_hkpExtendedMeshShapes[entity].Vertices = vertices;
|
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;
|
shape = mesh;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -422,11 +445,12 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_PhysicsWorld->markForWrite();
|
|
||||||
|
|
||||||
VehicleSetup vehicleSetup;
|
VehicleSetup vehicleSetup;
|
||||||
// Create the basic vehicle.
|
// Create the basic vehicle.
|
||||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||||
// Add the vehicle's entities and phantoms to the world
|
// Add the vehicle's entities and phantoms to the world
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include <Physics2012/Utilities/VisualDebugger/hkpPhysicsContext.h>
|
#include <Physics2012/Utilities/VisualDebugger/hkpPhysicsContext.h>
|
||||||
|
|
||||||
#include <Physics2012/Collide/Shape/Compound/Collection/ExtendedMeshShape/hkpExtendedMeshShape.h>
|
#include <Physics2012/Collide/Shape/Compound/Collection/ExtendedMeshShape/hkpExtendedMeshShape.h>
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Tree/Mopp/hkpMoppBvTreeShape.h>
|
||||||
|
#include <Physics2012/Collide/Shape/Compound/Tree/Mopp/hkpMoppUtility.h>
|
||||||
|
|
||||||
#include <Common/Base/Thread/JobQueue/hkJobQueue.h>
|
#include <Common/Base/Thread/JobQueue/hkJobQueue.h>
|
||||||
#include <Common/Base/Thread/Job/ThreadPool/Cpu/hkCpuJobThreadPool.h>
|
#include <Common/Base/Thread/Job/ThreadPool/Cpu/hkCpuJobThreadPool.h>
|
||||||
@@ -93,8 +95,10 @@ private:
|
|||||||
hkpExtendedMeshShape* ExtendedMeshShape;
|
hkpExtendedMeshShape* ExtendedMeshShape;
|
||||||
std::vector<hkReal>* Vertices;
|
std::vector<hkReal>* Vertices;
|
||||||
std::vector<hkUint16>* VertexIndices;
|
std::vector<hkUint16>* VertexIndices;
|
||||||
|
hkpMoppCode* Code;
|
||||||
|
hkpMoppBvTreeShape* MoppShape;
|
||||||
};
|
};
|
||||||
std::unordered_map<EntityID, ExtendedShapeData > m_hkpExtendedMeshShapes;
|
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2013
|
# Visual Studio 2012
|
||||||
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}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
|
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
|
||||||
@@ -41,7 +39,4 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(Performance) = preSolution
|
|
||||||
HasPerformanceSessions = true
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
Reference in New Issue
Block a user