00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_TRANSFORM_H
00024 #define LUX_TRANSFORM_H
00025
00026 #include "lux.h"
00027 #include "geometry.h"
00028
00029 namespace lux
00030 {
00031
00032
00033 class Transform {
00034 public:
00035
00036 Transform() {
00037 boost::shared_ptr<Matrix4x4> o (new Matrix4x4());
00038 m = mInv = o;
00039 }
00040 Transform(float mat[4][4]) {
00041 boost::shared_ptr<Matrix4x4> o (new Matrix4x4(mat[0][0],mat[0][1],mat[0][2],mat[0][3],
00042 mat[1][0],mat[1][1],mat[1][2],mat[1][3],
00043 mat[2][0],mat[2][1],mat[2][2],mat[2][3],
00044 mat[3][0],mat[3][1],mat[3][2],mat[3][3]));
00045 m = o;
00046 mInv = m->Inverse();
00047 }
00048 Transform(const boost::shared_ptr<Matrix4x4> &mat) {
00049 m = mat;
00050 mInv = m->Inverse();
00051 }
00052 Transform(const boost::shared_ptr<Matrix4x4> &mat,
00053 const boost::shared_ptr<Matrix4x4> &minv) {
00054 m = mat;
00055 mInv = minv;
00056 }
00057 friend ostream &operator<<(ostream &, const Transform &);
00058 Transform GetInverse() const {
00059 return Transform(mInv, m);
00060 }
00061 bool HasScale() const;
00062 inline Point operator()(const Point &pt) const;
00063 inline void operator()(const Point &pt,Point *ptrans) const;
00064 inline Vector operator()(const Vector &v) const;
00065 inline void operator()(const Vector &v, Vector *vt) const;
00066 inline Normal operator()(const Normal &) const;
00067 inline void operator()(const Normal &, Normal *nt) const;
00068 inline Ray operator()(const Ray &r) const;
00069 inline void operator()(const Ray &r, Ray *rt) const;
00070 BBox operator()(const BBox &b) const;
00071 Transform operator*(const Transform &t2) const;
00072 bool SwapsHandedness() const;
00073 private:
00074
00075 boost::shared_ptr<Matrix4x4> m, mInv;
00076 };
00077
00078 #ifdef LUX_USE_SSE
00079 #include "transform-sse.inl"
00080 #else
00081 #include "transform.inl"
00082 #endif
00083
00084 inline Ray Transform::operator()(const Ray &r) const {
00085 Ray ret;
00086 (*this)(r.o, &ret.o);
00087 (*this)(r.d, &ret.d);
00088 ret.mint = r.mint;
00089 ret.maxt = r.maxt;
00090 ret.time = r.time;
00091 return ret;
00092 }
00093 inline void Transform::operator()(const Ray &r,
00094 Ray *rt) const {
00095 (*this)(r.o, &rt->o);
00096 (*this)(r.d, &rt->d);
00097 rt->mint = r.mint;
00098 rt->maxt = r.maxt;
00099 rt->time = r.time;
00100 }
00101
00102 Transform Translate(const Vector &delta);
00103 Transform Scale(float x, float y, float z);
00104 Transform RotateX(float angle);
00105 Transform RotateY(float angle);
00106 Transform RotateZ(float angle);
00107 Transform Rotate(float angle, const Vector &axis);
00108 Transform LookAt(const Point &pos, const Point &look, const Vector &up);
00109 Transform Orthographic(float znear, float zfar);
00110 Transform Perspective(float fov, float znear, float zfar);
00111 void TransformAccordingNormal(const Normal &nn, const Vector &woL, Vector *woW);
00112
00113 }
00114
00115
00116 #endif // LUX_TRANSFORM_H