quaternion moved to extra header file pyrit
authorRadek Brich <radek.brich@devl.cz>
Sun, 09 Dec 2007 23:10:58 +0100
branchpyrit
changeset 34 28f6e8b9d5d1
parent 33 83d0200d4c09
child 35 fb170fccb19f
quaternion moved to extra header file updated headers in all sources
TODO
demos/bunny.py
include/common.h
include/container.h
include/kdtree.h
include/matrix.h
include/noise.h
include/quaternion.h
include/raytracer.h
include/scene.h
include/vector.h
src/container.cc
src/kdtree.cc
src/noise.cc
src/raytracer.cc
src/raytracermodule.cc
src/scene.cc
--- a/TODO	Sun Dec 09 15:01:51 2007 +0100
+++ b/TODO	Sun Dec 09 23:10:58 2007 +0100
@@ -13,6 +13,7 @@
  * update Python binding: Camera, new classes
  * namespace
  * stochastic oversampling
+ * absorbtion of refracted rays in dense materials (can be computed using shape distance and some 'absorbance' constant)
 
 New Classes?
 ============
--- a/demos/bunny.py	Sun Dec 09 15:01:51 2007 +0100
+++ b/demos/bunny.py	Sun Dec 09 23:10:58 2007 +0100
@@ -18,11 +18,11 @@
 LoadStanfordPlyFile(rt, "../models/bunny/bun_zipper.ply",
 	mat, smooth=True, scale=(-29.0, 29.0, 29.0), trans=(-1,-2.5,-3))
 
-mat0 = Material(colour=(0.1, 0.2, 0.9))
+mat0 = Material(colour=(0.1, 0.2, 1.0))
 box1 = Box(L=(-20.0, -1.7, -20.0), H=(20.0, -1.5, 20.0), material=mat0)
 rt.addshape(box1)
 
-mat1 = Material(colour=(0.2, 0.8, 0.4))
+mat1 = Material(colour=(0.5, 0.2, 0.1))
 mat1.setReflectivity(0.0)
 box2 = Box(L=(-20.0, -20.0, -10.0), H=(20.0, 20.0, -12.0), material=mat1)
 rt.addshape(box2)
--- a/include/common.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/common.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: common.h
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #ifndef COMMON_H
 #define COMMON_H
 
--- a/include/container.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/container.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: container.h
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #ifndef CONTAINER_H
 #define CONTAINER_H
 
--- a/include/kdtree.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/kdtree.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: kdtree.h
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #ifndef KDTREE_H
 #define KDTREE_H
 
--- a/include/matrix.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/matrix.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: matrix.h
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 /* not used at this time */
--- a/include/noise.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/noise.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: noise.h
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #ifndef NOISE_H
 #define NOISE_H
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/quaternion.h	Sun Dec 09 23:10:58 2007 +0100
@@ -0,0 +1,64 @@
+/*
+ * Pyrit Ray Tracer
+ * file: quaternion.h
+ *
+ * Radek Brich, 2006-2007
+ */
+
+#ifndef QUATERNION_H
+#define QUATER_H
+
+class Quaternion
+{
+public:
+	union {
+		struct {
+			Float a,b,c,d;
+		};
+		struct {
+			Float t,x,y,z;
+		};
+	};
+	Quaternion(): a(0), b(0), c(0), d(0) {};
+	Quaternion(const Float aa, const Float ab, const Float ac, const Float ad):
+		a(aa), b(ab), c(ac), d(ad) {};
+	Quaternion(const Vector3& v): a(1), b(v.x), c(v.y), d(v.z) {};
+
+	Vector3 toVector() { return Vector3(b/a, c/a, d/a); };
+
+	Quaternion normalize()
+	{
+		Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d);
+		a *= f;
+		b *= f;
+		c *= f;
+		d *= f;
+		return *this;
+	};
+	Float mag2() const
+	{
+		return (a*a + b*b + c*c + d*d);
+	};
+	Float mag() const
+	{
+		return sqrtf(mag());
+	};
+	friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2)
+	{
+		return Quaternion(
+			q1.a*q2.a - q1.b*q2.b - q1.c*q2.c - q1.d*q2.d,
+			q1.a*q2.b + q1.b*q2.a + q1.c*q2.d - q1.d*q2.c,
+			q1.a*q2.c - q1.b*q2.d + q1.c*q2.a + q1.d*q2.b,
+			q1.a*q2.d + q1.b*q2.c - q1.c*q2.b + q1.d*q2.a);
+	};
+	friend Float dot(const Quaternion &q1, const Quaternion &q2)
+	{
+		return q1.a*q2.a + q1.b*q2.b + q1.c*q2.c + q1.d*q2.d;
+	};
+	friend Quaternion conjugate(const Quaternion &q)
+	{
+		return Quaternion(q.a, -q.b, -q.c, -q.d);
+	};
+};
+
+#endif
--- a/include/raytracer.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/raytracer.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: raytracer.h
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #ifndef RAYTRACER_H
--- a/include/scene.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/scene.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: scene.h
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #ifndef SCENE_H
@@ -13,6 +13,7 @@
 
 #include "noise.h"
 #include "vector.h"
+#include "quaternion.h"
 
 /*
 triangle intersection alghoritm
@@ -35,40 +36,6 @@
 		o(ao), dir(adir) {};
 };
 
-class Quaternion
-{
-public:
-	Float a,b,c,d;
-	Quaternion(): a(0), b(0), c(0), d(0) {};
-	Quaternion(const Float aa, const Float ab, const Float ac, const Float ad):
-		a(aa), b(ab), c(ac), d(ad) {};
-	Quaternion(const Vector3& v): a(1), b(v.x), c(v.y), d(v.z) {};
-
-	Vector3 toVector() { return Vector3(b/a, c/a, d/a); };
-
-	Quaternion normalize()
-	{
-		Float f = 1.0f / sqrtf(a * a + b * b + c * c + d * d);
-		a *= f;
-		b *= f;
-		c *= f;
-		d *= f;
-		return *this;
-	};
-	friend Quaternion operator*(const Quaternion &q1, const Quaternion &q2)
-	{
-		return Quaternion(
-			q1.a*q2.a - q1.b*q2.b - q1.c*q2.c - q1.d*q2.d,
-			q1.a*q2.b + q1.b*q2.a + q1.c*q2.d - q1.d*q2.c,
-			q1.a*q2.c + q1.c*q2.a + q1.d*q2.b - q1.b*q2.d,
-			q1.a*q2.d + q1.d*q2.a + q1.b*q2.c - q1.c*q2.b);
-	};
-	friend Quaternion conjugate(const Quaternion &q)
-	{
-		return Quaternion(q.a, -q.b, -q.c, -q.d);
-	}
-};
-
 class Camera
 {
 public:
--- a/include/vector.h	Sun Dec 09 15:01:51 2007 +0100
+++ b/include/vector.h	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: vector.h
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #ifndef VECTOR_H
--- a/src/container.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/container.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: container.cc
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #include "common.h"
 #include "container.h"
 
--- a/src/kdtree.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/kdtree.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: kdtree.cc
+ *
+ * Radek Brich, 2006-2007
+ */
+
 #include <algorithm>
 #include <stack>
 
--- a/src/noise.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/noise.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,3 +1,10 @@
+/*
+ * Pyrit Ray Tracer
+ * file: noise.cc
+ *
+ * Radek Brich, 2006-2007
+ */
+
 /*
 Based on
 JAVA REFERENCE IMPLEMENTATION OF IMPROVED NOISE
--- a/src/raytracer.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/raytracer.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: raytracer.cc
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #ifdef PTHREADS
--- a/src/raytracermodule.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/raytracermodule.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,9 +1,9 @@
 /*
- * C++ RayTracer
- * Module for Python
+ * Pyrit Ray Tracer
  * file: raytracermodule.cc
+ * a module for Python
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #include <Python.h>
--- a/src/scene.cc	Sun Dec 09 15:01:51 2007 +0100
+++ b/src/scene.cc	Sun Dec 09 23:10:58 2007 +0100
@@ -1,8 +1,8 @@
 /*
- * C++ RayTracer
+ * Pyrit Ray Tracer
  * file: scene.cc
  *
- * Radek Brich, 2006
+ * Radek Brich, 2006-2007
  */
 
 #include <math.h>