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 "matrix4x4.h"
00028 #include "point.h"
00029 #include "normal.h"
00030 #include "ray.h"
00031
00032 namespace lux
00033 {
00034
00035
00036 class Transform {
00037 public:
00038
00039 Transform() {
00040
00041 m = mInv = MAT_IDENTITY;
00042 }
00043 Transform(float mat[4][4]) {
00044 boost::shared_ptr<Matrix4x4> o (new Matrix4x4(mat[0][0],mat[0][1],mat[0][2],mat[0][3],
00045 mat[1][0],mat[1][1],mat[1][2],mat[1][3],
00046 mat[2][0],mat[2][1],mat[2][2],mat[2][3],
00047 mat[3][0],mat[3][1],mat[3][2],mat[3][3]));
00048 m = o;
00049 mInv = m->Inverse();
00050 }
00051 Transform(const boost::shared_ptr<Matrix4x4> &mat) {
00052 m = mat;
00053 mInv = m->Inverse();
00054 }
00055 Transform(const boost::shared_ptr<Matrix4x4> &mat,
00056 const boost::shared_ptr<Matrix4x4> &minv) {
00057 m = mat;
00058 mInv = minv;
00059 }
00060 friend ostream &operator<<(ostream &, const Transform &);
00061 Transform GetInverse() const {
00062 return Transform(mInv, m);
00063 }
00064 boost::shared_ptr<Matrix4x4> GetMatrix() const {
00065 return m;
00066 }
00067 bool HasScale() const;
00068 inline Point operator()(const Point &pt) const;
00069 inline void operator()(const Point &pt,Point *ptrans) const;
00070 inline Vector operator()(const Vector &v) const;
00071 inline void operator()(const Vector &v, Vector *vt) const;
00072 inline Normal operator()(const Normal &) const;
00073 inline void operator()(const Normal &, Normal *nt) const;
00074 inline Ray operator()(const Ray &r) const;
00075 inline void operator()(const Ray &r, Ray *rt) const;
00076 BBox operator()(const BBox &b) const;
00077 Transform operator*(const Transform &t2) const;
00078 bool SwapsHandedness() const;
00079 private:
00080
00081 boost::shared_ptr<Matrix4x4> m, mInv;
00082
00083 static const boost::shared_ptr<Matrix4x4> MAT_IDENTITY;
00084 };
00085
00086
00087
00088
00089 #include "transform.inl"
00090
00091
00092 inline Ray Transform::operator()(const Ray &r) const {
00093 Ray ret;
00094 (*this)(r.o, &ret.o);
00095 (*this)(r.d, &ret.d);
00096 ret.mint = r.mint;
00097 ret.maxt = r.maxt;
00098 ret.time = r.time;
00099 return ret;
00100 }
00101 inline void Transform::operator()(const Ray &r,
00102 Ray *rt) const {
00103 (*this)(r.o, &rt->o);
00104 (*this)(r.d, &rt->d);
00105 rt->mint = r.mint;
00106 rt->maxt = r.maxt;
00107 rt->time = r.time;
00108 }
00109
00110 Transform Translate(const Vector &delta);
00111 Transform Scale(float x, float y, float z);
00112 Transform RotateX(float angle);
00113 Transform RotateY(float angle);
00114 Transform RotateZ(float angle);
00115 Transform Rotate(float angle, const Vector &axis);
00116 Transform LookAt(const Point &pos, const Point &look, const Vector &up);
00117 Transform Orthographic(float znear, float zfar);
00118 Transform Perspective(float fov, float znear, float zfar);
00119 void TransformAccordingNormal(const Normal &nn, const Vector &woL, Vector *woW);
00120
00121 }
00122
00123
00124 #endif // LUX_TRANSFORM_H