Tank with 8 wheels

This commit is contained in:
ViktorLjung
2014-05-11 01:52:00 +02:00
parent 4c0b465c7f
commit d7e5630f1b
10 changed files with 357 additions and 64 deletions
+1 -1
Submodule assets updated: 672e8a2b11...8b6c48b26b
+3 -1
View File
@@ -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;
+16
View File
@@ -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__
+249 -20
View File
@@ -21,7 +21,7 @@ void GameWorld::Initialize()
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
auto model = AddComponent<Components::Model>(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<Components::Physics>(ground, "Physics");
physics->Mass = 10;
@@ -31,7 +31,7 @@ void GameWorld::Initialize()
auto groundshape = CreateEntity(ground);
auto transformshape = AddComponent<Components::Transform>(groundshape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(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<Components::Transform>(jeep, "Transform");
transform->Position = glm::vec3(0, 5, 0);
transform->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
physics->Mass = 1800;
// auto box = AddComponent<Components::Box>(jeep, "Box");
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
auto meshShape = AddComponent<Components::MeshShape>(jeep, "MeshShape");
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
AddComponent<Components::Input>(jeep, "Input");
{
auto shape = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
CommitEntity(shape);
// auto box = AddComponent<Components::Box>(jeep, "Box");
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
}
{
auto chassis = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
@@ -174,6 +179,236 @@ void GameWorld::Initialize()
}
CommitEntity(jeep);
}*/
{
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank, "Transform");
transform->Position = glm::vec3(0, 5, 0);
transform->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank, "Physics");
physics->Mass = 45000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank, "Vehicle");
vehicle->MaxTorque = 5200.f;
AddComponent<Components::Input>(tank, "Input");
{
auto shape = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto meshShape = AddComponent<Components::MeshShape>(shape, "MeshShape");
meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj";
CommitEntity(shape);
// auto box = AddComponent<Components::Box>(jeep, "Box");
// box->Width = 1.487f;
// box->Height = 0.727f;
// box->Depth = 2.594f;
}
{
auto chassis = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
transform->Position = glm::vec3(0, 0, 0); // 0.6577f
auto model = AddComponent<Components::Model>(chassis, "Model");
model->ModelFile = "Models/Tank/Fix/Chassi.obj";
}
{
auto top = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(top, "Transform");
transform->Position = glm::vec3(0, 1.2, 1.95); // 0.6577f
auto model = AddComponent<Components::Model>(top, "Model");
model->ModelFile = "Models/Tank/Fix/Top.obj";
{
auto top = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(top, "Transform");
transform->Position = glm::vec3(0, 1, 0.5); // 0.6577f
auto model = AddComponent<Components::Model>(top, "Model");
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
}
}
{
auto lightentity = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(lightentity, "Transform");
transform->Position = glm::vec3(0, 15, 0);
auto light = AddComponent<Components::PointLight>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 1.f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(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<Components::Transform>(wall, "Transform");
transform->Position = glm::vec3(10, 0, -20 + (-10 * i));
//transform->Orientation = glm::angleAxis(glm::pi<float>()/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<Components::Transform>(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++)
+14 -16
View File
@@ -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)
+3 -1
View File
@@ -21,6 +21,7 @@
#include <Physics2012/Vehicle/Engine/Default/hkpVehicleDefaultEngine.h>
#include <Physics2012/Vehicle/VelocityDamper/Default/hkpVehicleDefaultVelocityDamper.h>
#include <Physics2012/Vehicle/Steering/Default/hkpVehicleDefaultSteering.h>
#include <Physics2012/Vehicle/Steering/hkpVehicleSteering.h>
#include <Physics2012/Vehicle/Suspension/Default/hkpVehicleDefaultSuspension.h>
#include <Physics2012/Vehicle/Transmission/Default/hkpVehicleDefaultTransmission.h>
#include <Physics2012/Vehicle/WheelCollide/RayCast/hkpVehicleRayCastWheelCollide.h>
@@ -43,7 +44,7 @@ public:
Components::Wheel* WheelComponent;
Components::Transform* TransformComponent;
};
std::vector<WheelData> 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__
+66 -25
View File
@@ -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<Components::Physics>(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<Systems::TransformSystem>("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<Components::Vehicle >(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<Systems::TransformSystem>("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<hkProcessContext*> 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)
+1
View File
@@ -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
+1
View File
@@ -140,6 +140,7 @@
<ClInclude Include="..\..\src\Components\Transform.h" />
<ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\Wheel.h" />
<ClInclude Include="..\..\src\Components\WheelPair.h" />
<ClInclude Include="..\..\src\CubemapTexture.h" />
<ClInclude Include="..\..\src\Engine.h" />
<ClInclude Include="..\..\src\Entity.h" />
@@ -242,6 +242,9 @@
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\WheelPair.h">
<Filter>Physics\Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\AABB.frag.glsl">