Commit 9650806e9d2d28b1752c89aefc6869acd5cd1dc9
1 parent
154fe135
Modified Camera.h to work with the new class system. Tested and functional.
Showing
1 changed file
with
33 additions
and
34 deletions
Show diff stats
visualization/camera.h
1 | -#include <../math/vector.h> | |
2 | -#include <../math/point.h> | |
3 | -#include <../math/quaternion.h> | |
4 | -#include <../math/matrix.h> | |
1 | +#include "../math/vector.h" | |
2 | +#include "../math/quaternion.h" | |
3 | +#include "../math/matrix.h" | |
5 | 4 | |
6 | 5 | #include <ostream> |
7 | 6 | |
... | ... | @@ -12,32 +11,32 @@ namespace stim{ |
12 | 11 | |
13 | 12 | class camera |
14 | 13 | { |
15 | - vector<float, 3> d; //direction that the camera is pointing | |
16 | - point<float, 3> p; //position of the camera | |
17 | - vector<float, 3> up; //"up" direction | |
14 | + vec<float, 3> d; //direction that the camera is pointing | |
15 | + vec<float, 3> p; //position of the camera | |
16 | + vec<float, 3> up; //"up" direction | |
18 | 17 | float focus; //focal length of the camera |
19 | 18 | float fov; |
20 | 19 | |
21 | 20 | //private function makes sure that the up vector is orthogonal to the direction vector and both are normalized |
22 | 21 | void stabalize() |
23 | 22 | { |
24 | - vector<float, 3> side = up.cross(d); | |
23 | + vec<float, 3> side = up.cross(d); | |
25 | 24 | up = d.cross(side); |
26 | 25 | up = up.norm(); |
27 | 26 | d = d.norm(); |
28 | 27 | } |
29 | 28 | |
30 | 29 | public: |
31 | - void setPosition(point<float, 3> pos) | |
30 | + void setPosition(vec<float, 3> pos) | |
32 | 31 | { |
33 | 32 | p = pos; |
34 | 33 | } |
35 | - void setPosition(float x, float y, float z){setPosition(point<float, 3>(x, y, z));} | |
34 | + void setPosition(float x, float y, float z){setPosition(vec<float, 3>(x, y, z));} | |
36 | 35 | |
37 | 36 | void setFocalDistance(float distance){focus = distance;} |
38 | 37 | void setFOV(float field_of_view){fov = field_of_view;} |
39 | 38 | |
40 | - void LookAt(point<float, 3> pos) | |
39 | + void LookAt(vec<float, 3> pos) | |
41 | 40 | { |
42 | 41 | //find the new direction |
43 | 42 | d = pos - p; |
... | ... | @@ -48,22 +47,22 @@ public: |
48 | 47 | //stabalize the camera |
49 | 48 | stabalize(); |
50 | 49 | } |
51 | - void LookAt(float px, float py, float pz){LookAt(point<float, 3>(px, py, pz));} | |
52 | - void LookAt(point<float, 3> pos, vector<float, 3> new_up){up = new_up; LookAt(pos);} | |
53 | - void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(point<float, 3>(px, py, pz), vector<float, 3>(ux, uy, uz));} | |
50 | + void LookAt(float px, float py, float pz){LookAt(vec<float, 3>(px, py, pz));} | |
51 | + void LookAt(vec<float, 3> pos, vec<float, 3> new_up){up = new_up; LookAt(pos);} | |
52 | + void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(vec<float, 3>(px, py, pz), vec<float, 3>(ux, uy, uz));} | |
54 | 53 | void LookAtDolly(float lx, float ly, float lz) |
55 | 54 | { |
56 | 55 | //find the current focus point |
57 | - point<float, 3> f = p + focus*d; | |
58 | - vector<float, 3> T = point<float, 3>(lx, ly, lz) - f; | |
56 | + vec<float, 3> f = p + focus*d; | |
57 | + vec<float, 3> T = vec<float, 3>(lx, ly, lz) - f; | |
59 | 58 | p = p + T; |
60 | 59 | } |
61 | 60 | |
62 | - void Dolly(vector<float, 3> direction) | |
61 | + void Dolly(vec<float, 3> direction) | |
63 | 62 | { |
64 | 63 | p = p+direction; |
65 | 64 | } |
66 | - void Dolly(float x, float y, float z){Dolly(vector<float, 3>(x, y, z));} | |
65 | + void Dolly(float x, float y, float z){Dolly(vec<float, 3>(x, y, z));} | |
67 | 66 | void Push(float delta) |
68 | 67 | { |
69 | 68 | if(delta > focus) |
... | ... | @@ -81,7 +80,7 @@ public: |
81 | 80 | qx.CreateRotation(theta_x, up[0], up[1], up[2]); |
82 | 81 | |
83 | 82 | //y rotation is around the side axis |
84 | - vector<float, 3> side = up.cross(d); | |
83 | + vec<float, 3> side = up.cross(d); | |
85 | 84 | quaternion<float> qy; |
86 | 85 | qy.CreateRotation(theta_y, side[0], side[1], side[2]); |
87 | 86 | |
... | ... | @@ -119,28 +118,28 @@ public: |
119 | 118 | void OrbitFocus(float theta_x, float theta_y) |
120 | 119 | { |
121 | 120 | //find the focal point |
122 | - point<float, 3> focal_point = p + focus*d; | |
121 | + vec<float, 3> focal_point = p + focus*d; | |
123 | 122 | |
124 | 123 | //center the coordinate system on the focal point |
125 | - point<float, 3> centered = p - (focal_point - point<float, 3>(0, 0, 0)); | |
124 | + vec<float, 3> centered = p - (focal_point - vec<float, 3>(0, 0, 0)); | |
126 | 125 | |
127 | 126 | //create the x rotation (around the up vector) |
128 | 127 | quaternion<float> qx; |
129 | 128 | qx.CreateRotation(theta_x, up[0], up[1], up[2]); |
130 | - centered = point<float, 3>(0, 0, 0) + qx.toMatrix3()*(centered - point<float, 3>(0, 0, 0)); | |
129 | + centered = vec<float, 3>(0, 0, 0) + qx.toMatrix3()*(centered - vec<float, 3>(0, 0, 0)); | |
131 | 130 | |
132 | 131 | //get a side vector for theta_y rotation |
133 | - vector<float, 3> side = up.cross((point<float, 3>(0, 0, 0) - centered).norm()); | |
132 | + vec<float, 3> side = up.cross((vec<float, 3>(0, 0, 0) - centered).norm()); | |
134 | 133 | |
135 | 134 | quaternion<float> qy; |
136 | 135 | qy.CreateRotation(theta_y, side[0], side[1], side[2]); |
137 | - centered = point<float, 3>(0, 0, 0) + qy.toMatrix3()*(centered - point<float, 3>(0, 0, 0)); | |
136 | + centered = vec<float, 3>(0, 0, 0) + qy.toMatrix3()*(centered - vec<float, 3>(0, 0, 0)); | |
138 | 137 | |
139 | 138 | //perform the rotation on the centered camera position |
140 | 139 | //centered = final.toMatrix()*centered; |
141 | 140 | |
142 | 141 | //re-position the camera |
143 | - p = centered + (focal_point - point<float, 3>(0, 0, 0)); | |
142 | + p = centered + (focal_point - vec<float, 3>(0, 0, 0)); | |
144 | 143 | |
145 | 144 | //make sure we are looking at the focal point |
146 | 145 | LookAt(focal_point); |
... | ... | @@ -152,17 +151,17 @@ public: |
152 | 151 | |
153 | 152 | void Slide(float u, float v) |
154 | 153 | { |
155 | - vector<float, 3> V = up.norm(); | |
156 | - vector<float, 3> U = up.cross(d).norm(); | |
154 | + vec<float, 3> V = up.norm(); | |
155 | + vec<float, 3> U = up.cross(d).norm(); | |
157 | 156 | |
158 | 157 | p = p + (V * v) + (U * u); |
159 | 158 | } |
160 | 159 | |
161 | 160 | //accessor methods |
162 | - point<float, 3> getPosition(){return p;} | |
163 | - vector<float, 3> getUp(){return up;} | |
164 | - vector<float, 3> getDirection(){return d;} | |
165 | - point<float, 3> getLookAt(){return p + focus*d;} | |
161 | + vec<float, 3> getPosition(){return p;} | |
162 | + vec<float, 3> getUp(){return up;} | |
163 | + vec<float, 3> getDirection(){return d;} | |
164 | + vec<float, 3> getLookAt(){return p + focus*d;} | |
166 | 165 | float getFOV(){return fov;} |
167 | 166 | |
168 | 167 | //output the camera settings |
... | ... | @@ -183,9 +182,9 @@ public: |
183 | 182 | //constructor |
184 | 183 | camera() |
185 | 184 | { |
186 | - p = point<float, 3>(0, 0, 0); | |
187 | - d = vector<float, 3>(0, 0, 1); | |
188 | - up = vector<float, 3>(0, 1, 0); | |
185 | + p = vec<float, 3>(0, 0, 0); | |
186 | + d = vec<float, 3>(0, 0, 1); | |
187 | + up = vec<float, 3>(0, 1, 0); | |
189 | 188 | focus = 1; |
190 | 189 | |
191 | 190 | } | ... | ... |