src/shapes.cc
branchpyrit
changeset 91 9d66d323c354
parent 87 1081e3dd3f3e
child 92 9af5c039b678
--- a/src/shapes.cc	Tue Apr 29 23:31:08 2008 +0200
+++ b/src/shapes.cc	Fri May 02 13:27:47 2008 +0200
@@ -29,7 +29,7 @@
 
 bool Sphere::intersect(const Ray &ray, Float &dist) const
 {
-	Vector3 V = ray.o - center;
+	Vector V = ray.o - center;
 	register Float d = -dot(V, ray.dir);
 	register Float Det = d * d - (dot(V,V) - sqr_radius);
 	register Float t1,t2;
@@ -54,6 +54,7 @@
 	return false;
 }
 
+#ifndef NO_SSE
 __m128 Sphere::intersect_packet(const RayPacket &rays, __m128 &dists)
 {
 	VectorPacket V = rays.o - VectorPacket(center);
@@ -79,13 +80,14 @@
 	dists = _mm_or_ps(_mm_and_ps(mask, newdists), _mm_andnot_ps(mask, dists));
 	return mask;
 }
+#endif
 
 /* if there should be CSG sometimes, this may be needed... */
 bool Sphere::intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const
 {
 	//allts = new vector<Float>();
 
-	Vector3 V = ((Ray)ray).o - center;
+	Vector V = ((Ray)ray).o - center;
 	Float Vd = - dot(V, ray.dir);
 	Float Det = Vd * Vd - (dot(V,V) - sqr_radius);
 
@@ -175,6 +177,7 @@
 	return false;
 }
 
+#ifndef NO_SSE
 __m128 Box::intersect_packet(const RayPacket &rays, __m128 &dists)
 {
 	register __m128 tnear = mZero;
@@ -215,6 +218,7 @@
 	dists = _mm_or_ps(_mm_and_ps(mask, tnear), _mm_andnot_ps(mask, dists));
 	return mask;
 }
+#endif
 
 bool Box::intersect_bbox(const BBox &bbox) const
 {
@@ -224,10 +228,10 @@
 	H.z > bbox.L.z && L.z < bbox.H.z);
 }
 
-const Vector3 Box::normal(const Vector3 &P) const
+const Vector Box::normal(const Vector &P) const
 {
-	register Vector3 l = P - L;
-	register Vector3 h = H - P;
+	register Vector l = P - L;
+	register Vector h = H - P;
 
 	if (l.x < h.x)
 		h.x = -1;
@@ -273,7 +277,7 @@
 }
 
 #ifdef TRI_PLUCKER
-inline void Plucker(const Vector3 &p, const Vector3 &q, Float* pl)
+inline void Plucker(const Vector &p, const Vector &q, Float* pl)
 {
     pl[0] = p.x*q.y - q.x*p.y;
     pl[1] = p.x*q.z - q.x*p.z;
@@ -294,8 +298,8 @@
 {
 	material = amaterial;
 
-	const Vector3 c = B->P - A->P;
-	const Vector3 b = C->P - A->P;
+	const Vector c = B->P - A->P;
+	const Vector b = C->P - A->P;
 
 	N = cross(c, b);
 	N.normalize();
@@ -363,8 +367,8 @@
 
 #if defined(TRI_BARI) || defined(TRI_BARI_PRE)
 	static const int modulo3[5] = {0,1,2,0,1};
-	const Vector3 &O = ray.o;
-	const Vector3 &D = ray.dir;
+	const Vector &O = ray.o;
+	const Vector &D = ray.dir;
 	register const int u = modulo3[k+1];
 	register const int v = modulo3[k+2];
 #endif
@@ -392,8 +396,8 @@
 #ifdef TRI_BARI
 	// original barycentric coordinates based intesection
 	// not optimized, just for reference
-	const Vector3 c = B - A;
-	const Vector3 b = C - A;
+	const Vector c = B - A;
+	const Vector b = C - A;
 	// distance test
 	const Float t = - dot( (O-A), N) / dot(D,N);
 	if (t < Eps || t > dist)
@@ -415,7 +419,7 @@
 #endif
 }
 
-#ifdef TRI_BARI_PRE
+#if not defined(NO_SSE) and defined(TRI_BARI_PRE)
 __m128 Triangle::intersect_packet(const RayPacket &rays, __m128 &dists)
 {
 	static const int modulo3[5] = {0,1,2,0,1};
@@ -463,14 +467,14 @@
 
 bool Triangle::intersect_bbox(const BBox &bbox) const
 {
-	const Vector3 boxcenter = (bbox.L+bbox.H)*0.5;
-	const Vector3 boxhalfsize = (bbox.H-bbox.L)*0.5;
-	const Vector3 v0 = A->P - boxcenter;
-	const Vector3 v1 = B->P - boxcenter;
-	const Vector3 v2 = C->P - boxcenter;
-	const Vector3 e0 = v1-v0;
-	const Vector3 e1 = v2-v1;
-	const Vector3 e2 = v0-v2;
+	const Vector boxcenter = (bbox.L+bbox.H)*0.5;
+	const Vector boxhalfsize = (bbox.H-bbox.L)*0.5;
+	const Vector v0 = A->P - boxcenter;
+	const Vector v1 = B->P - boxcenter;
+	const Vector v2 = C->P - boxcenter;
+	const Vector e0 = v1-v0;
+	const Vector e1 = v2-v1;
+	const Vector e2 = v0-v2;
 
 	Float fex = fabsf(e0.x);
 	Float fey = fabsf(e0.y);
@@ -569,7 +573,7 @@
 	if(min>boxhalfsize.z || max<-boxhalfsize.z) return false;
 
 	/*  test if the box intersects the plane of the triangle */
-	Vector3 vmin,vmax;
+	Vector vmin,vmax;
 	Float v;
 	for(int q=0;q<3;q++)
 	{