-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.cpp
128 lines (102 loc) · 2.15 KB
/
Camera.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Cloud of voxels (CoV) project
* Author: mcidclan, m [.D'O'T.] cid [.D'O'T.] clan [.A'T.] gmail [.D'O'T.] com
* Creation Date: 2011
* Modification Date: 2020
*/
#include "./headers/Camera.h"
/*
* extern midentity
*/
extern const float midentity[16];
/*
* rotation matrix
*/
static float matrot[16] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
/*
* temporaries matrix
*/
static float mattmp_1[16] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
static float mattmp_2[16] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__)));
/*
* Constructor
*/
Camera::Camera()
{
this->resetTransformation();
this->nearcenter.x =
this->nearcenter.y =
this->nearcenter.z = 0.0f;
}
/*
* Destructor
*/
Camera::~Camera()
{
}
/*
* updateNearInfo
*/
void Camera::updateNearInfo(float* const m)
{
memcpy(&(this->basis.i), &m[0], sizeof(Vec3<float>));
memcpy(&(this->basis.j), &m[4], sizeof(Vec3<float>));
memcpy(&(this->basis.k), &m[8], sizeof(Vec3<float>));
math::normalize(&(this->basis.i));
math::normalize(&(this->basis.j));
math::normalize(&(this->basis.k));
}
/*
* position
*/
void Camera::setPosition(const float x, const float y , const float z)
{
this->nearcenter.x = x;
this->nearcenter.y = y;
this->nearcenter.z = z;
}
/*
* resetTransformation
*/
void Camera::resetTransformation()
{
memset(matrot, 0x0, sizeof(matrot));
matrot[0] =
matrot[5] =
matrot[10] =
matrot[15] = 1.0f;
}
/*
* rotate
*/
void Camera::rotate(const Vec3<float> axis, float angle)
{
math::eulerorientation(axis, angle, mattmp_1);
math::mat4xmat4(matrot, mattmp_1, mattmp_2);
memcpy(matrot, mattmp_2, sizeof(matrot));
this->updateNearInfo(matrot);
}
/*
* translate
*/
void Camera::translate(const Vec3<float> v)
{
math::translate(v, matrot);
this->nearcenter.x = matrot[12];
this->nearcenter.y = matrot[13];
this->nearcenter.z = matrot[14];
}
/*
* getBasis
*/
void Camera::getBasis(Mat3f* const basis)
{
*basis = this->basis;
}
/*
* Reajust the given coordinates to the camera center
*/
void Camera::reajust(Vec3<float>* const coordinates)
{
math::vecadd(this->nearcenter, coordinates);
}