From 2f2154ffe14e0046b45b91c8154bef2ff4f6ebb2 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Mon, 2 Jun 2014 17:50:46 +0200 Subject: [PATCH] Kind of retarded tank --- src/Components/Vehicle.h | 15 +++++++--- src/GameWorld.cpp | 57 +++++++----------------------------- src/Physics/VehicleSetup.cpp | 28 +++++++++++------- src/Physics/VehicleSetup.h | 1 + 4 files changed, 40 insertions(+), 61 deletions(-) diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 2957df5..5dfed54 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -10,9 +10,10 @@ namespace Components struct Vehicle : Component { Vehicle() - : MaxTorque(1000.0f), MinRPM(1000.0f), OptimalRPM(3000.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(130.0f), - MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f){ } - + : MaxTorque(1000.0f), MinRPM(0.0f), OptimalRPM(2000.0f), MaxRPM(3000.0f), MaxSteeringAngle(35), TopSpeed(70.0f), + MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(2500.0f), DownshiftRPM(500.0f), + gearsRatio0(4.5f), gearsRatio1(2.5f), gearsRatio2(1.0f), gearsRatio3(0.5f){ } + //gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f) float MaxTorque; float MinRPM; float OptimalRPM; @@ -23,7 +24,13 @@ struct Vehicle : Component float TopSpeed; float MaxSpeedFullSteeringAngle; float SpringDamping; - + float DownshiftRPM; + float UpshiftRPM; + float gearsRatio0; + float gearsRatio1; + float gearsRatio2; + float gearsRatio3; + Vehicle* Clone() const override { return new Vehicle(*this); } }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 52f657d..aaa25bc 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -71,33 +71,6 @@ void GameWorld::Initialize() e.ViewportFrame = "ViewportFreeCam"; EventBroker->Publish(e); } - - //{ - // auto ground = CreateEntity(); - // auto transform = AddComponent(ground); - // transform->Position = glm::vec3(0, -50, 0); - // //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); - // transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); - // auto model = AddComponent(ground); - // model->ModelFile = "Models/TestScene3/testScene.obj"; - // //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; - // - // auto physics = AddComponent(ground); - // physics->Mass = 10; - // physics->Static = true; - - - // auto groundshape = CreateEntity(ground); - // auto transformshape = AddComponent(groundshape); - // auto meshShape = AddComponent(groundshape); - // //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; - // meshShape->ResourceName = "Models/TestScene3/testScene.obj"; - - // - // CommitEntity(groundshape); - // CommitEntity(ground); - //} - { auto ground = CreateEntity(); @@ -575,7 +548,6 @@ void GameWorld::CreateGate(glm::vec3 Position) } } - EntityID GameWorld::CreateTank(int playerID) { auto tank = CreateEntity(); @@ -586,7 +558,7 @@ EntityID GameWorld::CreateTank(int playerID) physics->Mass = 63000 - 16000; physics->Static = false; auto vehicle = AddComponent(tank); - vehicle->MaxTorque = 36000.f; + vehicle->MaxTorque = 8000.f; vehicle->MaxSteeringAngle = 90.f; vehicle->MaxSpeedFullSteeringAngle = 4.f; auto player = AddComponent(tank); @@ -784,7 +756,7 @@ void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int ax Wheel->Radius = 0.6f; Wheel->Steering = steering; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; @@ -807,7 +779,7 @@ void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int ax Wheel->Radius = 0.6f; Wheel->Steering = steering; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; @@ -859,7 +831,14 @@ EntityID GameWorld::CreateJeep(int playerID) physics->Mass = 1800; physics->Static = false; auto vehicle = AddComponent(jeep); + vehicle->DownshiftRPM = 3500.f; + vehicle->UpshiftRPM = 6000.f; + AddComponent(jeep); + auto player = AddComponent(jeep); + player->ID = playerID; + auto health = AddComponent(jeep); + health->Amount = 100.f; { auto shape = CreateEntity(jeep); @@ -867,12 +846,6 @@ EntityID GameWorld::CreateJeep(int playerID) auto meshShape = AddComponent(shape); meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; CommitEntity(shape); - - // auto box = AddComponent(jeep); - // box->Width = 1.487f; - // box->Height = 0.727f; - // box->Depth = 2.594f; - } { @@ -883,16 +856,6 @@ EntityID GameWorld::CreateJeep(int playerID) model->ModelFile = "Models/Jeep/Chassi/chassi.obj"; } - { - auto lightentity = CreateEntity(jeep); - auto transform = AddComponent(lightentity); - transform->Position = glm::vec3(0, 15, 0); - auto light = AddComponent(lightentity); - light->Diffuse = glm::vec3(128.f / 255.f, 172.f / 255.f, 242.f / 255.f); - light->Specular = glm::vec3(1.f); - } - - //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 3568a26..893ced8 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -8,7 +8,8 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpVehicleInstance& vehicle, EntityID vehicleEntity, std::vector wheelEntities) { auto vehicleComponent = world->GetComponent(vehicleEntity); - + auto tankSteeringComponent = world->GetComponent(vehicleEntity); + WheelData wheelData; for (int i = 0; i < wheelEntities.size(); i++) { @@ -22,7 +23,14 @@ void VehicleSetup::buildVehicle(World *world, const hkpWorld* physicsWorld, hkpV // vehicle.m_data = new hkpVehicleData; vehicle.m_driverInput = new hkpVehicleDefaultAnalogDriverInput; - vehicle.m_steering = new TankSteering; + if(tankSteeringComponent) + { + vehicle.m_steering = new TankSteering; + } + else + { + vehicle.m_steering = new hkpVehicleDefaultSteering; + } vehicle.m_engine = new hkpVehicleDefaultEngine; vehicle.m_transmission = new hkpVehicleDefaultTransmission; vehicle.m_brake = new hkpVehicleDefaultBrake; @@ -196,15 +204,15 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_gearsRatio.setSize(numberOfGears); transmission.m_wheelsTorqueRatio.setSize(data.m_numWheels); - transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent - transmission.m_upshiftRPM = 7000.0f; + transmission.m_downshiftRPM = vehicleComponent.DownshiftRPM; //HACK: Should be in VehicleComponent + transmission.m_upshiftRPM = vehicleComponent.UpshiftRPM; - transmission.m_clutchDelayTime = 1.5f; + transmission.m_clutchDelayTime = 0.0f; transmission.m_reverseGearRatio = 1.0f; - transmission.m_gearsRatio[0] = 3.0f; - transmission.m_gearsRatio[1] = 2.25f; - transmission.m_gearsRatio[2] = 1.5f; - transmission.m_gearsRatio[3] = 1.0f; + transmission.m_gearsRatio[0] = vehicleComponent.gearsRatio0; + transmission.m_gearsRatio[1] = vehicleComponent.gearsRatio1; + transmission.m_gearsRatio[2] = vehicleComponent.gearsRatio2; + transmission.m_gearsRatio[3] = vehicleComponent.gearsRatio3; for(int i = 0; i < m_Wheels.size(); i++) { @@ -212,7 +220,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT transmission.m_wheelsTorqueRatio[i] = m_Wheels[i].WheelComponent->TorqueRatio; } - transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatio( + transmission.m_primaryTransmissionRatio = hkpVehicleDefaultTransmission::calculatePrimaryTransmissionRatioKPH( vehicleComponent.TopSpeed, m_Wheels[0].WheelComponent->Radius, // HACK: All wheels are the same size right? vehicleComponent.MaxRPM, diff --git a/src/Physics/VehicleSetup.h b/src/Physics/VehicleSetup.h index bf75840..2f18ed8 100644 --- a/src/Physics/VehicleSetup.h +++ b/src/Physics/VehicleSetup.h @@ -32,6 +32,7 @@ #include "Components/Vehicle.h" #include "Components/Wheel.h" #include "Components/Transform.h" +#include "Components/TankSteering.h" /// Tank specific steering implementation. Rear wheels steer in opposite direction