22 Vector3 o, dir; |
22 Vector3 o, dir; |
23 Ray(const Vector3 &ao, const Vector3 &adir): |
23 Ray(const Vector3 &ao, const Vector3 &adir): |
24 o(ao), dir(adir) {}; |
24 o(ao), dir(adir) {}; |
25 }; |
25 }; |
26 |
26 |
|
27 class Quaternion |
|
28 { |
|
29 public: |
|
30 float a,b,c,d; |
|
31 Quaternion(): a(0), b(0), c(0), d(0) {}; |
|
32 Quaternion(const float aa, const float ab, const float ac, const float ad): |
|
33 a(aa), b(ab), c(ac), d(ad) {}; |
|
34 Quaternion(const Vector3& v): a(1), b(v.x), c(v.y), d(v.z) {}; |
|
35 |
|
36 Vector3 toVector() { return Vector3(b/a, c/a, d/a); }; |
|
37 |
|
38 Quaternion normalize() |
|
39 { |
|
40 float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d); |
|
41 a *= f; |
|
42 b *= f; |
|
43 c *= f; |
|
44 d *= f; |
|
45 return *this; |
|
46 }; |
|
47 friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2) |
|
48 { |
|
49 return Quaternion( |
|
50 q1.a*q2.a - q1.b*q2.b - q1.c*q2.c - q1.d*q2.d, |
|
51 q1.a*q2.b + q1.b*q2.a + q1.c*q2.d - q1.d*q2.c, |
|
52 q1.a*q2.c + q1.c*q2.a + q1.d*q2.b - q1.b*q2.d, |
|
53 q1.a*q2.d + q1.d*q2.a + q1.b*q2.c - q1.c*q2.b); |
|
54 }; |
|
55 friend Quaternion conjugate(const Quaternion &q) |
|
56 { |
|
57 return Quaternion(q.a, -q.b, -q.c, -q.d); |
|
58 } |
|
59 }; |
|
60 |
27 class Camera |
61 class Camera |
28 { |
62 { |
29 public: |
63 public: |
30 Vector3 eye, p, u, v; |
64 Vector3 eye, p, u, v; |
31 float f; |
65 float f; |
32 |
66 |
33 Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), f(3.14/4.0) {}; |
67 Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), f(3.14/4.0) {}; |
34 Camera(const Vector3 &C, const Vector3 &ap, const Vector3 &au, const Vector3 &av): |
68 Camera(const Vector3 &C, const Vector3 &ap, const Vector3 &au, const Vector3 &av): |
35 eye(C), p(ap), u(au), v(av), f(3.14/4.0) {}; |
69 eye(C), p(ap), u(au), v(av), f(3.14/4.0) {}; |
36 void setEye(const Vector3 &aeye) { eye = aeye; }; |
70 void setEye(const Vector3 &aeye) { eye = aeye; }; |
37 void setFocusLength(const float af) { f = af; }; |
71 void setFocalLength(const float af) { f = af; }; |
|
72 void rotate(const Quaternion &q); |
|
73 void move(const float fw, const float left, const float up); |
38 }; |
74 }; |
39 |
75 |
40 /* axis-aligned bounding box */ |
76 /* axis-aligned bounding box */ |
41 class BBox |
77 class BBox |
42 { |
78 { |