-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackerNode.cpp
66 lines (57 loc) · 1.4 KB
/
TrackerNode.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
#include "Util.h"
#include "TrackerNode.h"
#include "math/common.h"
using namespace std;
TrackerNode :: TrackerNode()
{
//m_wpFocus = NULL;
m_FocusFlag = FOCUS_NONE;
m_bNeedsUpdate = false;
}
TrackerNode :: TrackerNode(weak_ptr<Node> nfocus, TrackerNode::FocusFlag ff)
{
//_follow(t, ts);
focus(nfocus, ff);
}
void TrackerNode :: update()
{
if(shared_ptr<Node> focus = m_wpFocus.lock())
{
if(m_FocusFlag == FOCUS_ATTACH)
{
Matrix::translation(m_Matrix, Matrix::translation(*focus->matrix()));
}
else if(m_FocusFlag == FOCUS_ORIENT)
{
glm::vec3 pos = Matrix::translation(*focus->matrix());
m_Matrix = *focus->matrix();
//m_Matrix.clear(Matrix::COPY, *focus->matrix());
Matrix::translation(m_Matrix, pos);
}
else if(m_FocusFlag == FOCUS_COPY)
{
m_Matrix = *focus->matrix();
//m_Matrix.clear(Matrix::COPY, *focus->matrix());
}
m_bNeedsUpdate = false;
}
}
glm::mat4* TrackerNode :: matrix()
{
if(m_bNeedsUpdate)
update();
return &m_Matrix;
}
void TrackerNode :: focus(weak_ptr<Node> nfocus, FocusFlag ff)
{
//if(!nfocus)
//{
// m_wpFocus = NULL;
// return;
//}
if(nfocus.lock() == m_wpFocus.lock())
return;
m_wpFocus = nfocus;
m_FocusFlag = ff;
m_bNeedsUpdate = true;
}