include/shapes.h
branchpyrit
changeset 92 9af5c039b678
parent 91 9d66d323c354
child 93 96d65f841791
equal deleted inserted replaced
91:9d66d323c354 92:9af5c039b678
    53 	virtual ~Shape() {};
    53 	virtual ~Shape() {};
    54 
    54 
    55 	// first intersection point
    55 	// first intersection point
    56 	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
    56 	virtual bool intersect(const Ray &ray, Float &dist) const = 0;
    57 
    57 
    58 #ifndef NO_SSE
    58 #ifndef NO_SIMD
    59 	virtual __m128 intersect_packet(const RayPacket &rays, __m128 &dists)
    59 	virtual mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const
    60 	{
    60 	{
    61 		__m128 results;
    61 		mfloat4 results;
    62 		((int*)&results)[0] = intersect(rays[0], ((float*)&dists)[0]) ? -1 : 0;
    62 		((int*)&results)[0] = intersect(rays[0], ((float*)&dists)[0]) ? -1 : 0;
    63 		((int*)&results)[1] = intersect(rays[1], ((float*)&dists)[1]) ? -1 : 0;
    63 		((int*)&results)[1] = intersect(rays[1], ((float*)&dists)[1]) ? -1 : 0;
    64 		((int*)&results)[2] = intersect(rays[2], ((float*)&dists)[2]) ? -1 : 0;
    64 		((int*)&results)[2] = intersect(rays[2], ((float*)&dists)[2]) ? -1 : 0;
    65 		((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0;
    65 		((int*)&results)[3] = intersect(rays[3], ((float*)&dists)[3]) ? -1 : 0;
    66 		return results;
    66 		return results;
   107 	const Vector normal(const Vector &P) const { return (P - center) * inv_radius; };
   107 	const Vector normal(const Vector &P) const { return (P - center) * inv_radius; };
   108 	BBox get_bbox() const;
   108 	BBox get_bbox() const;
   109 	const Vector getCenter() const { return center; };
   109 	const Vector getCenter() const { return center; };
   110 	Float getRadius() const { return radius; };
   110 	Float getRadius() const { return radius; };
   111 	ostream & dump(ostream &st) const;
   111 	ostream & dump(ostream &st) const;
   112 #ifndef NO_SSE
   112 #ifndef NO_SIMD
   113 	__m128 intersect_packet(const RayPacket &rays, __m128 &dists);
   113 	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
   114 #endif
   114 #endif
   115 };
   115 };
   116 
   116 
   117 /**
   117 /**
   118  * box shape
   118  * box shape
   123 	Vector H;
   123 	Vector H;
   124 public:
   124 public:
   125 	Box(const Vector &aL, const Vector &aH, Material *amaterial): L(aL), H(aH)
   125 	Box(const Vector &aL, const Vector &aH, Material *amaterial): L(aL), H(aH)
   126 	{
   126 	{
   127 		for (int i = 0; i < 3; i++)
   127 		for (int i = 0; i < 3; i++)
   128 			if (L.cell[i] > H.cell[i])
   128 			if (L[i] > H[i])
   129 				swap(L.cell[i], H.cell[i]);
   129 				swap(L[i], H[i]);
   130 		material = amaterial;
   130 		material = amaterial;
   131 	};
   131 	};
   132 	bool intersect(const Ray &ray, Float &dist) const;
   132 	bool intersect(const Ray &ray, Float &dist) const;
   133 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
   133 	bool intersect_all(const Ray &ray, Float dist, vector<Float> &allts) const { return false; };
   134 	bool intersect_bbox(const BBox &bbox) const;
   134 	bool intersect_bbox(const BBox &bbox) const;
   135 	const Vector normal(const Vector &P) const;
   135 	const Vector normal(const Vector &P) const;
   136 	BBox get_bbox() const { return BBox(L, H); };
   136 	BBox get_bbox() const { return BBox(L, H); };
   137 	const Vector getL() const { return L; };
   137 	const Vector getL() const { return L; };
   138 	const Vector getH() const { return H; };
   138 	const Vector getH() const { return H; };
   139 	ostream & dump(ostream &st) const;
   139 	ostream & dump(ostream &st) const;
   140 #ifndef NO_SSE
   140 #ifndef NO_SIMD
   141 	__m128 intersect_packet(const RayPacket &rays, __m128 &dists);
   141 	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
   142 #endif
   142 #endif
   143 };
   143 };
   144 
   144 
   145 /**
   145 /**
   146  * triangle vertex
   146  * triangle vertex
   147  */
   147  */
   148 class Vertex
   148 class Vertex
   149 {
   149 {
   150 public:
   150 public:
   151 	Vector P;
   151 	Vector P;
       
   152 
   152 	Vertex(const Vector &aP): P(aP) {};
   153 	Vertex(const Vector &aP): P(aP) {};
   153 	virtual ~Vertex() {};
   154 	virtual ~Vertex() {};
   154 	virtual ostream & dump(ostream &st) const;
   155 	virtual ostream & dump(ostream &st) const;
   155 };
   156 };
   156 
   157 
   159  */
   160  */
   160 class NormalVertex: public Vertex
   161 class NormalVertex: public Vertex
   161 {
   162 {
   162 public:
   163 public:
   163 	Vector N;
   164 	Vector N;
       
   165 
   164 	NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {};
   166 	NormalVertex(const NormalVertex *v): Vertex(v->P), N(v->N) {};
   165 	NormalVertex(const Vector &aP): Vertex(aP) {};
   167 	NormalVertex(const Vector &aP): Vertex(aP) {};
   166 	NormalVertex(const Vector &aP, const Vector &aN): Vertex(aP), N(aN) {};
   168 	NormalVertex(const Vector &aP, const Vector &aN): Vertex(aP), N(aN) {};
   167 	const Vector &getNormal() { return N; };
   169 	const Vector &getNormal() { return N; };
   168 	void setNormal(const Vector &aN) { N = aN; };
   170 	void setNormal(const Vector &aN) { N = aN; };
   217 	bool intersect_bbox(const BBox &bbox) const;
   219 	bool intersect_bbox(const BBox &bbox) const;
   218 	const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); };
   220 	const Vector normal(const Vector &P) const { return (material->smooth ? smooth_normal(P) : N); };
   219 	const Vector getNormal() const { return N; };
   221 	const Vector getNormal() const { return N; };
   220 	BBox get_bbox() const;
   222 	BBox get_bbox() const;
   221 	ostream & dump(ostream &st) const;
   223 	ostream & dump(ostream &st) const;
   222 #if not defined(NO_SSE) and defined(TRI_BARI_PRE)
   224 #if !defined(NO_SIMD) && defined(TRI_BARI_PRE)
   223 	__m128 intersect_packet(const RayPacket &rays, __m128 &dists);
   225 	mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &dists) const;
   224 #endif
   226 #endif
   225 };
   227 };
   226 
   228 
   227 template <class T> class Array
   229 template <class T> class Array
   228 {
   230 {