#include "PrecompiledHeader.h" #include "GameWorld.h" void GameWorld::Initialize() { World::Initialize(); m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); m_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); //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); } CommitEntity(camera); auto viewport1 = CreateEntity(); { auto viewport = AddComponent(viewport1); viewport->Right = 0.5f; viewport->Camera = camera; } CommitEntity(viewport1); auto viewport2 = CreateEntity(); { auto viewport = AddComponent(viewport2); viewport->Left = 0.5f; } CommitEntity(viewport2); { auto ground = CreateEntity(); auto transform = AddComponent(ground); transform->Position = glm::vec3(0, 0, 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/TestScene/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/TestScene/testScene.obj"; CommitEntity(groundshape); CommitEntity(ground); } /*{ 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); light->constantAttenuation = 0.3f; light->linearAttenuation = 0.003f; light->quadraticAttenuation = 0.002f; } //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); }*/ { 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 = 8000.f; vehicle->MaxSteeringAngle = 90.f; vehicle->MaxSpeedFullSteeringAngle = 4.f; AddComponent(tank); AddComponent(tank); { 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/Fix/Chassi.obj"; } { auto tower = CreateEntity(tank); SetProperty(tower, "Name", "tower"); auto transform = AddComponent(tower); transform->Position = glm::vec3(0.f, 1.2f, 1.8f); auto model = AddComponent(tower); model->ModelFile = "Models/Tank/Fix/Top.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.018f, -0.2, -1.3f); auto model = AddComponent(barrel); model->ModelFile = "Models/Tank/Fix/Barrel.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; auto modelComponent = AddComponent(shot); modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; { 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; } CommitEntity(barrel); } auto cameraTower = CreateEntity(tower); { auto transform = AddComponent(cameraTower); transform->Position.z = 11.f; transform->Position.y = 4.f; //transform->Orientation = glm::quat(glm::vec3(glm::pi() / 8.f, 0.f, 0.f)); auto cameraComp = AddComponent(cameraTower); cameraComp->FarClip = 2000.f; //auto freeSteering = AddComponent(cameraTower); } CommitEntity(cameraTower); GetComponent(viewport2)->Camera = cameraTower; } { 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"); //Create wheels float wheelOffset = 0.4f; float springLength = 0.3f; float suspensionStrength = 15.f; { 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 = 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.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); } //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); } { 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); 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); } /* for(int i = 0; i < 10; i++) { auto entity = CreateEntity(); auto transform = AddComponent(entity); transform->Position = glm::vec3(30 + i*0.1f, 0 + i*0.1f, 10 + i*0.1f); transform->Scale = glm::vec3(0); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); std::stringstream ss; ss << "Models/Placeholders/ShatterTest/" << i+1 << ".obj"; auto model = AddComponent(entity); model->ModelFile = ss.str(); auto physics = AddComponent(entity); physics->Mass = 100; physics->Static = true; auto meshShape = AddComponent(entity); meshShape->ResourceName = ss.str(); CommitEntity(entity); }*/ for(int i = 0; i < 1; i++) { for (int y = 0; y < 15; y++) { for (int x = -5; x < 5; x++) { auto brick = CreateEntity(); auto transform = AddComponent(brick); transform->Position = glm::vec3(x + 0.01f, y * 0.3f + 0.01f, -20); transform->Position.x += (y % 2)*0.5f; 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->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; auto physics = AddComponent(brick); physics->Mass = 3; auto shape = CreateEntity(brick); auto transformshape = AddComponent(shape); auto box = AddComponent(shape); box->Width = 0.5f; box->Height = 0.15f; box->Depth = 0.3f; CommitEntity(shape); CommitEntity(brick); } } } /*for (int x = 0; x < 5; x++) for (int y = 0; y < 5; y++) { auto cube = CreateEntity(); auto transform = AddComponent(cube); transform->Position = glm::vec3(3 * x + 0.1f + -20.f, 3 * y + 0.1f + 1.f, 0); transform->Scale = glm::vec3(3); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(cube); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj"; auto physics = AddComponent(cube); physics->Mass = 100; auto box = AddComponent(cube); box->Width = 1.5f; box->Height = 1.5f; box->Depth = 1.5f; CommitEntity(cube); } */ /*{ auto entity = CreateEntity(); AddComponent(entity, "Transform"); auto emitter = AddComponent(entity); emitter->Path = "Sounds/korvring.wav"; emitter->Loop = true; GetSystem("SoundSystem")->PlaySound(emitter); CommitEntity(entity); }*/ } 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(); }); } void GameWorld::RegisterSystems() { m_SystemFactory.Register([this]() { return new Systems::TransformSystem(this, m_EventBroker); }); //m_SystemFactory.Register([this]() { return new Systems::LevelGenerationSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::InputSystem(this, m_EventBroker); }); m_SystemFactory.Register([this]() { return new Systems::DebugSystem(this, m_EventBroker); }); //m_SystemFactory.Register([this]() { return new Systems::CollisionSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::ParticleSystem(this, m_EventBroker); }); //m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, m_EventBroker); }); m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, m_EventBroker); }); m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, m_EventBroker); }); m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, m_EventBroker); }); m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, m_EventBroker, m_Renderer); }); } void GameWorld::AddSystems() { 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; m_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; m_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; m_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; m_EventBroker->Publish(e); }