diff --git a/assets b/assets index 8b6c48b..05b3d22 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 8b6c48b26b3bbc10f5e66c1f59fec6ca935f641b +Subproject commit 05b3d22b01131512cc370dacd507a22e88c46e57 diff --git a/src/Components/BarrelSteering.h b/src/Components/BarrelSteering.h index 58ab2fa..f3ee943 100644 --- a/src/Components/BarrelSteering.h +++ b/src/Components/BarrelSteering.h @@ -10,9 +10,9 @@ namespace Components { BarrelSteering() : Velocity(1.f), Axis(glm::vec3(0,1,0)){ } - float Velocity; glm::vec3 Axis; + EntityID ShotTemplate; }; } diff --git a/src/Components/Shot.h b/src/Components/Shot.h new file mode 100644 index 0000000..324a9c5 --- /dev/null +++ b/src/Components/Shot.h @@ -0,0 +1,17 @@ +#ifndef Shot_h__ +#define Shot_h__ + +#include "Component.h" + +namespace Components +{ + + struct Shot : Component + { + Shot(); + float Speed; + }; + +} + +#endif // Shot_h__ \ No newline at end of file diff --git a/src/Events/SetVelocity.h b/src/Events/SetVelocity.h new file mode 100644 index 0000000..3bdb8a1 --- /dev/null +++ b/src/Events/SetVelocity.h @@ -0,0 +1,17 @@ +#ifndef Events_SetVelocity_h__ +#define Events_SetVelocity_h__ +#include "Entity.h" +#include "EventBroker.h" + +namespace Events +{ + + struct SetVelocity : Event + { + EntityID Entity; + glm::vec3 Velocity; + }; + +} + +#endif // Events_SetVelocity_h__ \ No newline at end of file diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 2d743f9..411d27f 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -19,6 +19,8 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_RIGHT, "tower_rotation", -1.f); BindKey(GLFW_KEY_SPACE, "handbrake", 1.f); + + BindKey(GLFW_KEY_Z, "shoot", 1.f); // // BindKey(GLFW_KEY_UP, "vertical", -1.f); // BindKey(GLFW_KEY_DOWN, "vertical", 1.f); @@ -264,7 +266,7 @@ void GameWorld::Initialize() auto tower = CreateEntity(tank); SetProperty(tower, "Name", "tower"); auto transform = AddComponent(tower, "Transform"); - transform->Position = glm::vec3(0, 1.2, 1.95); + transform->Position = glm::vec3(0.f, 1.2f, 1.8f); auto model = AddComponent(tower, "Model"); model->ModelFile = "Models/Tank/Fix/Top.obj"; auto towerSteering = AddComponent(tower, "TowerSteering"); @@ -273,12 +275,37 @@ void GameWorld::Initialize() { auto barrel = CreateEntity(tower); auto transform = AddComponent(barrel, "Transform"); - transform->Position = glm::vec3(0, 0, -2.f); + transform->Position = glm::vec3(-0.018f, -0.2, -1.3f); auto model = AddComponent(barrel, "Model"); model->ModelFile = "Models/Tank/Fix/Barrel.obj"; auto barrelSteering = AddComponent(barrel, "BarrelSteering"); barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); barrelSteering->Velocity = glm::pi()/4.f; + { + auto shot = CreateEntity(barrel); + auto transform = AddComponent(shot, "Transform"); + transform->Position = glm::vec3(0.35f, 1.f, -2.f); + auto shotComponent = AddComponent(shot, "Shot"); + shotComponent->Speed = 5; + auto physics = AddComponent(shot, "Physics"); + physics->Mass = 10.f; + physics->Static = false; + auto modelComponent = AddComponent(shot, "Model"); + modelComponent->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; + + { + auto shape = CreateEntity(tank); + auto transform = AddComponent(shape, "Transform"); + auto boxShape = AddComponent(shape, "BoxShape"); + boxShape->Width = 0.5f; + boxShape->Height = 0.5f; + boxShape->Depth = 0.5f; + CommitEntity(shape); + } + CommitEntity(shot); + barrelSteering->ShotTemplate = shot; + } + CommitEntity(barrel); } } @@ -306,7 +333,7 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -2.6f); + 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"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; @@ -320,12 +347,23 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -0.83f); + 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"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; @@ -339,13 +377,24 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -2.6f); + 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"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; @@ -359,12 +408,23 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -0.83f); + 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"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; @@ -378,6 +438,17 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } CommitEntity(wheel); } @@ -386,7 +457,7 @@ void GameWorld::Initialize() { auto wheel = CreateEntity(tank); auto transform = AddComponent(wheel, "Transform"); - transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 1.f); + transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel, "Wheel"); @@ -399,12 +470,23 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 2.95f); + transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel, "Wheel"); @@ -417,13 +499,24 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 1.f); + 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"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; @@ -437,12 +530,23 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + 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"); - transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 2.95f); + transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f); auto model = AddComponent(wheel, "Model"); model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj"; auto Wheel = AddComponent(wheel, "Wheel"); @@ -455,6 +559,17 @@ void GameWorld::Initialize() Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; + Wheel->Width = 0.6f; + { + auto shape = CreateEntity(wheel); + auto shapetransform = AddComponent(shape, "Transform"); + shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position; + auto boxShape = AddComponent(shape, "BoxShape"); + boxShape->Width = 0.7f; + boxShape->Height = 0.34f; + boxShape->Depth = 0.7f; + CommitEntity(shape); + } CommitEntity(wheel); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 2dfcb96..e924cc0 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -37,7 +37,7 @@ #include "Components/TankSteering.h" #include "Components/TowerSteering.h" #include "Components/BarrelSteering.h" - +#include "Components/Shot.h" class GameWorld : public World { diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 02259ad..5e4a71f 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -31,6 +31,7 @@ void Systems::PhysicsSystem::Initialize() // Events EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer); + EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnSetVelocity); hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); @@ -579,3 +580,8 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) return true; } + +bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) +{ + +} diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 968db95..7b2d259 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -14,6 +14,7 @@ #include "Components/WheelPair.h" #include "Components/TowerSteering.h" #include "Events/TankSteer.h" +#include "Events/SetVelocity.h" #include "OBJ.h" // Math and base include @@ -85,6 +86,9 @@ private: EventRelay m_ETankSteer; bool OnTankSteer(const Events::TankSteer &event); + EventRelay m_ESetVelocity; + bool OnSetVelocity(const Events::SetVelocity &event); + void SetUpPhysicsState(EntityID entity, EntityID parent); void TearDownPhysicsState(EntityID entity, EntityID parent); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index eee50cc..5e6c025 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -49,6 +49,19 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit glm::quat orientation = glm::angleAxis(barrelSteeringComponent->Velocity * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); transformComponent->Orientation *= orientation; } + + auto shotComponent = m_World->GetComponent(entity, "Shot"); + if(shotComponent) + { + if(m_TowerInputController->shoot) + { + auto absoluteOrientation = m_World->GetSystem("TransformSystem")->AbsoluteOrientation(entity); + Events::SetVelocity e; + e.Entity = entity; + e.Velocity = absoluteOrientation * (glm::vec3(0.f, 0.f, 1.f) * shotComponent->Speed * (float)dt); + EventBroker->Publish(e); + } + } } void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt ) @@ -61,6 +74,7 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d { TowerDirection = m_TowerDirection; BarrelDirection = m_BarrelDirection; + shoot = m_Shoot; } bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event) @@ -94,6 +108,11 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const { m_BarrelDirection = val; } + + else if (event.Command == "shoot") + { + shoot = (bool)val; + } return true; } diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index dee4707..1622063 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -2,11 +2,14 @@ #include "System.h" #include "Events/TankSteer.h" +#include "Events/SetVelocity.h" #include "Components/Transform.h" #include "Components/TankSteering.h" #include "Components/TowerSteering.h" #include "Components/BarrelSteering.h" #include "Components/Vehicle.h" +#include "Components/Shot.h" +#include "Systems/TransformSystem.h" #include "InputController.h" namespace Systems @@ -67,10 +70,13 @@ namespace Systems m_BarrelDirection = 0.f; TowerDirection = 0.f; BarrelDirection = 0.f; + + m_Shoot = false; } float TowerDirection; float BarrelDirection; + bool shoot; void Update(double dt); protected: virtual bool OnCommand(const Events::InputCommand &event); @@ -78,7 +84,8 @@ namespace Systems private: float m_TowerDirection; - float m_BarrelDirection; + float m_BarrelDirection; + bool m_Shoot; }; } \ No newline at end of file diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 9affcba..4b16aef 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -137,6 +137,7 @@ + @@ -159,6 +160,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 0323b51..21aa2cd 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -328,6 +328,12 @@ Physics\Components + + Physics\Components + + + Physics\Events +