From 70960c9eba585d896956cffc0b5b47b898216f38 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Wed, 4 Jun 2014 15:43:20 +0200 Subject: [PATCH] Jeep working --- assets | 2 +- src/GameWorld.cpp | 113 ++++++++++++++++++++++++++-- src/Physics/VehicleSetup.cpp | 2 +- src/Systems/JeepSteeringSystem.cpp | 114 +++++++++++++++++++---------- src/Systems/TankSteeringSystem.cpp | 4 +- 5 files changed, 186 insertions(+), 49 deletions(-) diff --git a/assets b/assets index e09ebf5..cb920fb 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit e09ebf5a29f007cb8ee884f48dc600926f0665bc +Subproject commit cb920fb0deaa4214d111e62d00d97b674ee4c207 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index aa182bc..9e25c5e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -43,6 +43,8 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_Z, "shoot", 1.f); BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f); + BindGamepadAxis(Gamepad::Axis::RightTrigger, "jeep_vertical", 1.f); + BindGamepadAxis(Gamepad::Axis::LeftTrigger, "jeep_vertical", -1.f); BindKey(GLFW_KEY_X, "use", 1.f); BindGamepadButton(Gamepad::Button::X, "use", 1.f); @@ -1011,14 +1013,69 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID) { auto shape = CreateEntity(bridge_middle); - auto transformshape = AddComponent(shape); - auto meshShape = AddComponent(shape); - meshShape->ResourceName = "Models/TerrainFiveIstles/Bridges/MiddleBridgeCollision.obj"; + auto transform = AddComponent(shape); + transform->Position = glm::vec3(70.31883f, 26.42735f, 0.50379f); + auto box = AddComponent(shape); + box->Width = 26.324f; + box->Height = 2.727f; + box->Depth = 6.798f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_middle); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(70.43447f, 29.23594f, 7.37155f); + auto box = AddComponent(shape); + box->Width = 27.724f; + box->Height = 1.334f; + box->Depth = 0.571f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_middle); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(70.43447f, 29.26906f, -6.68171f); + auto box = AddComponent(shape); + box->Width = 27.724f; + box->Height = 1.334f; + box->Depth = 0.571f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_middle); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(70.36976f, 33.56011f, 9.68543f); + auto box = AddComponent(shape); + box->Width = 1.8f; + box->Height = 15.984f; + box->Depth = 1.456f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_middle); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(70.36976f, 33.56011f, -8.67785f); + auto box = AddComponent(shape); + box->Width = 1.799f; + box->Height = 15.983f; + box->Depth = 1.456f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_middle); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(99.16043f, 25.0318f, 0.54486f); + transform->Orientation = glm::angleAxis(glm::radians(-9.087f), glm::vec3(0, 0, 1)); + auto box = AddComponent(shape); + box->Width = 3.566f; + box->Height = 3.566f; + box->Depth = 7.632f; CommitEntity(shape); } CommitEntity(bridge_middle); } + { auto terrain_base = CreateEntity(base); auto transform = AddComponent(terrain_base); @@ -1099,11 +1156,55 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID) { auto shape = CreateEntity(bridge_base); - auto transformshape = AddComponent(shape); - auto meshShape = AddComponent(shape); - meshShape->ResourceName = "Models/TerrainFiveIstles/Bridges/BaseBridge.obj"; + auto transform = AddComponent(shape); + transform->Position = glm::vec3(166.19089f, 25.99645f, -0.50379f); + auto box = AddComponent(shape); + box->Width = 27.723f; + box->Height = 2.727f; + box->Depth = 6.798f; CommitEntity(shape); } + { + auto shape = CreateEntity(bridge_base); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(166.19089f, 28.37571f, -6.68171f); + auto box = AddComponent(shape); + box->Width = 27.724f; + box->Height = 1.334f; + box->Depth = 0.571f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_base); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(166.19089f, 28.37571f, 7.68929f); + auto box = AddComponent(shape); + box->Width = 27.724f; + box->Height = 1.334f; + box->Depth = 0.571f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_base); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(166.12617f, 33.56011f, -8.67785f); + auto box = AddComponent(shape); + box->Width = 1.8; + box->Height = 15.984f; + box->Depth = 1.456f; + CommitEntity(shape); + } + { + auto shape = CreateEntity(bridge_base); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(166.12617f, 33.56011f, 9.68543f); + auto box = AddComponent(shape); + box->Width = 1.8; + box->Height = 15.984f; + box->Depth = 1.456f; + CommitEntity(shape); + } + CommitEntity(bridge_base); } #pragma endregion Terrain diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 893ced8..d06f4ba 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -114,7 +114,7 @@ void VehicleSetup::setupVehicleData(const hkpWorld* world, hkpVehicleData& data data.m_chassisUnitInertiaYaw = 0.8f; data.m_chassisUnitInertiaRoll = 1.0f; - data.m_chassisUnitInertiaPitch = 1.0f; + data.m_chassisUnitInertiaPitch = 2.0f; // Adds or removes torque around the yaw axis // based on the current steering angle. This will diff --git a/src/Systems/JeepSteeringSystem.cpp b/src/Systems/JeepSteeringSystem.cpp index d5c501b..62f2705 100644 --- a/src/Systems/JeepSteeringSystem.cpp +++ b/src/Systems/JeepSteeringSystem.cpp @@ -51,7 +51,7 @@ void Systems::JeepSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit bool Systems::JeepSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event) { - + if (event.VehicleType != "Jeep") return false; @@ -62,21 +62,21 @@ bool Systems::JeepSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve return false; } - for (auto &spawnPointComponent : *spawnPointComponents) + for (auto &component : *spawnPointComponents) { - auto spawnPoint = spawnPointComponent->Entity; - auto spawnPointBaseParent = m_World->GetEntityBaseParent(spawnPoint); - auto playerComponent = m_World->GetComponent(spawnPointBaseParent); + auto spawnPoint = component->Entity; + auto spawnPointComponent = std::dynamic_pointer_cast(component); + auto playerComponent = m_World->GetComponent(spawnPointComponent->Player); if (!playerComponent || playerComponent->ID != event.PlayerID) continue; - + Components::Transform absoluteTransform = m_World->GetSystem()->AbsoluteTransform(spawnPoint); - // Create a tank + // Create a Jeep EntityID Jeep = CreateJeep(event.PlayerID); auto tankTransform = m_World->GetComponent(Jeep); - tankTransform->Position = glm::vec3(0, 50, 0);//absoluteTransform.Position; -// tankTransform->Orientation = absoluteTransform.Orientation; + tankTransform->Position = absoluteTransform.Position; + tankTransform->Orientation = absoluteTransform.Orientation; // Set the viewport correctly Events::SetViewportCamera e; e.CameraEntity = m_World->GetProperty(Jeep, "Camera"); @@ -97,19 +97,20 @@ EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID) transform->Position = glm::vec3(0, 5, 0); //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); auto physics = m_World->AddComponent(jeep); - physics->Mass = 1600; + physics->Mass = 2000; physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->CenterOfMass = glm::vec3(0, 0, 0); auto vehicle = m_World->AddComponent(jeep); - vehicle->MaxTorque = 400.f; - vehicle->MaxSteeringAngle = 50.f; - vehicle->MaxSpeedFullSteeringAngle = 20.f; + vehicle->MaxTorque = 500.0f; + vehicle->MaxSteeringAngle = 40.f; + vehicle->MaxSpeedFullSteeringAngle = 12.f; vehicle->MinRPM = 1000.0f; - vehicle->OptimalRPM = 4000.0f, - vehicle->MaxRPM = 6000.0f; + vehicle->OptimalRPM = 5500.0f, + vehicle->MaxRPM = 7500.0f; vehicle->TopSpeed = 90.0f; - vehicle->SpringDamping = 1.f; - vehicle->UpshiftRPM = 5500.0f; - vehicle->DownshiftRPM = 1500.0f; + vehicle->SpringDamping = 5.f; + vehicle->UpshiftRPM = 6500.0f; + vehicle->DownshiftRPM = 3500.0f; vehicle->gearsRatio0 = 3.0f; vehicle->gearsRatio1 = 2.25f; vehicle->gearsRatio2 = 1.5f; @@ -117,19 +118,18 @@ EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID) auto player = m_World->AddComponent(jeep); player->ID = playerID; - auto tankSteering = m_World->AddComponent(jeep); + auto jeepSteering = m_World->AddComponent(jeep); m_World->AddComponent(jeep); auto health = m_World->AddComponent(jeep); health->Amount = 100.f; - { + /*{ auto shape = m_World->CreateEntity(jeep); auto transform = m_World->AddComponent(shape); auto meshShape = m_World->AddComponent(shape); meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj"; m_World->CommitEntity(shape); - } - + }*/ { auto chassis = m_World->CreateEntity(jeep); auto transform = m_World->AddComponent(chassis); @@ -138,6 +138,47 @@ EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID) model->ModelFile = "Models/Jeep/Chassi/Chassi.OBJ"; } + + { + auto shape = m_World->CreateEntity(jeep); + auto transform = m_World->AddComponent(shape); + transform->Position = glm::vec3(-0.0219f ,0.88937f, -0.48469f); + auto box = m_World->AddComponent(shape); + box->Width = 0.993f; + box->Height = 0.626f; + box->Depth = 1.316f; + m_World->CommitEntity(shape); + } + { + auto shape = m_World->CreateEntity(jeep); + auto transform = m_World->AddComponent(shape); + transform->Position = glm::vec3(-0.02551f ,0.55419f, 1.78935f); + auto box = m_World->AddComponent(shape); + box->Width = 0.849f; + box->Height = 0.415f; + box->Depth = 1.058f; + m_World->CommitEntity(shape); + } + { + auto shape = m_World->CreateEntity(jeep); + auto transform = m_World->AddComponent(shape); + transform->Position = glm::vec3(-1.63274f ,0.98825f, -0.89907f); + auto box = m_World->AddComponent(shape); + box->Width = 0.697f; + box->Height = 0.401f; + box->Depth = 0.868f; + m_World->CommitEntity(shape); + } + { + auto shape = m_World->CreateEntity(jeep); + auto transform = m_World->AddComponent(shape); + transform->Position = glm::vec3(1.63274f ,0.98825f, -0.89907f); + auto box = m_World->AddComponent(shape); + box->Width = 0.697f; + box->Height = 0.401f; + box->Depth = 0.868f; + m_World->CommitEntity(shape); + } auto cameraTower = m_World->CreateEntity(jeep); { @@ -150,11 +191,6 @@ EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID) m_World->SetProperty(jeep, "Camera", cameraTower); } - - - - - #pragma region Wheels //Create wheels float wheelOffset = 0.f;//-0.83f; @@ -198,9 +234,9 @@ EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID) void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity) { //Create wheels - float wheelOffset = 0.4f; - float springLength = 0.3f; - float suspensionStrength = 45.f; + float wheelOffset = 0.5f; + float springLength = 0.2f; + float suspensionStrength = 35.f; { auto wheel = m_World->CreateEntity(jeepEntity); auto transform = m_World->AddComponent(wheel); @@ -215,7 +251,7 @@ void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity) Wheel->Radius = 0.837f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 4.f; + Wheel->Friction = 2.5f; Wheel->ConnectedToHandbrake = true; m_World->CommitEntity(wheel); } @@ -235,7 +271,7 @@ void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity) Wheel->Radius = 0.837f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 4.f; + Wheel->Friction = 2.5f; Wheel->ConnectedToHandbrake = true; m_World->CommitEntity(wheel); } @@ -243,17 +279,17 @@ void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity) { auto wheel = m_World->CreateEntity(jeepEntity); auto transform = m_World->AddComponent(wheel); - transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); + transform->Position = glm::vec3(0.2726f, 0.2805f - (wheelOffset/2), 1.9307f); auto model = m_World->AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = m_World->AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; - Wheel->Mass = 50; + Wheel->Mass = 150; Wheel->Radius = 0.737f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 4.f; + Wheel->Friction = 2.5f; Wheel->ConnectedToHandbrake = true; m_World->CommitEntity(wheel); } @@ -261,18 +297,18 @@ void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity) { auto wheel = m_World->CreateEntity(jeepEntity); auto transform = m_World->AddComponent(wheel); - transform->Position = glm::vec3(-0.2726f, 0.2805f - wheelOffset, 1.9307f); + transform->Position = glm::vec3(-0.2726f, 0.2805f - (wheelOffset/2), 1.9307f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 0, 1)); auto model = m_World->AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = m_World->AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; - Wheel->Mass = 50; + Wheel->Mass = 150; Wheel->Radius = 0.737f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 4.f; + Wheel->Friction = 2.5f; Wheel->ConnectedToHandbrake = true; m_World->CommitEntity(wheel); } @@ -298,7 +334,7 @@ bool Systems::JeepSteeringSystem::JeepSteeringInputController::OnCommand(const E { m_Horizontal = val; } - else if (event.Command == "vertical") + else if (event.Command == "jeep_vertical") { m_Vertical = -val; } diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index edc92c8..f1c9caa 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -365,8 +365,8 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve // Create a tank EntityID tank = CreateTank(event.PlayerID); auto tankTransform = m_World->GetComponent(tank); - tankTransform->Position = glm::vec3(0, 50, 0);//absoluteTransform.Position; -// tankTransform->Orientation = absoluteTransform.Orientation; + tankTransform->Position = absoluteTransform.Position; + tankTransform->Orientation = absoluteTransform.Orientation; // Set the viewport correctly Events::SetViewportCamera e; e.CameraEntity = m_World->GetProperty(tank, "Camera");