Proper rotation of child physics objects
This commit is contained in:
@@ -10,7 +10,8 @@ namespace Components
|
|||||||
struct Vehicle : Component
|
struct Vehicle : Component
|
||||||
{
|
{
|
||||||
Vehicle()
|
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 MaxTorque;
|
||||||
float MinRPM;
|
float MinRPM;
|
||||||
@@ -19,6 +20,7 @@ struct Vehicle : Component
|
|||||||
// Degrees
|
// Degrees
|
||||||
float MaxSteeringAngle;
|
float MaxSteeringAngle;
|
||||||
float TopSpeed;
|
float TopSpeed;
|
||||||
|
float MaxSpeedFullSteeringAngle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+83
-40
@@ -64,37 +64,46 @@ void GameWorld::Initialize()
|
|||||||
|
|
||||||
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
||||||
|
|
||||||
auto light = AddComponent<Components::PointLight>(jeep, "PointLight");
|
|
||||||
light->Diffuse = glm::vec3(0, 1, 0);
|
|
||||||
light->constantAttenuation = 0.0005f;
|
|
||||||
light->linearAttenuation = 0.001f;
|
|
||||||
light->quadraticAttenuation = 0.001f;
|
|
||||||
|
|
||||||
AddComponent<Components::Input>(jeep, "Input");
|
AddComponent<Components::Input>(jeep, "Input");
|
||||||
|
|
||||||
{
|
{
|
||||||
auto chassis = CreateEntity(jeep);
|
auto chassis = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
||||||
transform->Position = glm::vec3(0, -0.6577f, 0);
|
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/chassi.OBJ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto lightentity = CreateEntity(jeep);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
float wheelOffset = -0.2f;
|
||||||
|
float hardPointOffset = 0.0f;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(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->Scale = glm::vec3(1.0f);
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(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->AxleID = 0;
|
||||||
Wheel->Mass = 50;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.837f;
|
Wheel->Radius = 0.837f;
|
||||||
Wheel->Steering = true;
|
Wheel->Steering = true;
|
||||||
Wheel->SuspensionStrength = 40.f;
|
Wheel->SuspensionStrength = 50.f;
|
||||||
Wheel->Friction = 3.0f;
|
Wheel->Friction = 3.5f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
@@ -102,19 +111,19 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(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->Scale = glm::vec3(1.0f);
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(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->AxleID = 0;
|
||||||
Wheel->Mass = 50;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.837f;
|
Wheel->Radius = 0.837f;
|
||||||
Wheel->Steering = true;
|
Wheel->Steering = true;
|
||||||
Wheel->SuspensionStrength = 40.f;
|
Wheel->SuspensionStrength = 50.f;
|
||||||
Wheel->Friction = 3.0f;
|
Wheel->Friction = 3.5f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
@@ -122,17 +131,17 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(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<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(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->AxleID = 1;
|
||||||
Wheel->Mass = 10;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.737f;
|
Wheel->Radius = 0.737f;
|
||||||
Wheel->Steering = false;
|
Wheel->Steering = false;
|
||||||
Wheel->SuspensionStrength = 20.f;
|
Wheel->SuspensionStrength = 40.f;
|
||||||
Wheel->Friction = 3.0f;
|
Wheel->Friction = 3.5f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
@@ -140,44 +149,78 @@ void GameWorld::Initialize()
|
|||||||
{
|
{
|
||||||
auto wheel = CreateEntity(jeep);
|
auto wheel = CreateEntity(jeep);
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
auto transform = AddComponent<Components::Transform>(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<float>(), glm::vec3(0, 0, 1));
|
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
auto model = AddComponent<Components::Model>(wheel, "Model");
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
auto Wheel = AddComponent<Components::Wheel>(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->AxleID = 1;
|
||||||
Wheel->Mass = 10;
|
Wheel->Mass = 50;
|
||||||
Wheel->Radius = 0.737f;
|
Wheel->Radius = 0.737f;
|
||||||
Wheel->Steering = false;
|
Wheel->Steering = false;
|
||||||
Wheel->SuspensionStrength = 20.f;
|
Wheel->SuspensionStrength = 40.f;
|
||||||
Wheel->Friction = 3.0f;
|
Wheel->Friction = 3.5f;
|
||||||
Wheel->ConnectedToHandbrake = true;
|
Wheel->ConnectedToHandbrake = true;
|
||||||
CommitEntity(wheel);
|
CommitEntity(wheel);
|
||||||
}
|
}
|
||||||
CommitEntity(jeep);
|
CommitEntity(jeep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for (int x = 0; x < 5; x++)
|
for(int i = 0; i < 10; i++)
|
||||||
for (int y = 0; y < 5; y++)
|
|
||||||
{
|
{
|
||||||
auto cube = CreateEntity();
|
auto entity = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
auto transform = AddComponent<Components::Transform>(entity, "Transform");
|
||||||
transform->Position = glm::vec3(3 * x + 0.1f + 20.f, 3 * y + 0.1f + 1.f, 0);
|
transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f);
|
||||||
transform->Scale = glm::vec3(3);
|
transform->Scale = glm::vec3(0);
|
||||||
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>(cube, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
std::stringstream ss;
|
||||||
|
ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj";
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
auto model = AddComponent<Components::Model>(entity, "Model");
|
||||||
|
model->ModelFile = ss.str();
|
||||||
|
|
||||||
|
auto physics = AddComponent<Components::Physics>(entity, "Physics");
|
||||||
physics->Mass = 100;
|
physics->Mass = 100;
|
||||||
auto box = AddComponent<Components::BoxShape>(cube, "BoxShape");
|
physics->Static = true;
|
||||||
box->Width = 1.5f;
|
auto meshShape = AddComponent<Components::MeshShape>(entity, "MeshShape");
|
||||||
box->Height = 1.5f;
|
meshShape->ResourceName = ss.str();
|
||||||
box->Depth = 1.5f;
|
|
||||||
CommitEntity(cube);
|
CommitEntity(entity);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
{
|
||||||
|
auto wall = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(wall, "Transform");
|
||||||
|
transform->Position = glm::vec3(10, 0, -20);
|
||||||
|
transform->Orientation = glm::angleAxis(glm::pi<float>()/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<Components::Transform>(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<Components::Model>(brick, "Model");
|
||||||
|
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
||||||
|
|
||||||
|
auto physics = AddComponent<Components::Physics>(brick, "Physics");
|
||||||
|
physics->Mass = 1;
|
||||||
|
auto box = AddComponent<Components::BoxShape>(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 x = 0; x < 5; x++)
|
||||||
for (int y = 0; y < 5; y++)
|
for (int y = 0; y < 5; y++)
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultS
|
|||||||
|
|
||||||
// [mph/h] The steering angle decreases linearly
|
// [mph/h] The steering angle decreases linearly
|
||||||
// based on your overall max speed of the vehicle.
|
// 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++)
|
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_gearsRatio.setSize(numberOfGears);
|
||||||
transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels);
|
transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels);
|
||||||
|
|
||||||
transmission.m_downshiftRPM = 3500.0f;
|
transmission.m_downshiftRPM = 1500.0f;
|
||||||
transmission.m_upshiftRPM = 6500.0f;
|
transmission.m_upshiftRPM = 3500.0f;
|
||||||
|
|
||||||
transmission.m_clutchDelayTime = 0.0f;
|
transmission.m_clutchDelayTime = 0.0f;
|
||||||
transmission.m_reverseGearRatio = 1.0f;
|
transmission.m_reverseGearRatio = 1.0f;
|
||||||
@@ -267,7 +267,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultA
|
|||||||
aerodynamics.m_liftCoefficient = -0.3f;
|
aerodynamics.m_liftCoefficient = -0.3f;
|
||||||
|
|
||||||
// Extra gavity applies in world space (independent of m_chassisCoordinateSystem).
|
// 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)
|
void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent)
|
||||||
|
|||||||
+1
-1
@@ -191,7 +191,7 @@ void Renderer::DrawSkybox()
|
|||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
m_ShaderProgramSkybox.Bind();
|
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));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
m_Skybox->Draw();
|
m_Skybox->Draw();
|
||||||
|
|||||||
@@ -129,21 +129,21 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if(m_RigidBodies[entity]->isActive())
|
/*if(m_RigidBodies[entity]->isActive())
|
||||||
{
|
{
|
||||||
m_PhysicsWorld->markForWrite();
|
m_PhysicsWorld->markForWrite();
|
||||||
hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
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);
|
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)
|
||||||
{
|
{
|
||||||
@@ -189,36 +189,84 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
m_PhysicsWorld->unmarkForWrite();
|
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())
|
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||||
{
|
{
|
||||||
m_PhysicsWorld->markForWrite();
|
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||||
|
//m_PhysicsWorld->markForWrite();
|
||||||
hkVector4 position = m_RigidBodies[entity]->getPosition();
|
hkVector4 position = m_RigidBodies[entity]->getPosition();
|
||||||
transformComponent->Position = glm::vec3(position(0), position(1), position(2));
|
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();
|
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();
|
if (transformComponentParent)
|
||||||
|
{
|
||||||
|
transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation);
|
||||||
|
}
|
||||||
|
//m_PhysicsWorld->unmarkForWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HACK: Vehicle test-controls
|
// HACK: Vehicle test-controls
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(entity, "Vehicle");
|
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(entity, "Vehicle");
|
||||||
auto inputComponent = m_World->GetComponent<Components::Input>(entity, "Input");
|
auto inputComponent = m_World->GetComponent<Components::Input>(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();
|
m_PhysicsWorld->markForWrite();
|
||||||
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus;
|
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];
|
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();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,8 +370,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
|
|
||||||
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
|
part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mesh->addTrianglesSubpart(part);
|
mesh->addTrianglesSubpart(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,8 +393,9 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||||
rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
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_inertiaTensor = massProperties.m_inertiaTensor;
|
||||||
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
//rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
||||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
rigidBodyInfo.m_mass = massProperties.m_mass;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define PhysicsSystem_h__
|
#define PhysicsSystem_h__
|
||||||
|
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Physics.h"
|
#include "Components/Physics.h"
|
||||||
#include "Components/BoxShape.h"
|
#include "Components/BoxShape.h"
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ void Texture::Load(std::string path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Texture = m_TextureCache[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()
|
void Texture::Bind()
|
||||||
|
|||||||
@@ -39,4 +39,7 @@ 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