Shots fired! ( ゚Д゚)
This commit is contained in:
+1
-1
Submodule assets updated: 05b3d22b01...15ac02523a
@@ -9,10 +9,13 @@ namespace Components
|
||||
struct BarrelSteering : Component
|
||||
{
|
||||
BarrelSteering()
|
||||
: Velocity(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||
float Velocity;
|
||||
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||
float TurnSpeed;
|
||||
glm::vec3 Axis;
|
||||
EntityID ShotTemplate;
|
||||
float ShotSpeed;
|
||||
|
||||
virtual BarrelSteering* Clone() const override { return new BarrelSteering(*this); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef Shot_h__
|
||||
#define Shot_h__
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Shot : Component
|
||||
{
|
||||
Shot();
|
||||
float Speed;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Shot_h__
|
||||
@@ -9,10 +9,11 @@
|
||||
struct TowerSteering : Component
|
||||
{
|
||||
TowerSteering()
|
||||
: Velocity(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||
: TurnSpeed(1.f), Axis(glm::vec3(0,1,0)){ }
|
||||
|
||||
float Velocity;
|
||||
float TurnSpeed;
|
||||
glm::vec3 Axis;
|
||||
virtual TowerSteering* Clone() const override { return new TowerSteering(*this); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+33
-31
@@ -221,7 +221,7 @@ void GameWorld::Initialize()
|
||||
auto tank = CreateEntity();
|
||||
auto transform = AddComponent<Components::Transform>(tank, "Transform");
|
||||
transform->Position = glm::vec3(0, 5, 0);
|
||||
transform->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(0, 1, 0));
|
||||
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
|
||||
auto physics = AddComponent<Components::Physics>(tank, "Physics");
|
||||
physics->Mass = 45000;
|
||||
physics->Static = false;
|
||||
@@ -260,7 +260,7 @@ void GameWorld::Initialize()
|
||||
model->ModelFile = "Models/Tank/Fix/Top.obj";
|
||||
auto towerSteering = AddComponent<Components::TowerSteering>(tower, "TowerSteering");
|
||||
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
|
||||
towerSteering->Velocity = glm::pi<float>()/4.f;
|
||||
towerSteering->TurnSpeed = glm::pi<float>()/4.f;
|
||||
{
|
||||
auto barrel = CreateEntity(tower);
|
||||
auto transform = AddComponent<Components::Transform>(barrel, "Transform");
|
||||
@@ -269,21 +269,23 @@ void GameWorld::Initialize()
|
||||
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
|
||||
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel, "BarrelSteering");
|
||||
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
|
||||
barrelSteering->Velocity = glm::pi<float>()/4.f;
|
||||
barrelSteering->TurnSpeed = glm::pi<float>()/4.f;
|
||||
barrelSteering->ShotSpeed = 70.f;
|
||||
{
|
||||
auto shot = CreateEntity(barrel);
|
||||
auto transform = AddComponent<Components::Transform>(shot, "Transform");
|
||||
transform->Position = glm::vec3(0.35f, 1.f, -2.f);
|
||||
auto shotComponent = AddComponent<Components::Shot>(shot, "Shot");
|
||||
shotComponent->Speed = 5;
|
||||
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
|
||||
transform->Orientation = glm::angleAxis(-glm::pi<float>()/2.f, glm::vec3(1, 0, 0));
|
||||
transform->Scale = glm::vec3(3.f);
|
||||
AddComponent(shot, "Template");
|
||||
auto physics = AddComponent<Components::Physics>(shot, "Physics");
|
||||
physics->Mass = 10.f;
|
||||
physics->Static = false;
|
||||
auto modelComponent = AddComponent<Components::Model>(shot, "Model");
|
||||
modelComponent->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
|
||||
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||
|
||||
{
|
||||
auto shape = CreateEntity(tank);
|
||||
auto shape = CreateEntity(shot);
|
||||
auto transform = AddComponent<Components::Transform>(shape, "Transform");
|
||||
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
|
||||
boxShape->Width = 0.5f;
|
||||
@@ -501,7 +503,7 @@ void GameWorld::Initialize()
|
||||
}
|
||||
CommitEntity(wheel);
|
||||
|
||||
auto entity = CreateEntity(tank);
|
||||
/*auto entity = CreateEntity(tank);
|
||||
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
|
||||
transformComponent->Position = glm::vec3(2,-1.7,2.0);
|
||||
transformComponent->Scale = glm::vec3(3,3,3);
|
||||
@@ -523,7 +525,7 @@ void GameWorld::Initialize()
|
||||
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
|
||||
emitterComponent->ParticleTemplate = particleEntity;
|
||||
|
||||
CommitEntity(particleEntity);
|
||||
CommitEntity(particleEntity);*/
|
||||
}
|
||||
|
||||
{
|
||||
@@ -585,29 +587,29 @@ void GameWorld::Initialize()
|
||||
}
|
||||
CommitEntity(wheel);
|
||||
|
||||
auto entity = CreateEntity(tank);
|
||||
auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
|
||||
transformComponent->Position = glm::vec3(-2,-1.7,2.0);
|
||||
transformComponent->Scale = glm::vec3(3,3,3);
|
||||
transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
|
||||
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||
emitterComponent->SpawnCount = 2;
|
||||
emitterComponent->SpawnFrequency = 0.005;
|
||||
emitterComponent->SpreadAngle = glm::pi<float>();
|
||||
emitterComponent->UseGoalVelocity = false;
|
||||
emitterComponent->LifeTime = 0.5;
|
||||
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
|
||||
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
|
||||
CommitEntity(entity);
|
||||
//auto entity = CreateEntity(tank);
|
||||
//auto transformComponent = AddComponent<Components::Transform>(entity, "Transform");
|
||||
//transformComponent->Position = glm::vec3(-2,-1.7,2.0);
|
||||
//transformComponent->Scale = glm::vec3(3,3,3);
|
||||
//transformComponent->Orientation = glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0));
|
||||
//auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity, "ParticleEmitter");
|
||||
//emitterComponent->SpawnCount = 2;
|
||||
//emitterComponent->SpawnFrequency = 0.005;
|
||||
//emitterComponent->SpreadAngle = glm::pi<float>();
|
||||
//emitterComponent->UseGoalVelocity = false;
|
||||
//emitterComponent->LifeTime = 0.5;
|
||||
////emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
|
||||
//emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
|
||||
//CommitEntity(entity);
|
||||
|
||||
auto particleEntity = CreateEntity(entity);
|
||||
auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
|
||||
TEMP->Scale = glm::vec3(0);
|
||||
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
|
||||
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
|
||||
emitterComponent->ParticleTemplate = particleEntity;
|
||||
//auto particleEntity = CreateEntity(entity);
|
||||
//auto TEMP = AddComponent<Components::Transform>(particleEntity, "Transform");
|
||||
//TEMP->Scale = glm::vec3(0);
|
||||
//auto spriteComponent = AddComponent<Components::Sprite>(particleEntity, "Sprite");
|
||||
//spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
|
||||
//emitterComponent->ParticleTemplate = particleEntity;
|
||||
|
||||
CommitEntity(particleEntity);
|
||||
//CommitEntity(particleEntity);
|
||||
}
|
||||
|
||||
CommitEntity(tank);
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Components/BarrelSteering.h"
|
||||
#include "Components/Shot.h"
|
||||
|
||||
class GameWorld : public World
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
|
||||
// Events
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||
|
||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||
@@ -583,5 +583,8 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||
|
||||
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
{
|
||||
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(ConvertPosition(event.Velocity));
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
if(towerSteeringComponent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
glm::quat orientation = glm::angleAxis(towerSteeringComponent->Velocity * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
|
||||
glm::quat orientation = glm::angleAxis(towerSteeringComponent->TurnSpeed * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
|
||||
@@ -46,21 +46,25 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
if(barrelSteeringComponent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->Velocity * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(entity);
|
||||
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
|
||||
auto shotComponent = m_World->GetComponent<Components::Shot>(entity, "Shot");
|
||||
if(shotComponent)
|
||||
{
|
||||
if(m_TowerInputController->shoot)
|
||||
if(m_TowerInputController->Shoot && m_TimeSinceLastShot[entity] > 1.0)
|
||||
{
|
||||
auto absoluteOrientation = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteOrientation(entity);
|
||||
EntityID clone = m_World->CloneEntity(barrelSteeringComponent->ShotTemplate);
|
||||
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteTransform(barrelSteeringComponent->ShotTemplate);
|
||||
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone, "Transform");
|
||||
cloneTransform->Position = templateAbsoluteTransform.Position;
|
||||
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
|
||||
Events::SetVelocity e;
|
||||
e.Entity = entity;
|
||||
e.Velocity = absoluteOrientation * (glm::vec3(0.f, 0.f, 1.f) * shotComponent->Speed * (float)dt);
|
||||
e.Entity = clone;
|
||||
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||
EventBroker->Publish(e);
|
||||
m_TimeSinceLastShot[entity] = 0;
|
||||
}
|
||||
|
||||
m_TimeSinceLastShot[entity] += dt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +78,7 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
|
||||
{
|
||||
TowerDirection = m_TowerDirection;
|
||||
BarrelDirection = m_BarrelDirection;
|
||||
shoot = m_Shoot;
|
||||
Shoot = m_Shoot;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
@@ -111,7 +115,7 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
|
||||
|
||||
else if (event.Command == "shoot")
|
||||
{
|
||||
shoot = (bool)val;
|
||||
m_Shoot = val > 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Components/BarrelSteering.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Components/Shot.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
@@ -32,6 +31,8 @@ namespace Systems
|
||||
std::unique_ptr<TankSteeringInputController> m_TankInputController;
|
||||
class TowerSteeringInputController;
|
||||
std::unique_ptr<TowerSteeringInputController> m_TowerInputController;
|
||||
|
||||
std::map<EntityID, double> m_TimeSinceLastShot;
|
||||
};
|
||||
|
||||
class TankSteeringSystem::TankSteeringInputController : InputController
|
||||
@@ -76,7 +77,7 @@ namespace Systems
|
||||
|
||||
float TowerDirection;
|
||||
float BarrelDirection;
|
||||
bool shoot;
|
||||
bool Shoot;
|
||||
void Update(double dt);
|
||||
protected:
|
||||
virtual bool OnCommand(const Events::InputCommand &event);
|
||||
|
||||
@@ -170,6 +170,8 @@ EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */)
|
||||
for (auto pair : m_EntityComponents[entity])
|
||||
{
|
||||
auto type = pair.first;
|
||||
if (type == "Template")
|
||||
continue;
|
||||
auto component = std::shared_ptr<Component>(pair.second->Clone());
|
||||
if (component != nullptr)
|
||||
{
|
||||
@@ -186,6 +188,8 @@ EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */)
|
||||
}
|
||||
}
|
||||
|
||||
CommitEntity(clone);
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,6 @@
|
||||
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
|
||||
<ClInclude Include="..\..\src\Components\Physics.h" />
|
||||
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
||||
<ClInclude Include="..\..\src\Components\Shot.h" />
|
||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
||||
<ClInclude Include="..\..\src\Components\SphereShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
||||
|
||||
@@ -337,9 +337,6 @@
|
||||
<ClInclude Include="..\..\src\Components\BarrelSteering.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Shot.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\SetVelocity.h">
|
||||
<Filter>Physics\Events</Filter>
|
||||
</ClInclude>
|
||||
|
||||
Reference in New Issue
Block a user