#include "PrecompiledHeader.h" #include "GameWorld.h" void GameWorld::Initialize() { World::Initialize(); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj"); BindKey(GLFW_KEY_W, "vertical", 1.f); BindKey(GLFW_KEY_S, "vertical", -1.f); BindKey(GLFW_KEY_A, "horizontal", -1.f); BindKey(GLFW_KEY_D, "horizontal", 1.f); BindGamepadAxis(Gamepad::Axis::LeftX, "horizontal", 1.f); BindGamepadAxis(Gamepad::Axis::LeftY, "vertical", 1.f); BindKey(GLFW_KEY_UP, "barrel_rotation", 1.f); BindKey(GLFW_KEY_DOWN, "barrel_rotation", -1.f); BindKey(GLFW_KEY_LEFT, "tower_rotation", -1.f); BindKey(GLFW_KEY_RIGHT, "tower_rotation", 1.f); BindGamepadAxis(Gamepad::Axis::RightX, "tower_rotation", 1.f); BindGamepadAxis(Gamepad::Axis::RightY, "barrel_rotation", 1.f); BindKey(GLFW_KEY_SPACE, "handbrake", 1.f); BindGamepadButton(Gamepad::Button::A, "handbrake", 1.f); BindKey(GLFW_KEY_Z, "shoot", 1.f); BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f); BindMouseButton(GLFW_MOUSE_BUTTON_1, "cam_lock", 1.f); BindKey(GLFW_KEY_Y, "cam_vertical", 1.f); BindKey(GLFW_KEY_H, "cam_vertical", -1.f); BindKey(GLFW_KEY_G, "cam_horizontal", -1.f); BindKey(GLFW_KEY_J, "cam_horizontal", 1.f); BindKey(GLFW_KEY_U, "cam_normal", 1.f); BindKey(GLFW_KEY_T, "cam_normal", -1.f); //BindGamepadButton(Gamepad::Button::Up, "Gamepad::Button::Up", 1.f); //BindGamepadButton(Gamepad::Button::Down, "Gamepad::Button::Down", 1.f); //BindGamepadButton(Gamepad::Button::Left, "Gamepad::Button::Left", 1.f); //BindGamepadButton(Gamepad::Button::Right, "Gamepad::Button::Right", 1.f); //BindGamepadButton(Gamepad::Button::Start, "Gamepad::Button::Start", 1.f); //BindGamepadButton(Gamepad::Button::Back, "Gamepad::Button::Back", 1.f); //BindGamepadButton(Gamepad::Button::LeftThumb, "Gamepad::Button::LeftThumb", 1.f); //BindGamepadButton(Gamepad::Button::RightThumb, "Gamepad::Button::RightThumb", 1.f); //BindGamepadButton(Gamepad::Button::LeftShoulder, "Gamepad::Button::LeftShoulder", 1.f); //BindGamepadButton(Gamepad::Button::RightShoulder, "Gamepad::Button::RightShoulder", 1.f); //BindGamepadButton(Gamepad::Button::A, "Gamepad::Button::A", 1.f); //BindGamepadButton(Gamepad::Button::B, "Gamepad::Button::B", 1.f); //BindGamepadButton(Gamepad::Button::X, "Gamepad::Button::X", 1.f); //BindGamepadButton(Gamepad::Button::Y, "Gamepad::Button::Y", 1.f); RegisterComponents(); auto camera = CreateEntity(); { auto transform = AddComponent(camera); transform->Position.z = 20.f; transform->Position.y = 20.f; //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); auto cameraComp = AddComponent(camera); cameraComp->FarClip = 2000.f; auto freeSteering = AddComponent(camera); } { Events::SetViewportCamera e; e.CameraEntity = camera; 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(); 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; physics->CollisionLayer = 1; 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); } EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); transform->Position.z = 50.f; Events::SetViewportCamera e; e.CameraEntity = GetProperty(tank1, "Camera"); e.ViewportFrame = "Viewport1"; EventBroker->Publish(e); } EntityID tank2 = CreateTank(2); { auto transform = GetComponent(tank2); transform->Position.x = 10.f; transform->Position.z = 50.f; Events::SetViewportCamera e; e.CameraEntity = GetProperty(tank2, "Camera"); e.ViewportFrame = "Viewport2"; EventBroker->Publish(e); } { auto flag = CreateEntity(); auto transform = AddComponent(flag); transform->Position = glm::vec3(0, -50, 100); auto model = AddComponent(flag); model->ModelFile = "Models/Flag/FishingRod/FishingRod.obj"; { auto fish = CreateEntity(flag); auto transform = AddComponent(fish); transform->Position = glm::vec3(-1.3f, 1.0, 0); auto model = AddComponent(fish); model->ModelFile = "Models/Flag/LeFish/Salmon.obj"; CommitEntity(fish); } auto trigger = AddComponent(flag); { auto shape = CreateEntity(flag); auto transform = AddComponent(shape); transform->Position = glm::vec3(-0.9f, 0.9f, 0); auto box = AddComponent(shape); box->Width = 1.1f; box->Depth = 0.7f; box->Height = 3.9f; CommitEntity(shape); } auto flagComponent = AddComponent(flag); CommitEntity(flag); } //for (int i = 0; i < 500; i++) //{ // auto Light = CreateEntity(); // auto transform = AddComponent(Light); // transform->Position = glm::vec3((5 + (i*2.f))*cos(i*2.f), 3.f, (5 + (i*2.f))*sin(i*2.f)); // auto light = AddComponent(Light); // light->Specular = glm::vec3(0.5f, 0.5f, 0.5f); // light->Diffuse = glm::vec3(0.5f, 0.5f, 0.5f); // light->Radius = 15.f; // light->specularExponent = 100.f; // CommitEntity(Light); // //auto model = AddComponent(Light, "Model"); // //model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; //} { auto gateBase = CreateEntity(); auto transform = AddComponent(gateBase); transform->Position = glm::vec3(0, -50, 150); auto model = AddComponent(gateBase); model->ModelFile = "Models/Gate/Lift/Lift.obj"; auto physics = AddComponent(gateBase); physics->Static = true; physics->CollisionLayer = 1; // Terrain-Layer { auto leftBaseShape = CreateEntity(gateBase); auto transform = AddComponent(leftBaseShape); transform->Position = glm::vec3(8.5f, 3, 0); auto box = AddComponent(leftBaseShape); box->Width = 3.f/2; box->Height = 6.094f/2; box->Depth = 4.f/2; CommitEntity(leftBaseShape); } { auto RightBaseShape = CreateEntity(gateBase); auto transform = AddComponent(RightBaseShape); transform->Position = glm::vec3(-8.5f, 3, 0); auto box = AddComponent(RightBaseShape); box->Width = 3.f/2; box->Height = 6.094f/2; box->Depth = 4.f/2; CommitEntity(RightBaseShape); } { auto LeftTopShape = CreateEntity(gateBase); auto transform = AddComponent(LeftTopShape); transform->Position = glm::vec3(7.5485f, 9.385f, 0); auto box = AddComponent(LeftTopShape); box->Width = 1.747f/2; box->Height = 6.851f/2; box->Depth = 1.767f/2; CommitEntity(LeftTopShape); } { auto RightTopShape = CreateEntity(gateBase); auto transform = AddComponent(RightTopShape); transform->Position = glm::vec3(-7.5485f, 9.385f, 0); auto box = AddComponent(RightTopShape); box->Width = 1.747f/2; box->Height = 6.851f/2; box->Depth = 1.767f/2; CommitEntity(RightTopShape); } { auto RampShape = CreateEntity(gateBase); auto transform = AddComponent(RampShape); transform->Position = glm::vec3(0, 0.24f, 0); auto box = AddComponent(RampShape); box->Width = 14.9f/2; box->Height = 0.38f/2; box->Depth = 1.484f/2; CommitEntity(RampShape); } CommitEntity(gateBase); } } void GameWorld::Update(double dt) { World::Update(dt); } void GameWorld::RegisterComponents() { m_ComponentFactory.Register([]() { return new Components::Transform(); }); m_ComponentFactory.Register([]() { return new Components::Template(); }); m_ComponentFactory.Register([]() { return new Components::Player(); }); m_ComponentFactory.Register([]() { return new Components::Flag(); }); } void GameWorld::RegisterSystems() { m_SystemFactory.Register([this]() { return new Systems::TimerSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::DamageSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::TransformSystem(this, EventBroker, ResourceManager); }); //m_SystemFactory.Register([this]() { return new Systems::LevelGenerationSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::InputSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::DebugSystem(this, EventBroker, ResourceManager); }); //m_SystemFactory.Register([this]() { return new Systems::CollisionSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::ParticleSystem(this, EventBroker, ResourceManager); }); //m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); } void GameWorld::AddSystems() { AddSystem(); AddSystem(); AddSystem(); //AddSystem(); AddSystem(); AddSystem(); //AddSystem(); AddSystem(); //AddSystem(); AddSystem(); AddSystem(); AddSystem(); AddSystem(); AddSystem(); AddSystem(); AddSystem(); } void GameWorld::BindKey(int keyCode, std::string command, float value) { Events::BindKey e; e.KeyCode = keyCode; e.Command = command; e.Value = value; EventBroker->Publish(e); } void GameWorld::BindMouseButton(int button, std::string command, float value) { Events::BindMouseButton e; e.Button = button; e.Command = command; e.Value = value; EventBroker->Publish(e); } void GameWorld::BindGamepadAxis(Gamepad::Axis axis, std::string command, float value) { Events::BindGamepadAxis e; e.Axis = axis; e.Command = command; e.Value = value; EventBroker->Publish(e); } void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, float value) { Events::BindGamepadButton e; e.Button = button; e.Command = command; e.Value = value; EventBroker->Publish(e); } EntityID GameWorld::CreateTank(int playerID) { auto tank = CreateEntity(); auto transform = AddComponent(tank); transform->Position = glm::vec3(0, 5, 0); //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); auto physics = AddComponent(tank); physics->Mass = 63000 - 16000; physics->Static = false; auto vehicle = AddComponent(tank); vehicle->MaxTorque = 36000.f; vehicle->MaxSteeringAngle = 90.f; vehicle->MaxSpeedFullSteeringAngle = 4.f; auto player = AddComponent(tank); player->ID = playerID; auto tankSteering = AddComponent(tank); AddComponent(tank); auto health = AddComponent(tank); health->Amount = 100.f; { auto shape = CreateEntity(tank); auto transform = AddComponent(shape); auto meshShape = AddComponent(shape); meshShape->ResourceName = "Models/Tank/Fix/ChassiCollision.obj"; CommitEntity(shape); // auto box = AddComponent(jeep); // box->Width = 1.487f; // box->Height = 0.727f; // box->Depth = 2.594f; } { auto chassis = CreateEntity(tank); auto transform = AddComponent(chassis); transform->Position = glm::vec3(0, 0, 0); auto model = AddComponent(chassis); model->ModelFile = "Models/Tank/tankBody.obj"; } { auto tower = CreateEntity(tank); SetProperty(tower, "Name", "tower"); auto transform = AddComponent(tower); transform->Position = glm::vec3(0.f, 0.68f, 0.9f); auto model = AddComponent(tower); model->ModelFile = "Models/Tank/tankTop.obj"; auto towerSteering = AddComponent(tower); towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); towerSteering->TurnSpeed = glm::pi() / 4.f; { auto barrel = CreateEntity(tower); auto transform = AddComponent(barrel); transform->Position = glm::vec3(-0.012f, 0.4f, -0.75); auto model = AddComponent(barrel); model->ModelFile = "Models/Tank/tankBarrel.obj"; auto barrelSteering = AddComponent(barrel); barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); barrelSteering->TurnSpeed = glm::pi() / 4.f; barrelSteering->ShotSpeed = 70.f; { auto shot = CreateEntity(barrel); auto transform = AddComponent(shot); transform->Position = glm::vec3(0.35f, 0.f, -2.f); transform->Orientation = glm::angleAxis(-glm::pi() / 2.f, glm::vec3(1, 0, 0)); transform->Scale = glm::vec3(3.f); AddComponent(shot); auto physics = AddComponent(shot); physics->Mass = 25.f; physics->Static = false; physics->CollisionEvent = true; auto modelComponent = AddComponent(shot); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; auto tankShellComponent = AddComponent(shot); tankShellComponent->Damage = 20.f; tankShellComponent->ExplosionRadius = 30.f; tankShellComponent->ExplosionStrength = 300000.f; { auto shape = CreateEntity(shot); auto transform = AddComponent(shape); auto boxShape = AddComponent(shape); boxShape->Width = 0.5f; boxShape->Height = 0.5f; boxShape->Depth = 0.5f; CommitEntity(shape); } CommitEntity(shot); barrelSteering->ShotTemplate = shot; auto cameraTower = CreateEntity(barrel); { auto transform = AddComponent(cameraTower); transform->Position.z = 16.f; transform->Position.y = 4.f; transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f)); auto cameraComp = AddComponent(cameraTower); cameraComp->FarClip = 2000.f; //auto freeSteering = AddComponent(cameraTower); } SetProperty(tank, "Camera", cameraTower); } CommitEntity(barrel); tankSteering->Barrel = barrel; } CommitEntity(tower); tankSteering->Turret = tower; } //{ // auto lightentity = CreateEntity(tank); // auto transform = AddComponent(lightentity); // transform->Position = glm::vec3(0, 0, 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); // /*light->ConstantAttenuation = 0.3f; // light->LinearAttenuation = 0.003f; // light->QuadraticAttenuation = 0.002f;*/ //} // auto wheelpair = CreateEntity(tank); // SetProperty(wheelpair, "Name", "WheelPair"); // AddComponent(wheelpair, "WheelPairThingy"); #pragma region Wheels //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; float suspensionStrength = 15.f; #pragma region Pair R1 { auto wheel1 = CreateEntity(tank); { auto transform = AddComponent(wheel1); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); auto model = AddComponent(wheel1); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel1); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel1); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel1); } auto wheel2 = CreateEntity(tank); { auto transform = AddComponent(wheel2); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); auto model = AddComponent(wheel2); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel2); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel2); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel2); } auto wheelPair = CreateEntity(tank); { auto transform = AddComponent(wheelPair); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -1.715f); auto pair = AddComponent(wheelPair); pair->FakeWheel1 = wheel1; pair->FakeWheel2 = wheel2; auto model = AddComponent(wheel2); model->ModelFile = "Models/Tank/tankWheel.obj"; } } #pragma endregion #pragma region Pair L1 { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); } { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 0; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); } #pragma endregion #pragma region Pair R2 //Back { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); } { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); auto entity = CreateEntity(tank); auto transformComponent = AddComponent(entity); transformComponent->Position = glm::vec3(2, -1.7, 2.0); transformComponent->Scale = glm::vec3(3, 3, 3); transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); auto emitterComponent = AddComponent(entity); emitterComponent->SpawnCount = 2; emitterComponent->SpawnFrequency = 0.005; emitterComponent->SpreadAngle = glm::pi(); emitterComponent->UseGoalVelocity = false; emitterComponent->LifeTime = 0.5; //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); auto particleEntity = CreateEntity(entity); auto TEMP = AddComponent(particleEntity); TEMP->Scale = glm::vec3(0); auto spriteComponent = AddComponent(particleEntity); spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; emitterComponent->ParticleTemplate = particleEntity; CommitEntity(particleEntity); } #pragma endregion #pragma region Pair L2 { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f); transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); } { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel); transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f); auto model = AddComponent(wheel); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel); Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f); Wheel->AxleID = 1; Wheel->Mass = 2000; Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; Wheel->Friction = 3.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; Wheel->Width = 0.6f; { auto shape = CreateEntity(wheel); auto shapetransform = AddComponent(shape); shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; auto boxShape = AddComponent(shape); boxShape->Width = 0.7f; boxShape->Height = 0.34f; boxShape->Depth = 0.7f; CommitEntity(shape); } CommitEntity(wheel); #pragma endregion #pragma endregion auto entity = CreateEntity(tank); auto transformComponent = AddComponent(entity); transformComponent->Position = glm::vec3(-2, -1.7, 2.0); transformComponent->Scale = glm::vec3(3, 3, 3); transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); auto emitterComponent = AddComponent(entity); emitterComponent->SpawnCount = 2; emitterComponent->SpawnFrequency = 0.005; emitterComponent->SpreadAngle = glm::pi(); emitterComponent->UseGoalVelocity = false; emitterComponent->LifeTime = 0.5; //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); auto particleEntity = CreateEntity(entity); auto TEMP = AddComponent(particleEntity); TEMP->Scale = glm::vec3(0); auto spriteComponent = AddComponent(particleEntity); spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; emitterComponent->ParticleTemplate = particleEntity; CommitEntity(particleEntity); } CommitEntity(tank); return tank; } EntityID GameWorld::CreateJeep(int playerID) { auto jeep = CreateEntity(); auto transform = AddComponent(jeep); transform->Position = glm::vec3(0, 5, 0); transform->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(0, 1, 0)); auto physics = AddComponent(jeep); physics->Mass = 1800; physics->Static = false; auto vehicle = AddComponent(jeep); AddComponent(jeep); { auto shape = CreateEntity(jeep); auto transform = AddComponent(shape); 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; } { auto chassis = CreateEntity(jeep); auto transform = AddComponent(chassis); transform->Position = glm::vec3(0, 0, 0); // 0.6577f auto model = AddComponent(chassis); 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; float suspensionStrength = 35.f; { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel); transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f); transform->Scale = glm::vec3(1.0f); auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel); 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 = suspensionStrength; Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel); 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->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj"; auto Wheel = AddComponent(wheel); 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 = suspensionStrength; Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel); transform->Position = glm::vec3(0.2726f, 0.2805f - wheelOffset, 1.9307f); auto model = AddComponent(wheel); model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel); 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 = suspensionStrength; Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } { auto wheel = CreateEntity(jeep); auto transform = AddComponent(wheel); 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->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj"; auto Wheel = AddComponent(wheel); 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 = suspensionStrength; Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; CommitEntity(wheel); } CommitEntity(jeep); return jeep; }