equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * C++ RayTracer |
2 * Pyrit Ray Tracer |
3 * file: scene.h |
3 * file: scene.h |
4 * |
4 * |
5 * Radek Brich, 2006 |
5 * Radek Brich, 2006-2007 |
6 */ |
6 */ |
7 |
7 |
8 #ifndef SCENE_H |
8 #ifndef SCENE_H |
9 #define SCENE_H |
9 #define SCENE_H |
10 |
10 |
11 #include <vector> |
11 #include <vector> |
12 #include <typeinfo> |
12 #include <typeinfo> |
13 |
13 |
14 #include "noise.h" |
14 #include "noise.h" |
15 #include "vector.h" |
15 #include "vector.h" |
|
16 #include "quaternion.h" |
16 |
17 |
17 /* |
18 /* |
18 triangle intersection alghoritm |
19 triangle intersection alghoritm |
19 chooses are: |
20 chooses are: |
20 TRI_PLUCKER |
21 TRI_PLUCKER |
31 { |
32 { |
32 public: |
33 public: |
33 Vector3 o, dir; |
34 Vector3 o, dir; |
34 Ray(const Vector3 &ao, const Vector3 &adir): |
35 Ray(const Vector3 &ao, const Vector3 &adir): |
35 o(ao), dir(adir) {}; |
36 o(ao), dir(adir) {}; |
36 }; |
|
37 |
|
38 class Quaternion |
|
39 { |
|
40 public: |
|
41 Float a,b,c,d; |
|
42 Quaternion(): a(0), b(0), c(0), d(0) {}; |
|
43 Quaternion(const Float aa, const Float ab, const Float ac, const Float ad): |
|
44 a(aa), b(ab), c(ac), d(ad) {}; |
|
45 Quaternion(const Vector3& v): a(1), b(v.x), c(v.y), d(v.z) {}; |
|
46 |
|
47 Vector3 toVector() { return Vector3(b/a, c/a, d/a); }; |
|
48 |
|
49 Quaternion normalize() |
|
50 { |
|
51 Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d); |
|
52 a *= f; |
|
53 b *= f; |
|
54 c *= f; |
|
55 d *= f; |
|
56 return *this; |
|
57 }; |
|
58 friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2) |
|
59 { |
|
60 return Quaternion( |
|
61 q1.a*q2.a - q1.b*q2.b - q1.c*q2.c - q1.d*q2.d, |
|
62 q1.a*q2.b + q1.b*q2.a + q1.c*q2.d - q1.d*q2.c, |
|
63 q1.a*q2.c + q1.c*q2.a + q1.d*q2.b - q1.b*q2.d, |
|
64 q1.a*q2.d + q1.d*q2.a + q1.b*q2.c - q1.c*q2.b); |
|
65 }; |
|
66 friend Quaternion conjugate(const Quaternion &q) |
|
67 { |
|
68 return Quaternion(q.a, -q.b, -q.c, -q.d); |
|
69 } |
|
70 }; |
37 }; |
71 |
38 |
72 class Camera |
39 class Camera |
73 { |
40 { |
74 public: |
41 public: |