From f471d7732f541cc9746ed931cab4f5506ffec3b1 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Tue, 29 Apr 2014 03:47:09 +0200 Subject: [PATCH] Vehicle tuning --- src/Components/Vehicle.h | 1 + src/GameWorld.cpp | 58 +++++++++++++++++++---------------- src/Physics/VehicleSetup.cpp | 2 +- src/Systems/PhysicsSystem.cpp | 28 ++++++++++------- vs11/Returngeance.sln | 4 ++- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 3892e8f..388d9f2 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -19,6 +19,7 @@ struct Vehicle : Component float MaxRPM; // Degrees float MaxSteeringAngle; + //TopSpeed not working fully yet float TopSpeed; float MaxSpeedFullSteeringAngle; }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index a120fb8..3388729 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -20,10 +20,11 @@ void GameWorld::Initialize() //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"); - model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; + model->ModelFile = "Models/TestScene/testScene.obj"; + //model->ModelFile = "Models/Placeholders/Terrain/Terrain.obj"; auto meshShape = AddComponent(ground, "MeshShape"); - meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; - + //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain.obj"; + meshShape->ResourceName = "Models/TestScene/testScene.obj"; auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; @@ -86,24 +87,26 @@ void GameWorld::Initialize() light->quadraticAttenuation = 0.002f; } - float wheelOffset = -0.2f; - float hardPointOffset = 0.0f; + //Create wheels + float wheelOffset = 0.4f; + float springLength = 0.3f; + float suspensionStrength = 20.f; { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); + transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -111,19 +114,19 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-1.9f, 0.5546f - 0.2 + wheelOffset, -0.9242f); + transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 50; Wheel->Radius = 0.837f; Wheel->Steering = true; - Wheel->SuspensionStrength = 50.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -131,17 +134,17 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(0.2726f, 0.2805f + wheelOffset, 1.9307f); + transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -149,18 +152,18 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(-0.2726f, 0.2805f + wheelOffset, 1.9307f); + transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel, "Wheel"); - Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f - hardPointOffset, 0.f); + Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 50; Wheel->Radius = 0.737f; Wheel->Steering = false; - Wheel->SuspensionStrength = 40.f; - Wheel->Friction = 3.5f; + Wheel->SuspensionStrength = suspensionStrength; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } @@ -191,27 +194,28 @@ void GameWorld::Initialize() CommitEntity(entity); }*/ + for(int i = 0; i < 0; i++) { auto wall = CreateEntity(); auto transform = AddComponent(wall, "Transform"); - transform->Position = glm::vec3(10, 0, -20); - transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); + transform->Position = glm::vec3(10, 0, -20 + (-10 * i)); + //transform->Orientation = glm::angleAxis(glm::pi()/2.f, glm::vec3(0, 1, 0)); - for (int y = 0; y < 10; y++) + for (int y = 0; y < 15; y++) { for (int x = -5; x < 5; x++) { auto brick = CreateEntity(wall); auto transform = AddComponent(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, 0); transform->Position.x += (y % 2)*0.5f; - transform->Scale = glm::vec3(1, 0.3f, 0.6f); + transform->Scale = glm::vec3(1, 0.3f, 0.4f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(brick, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; auto physics = AddComponent(brick, "Physics"); - physics->Mass = 1; + physics->Mass = 3; auto box = AddComponent(brick, "BoxShape"); box->Width = 0.5f; box->Height = 0.15f; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 5041b9d..2995fd1 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -267,7 +267,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultA aerodynamics.m_liftCoefficient = -0.3f; // Extra gavity applies in world space (independent of m_chassisCoordinateSystem). - aerodynamics.m_extraGravityws.set(0.0f, -0.982f, 0.0f); // fuck this shit + aerodynamics.m_extraGravityws.set(0.0f, -8.0f, 0.0f); // fuck this shit } void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultVelocityDamper& velocityDamper, Components::Vehicle vehicleComponent) diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 1b8bc81..b1d93cd 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -29,7 +29,7 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) { m_Accumulator = 0; - hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer + hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); hkBaseSystem::init(memoryRouter, HavokErrorReport); @@ -143,7 +143,7 @@ void Systems::PhysicsSystem::Update(double dt) - static const double timestep = 1 / 60.0; + static const double timestep = 1 / 30.0; m_Accumulator += dt; while (m_Accumulator >= timestep) { @@ -153,12 +153,14 @@ void Systems::PhysicsSystem::Update(double dt) m_Context->syncTimers(m_ThreadPool); // Step the visual debugger StepVisualDebugger(); + + // Clear accumulated timer data in this thread and all slave threads + hkMonitorStream::getInstance().reset(); + m_ThreadPool->clearTimerData(); } - // Clear accumulated timer data in this thread and all slave threads - hkMonitorStream::getInstance().reset(); - m_ThreadPool->clearTimerData(); + } void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -218,10 +220,9 @@ 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) { - deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.05f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.05f; + deviceStatus->m_positionY += inputComponent->KeyState[GLFW_KEY_UP] * -1 * 0.1f + inputComponent->KeyState[GLFW_KEY_DOWN] * 1 * 0.1f; } else { @@ -233,21 +234,26 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p else if(deviceStatus->m_positionY < -1) deviceStatus->m_positionY = -1; - + float turningSpeed = 0.02f; 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; + deviceStatus->m_positionX += inputComponent->KeyState[GLFW_KEY_LEFT] * -1 * turningSpeed + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1 * turningSpeed; } else { if(deviceStatus->m_positionX > 0) { - deviceStatus->m_positionX += -1 * 0.01f; + deviceStatus->m_positionX += -1 * turningSpeed; } else if(deviceStatus->m_positionX < 0) { - deviceStatus->m_positionX += 1 * 0.01f; + deviceStatus->m_positionX += 1 * turningSpeed; + } + + if (deviceStatus->m_positionX > -turningSpeed && deviceStatus->m_positionX < turningSpeed) + { + deviceStatus->m_positionX = 0.f; } } diff --git a/vs11/Returngeance.sln b/vs11/Returngeance.sln index 8daf9b5..f834d6d 100644 --- a/vs11/Returngeance.sln +++ b/vs11/Returngeance.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30110.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}" EndProject Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"