forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovementHelper.cpp
68 lines (61 loc) · 1.8 KB
/
MovementHelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "MovementHelper.hpp"
#include "Components.hpp"
#include "EntitySystem.hpp"
Ogre::Real MovementHelper::get_speed_modifier(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<MovementComponent>(id);
if(comp)
return comp->speed_modifier;
else
return Ogre::Real{};
}
void MovementHelper::set_speed_modifier(EntitySystem& ents, std::size_t id, Ogre::Real val)
{
auto comp = ents.get_component<MovementComponent>(id);
if(comp)
comp->speed_modifier = val;
}
Ogre::Vector3 MovementHelper::dir_to(EntitySystem& ents, std::size_t id1, std::size_t id2)
{
auto comp1 = ents.get_component<PhysicsComponent>(id1);
auto comp2 = ents.get_component<PhysicsComponent>(id2);
if(comp1 && comp2)
{
auto pos = comp2->position - comp1->position;
return pos;
}
else
return Ogre::Vector3{0, 0, 0};
}
Ogre::Vector3 MovementHelper::get_dir(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<GraphicsComponent>(id);
if(comp)
return comp->node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
else
return Ogre::Vector3{0, 0, 0};
}
Ogre::Vector3 MovementHelper::get_dir_back(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<GraphicsComponent>(id);
if(comp)
return comp->node->getOrientation() * Ogre::Vector3::UNIT_Z;
else
return Ogre::Vector3{0, 0, 0};
}
Ogre::Vector3 MovementHelper::get_dir_left(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<GraphicsComponent>(id);
if(comp)
return comp->node->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_X;
else
return Ogre::Vector3{0, 0, 0};
}
Ogre::Vector3 MovementHelper::get_dir_right(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<GraphicsComponent>(id);
if(comp)
return comp->node->getOrientation() * Ogre::Vector3::UNIT_X;
else
return Ogre::Vector3{0, 0, 0};
}