--- a/include/shapes.h Tue Apr 29 23:31:08 2008 +0200
+++ b/include/shapes.h Fri May 02 13:27:47 2008 +0200
@@ -55,6 +55,7 @@
// first intersection point
virtual bool intersect(const Ray &ray, Float &dist) const = 0;
+#ifndef NO_SSE
virtual __m128 intersect_packet(const RayPacket &rays, __m128 &dists)
{
__m128 results;
@@ -64,6 +65,7 @@
((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0;
return results;
};
+#endif
// all intersections (only for CSG)
virtual bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const = 0;
@@ -72,7 +74,7 @@
virtual bool intersect_bbox(const BBox &bbox) const = 0;
// normal at point P
- virtual const Vector3 normal(const Vector3 &P) const = 0;
+ virtual const Vector normal(const Vector &P) const = 0;
virtual BBox get_bbox() const = 0;
@@ -89,25 +91,27 @@
*/
class Sphere: public Shape
{
- Vector3 center;
+ Vector center;
Float radius;
Float sqr_radius;
Float inv_radius;
public:
- Sphere(const Vector3 &acenter, const Float aradius, Material *amaterial):
+ Sphere(const Vector &acenter, const Float aradius, Material *amaterial):
center(acenter), radius(aradius),
sqr_radius(aradius*aradius), inv_radius(1.0f/aradius)
{ material = amaterial; }
bool intersect(const Ray &ray, Float &dist) const;
- __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const;
bool intersect_bbox(const BBox &bbox) const;
- const Vector3 normal(const Vector3 &P) const { return (P - center) * inv_radius; };
+ const Vector normal(const Vector &P) const { return (P - center) * inv_radius; };
BBox get_bbox() const;
- const Vector3 getCenter() const { return center; };
+ const Vector getCenter() const { return center; };
Float getRadius() const { return radius; };
ostream & dump(ostream &st) const;
+#ifndef NO_SSE
+ __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
+#endif
};
/**
@@ -115,10 +119,10 @@
*/
class Box: public Shape
{
- Vector3 L;
- Vector3 H;
+ Vector L;
+ Vector H;
public:
- Box(const Vector3 &aL, const Vector3 &aH, Material *amaterial): L(aL), H(aH)
+ Box(const Vector &aL, const Vector &aH, Material *amaterial): L(aL), H(aH)
{
for (int i = 0; i < 3; i++)
if (L.cell[i] > H.cell[i])
@@ -126,14 +130,16 @@
material = amaterial;
};
bool intersect(const Ray &ray, Float &dist) const;
- __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
bool intersect_bbox(const BBox &bbox) const;
- const Vector3 normal(const Vector3 &P) const;
+ const Vector normal(const Vector &P) const;
BBox get_bbox() const { return BBox(L, H); };
- const Vector3 getL() const { return L; };
- const Vector3 getH() const { return H; };
+ const Vector getL() const { return L; };
+ const Vector getH() const { return H; };
ostream & dump(ostream &st) const;
+#ifndef NO_SSE
+ __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
+#endif
};
/**
@@ -142,8 +148,8 @@
class Vertex
{
public:
- Vector3 P;
- Vertex(const Vector3 &aP): P(aP) {};
+ Vector P;
+ Vertex(const Vector &aP): P(aP) {};
virtual ~Vertex() {};
virtual ostream & dump(ostream &st) const;
};
@@ -154,12 +160,12 @@
class NormalVertex: public Vertex
{
public:
- Vector3 N;
+ Vector N;
NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {};
- NormalVertex(const Vector3 &aP): Vertex(aP) {};
- NormalVertex(const Vector3 &aP, const Vector3 &aN): Vertex(aP), N(aN) {};
- const Vector3 &getNormal() { return N; };
- void setNormal(const Vector3 &aN) { N = aN; };
+ NormalVertex(const Vector &aP): Vertex(aP) {};
+ NormalVertex(const Vector &aP, const Vector &aN): Vertex(aP), N(aN) {};
+ const Vector &getNormal() { return N; };
+ void setNormal(const Vector &aN) { N = aN; };
ostream & dump(ostream &st) const;
};
@@ -180,13 +186,13 @@
#ifdef TRI_PLUCKER
Float pla[6], plb[6], plc[6];
#endif
- Vector3 N;
- const Vector3 smooth_normal(const Vector3 &P) const
+ Vector N;
+ const Vector smooth_normal(const Vector &P) const
{
#ifdef TRI_BARI_PRE
- const Vector3 &NA = static_cast<NormalVertex*>(A)->N;
- const Vector3 &NB = static_cast<NormalVertex*>(B)->N;
- const Vector3 &NC = static_cast<NormalVertex*>(C)->N;
+ const Vector &NA = static_cast<NormalVertex*>(A)->N;
+ const Vector &NB = static_cast<NormalVertex*>(B)->N;
+ const Vector &NC = static_cast<NormalVertex*>(C)->N;
static const int modulo3[5] = {0,1,2,0,1};
register const int ku = modulo3[k+1];
register const int kv = modulo3[k+2];
@@ -194,7 +200,7 @@
const Float pv = P[kv] - A->P[kv];
const Float u = pv * bnu + pu * bnv;
const Float v = pu * cnv + pv * cnu;
- Vector3 n = NA + u * (NB - NA) + v * (NC - NA);
+ Vector n = NA + u * (NB - NA) + v * (NC - NA);
n.normalize();
return n;
#else
@@ -207,15 +213,15 @@
Triangle() {};
Triangle(Vertex *aA, Vertex *aB, Vertex *aC, Material *amaterial);
bool intersect(const Ray &ray, Float &dist) const;
-#ifdef TRI_BARI_PRE
- __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
-#endif
bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const {return false;};
bool intersect_bbox(const BBox &bbox) const;
- const Vector3 normal(const Vector3 &P) const { return (material->smooth ? smooth_normal(P) : N); };
- const Vector3 getNormal() const { return N; };
+ const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); };
+ const Vector getNormal() const { return N; };
BBox get_bbox() const;
ostream & dump(ostream &st) const;
+#if not defined(NO_SSE) and defined(TRI_BARI_PRE)
+ __m128 intersect_packet(const RayPacket &rays, __m128 &dists);
+#endif
};
template <class T> class Array