include/scene.h
branchpyrit
changeset 91 9d66d323c354
parent 86 ce6abe0aeeae
child 92 9af5c039b678
equal deleted inserted replaced
90:f6a72eb99631 91:9d66d323c354
    39  * ray
    39  * ray
    40  */
    40  */
    41 class Ray
    41 class Ray
    42 {
    42 {
    43 public:
    43 public:
    44 	Vector3 o, dir;
    44 	Vector o, dir;
    45 	Ray(): o(), dir() {};
    45 	Ray(): o(), dir() {};
    46 	Ray(const Vector3 &ao, const Vector3 &adir):
    46 	Ray(const Vector &ao, const Vector &adir):
    47 		o(ao), dir(adir) {};
    47 		o(ao), dir(adir) {};
    48 };
    48 };
    49 
    49 
       
    50 #ifndef NO_SSE
    50 /**
    51 /**
    51  * packet of 4 rays
    52  * packet of 4 rays
    52  */
    53  */
    53 class RayPacket
    54 class RayPacket
    54 {
    55 {
    55 public:
    56 public:
    56 	VectorPacket o, dir;
    57 	VectorPacket o, dir;
    57 
    58 
       
    59 	RayPacket(): o(), dir() {};
       
    60 	RayPacket(const VectorPacket &ao, const VectorPacket &adir):
       
    61 		o(ao), dir(adir) {};
       
    62 
    58 	// index operator - get a ray
    63 	// index operator - get a ray
    59 	Ray operator[](int i) const
    64 	Ray operator[](int i) const
    60 	{
    65 	{
    61 		return Ray(
    66 		return Ray(
    62 			Vector3(o.x[i], o.y[i], o.z[i]),
    67 			Vector(o.x[i], o.y[i], o.z[i]),
    63 			Vector3(dir.x[i], dir.y[i], dir.z[i]));
    68 			Vector(dir.x[i], dir.y[i], dir.z[i]));
    64 	};
    69 	};
    65 };
    70 };
       
    71 #endif
    66 
    72 
    67 /**
    73 /**
    68  * a camera
    74  * a camera
    69  */
    75  */
    70 class Camera
    76 class Camera
    71 {
    77 {
    72 public:
    78 public:
    73 	Vector3 eye, p, u, v;
    79 	Vector eye, p, u, v;
    74 	Float F;
    80 	Float F;
    75 
    81 
    76 	Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), F(2.*tan(M_PI/8.)) {};
    82 	Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), F(2.*tan(M_PI/8.)) {};
    77 	Camera(const Vector3 &C, const Vector3 &ap, const Vector3 &au, const Vector3 &av):
    83 	Camera(const Vector &C, const Vector &ap, const Vector &au, const Vector &av):
    78 		eye(C), p(ap), u(au), v(av), F(2.*tan(M_PI/8.)) {};
    84 		eye(C), p(ap), u(au), v(av), F(2.*tan(M_PI/8.)) {};
    79 	Camera(const Vector3 &from, const Vector3 &lookat, const Vector3 &up):
    85 	Camera(const Vector &from, const Vector &lookat, const Vector &up):
    80 		eye(from), F(2.*tan(M_PI/8.))
    86 		eye(from), F(2.*tan(M_PI/8.))
    81 	{
    87 	{
    82 		p = lookat - from; u = cross(up, p);
    88 		p = lookat - from; u = cross(up, p);
    83 		p.normalize(); u.normalize();
    89 		p.normalize(); u.normalize();
    84 		v = cross(p, u);
    90 		v = cross(p, u);
    85 	};
    91 	};
    86 	void setEye(const Vector3 &aeye) { eye = aeye; };
    92 	void setEye(const Vector &aeye) { eye = aeye; };
    87 	void setAngle(const Float angle) { F = 2.*tan(angle/2.); };
    93 	void setAngle(const Float angle) { F = 2.*tan(angle/2.); };
    88 	void rotate(const Quaternion &q);
    94 	void rotate(const Quaternion &q);
    89 	void move(const Float fw, const Float left, const Float up);
    95 	void move(const Float fw, const Float left, const Float up);
    90 
    96 
    91 	Ray makeRay(Sample &samp)
    97 	Ray makeRay(Sample &samp)
    92 	{
    98 	{
    93 		Vector3 dir = p - (u*samp.x + v*samp.y)*F;
    99 		Vector dir = p - (u*samp.x + v*samp.y)*F;
    94 		dir.normalize();
   100 		dir.normalize();
    95 		return Ray(eye, dir);
   101 		return Ray(eye, dir);
    96 	};
   102 	};
    97 
   103 
       
   104 #ifndef NO_SSE
    98 	void makeRayPacket(Sample *samples, RayPacket &rays)
   105 	void makeRayPacket(Sample *samples, RayPacket &rays)
    99 	{
   106 	{
   100 		__m128 m1x,m1y,m1z;
   107 		__m128 m1x,m1y,m1z;
   101 		__m128 m2x,m2y,m2z;
   108 		__m128 m2x,m2y,m2z;
   102 		__m128 m;
   109 		__m128 m;
   143 		rays.o.my = _mm_set_ps1(eye.y);
   150 		rays.o.my = _mm_set_ps1(eye.y);
   144 		rays.o.mz = _mm_set_ps1(eye.z);
   151 		rays.o.mz = _mm_set_ps1(eye.z);
   145 
   152 
   146 		rays.dir.normalize();
   153 		rays.dir.normalize();
   147 	};
   154 	};
       
   155 #endif
   148 };
   156 };
   149 
   157 
   150 /**
   158 /**
   151  * light object
   159  * light object
   152  */
   160  */
   153 class Light
   161 class Light
   154 {
   162 {
   155 public:
   163 public:
   156 	Vector3 pos;
   164 	Vector pos;
   157 	Colour colour;
   165 	Colour colour;
   158 	bool cast_shadows;
   166 	bool cast_shadows;
   159 
   167 
   160 	Light():
   168 	Light():
   161 		pos(Vector3(0,0,0)), colour(Colour(1,1,1)), cast_shadows(true) {};
   169 		pos(Vector(0,0,0)), colour(Colour(1,1,1)), cast_shadows(true) {};
   162 	Light(const Vector3 &position, const Colour &acolour):
   170 	Light(const Vector &position, const Colour &acolour):
   163 		pos(position), colour(acolour), cast_shadows(true) {};
   171 		pos(position), colour(acolour), cast_shadows(true) {};
   164 	void castShadows(bool cast) { cast_shadows = cast; };
   172 	void castShadows(bool cast) { cast_shadows = cast; };
   165 };
   173 };
   166 
   174 
   167 /**
   175 /**
   168  * axis-aligned bounding box
   176  * axis-aligned bounding box
   169  */
   177  */
   170 class BBox
   178 class BBox
   171 {
   179 {
   172 public:
   180 public:
   173 	Vector3 L;
   181 	Vector L;
   174 	Vector3 H;
   182 	Vector H;
   175 	BBox(): L(), H() {};
   183 	BBox(): L(), H() {};
   176 	BBox(const Vector3 aL, const Vector3 aH): L(aL), H(aH) {};
   184 	BBox(const Vector aL, const Vector aH): L(aL), H(aH) {};
   177 	Float w() { return H.x-L.x; };
   185 	Float w() { return H.x-L.x; };
   178 	Float h() { return H.y-L.y; };
   186 	Float h() { return H.y-L.y; };
   179 	Float d() { return H.z-L.z; };
   187 	Float d() { return H.z-L.z; };
   180 	bool intersect(const Ray &ray, Float &a, Float &b);
   188 	bool intersect(const Ray &ray, Float &a, Float &b);
       
   189 #ifndef NO_SSE
   181 	__m128 intersect_packet(const RayPacket &rays, __m128 &a, __m128 &b);
   190 	__m128 intersect_packet(const RayPacket &rays, __m128 &a, __m128 &b);
       
   191 #endif
   182 };
   192 };
   183 
   193 
   184 #endif
   194 #endif