Tank tower and barrel steering working
This commit is contained in:
@@ -5,19 +5,20 @@
|
||||
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||
{
|
||||
cf->Register("TankSteering", []() { return new Components::TankSteering(); });
|
||||
cf->Register("TowerSteering", []() { return new Components::TowerSteering(); });
|
||||
cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); });
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::Initialize()
|
||||
{
|
||||
m_InputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker));
|
||||
m_InputController->PositionX = 0;
|
||||
m_InputController->PositionY = 0;
|
||||
m_InputController->Handbrake = false;
|
||||
m_TankInputController = std::unique_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker));
|
||||
m_TowerInputController = std::unique_ptr<TowerSteeringInputController>(new TowerSteeringInputController(EventBroker));
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::Update(double dt)
|
||||
{
|
||||
|
||||
m_TankInputController->Update(dt);
|
||||
m_TowerInputController->Update(dt);
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
@@ -27,61 +28,85 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
{
|
||||
Events::TankSteer e;
|
||||
e.Entity = entity;
|
||||
e.PositionX = m_InputController->PositionX;
|
||||
e.PositionY = m_InputController->PositionY;
|
||||
e.Handbrake = m_InputController->Handbrake;
|
||||
e.PositionX = m_TankInputController->PositionX;
|
||||
e.PositionY = m_TankInputController->PositionY;
|
||||
e.Handbrake = m_TankInputController->Handbrake;
|
||||
EventBroker->Publish(e);
|
||||
}
|
||||
|
||||
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(entity, "TowerSteering");
|
||||
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);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
|
||||
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(entity, "BarrelSteering");
|
||||
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);
|
||||
transformComponent->Orientation *= orientation;
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
|
||||
{
|
||||
PositionX = m_Horizontal;
|
||||
PositionY = m_Vertical;
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double dt )
|
||||
{
|
||||
TowerDirection = m_TowerDirection;
|
||||
BarrelDirection = m_BarrelDirection;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
{
|
||||
float val = boost::any_cast<float>(event.Value);
|
||||
if (event.Command == "+right")
|
||||
float val = event.Value;
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
PositionX += val;
|
||||
m_Horizontal = val;
|
||||
}
|
||||
else if (event.Command == "-right")
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
PositionX -= val;
|
||||
m_Vertical = val;
|
||||
}
|
||||
else if (event.Command == "+left")
|
||||
|
||||
else if (event.Command == "handbrake")
|
||||
{
|
||||
PositionX += -val;
|
||||
}
|
||||
else if (event.Command == "-left")
|
||||
{
|
||||
PositionX -= -val;
|
||||
}
|
||||
else if (event.Command == "+forward")
|
||||
{
|
||||
PositionY += -val;
|
||||
}
|
||||
else if (event.Command == "-forward")
|
||||
{
|
||||
PositionY -= -val;
|
||||
}
|
||||
else if (event.Command == "+backward")
|
||||
{
|
||||
PositionY += val;
|
||||
}
|
||||
else if (event.Command == "-backward")
|
||||
{
|
||||
PositionY -= val;
|
||||
Handbrake = val;
|
||||
}
|
||||
|
||||
else if (event.Command == "+handbrake")
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const Events::InputCommand &event )
|
||||
{
|
||||
float val = event.Value;
|
||||
if(event.Command == "tower_rotation")
|
||||
{
|
||||
Handbrake = true;
|
||||
m_TowerDirection = val;
|
||||
}
|
||||
else if (event.Command == "-handbrake")
|
||||
else if(event.Command == "barrel_rotation")
|
||||
{
|
||||
Handbrake = false;
|
||||
m_BarrelDirection = val;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TowerSteeringInputController::OnMouseMove( const Events::MouseMove &event )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user