src/scene.cc
branchpyrit
changeset 20 f22952603f29
parent 15 a0a3e334744f
child 21 79b516a3803d
--- a/src/scene.cc	Mon Nov 26 23:12:40 2007 +0100
+++ b/src/scene.cc	Thu Nov 29 18:30:16 2007 +0100
@@ -10,6 +10,48 @@
 #include "common.h"
 #include "scene.h"
 
+void Camera::rotate(const Quaternion &q)
+{
+	Quaternion res;
+	res = q * Quaternion(u) * conjugate(q);
+	u = res.toVector();
+	res = q * Quaternion(v) * conjugate(q);
+	v = res.toVector();
+	res = q * Quaternion(p) * conjugate(q);
+	p = res.toVector();
+	p.normalize();
+	u.normalize();
+	v.normalize();
+/*  // optimized version
+	float t2 =   q.a*q.b;
+	float t3 =   q.a*q.c;
+	float t4 =   q.a*q.d;
+	float t5 =  -q.b*q.b;
+	float t6 =   q.b*q.c;
+	float t7 =   q.b*q.d;
+	float t8 =  -q.c*q.c;
+	float t9 =   q.c*q.d;
+	float t10 = -q.d*q.d;
+	float x,y,z;
+	x = 2*( (t8 + t10)*p.x + (t6 -  t4)*p.y + (t3 + t7)*p.z ) + p.x;
+	y = 2*( (t4 +  t6)*p.x + (t5 + t10)*p.y + (t9 - t2)*p.z ) + p.y;
+	z = 2*( (t7 -  t3)*p.x + (t2 +  t9)*p.y + (t5 + t8)*p.z ) + p.z;
+	p = Vector3(x,y,z);
+	x = 2*( (t8 + t10)*u.x + (t6 -  t4)*u.y + (t3 + t7)*u.z ) + u.x;
+	y = 2*( (t4 +  t6)*u.x + (t5 + t10)*u.y + (t9 - t2)*u.z ) + u.y;
+	z = 2*( (t7 -  t3)*u.x + (t2 +  t9)*u.y + (t5 + t8)*u.z ) + u.z;
+	u = Vector3(x,y,z);
+	x = 2*( (t8 + t10)*v.x + (t6 -  t4)*v.y + (t3 + t7)*v.z ) + v.x;
+	y = 2*( (t4 +  t6)*v.x + (t5 + t10)*v.y + (t9 - t2)*v.z ) + v.y;
+	z = 2*( (t7 -  t3)*v.x + (t2 +  t9)*v.y + (t5 + t8)*v.z ) + v.z;
+	v = Vector3(x,y,z);*/
+}
+
+void Camera::move(const float fw, const float left, const float up)
+{
+	eye = eye + fw*p + left*u + up*v;
+}
+
 /* http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm */
 bool BBox::intersect(const Ray &ray, float &a, float &b)
 {