WIP WheelPair

This commit is contained in:
2014-05-29 17:45:15 +02:00
parent 04b15fe92a
commit 0db4ebea95
7 changed files with 144 additions and 58 deletions
+35
View File
@@ -0,0 +1,35 @@
#include "PrecompiledHeader.h"
#include "WheelPairSystem.h"
#include "World.h"
void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
}
void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto wheelPair = m_World->GetComponent<Components::WheelPair>(entity);
if (!wheelPair)
return;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
return;
auto transformFake1 = m_World->GetComponent<Components::Transform>(wheelPair->FakeWheel1);
if (!transformFake1)
return;
auto transformFake2 = m_World->GetComponent<Components::Transform>(wheelPair->FakeWheel2);
if (!transformFake2)
return;
glm::vec3 thing = transformFake2->Position - transformFake1->Position;
glm::vec3 forward = glm::normalize(glm::vec3(thing.x, 0, thing.z));
glm::vec3 up = glm::vec3(0, 1, 0);
float angle = glm::acos(glm::dot(glm::normalize(thing), forward));
float height = (thing / 2.f).y;
transform->Position.y = height;
//transform->Orientation = glm::quat(glm::vec3())
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef Systems_WheelPairSystem_h__
#define Systems_WheelPairSystem_h__
#include "World.h"
#include "System.h"
#include "Components/Transform.h"
#include "Components/WheelPair.h"
namespace Systems
{
class WheelPairSystem : public System
{
public:
WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void RegisterComponents(ComponentFactory* cf) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
};
}
#endif // Systems_WheelPairSystem_h__