-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCameraTracking.h
53 lines (49 loc) · 1022 Bytes
/
CameraTracking.h
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
#pragma once
#include "Camera.h"
#include <fstream>
#include <stdlib.h>
#include "KeyFrame.h"
#define PI 3.141592654
class CameraTrack {
public:
vector<TranslationKeyFrame> keys;
Vector3 pos = Vector3(0, 0, 0);
Vector3 LastPos = Vector3(0, 0, 0);
Vector3 d;
Quaternion q = Quaternion::IDENTITY;
int frame = 0;
SceneNode* Node = NULL;
void Track(Vector3 newpos) {
frame++;
LastPos = pos;
pos = newpos;
Vector3 tmpd = newpos - LastPos;
if (tmpd.length() < 1e-5)
return;
d = newpos - LastPos;
d.normalize();
}
void UpdateNode() {
Node->setTranslation(GetPos());
Node->setOrientation(GetOrientation());
}
Vector3 GetPos() {
return pos;
}
Quaternion GetOrientation() {
Vector3 d0 = Vector3(0, 0, 1);
if ((d - d0).length() < 1e-5) {
q.fromAngleAxis(0, Vector3(0, 1, 0));
}
else
{
float c = d.dotProduct(d0);
float angle = acos(c);
float clockwise = 1;
if (d.x < 0)
clockwise = -1;
q.fromAngleAxis(clockwise*angle, Vector3(0, 1, 0));
}
return q;
}
};