Tower not aiming towards the player.

This commit is contained in:
Tleety
2014-06-05 00:35:15 +02:00
parent 6cae09c5d8
commit 93c4805a22
8 changed files with 238 additions and 17 deletions
+24
View File
@@ -0,0 +1,24 @@
#ifndef Tower_h__
#define Tower_h__
#include "Component.h"
namespace Components
{
struct Tower : Component
{
Tower()
: ID(0) { }
int ID;
EntityID GunBase;
EntityID Gun;
virtual Tower* Clone() const override { return new Tower(*this); }
};
}
#endif // Tower_h__
View File
+88 -8
View File
@@ -292,8 +292,6 @@ void GameWorld::Initialize()
EventBroker->Publish(e);
}*/
{
auto flag = CreateEntity();
auto transform = AddComponent<Components::Transform>(flag);
@@ -442,6 +440,7 @@ void GameWorld::RegisterSystems()
m_SystemFactory.Register<Systems::FollowSystem>([this]() { return new Systems::FollowSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::GarageSystem>([this]() { return new Systems::GarageSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::WallSystem>([this]() { return new Systems::WallSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::TowerSystem>([this]() { return new Systems::TowerSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::RenderSystem>([this]() { return new Systems::RenderSystem(this, EventBroker, ResourceManager); });
}
@@ -465,6 +464,7 @@ void GameWorld::AddSystems()
AddSystem<Systems::FollowSystem>();
AddSystem<Systems::GarageSystem>();
AddSystem<Systems::WallSystem>();
AddSystem<Systems::TowerSystem>();
AddSystem<Systems::RenderSystem>();
}
@@ -628,6 +628,85 @@ void GameWorld::CreateGate(EntityID parent, glm::vec3 position, glm::quat orient
}
}
EntityID GameWorld::CreateTower(EntityID parent, glm::vec3 pos, int playerID)
{
auto towerBase = CreateEntity(parent);
auto transform = AddComponent<Components::Transform>(towerBase);
transform->Position = pos;
auto towerComponent = AddComponent<Components::Tower>(towerBase);
auto physics = AddComponent<Components::Physics>(towerBase);
physics->Mass = 100.f;
physics->MotionType = Components::Physics::MotionTypeEnum::Fixed;
auto model = AddComponent<Components::Model>(towerBase);
model->ModelFile = "Models/Turret/Base/Base.obj";
auto health = AddComponent<Components::Health>(towerBase);
health->Amount = 50.f;
auto shape = CreateEntity(towerBase);
auto shapetransform = AddComponent<Components::Transform>(shape);
auto shapemesh = AddComponent<Components::MeshShape>(shape);
shapemesh->ResourceName = "Models/Turret/Base/Base.obj";
CommitEntity(shape);
{
auto towerGunRotation = CreateEntity(towerBase);
auto transform = AddComponent<Components::Transform>(towerGunRotation);
transform->Position = glm::vec3(0.f, 5.889f-0.92791f, 0.f);
auto towerGunBaseModel = CreateEntity(towerGunRotation);
{
auto transform = AddComponent<Components::Transform>(towerGunBaseModel);
transform->Orientation = glm::quat(glm::vec3(0, -glm::pi<float>() / 2.f, 0));
auto model = AddComponent<Components::Model>(towerGunBaseModel);
model->ModelFile = "Models/Turret/GunRotation/GunRotation.obj";
}
CommitEntity(towerGunBaseModel);
auto health = AddComponent<Components::Health>(towerGunRotation);
health->Amount = 50.f;
{
auto towerGun = CreateEntity(towerGunRotation);
auto transform = AddComponent<Components::Transform>(towerGun);
transform->Position = glm::vec3(0.f, 4.12801f, 1.18125f);
//transform->Orientation = glm::quat(glm::vec3(0, -glm::pi<float>() / 2.f, 0));
auto towerGunModel = CreateEntity(towerGun);
{
auto transform = AddComponent<Components::Transform>(towerGunModel);
transform->Orientation = glm::quat(glm::vec3(0, -glm::pi<float>() / 2.f, 0));
auto model = AddComponent<Components::Model>(towerGunModel);
model->ModelFile = "Models/Turret/Gun/Gun.obj";
}
CommitEntity(towerGunModel);
auto health = AddComponent<Components::Health>(towerGun);
health->Amount = 50.f;
CommitEntity(towerGun);
towerComponent->Gun = towerGun;
}
CommitEntity(towerGunRotation);
towerComponent->GunBase = towerGunRotation;
}
towerComponent->ID = playerID;
CommitEntity(towerBase);
return towerBase;
}
EntityID GameWorld::CreateWall(EntityID parent, glm::vec3 pos, glm::quat orientation)
{
auto wall = CreateEntity(parent);
@@ -1100,12 +1179,13 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID)
CreateGate(base, glm::vec3(273.f, 40.185f, 0.06f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -55.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateTower(base, glm::vec3(290.f, 40.3f, 15.f), playerID);
CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)), playerID);
}
+2
View File
@@ -23,6 +23,7 @@
#include "Systems/WheelPairSystem.h"
#include "Systems/FollowSystem.h"
#include "Systems/WallSystem.h"
#include "Systems/TowerSystem.h"
#include "Systems/GarageSystem.h"
#include "Components/Camera.h"
@@ -82,6 +83,7 @@ private:
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering);
EntityID CreateJeep(int playerID);
EntityID CreateWall(EntityID parent, glm::vec3 pos, glm::quat orientation);
EntityID CreateTower(EntityID parent, glm::vec3 pos, int playerID);
EntityID CreateGarage(EntityID parent, glm::vec3 Position, glm::quat orientation, int playerID);
void CreateTerrain();
void CreateBase(glm::quat orientation, int playerID);
+69
View File
@@ -0,0 +1,69 @@
#include "PrecompiledHeader.h"
#include "TowerSystem.h"
#include "World.h"
void Systems::TowerSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Tower>([]() { return new Components::Tower(); });
}
void Systems::TowerSystem::Initialize()
{
//EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage);
}
//bool Systems::TowerSystem::Damage( const Events::Damage &event )
//{
// return true;
//}
void Systems::TowerSystem::Update( double dt )
{
}
void Systems::TowerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
auto towerComponent = m_World->GetComponent<Components::Tower>(entity);
if(!towerComponent)
return;
Components::Transform absoluteTowerGunTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(towerComponent->Gun);
auto towerGunTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->Gun);
if(!towerGunTransformComponent)
return;
auto towerGunBaseTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->GunBase);
if(!towerGunBaseTransformComponent)
return;
auto players = m_World->GetComponentsOfType<Components::Player>();
for(auto player : *players)
{
auto playerComponent = std::dynamic_pointer_cast<Components::Player>(player);
if(towerComponent->ID != playerComponent->ID) //!= betyder att den bara targetar sitt eget lag, == fienden.
continue;
auto playerTransform = m_World->GetComponent<Components::Transform>(player->Entity);
if(!playerTransform)
continue;
Components::Transform absolutePlayerTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(player->Entity);
glm::quat baseLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absoluteTowerGunTransform.Position.y, absolutePlayerTransform.Position.z), glm::vec3(0, 1, 0))));
glm::quat gunLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absolutePlayerTransform.Position.y, absolutePlayerTransform.Position.z ), glm::vec3(0, 1, 0))));
//glm::vec3 axisAngle = glm::eulerAngles(angle) - glm::pi<float>();
//glm::quat yaw = glm::quat(axisAngle * glm::vec3(0, 1, 0));
//glm::quat pitch = glm::quat(axisAngle * glm::vec3(1, 0, 0));
//LOG_INFO("yaw: %f", glm::degrees(axisAngle.y));
towerGunTransformComponent->Orientation = glm::inverse(baseLookAt) * gunLookAt;
towerGunBaseTransformComponent->Orientation = baseLookAt;
}
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef TowerSystem_h__
#define TowerSystem_h__
#include "System.h"
#include "Systems/TransformSystem.h"
#include "Components/Player.h"
#include "Components/Tower.h"
namespace Systems
{
class TowerSystem : public System
{
public:
TowerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
virtual void Update(double dt);
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent);
//EventRelay<TowerSystem, Events::Damage> m_eDamage;
//bool Damage(const Events::Damage &event);
private:
};
}
#endif // TowerSystem_h__
+3
View File
@@ -122,6 +122,7 @@
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TimerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
@@ -144,6 +145,7 @@
<ClInclude Include="..\..\src\Components\Garage.h" />
<ClInclude Include="..\..\src\Components\Move.h" />
<ClInclude Include="..\..\src\Components\Rotate.h" />
<ClInclude Include="..\..\src\Components\Tower.h" />
<ClInclude Include="..\..\src\Components\TriggerMove.h" />
<ClInclude Include="..\..\src\Components\Timer.h" />
<ClInclude Include="..\..\src\Components\TriggerExplosion.h" />
@@ -250,6 +252,7 @@
<ClInclude Include="..\..\src\Systems\SoundSystem.h" />
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\TimerSystem.h" />
<ClInclude Include="..\..\src\Systems\TowerSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Systems\TriggerSystem.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
+16 -9
View File
@@ -78,15 +78,18 @@
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Gameplay\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Sound.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -526,9 +529,6 @@
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Gameplay\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LeaveTrigger.h">
<Filter>Physics\Events</Filter>
</ClInclude>
@@ -565,9 +565,6 @@
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Gameplay\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter>
</ClInclude>
@@ -577,6 +574,16 @@
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\TowerSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Tower.h">
<Filter>Game\Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">