diff --git a/src/Components/TankSteering.h b/src/Components/TankSteering.h index 2c4b123..c47c5c8 100644 --- a/src/Components/TankSteering.h +++ b/src/Components/TankSteering.h @@ -7,7 +7,6 @@ namespace Components { struct TankSteering : Component { - EntityID Player; EntityID Turret; EntityID Barrel; TankSteering* Clone() const override { return new TankSteering(*this); } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index d25c813..659e628 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -194,6 +194,31 @@ void GameWorld::Initialize() //} + /*{ + auto gate = CreateEntity(); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(0, -50, 100); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/FishingRod/FishingRod.obj"; + + + { + //shape + } + + + { + auto fish = CreateEntity(flag); + auto transform = AddComponent(gate); + transform->Position = glm::vec3(-1.3f, 1.0, 0); + auto model = AddComponent(gate); + model->ModelFile = "Models/Flag/LeFish/Salmon.obj"; + CommitEntity(fish); + } + + CommitEntity(gate); + }*/ + } void GameWorld::Update(double dt) @@ -285,12 +310,6 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f EntityID GameWorld::CreateTank(int playerID) { - auto playerEnt = CreateEntity(); - { - auto player = AddComponent(playerEnt); - player->ID = playerID; - } - auto tank = CreateEntity(); auto transform = AddComponent(tank); transform->Position = glm::vec3(0, 5, 0); @@ -305,7 +324,6 @@ EntityID GameWorld::CreateTank(int playerID) auto player = AddComponent(tank); player->ID = playerID; auto tankSteering = AddComponent(tank); - tankSteering->Player = playerEnt; AddComponent(tank); auto health = AddComponent(tank); health->Amount = 100.f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index e319834..3568a26 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -183,7 +183,6 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultE engine.m_maxRPM = vehicleComponent.MaxRPM; - engine.m_torqueFactorAtMinRPM = 0.8f; engine.m_torqueFactorAtMaxRPM = 0.8f; 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_upshiftRPM = 7000.0f; - transmission.m_clutchDelayTime = 0.0f; + transmission.m_clutchDelayTime = 1.5f; transmission.m_reverseGearRatio = 1.0f; transmission.m_gearsRatio[0] = 3.0f; transmission.m_gearsRatio[1] = 2.25f; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index a9d4e76..13f136c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -156,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) void Systems::PhysicsSystem::Update(double dt) { + + for (auto pair : *m_World->GetEntities()) { EntityID entity = pair.first; @@ -172,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt) { hkVector4 position; hkQuaternion rotation; + hkVector4 velocity; if (parent) { auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity); } else { position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position); rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity); } m_PhysicsWorld->markForWrite(); m_RigidBodies[entity]->setPositionAndRotation(position, rotation); + m_RigidBodies[entity]->setLinearVelocity(velocity); 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; @@ -241,11 +256,12 @@ 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); - transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition()); 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 + // HACK: WTF IS THIS? if (transformComponentParent) { 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 hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT); // Save the listShape for further use @@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) if(triggerComponent) { auto parentTransformComponent = m_World->GetComponent(entityParent); - PhantomCallbackShape* phantom = new PhantomCallbackShape(this); 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)); float dotProduct = glm::dot(forward, velocityNormalized); - - if(dotProduct < 0) { steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 2def044..1d028d9 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit if(!tankSteeringComponent) return; - auto playerComponent = m_World->GetComponent(tankSteeringComponent->Player); + auto playerComponent = m_World->GetComponent(entity); if (!playerComponent) return; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 9a08e59..01fc27a 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -30,6 +30,7 @@ #include "Events/Damage.h" #include "Components/Vehicle.h" +#include "Components/Player.h" namespace Systems {