Velocity now updating in transformcomponent
This commit is contained in:
@@ -7,7 +7,6 @@ namespace Components
|
|||||||
{
|
{
|
||||||
struct TankSteering : Component
|
struct TankSteering : Component
|
||||||
{
|
{
|
||||||
EntityID Player;
|
|
||||||
EntityID Turret;
|
EntityID Turret;
|
||||||
EntityID Barrel;
|
EntityID Barrel;
|
||||||
TankSteering* Clone() const override { return new TankSteering(*this); }
|
TankSteering* Clone() const override { return new TankSteering(*this); }
|
||||||
|
|||||||
+25
-7
@@ -194,6 +194,31 @@ void GameWorld::Initialize()
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
/*{
|
||||||
|
auto gate = CreateEntity();
|
||||||
|
auto transform = AddComponent<Components::Transform>(gate);
|
||||||
|
transform->Position = glm::vec3(0, -50, 100);
|
||||||
|
auto model = AddComponent<Components::Model>(gate);
|
||||||
|
model->ModelFile = "Models/Flag/FishingRod/FishingRod.obj";
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
//shape
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
auto fish = CreateEntity(flag);
|
||||||
|
auto transform = AddComponent<Components::Transform>(gate);
|
||||||
|
transform->Position = glm::vec3(-1.3f, 1.0, 0);
|
||||||
|
auto model = AddComponent<Components::Model>(gate);
|
||||||
|
model->ModelFile = "Models/Flag/LeFish/Salmon.obj";
|
||||||
|
CommitEntity(fish);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommitEntity(gate);
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::Update(double dt)
|
void GameWorld::Update(double dt)
|
||||||
@@ -285,12 +310,6 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f
|
|||||||
|
|
||||||
EntityID GameWorld::CreateTank(int playerID)
|
EntityID GameWorld::CreateTank(int playerID)
|
||||||
{
|
{
|
||||||
auto playerEnt = CreateEntity();
|
|
||||||
{
|
|
||||||
auto player = AddComponent<Components::Player>(playerEnt);
|
|
||||||
player->ID = playerID;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto tank = CreateEntity();
|
auto tank = CreateEntity();
|
||||||
auto transform = AddComponent<Components::Transform>(tank);
|
auto transform = AddComponent<Components::Transform>(tank);
|
||||||
transform->Position = glm::vec3(0, 5, 0);
|
transform->Position = glm::vec3(0, 5, 0);
|
||||||
@@ -305,7 +324,6 @@ EntityID GameWorld::CreateTank(int playerID)
|
|||||||
auto player = AddComponent<Components::Player>(tank);
|
auto player = AddComponent<Components::Player>(tank);
|
||||||
player->ID = playerID;
|
player->ID = playerID;
|
||||||
auto tankSteering = AddComponent<Components::TankSteering>(tank);
|
auto tankSteering = AddComponent<Components::TankSteering>(tank);
|
||||||
tankSteering->Player = playerEnt;
|
|
||||||
AddComponent<Components::Input>(tank);
|
AddComponent<Components::Input>(tank);
|
||||||
auto health = AddComponent<Components::Health>(tank);
|
auto health = AddComponent<Components::Health>(tank);
|
||||||
health->Amount = 100.f;
|
health->Amount = 100.f;
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultE
|
|||||||
engine.m_maxRPM = vehicleComponent.MaxRPM;
|
engine.m_maxRPM = vehicleComponent.MaxRPM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
engine.m_torqueFactorAtMinRPM = 0.8f;
|
engine.m_torqueFactorAtMinRPM = 0.8f;
|
||||||
engine.m_torqueFactorAtMaxRPM = 0.8f;
|
engine.m_torqueFactorAtMaxRPM = 0.8f;
|
||||||
engine.m_resistanceFactorAtMinRPM = 0.05f;
|
engine.m_resistanceFactorAtMinRPM = 0.05f;
|
||||||
@@ -200,7 +199,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT
|
|||||||
transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent
|
transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent
|
||||||
transmission.m_upshiftRPM = 7000.0f;
|
transmission.m_upshiftRPM = 7000.0f;
|
||||||
|
|
||||||
transmission.m_clutchDelayTime = 0.0f;
|
transmission.m_clutchDelayTime = 1.5f;
|
||||||
transmission.m_reverseGearRatio = 1.0f;
|
transmission.m_reverseGearRatio = 1.0f;
|
||||||
transmission.m_gearsRatio[0] = 3.0f;
|
transmission.m_gearsRatio[0] = 3.0f;
|
||||||
transmission.m_gearsRatio[1] = 2.25f;
|
transmission.m_gearsRatio[1] = 2.25f;
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
|||||||
|
|
||||||
void Systems::PhysicsSystem::Update(double dt)
|
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;
|
||||||
@@ -172,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt)
|
|||||||
{
|
{
|
||||||
hkVector4 position;
|
hkVector4 position;
|
||||||
hkQuaternion rotation;
|
hkQuaternion rotation;
|
||||||
|
hkVector4 velocity;
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||||
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||||
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||||
|
velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
|
position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
|
||||||
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
|
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
|
||||||
|
velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity);
|
||||||
}
|
}
|
||||||
m_PhysicsWorld->markForWrite();
|
m_PhysicsWorld->markForWrite();
|
||||||
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
||||||
|
m_RigidBodies[entity]->setLinearVelocity(velocity);
|
||||||
m_PhysicsWorld->unmarkForWrite();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
|
glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition());
|
||||||
|
pos1 += glm::vec3(1, 1, 1)*(float)dt;
|
||||||
|
hkVector4 pos = GLMVEC3_TO_HKVECTOR4(pos1);
|
||||||
|
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
m_RigidBodies[m_World->m_Terrain]->setPositionAndRotation(pos, GLMQUAT_TO_HKQUATERNION(glm::quat()));
|
||||||
|
m_PhysicsWorld->unmarkForWrite();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static const double timestep = 1 / 60.0;
|
static const double timestep = 1 / 60.0;
|
||||||
@@ -241,11 +256,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
|||||||
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||||
{
|
{
|
||||||
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
|
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
|
||||||
|
|
||||||
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
|
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
|
||||||
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
|
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
|
||||||
|
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
|
||||||
// TODO: No support for Scale, MIGHT be possible
|
// TODO: No support for Scale, MIGHT be possible
|
||||||
|
|
||||||
|
// HACK: WTF IS THIS?
|
||||||
if (transformComponentParent)
|
if (transformComponentParent)
|
||||||
{
|
{
|
||||||
transformComponent->Position -= transformComponentParent->Position;
|
transformComponent->Position -= transformComponentParent->Position;
|
||||||
@@ -320,7 +336,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create a hkpListShape* of all the childEntities collected in m_ShapeArrays
|
// Create a hkpListShape* of all the childEntities collected in m_ShapeArrays
|
||||||
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
||||||
// Save the listShape for further use
|
// Save the listShape for further use
|
||||||
@@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
if(triggerComponent)
|
if(triggerComponent)
|
||||||
{
|
{
|
||||||
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
|
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
|
||||||
|
|
||||||
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
|
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
|
||||||
hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom);
|
hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom);
|
||||||
|
|
||||||
@@ -719,8 +733,6 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
|||||||
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
|
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
|
||||||
float dotProduct = glm::dot(forward, velocityNormalized);
|
float dotProduct = glm::dot(forward, velocityNormalized);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(dotProduct < 0)
|
if(dotProduct < 0)
|
||||||
{
|
{
|
||||||
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
|
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
|||||||
if(!tankSteeringComponent)
|
if(!tankSteeringComponent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
|
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
|
||||||
if (!playerComponent)
|
if (!playerComponent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "Events/Damage.h"
|
#include "Events/Damage.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
|
#include "Components/Player.h"
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user