src/scene.h
branchpyrit
changeset 20 f22952603f29
parent 19 4e0955fca797
child 21 79b516a3803d
equal deleted inserted replaced
19:4e0955fca797 20:f22952603f29
    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 {
    88 
   124 
    89 	Material(const Colour &acolour) {
   125 	Material(const Colour &acolour) {
    90 		texture.colour = acolour;
   126 		texture.colour = acolour;
    91 		ambient = 0.1;
   127 		ambient = 0.1;
    92 		diffuse = 0.5;
   128 		diffuse = 0.5;
    93 		specular = 1.0;
   129 		specular = 0.1;
    94 		shininess = 20.0;
   130 		shininess = 0.5;
    95 		reflection = 0.5;
   131 		reflection = 0.5;
    96 	}
   132 	}
    97 };
   133 };
    98 
   134 
    99 class Shape
   135 class Shape