diff --git a/assets b/assets index e077e44..0f0dc5d 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit e077e4412bad4e43a6ae88454efd25880b5d03f2 +Subproject commit 0f0dc5d839ef6fb47818e5dbf3646e8ce23a78ff diff --git a/src/Components/BarrelSteering.h b/src/Components/BarrelSteering.h index 1cd71be..0d62389 100644 --- a/src/Components/BarrelSteering.h +++ b/src/Components/BarrelSteering.h @@ -15,6 +15,9 @@ namespace Components EntityID ShotTemplate; float ShotSpeed; + float LowerRotationLimit; + float UpperRotationLimit; + virtual BarrelSteering* Clone() const override { return new BarrelSteering(*this); } }; diff --git a/src/Components/Follow.h b/src/Components/Follow.h new file mode 100644 index 0000000..7ccaa8d --- /dev/null +++ b/src/Components/Follow.h @@ -0,0 +1,20 @@ +#ifndef Components_Follow_h__ +#define Components_Follow_h__ + +#include "Component.h" +#include "Entity.h" + +namespace Components +{ + + struct Follow : Component + { + EntityID Entity; + glm::vec3 FollowAxis; + float Distance; + + virtual Follow* Clone() const override { return new Follow(*this); } + }; + +} +#endif // !Components_Follow_h__ \ No newline at end of file diff --git a/src/Components/TriggerMove.h b/src/Components/TriggerMove.h index 90dcd81..6f78611 100644 --- a/src/Components/TriggerMove.h +++ b/src/Components/TriggerMove.h @@ -9,7 +9,8 @@ namespace Components struct TriggerMove : Component { EntityID Entity; - float Time; + float Speed; + glm::vec3 StartPosition; glm::vec3 GoalPosition; virtual TriggerMove* Clone() const override { return new TriggerMove(*this); } }; diff --git a/src/Events/Move.h b/src/Events/Move.h index 8c2a03d..21627df 100644 --- a/src/Events/Move.h +++ b/src/Events/Move.h @@ -10,7 +10,7 @@ namespace Events { EntityID Entity; glm::vec3 GoalPosition; - double Time; + float Speed; bool Queue; }; diff --git a/src/Events/Rotate.h b/src/Events/Rotate.h new file mode 100644 index 0000000..87f87f2 --- /dev/null +++ b/src/Events/Rotate.h @@ -0,0 +1,19 @@ +#ifndef Event_Rotate_h__ +#define Event_Rotate_h__ + +#include "EventBroker.h" + +namespace Events +{ + + struct Rotate : Event + { + EntityID Entity; + glm::quat GoalRotation; + double Time; + bool Queue; + }; + +} + +#endif // Event_Rotate_h__ diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index c635246..772079b 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -35,6 +35,8 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_J, "cam_horizontal", 1.f); BindKey(GLFW_KEY_U, "cam_normal", 1.f); BindKey(GLFW_KEY_T, "cam_normal", -1.f); + BindKey(GLFW_KEY_B, "cam_speed", -1.f); + BindKey(GLFW_KEY_N, "cam_speed", 1.f); //BindGamepadButton(Gamepad::Button::Up, "Gamepad::Button::Up", 1.f); //BindGamepadButton(Gamepad::Button::Down, "Gamepad::Button::Down", 1.f); @@ -126,8 +128,9 @@ void GameWorld::Initialize() EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); - transform->Position.z = 145.f; - + transform->Position.z = 125.f; + transform->Position.y = -20.f; + transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0)); Events::SetViewportCamera e; e.CameraEntity = GetProperty(tank1, "Camera"); e.ViewportFrame = "Viewport1"; @@ -178,6 +181,8 @@ void GameWorld::Initialize() CommitEntity(flag); } + CreateGate(glm::vec3(0, -50, 150)); + //for (int i = 0; i < 500; i++) //{ // auto Light = CreateEntity(); @@ -192,126 +197,6 @@ void GameWorld::Initialize() // //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 = (int)Components::Physics::CollisionLayer::STATIC; - - { - 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 mesh = AddComponent(RampShape); - mesh->ResourceName = "Models/Gate/Lift/RampCollision.obj"; - CommitEntity(RampShape); - } - CommitEntity(gateBase); - } - - { - auto gate = CreateEntity(); - auto transform = AddComponent(gate); - transform->Position = glm::vec3(0, -50, 150); - auto model = AddComponent(gate); - model->ModelFile = "Models/Gate/Gate/Gate.obj"; - auto physics = AddComponent(gate); - physics->Static = true; - physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; - - { - auto mainShape = CreateEntity(gate); - auto transform = AddComponent(mainShape); - transform->Position = glm::vec3(0.f, 3.09776f, 0.f); - auto box = AddComponent(mainShape); - box->Width = 6.963f; - box->Height = 2.478f; - box->Depth = 0.522f; - CommitEntity(mainShape); - } - { - auto lowerShape = CreateEntity(gate); - auto transform = AddComponent(lowerShape); - transform->Position = glm::vec3(0.f, 0.35f, 0.f); - auto box = AddComponent(lowerShape); - box->Width = 6.963f; - box->Height = 0.308f; - box->Depth = 0.222f; - CommitEntity(lowerShape); - } - CommitEntity(gate); - - { - auto gateTrigger = CreateEntity(); - auto transform = AddComponent(gateTrigger); - transform->Position = glm::vec3(0, -50 + 2.8241, 150); - auto trigger = AddComponent(gateTrigger); - auto triggerMove = AddComponent(gateTrigger); - triggerMove->Entity = gate; - triggerMove->Time = 0.5f; - triggerMove->GoalPosition = glm::vec3(0, -50 + 9.02345f, 150); - - - { - auto shape = CreateEntity(gateTrigger); - auto transform = AddComponent(shape); - transform->Position = glm::vec3(0.f, 2.8241f, 0.f); - auto box = AddComponent(shape); - box->Width = 6.963f; - box->Height = 3.104f; - box->Depth = 10.356f; - CommitEntity(shape); - } - CommitEntity(gateTrigger); - } - - } } void GameWorld::Update(double dt) @@ -344,6 +229,7 @@ void GameWorld::RegisterSystems() 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::FollowSystem(this, EventBroker, ResourceManager); }); m_SystemFactory.Register([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); }); } @@ -364,6 +250,7 @@ void GameWorld::AddSystems() AddSystem(); AddSystem(); AddSystem(); + AddSystem(); AddSystem(); } @@ -457,13 +344,15 @@ EntityID GameWorld::CreateTank(int playerID) { auto barrel = CreateEntity(tower); auto transform = AddComponent(barrel); - transform->Position = glm::vec3(-0.012f, 0.4f, -0.75); + transform->Position = glm::vec3(-0.012f, 0.3f, -0.95); 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; + barrelSteering->LowerRotationLimit = glm::radians(-10.f); + barrelSteering->UpperRotationLimit = glm::radians(40.f); { auto shot = CreateEntity(barrel); auto transform = AddComponent(shot); @@ -494,15 +383,18 @@ EntityID GameWorld::CreateTank(int playerID) barrelSteering->ShotTemplate = shot; - auto cameraTower = CreateEntity(barrel); + auto cameraTower = CreateEntity(); { + auto model = AddComponent(cameraTower); + model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; 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)); + transform->Scale = glm::vec3(10); auto cameraComp = AddComponent(cameraTower); cameraComp->FarClip = 2000.f; - //auto freeSteering = AddComponent(cameraTower); + auto follow = AddComponent(cameraTower); + follow->Entity = barrel; + follow->Distance = 15.f; + follow->FollowAxis = glm::vec3(1, 1, 1); } SetProperty(tank, "Camera", cameraTower); @@ -576,6 +468,129 @@ EntityID GameWorld::CreateTank(int playerID) return tank; } +void GameWorld::CreateGate(glm::vec3 Position) +{ + { + auto gateBase = CreateEntity(); + auto transform = AddComponent(gateBase); + transform->Position = Position; + auto model = AddComponent(gateBase); + model->ModelFile = "Models/Gate/Lift/Lift.obj"; + auto physics = AddComponent(gateBase); + physics->Static = true; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + + { + 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 mesh = AddComponent(RampShape); + mesh->ResourceName = "Models/Gate/Lift/RampCollision.obj"; + CommitEntity(RampShape); + } + CommitEntity(gateBase); + } + + { + auto gate = CreateEntity(); + auto transform = AddComponent(gate); + transform->Position = Position; + auto model = AddComponent(gate); + model->ModelFile = "Models/Gate/Gate/Gate.obj"; + auto physics = AddComponent(gate); + physics->Static = true; + physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; + + { + auto mainShape = CreateEntity(gate); + auto transform = AddComponent(mainShape); + transform->Position = glm::vec3(0.f, 3.09776f, 0.f); + auto box = AddComponent(mainShape); + box->Width = 6.963f; + box->Height = 2.478f; + box->Depth = 0.522f; + CommitEntity(mainShape); + } + { + auto lowerShape = CreateEntity(gate); + auto transform = AddComponent(lowerShape); + transform->Position = glm::vec3(0.f, 0.35f, 0.f); + auto box = AddComponent(lowerShape); + box->Width = 6.963f; + box->Height = 0.308f; + box->Depth = 0.222f; + CommitEntity(lowerShape); + } + CommitEntity(gate); + + { + auto gateTrigger = CreateEntity(); + auto transform = AddComponent(gateTrigger); + transform->Position = glm::vec3(Position.x, Position.y + 2.8241, Position.z); + auto trigger = AddComponent(gateTrigger); + auto triggerMove = AddComponent(gateTrigger); + triggerMove->Entity = gate; + triggerMove->Speed = 5.f; + triggerMove->GoalPosition = glm::vec3(0, -50 + 9.02345f, 150); + triggerMove->StartPosition = glm::vec3(0, -50, 150); + + + { + auto shape = CreateEntity(gateTrigger); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0.f, 2.8241f, 0.f); + auto box = AddComponent(shape); + box->Width = 6.963f; + box->Height = 3.104f; + box->Depth = 10.356f; + CommitEntity(shape); + } + CommitEntity(gateTrigger); + } + + } +} + void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front) { const float separation = 1.77f; diff --git a/src/GameWorld.h b/src/GameWorld.h index aae2472..c878b1a 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -21,6 +21,7 @@ #include "Systems/TimerSystem.h" #include "Systems/DamageSystem.h" #include "Systems/WheelPairSystem.h" +#include "Systems/FollowSystem.h" #include "Components/Camera.h" #include "Components/DirectionalLight.h" @@ -49,6 +50,7 @@ #include "Components/Trigger.h" #include "Components/Flag.h" #include "Components/WheelPair.h" +#include "Components/Follow.h" class GameWorld : public World { @@ -72,6 +74,7 @@ private: void BindGamepadButton(Gamepad::Button button, std::string command, float value); EntityID CreateTank(int playerID); + void CreateGate(glm::vec3 Position); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); EntityID CreateJeep(int playerID); }; diff --git a/src/Systems/FollowSystem.cpp b/src/Systems/FollowSystem.cpp new file mode 100644 index 0000000..b4dcbe7 --- /dev/null +++ b/src/Systems/FollowSystem.cpp @@ -0,0 +1,26 @@ +#include "PrecompiledHeader.h" +#include "FollowSystem.h" +#include "World.h" + +void Systems::FollowSystem::RegisterComponents( ComponentFactory* cf ) +{ + cf->Register([]() { return new Components::Follow(); }); +} + +void Systems::FollowSystem::Update( double dt ) +{ + +} + +void Systems::FollowSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) +{ + auto followComponent = m_World->GetComponent(entity); + auto transformComponent = m_World->GetComponent(entity); + if(!followComponent || !transformComponent) + return; + auto absoluteTransformTarget = m_World->GetSystem()->AbsoluteTransform(followComponent->Entity); + + glm::vec3 Offset = (absoluteTransformTarget.Orientation * glm::normalize(absoluteTransformTarget.Position) * followComponent->Distance); + transformComponent->Position = (absoluteTransformTarget.Position + Offset); + transformComponent->Orientation = -glm::quat(glm::eulerAngles(absoluteTransformTarget.Orientation) * followComponent->FollowAxis); +} diff --git a/src/Systems/FollowSystem.h b/src/Systems/FollowSystem.h new file mode 100644 index 0000000..c57b775 --- /dev/null +++ b/src/Systems/FollowSystem.h @@ -0,0 +1,37 @@ +#ifndef FollowSystem_h__ +#define FollowSystem_h__ + + +#include "System.h" +#include "Systems/TransformSystem.h" +#include "Components/Transform.h" +#include "Components/Follow.h" + +#include "Events/Move.h" +#include "Events/Rotate.h" + + +namespace Systems +{ + class FollowSystem : public System + { + public: + + FollowSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + //void Initialize() override; + void RegisterComponents(ComponentFactory* cf) override; + void Update(double dt) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + /*void OnComponentCreated(std::string type, std::shared_ptr component) override; + void OnComponentRemoved(EntityID entity, std::string type, Component* component) override; + void OnEntityCommit(EntityID entity) override; + void OnEntityRemoved(EntityID entity) override;*/ + + private: + + }; + +} +#endif // FollowSystem_h__ diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 46741c9..31f9871 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -158,31 +158,34 @@ void Systems::PhysicsSystem::Update(double dt) if (!transformComponent) continue; - if(/*m_RigidBodies[entity]->isActive()*/ true) - { - hkVector4 position; - hkQuaternion rotation; - hkVector4 velocity; + + hkVector4 position; + hkQuaternion rotation; + hkVector4 velocity; - if (parent) - { - auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); - position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); - rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); - velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity); - } - else - { - position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position); - rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation); - velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity); - } - m_PhysicsWorld->markForWrite(); - m_RigidBodies[entity]->setPositionAndRotation(position, rotation); - m_RigidBodies[entity]->setLinearVelocity(velocity); - m_PhysicsWorld->unmarkForWrite(); - + if (parent) + { + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(entity); + position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); + rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity); } + else + { + position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position); + rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation); + velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity); + } + m_PhysicsWorld->markForWrite(); + m_RigidBodies[entity]->setPositionAndRotation(position, rotation); + + if(m_RigidBodies[entity]->getMotionType() != hkpMotion::MOTION_FIXED) + { + m_RigidBodies[entity]->setLinearVelocity(velocity); + } + m_PhysicsWorld->unmarkForWrite(); + + /* glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition()); @@ -751,9 +754,9 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) { if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { + m_PhysicsWorld->markForWrite(); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); - auto transformComponent = m_World->GetComponent(event.Entity); transformComponent->Velocity = event.Velocity; m_PhysicsWorld->unmarkForWrite(); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index cc1008b..f5edcaa 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -68,6 +68,20 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); transformComponent->Orientation *= orientation; + glm::vec3 angles = glm::eulerAngles(transformComponent->Orientation); + if(angles.x > barrelSteeringComponent->UpperRotationLimit) + { + angles.x = barrelSteeringComponent->UpperRotationLimit; + transformComponent->Orientation = glm::quat(angles); + } + else if(angles.x < barrelSteeringComponent->LowerRotationLimit) + { + angles.x = barrelSteeringComponent->LowerRotationLimit; + transformComponent->Orientation = glm::quat(angles); + } + + + if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5) { EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate); diff --git a/src/Systems/TransformSystem.cpp b/src/Systems/TransformSystem.cpp index 2e2e7f3..5823d12 100755 --- a/src/Systems/TransformSystem.cpp +++ b/src/Systems/TransformSystem.cpp @@ -16,6 +16,7 @@ void Systems::TransformSystem::Initialize() { EVENT_SUBSCRIBE_MEMBER(m_EMove, &Systems::TransformSystem::OnMove); + EVENT_SUBSCRIBE_MEMBER(m_ERotate, &Systems::TransformSystem::OnRotate); } void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) @@ -23,14 +24,16 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI if(m_MoveItems.find(entity) != m_MoveItems.end()) { auto transform = m_World->GetComponent(entity); - glm::vec3 move = m_MoveItems[entity].GoalPosition - transform->Position; - move /= m_MoveItems[entity].Time; - m_MoveItems[entity].Time -= dt; - if(m_MoveItems[entity].Time <= 0) + glm::vec3 direction = glm::normalize(m_MoveItems[entity].GoalPosition - transform->Position); + glm::vec3 movement = direction * m_MoveItems[entity].Speed * (float)dt; + + glm::vec3 v1 = m_MoveItems[entity].GoalPosition - transform->Position; + glm::vec3 v2 = movement; + + if(glm::length(v2) >= glm::length(v1)) { - float movetime = dt + m_MoveItems[entity].Time; - transform->Position += move * movetime; + transform->Position = m_MoveItems[entity].GoalPosition; m_MoveItems.erase(entity); @@ -43,23 +46,80 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI } else { - transform->Position += move * (float)dt; + transform->Position += movement; + } + + } + + if(m_RotationItems.find(entity) != m_RotationItems.end()) + { + auto transform = m_World->GetComponent(entity); + + float percentage = dt/m_RotationItems[entity].Time; + m_RotationItems[entity].Time -= dt; + glm::clamp(percentage, 0.f, 1.0f); + transform->Orientation = glm::slerp(transform->Orientation, m_RotationItems[entity].GoalRotation, percentage); + + if(m_RotationItems[entity].Time <= 0) + { + m_RotationItems.erase(entity); + + if(m_QueuedRotationItems.find(entity) != m_QueuedRotationItems.end()) + { + auto it = m_QueuedRotationItems.find(entity); + m_RotationItems[entity] = it->second; + m_QueuedRotationItems.erase(it->first); + } } } } +bool Systems::TransformSystem::OnRotate( const Events::Rotate &event ) +{ + RotationItems item; + item.Entity = event.Entity; + item.GoalRotation = event.GoalRotation; + item.Time = event.Time; + + if(event.Queue) + { + if(m_RotationItems.find(event.Entity) != m_RotationItems.end()) + { + m_QueuedRotationItems.insert(std::make_pair(event.Entity, item)); + } + else + { + m_RotationItems[event.Entity] = item; + } + } + else + { + m_RotationItems[event.Entity] = item; + } + return true; +} bool Systems::TransformSystem::OnMove( const Events::Move &event ) { MoveItems item; item.Entity = event.Entity; item.GoalPosition = event.GoalPosition; - item.Time = event.Time; - m_MoveItems[event.Entity] = item; - + item.Speed = event.Speed; + if(event.Queue) { - m_QueuedMoveItems.insert(std::make_pair(event.Entity, item)); + if(m_MoveItems.find(event.Entity) != m_MoveItems.end()) + { + m_QueuedMoveItems.insert(std::make_pair(event.Entity, item)); + } + else + { + m_MoveItems[event.Entity] = item; + } + } + else + { + m_MoveItems[event.Entity] = item; } return true; } diff --git a/src/Systems/TransformSystem.h b/src/Systems/TransformSystem.h index 2e8521e..7d6f30e 100755 --- a/src/Systems/TransformSystem.h +++ b/src/Systems/TransformSystem.h @@ -4,6 +4,7 @@ #include "System.h" #include "Components/Transform.h" #include "Events/Move.h" +#include "Events/Rotate.h" #include @@ -29,16 +30,25 @@ public: // Events EventRelay m_EMove; bool OnMove(const Events::Move &event); + EventRelay m_ERotate; + bool OnRotate(const Events::Rotate &event); private: struct MoveItems { EntityID Entity; glm::vec3 GoalPosition; - double Time; + float Speed; }; std::unordered_map m_MoveItems; std::multimap m_QueuedMoveItems; - + struct RotationItems + { + EntityID Entity; + glm::quat GoalRotation; + double Time; + }; + std::unordered_map m_RotationItems; + std::multimap m_QueuedRotationItems; }; } diff --git a/src/Systems/TriggerSystem.cpp b/src/Systems/TriggerSystem.cpp index 6d48a41..ccfa716 100644 --- a/src/Systems/TriggerSystem.cpp +++ b/src/Systems/TriggerSystem.cpp @@ -121,11 +121,13 @@ void Systems::TriggerSystem::Move( EntityID entity ) Events::Move e; e.Entity = trigger->Entity; e.GoalPosition = trigger->GoalPosition; - e.Time = trigger->Time; + e.Speed = trigger->Speed; e.Queue = false; EventBroker->Publish(e); - trigger->GoalPosition = transform->Position; + glm::vec3 temp = trigger->GoalPosition; + trigger->GoalPosition = trigger->StartPosition; + trigger->StartPosition = temp; } diff --git a/src/Systems/TriggerSystem.h b/src/Systems/TriggerSystem.h index 193626e..e006e26 100644 --- a/src/Systems/TriggerSystem.h +++ b/src/Systems/TriggerSystem.h @@ -19,6 +19,7 @@ #include "Components/TriggerMove.h" #include "Components/Player.h" #include "Events/Move.h" +#include "Events/Rotate.h" #include namespace Systems { diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 1be4904..0f1cef3 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -111,6 +111,7 @@ + @@ -135,6 +136,7 @@ + @@ -190,6 +192,7 @@ + @@ -219,6 +222,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 624a222..c1ed260 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -64,7 +64,7 @@ Physics\Systems - Gameplay\Vehicles\Helicopter\Systems + Game\Vehicles\Helicopter\Systems Physics\Systems @@ -73,9 +73,12 @@ Base\Systems - Gameplay\Systems + Game\Systems + + Game\Systems + @@ -150,36 +153,36 @@ {42ae084f-ade8-402c-87ba-f03f6b846bc8} - - {5b992473-73e6-485e-8f13-17e0801fb2ca} - - - {8a78be3a-a3c5-4054-a2f1-1456f3fcbab0} - - - {8ccc0abe-5bdd-4656-ab11-5708a39c71ae} - - - {b2416d05-a49e-4fef-a5c4-cd03d8cc2efd} - - - {b34c0c95-a887-4cf4-af24-cf7c1f459aa8} - - - {cb06b441-90b8-46ed-b347-4190dac7185b} - - - {3c2ea0e5-41a1-4b11-a891-1d59ead7223c} - {a025d51e-594d-4844-983b-f683726bf1bf} - - {9702064a-02a2-4b3c-a2ab-47c23a9cf49c} - {ffab6cc2-2fbf-400f-9398-a6741b6cc95c} + + {5b992473-73e6-485e-8f13-17e0801fb2ca} + + + {8a78be3a-a3c5-4054-a2f1-1456f3fcbab0} + + + {8ccc0abe-5bdd-4656-ab11-5708a39c71ae} + + + {b2416d05-a49e-4fef-a5c4-cd03d8cc2efd} + + + {b34c0c95-a887-4cf4-af24-cf7c1f459aa8} + + + {cb06b441-90b8-46ed-b347-4190dac7185b} + + + {3c2ea0e5-41a1-4b11-a891-1d59ead7223c} + + + {9702064a-02a2-4b3c-a2ab-47c23a9cf49c} + @@ -405,10 +408,10 @@ Input\Events - Gameplay\Vehicles\Helicopter\Components + Game\Vehicles\Helicopter\Components - Gameplay\Vehicles\Helicopter\Systems + Game\Vehicles\Helicopter\Systems Physics\Events @@ -417,7 +420,7 @@ Physics\Events - Gameplay\Components + Game\Components Physics\Events @@ -456,13 +459,13 @@ Base\Components - Gameplay\Systems + Game\Systems - Gameplay\Events + Game\Events - Gameplay\Components + Game\Components GUI @@ -491,6 +494,16 @@ Physics\Events + + + Game\Components + + + Game\Systems + + + Base\Events +