src/scene.cc
branchpyrit
changeset 20 f22952603f29
parent 15 a0a3e334744f
child 21 79b516a3803d
equal deleted inserted replaced
19:4e0955fca797 20:f22952603f29
     7 
     7 
     8 #include <math.h>
     8 #include <math.h>
     9 
     9 
    10 #include "common.h"
    10 #include "common.h"
    11 #include "scene.h"
    11 #include "scene.h"
       
    12 
       
    13 void Camera::rotate(const Quaternion &q)
       
    14 {
       
    15 	Quaternion res;
       
    16 	res = q * Quaternion(u) * conjugate(q);
       
    17 	u = res.toVector();
       
    18 	res = q * Quaternion(v) * conjugate(q);
       
    19 	v = res.toVector();
       
    20 	res = q * Quaternion(p) * conjugate(q);
       
    21 	p = res.toVector();
       
    22 	p.normalize();
       
    23 	u.normalize();
       
    24 	v.normalize();
       
    25 /*  // optimized version
       
    26 	float t2 =   q.a*q.b;
       
    27 	float t3 =   q.a*q.c;
       
    28 	float t4 =   q.a*q.d;
       
    29 	float t5 =  -q.b*q.b;
       
    30 	float t6 =   q.b*q.c;
       
    31 	float t7 =   q.b*q.d;
       
    32 	float t8 =  -q.c*q.c;
       
    33 	float t9 =   q.c*q.d;
       
    34 	float t10 = -q.d*q.d;
       
    35 	float x,y,z;
       
    36 	x = 2*( (t8 + t10)*p.x + (t6 -  t4)*p.y + (t3 + t7)*p.z ) + p.x;
       
    37 	y = 2*( (t4 +  t6)*p.x + (t5 + t10)*p.y + (t9 - t2)*p.z ) + p.y;
       
    38 	z = 2*( (t7 -  t3)*p.x + (t2 +  t9)*p.y + (t5 + t8)*p.z ) + p.z;
       
    39 	p = Vector3(x,y,z);
       
    40 	x = 2*( (t8 + t10)*u.x + (t6 -  t4)*u.y + (t3 + t7)*u.z ) + u.x;
       
    41 	y = 2*( (t4 +  t6)*u.x + (t5 + t10)*u.y + (t9 - t2)*u.z ) + u.y;
       
    42 	z = 2*( (t7 -  t3)*u.x + (t2 +  t9)*u.y + (t5 + t8)*u.z ) + u.z;
       
    43 	u = Vector3(x,y,z);
       
    44 	x = 2*( (t8 + t10)*v.x + (t6 -  t4)*v.y + (t3 + t7)*v.z ) + v.x;
       
    45 	y = 2*( (t4 +  t6)*v.x + (t5 + t10)*v.y + (t9 - t2)*v.z ) + v.y;
       
    46 	z = 2*( (t7 -  t3)*v.x + (t2 +  t9)*v.y + (t5 + t8)*v.z ) + v.z;
       
    47 	v = Vector3(x,y,z);*/
       
    48 }
       
    49 
       
    50 void Camera::move(const float fw, const float left, const float up)
       
    51 {
       
    52 	eye = eye + fw*p + left*u + up*v;
       
    53 }
    12 
    54 
    13 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */
    55 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */
    14 bool BBox::intersect(const Ray &ray, float &a, float &b)
    56 bool BBox::intersect(const Ray &ray, float &a, float &b)
    15 {
    57 {
    16 	float tnear = -FLT_MAX;
    58 	float tnear = -FLT_MAX;