00001 #ifndef __PROJ_TRANSFO__
00002 #define __PROJ_TRANSFO__
00003
00004 #include "Vec4.h"
00005 #include "Vec3.h"
00006 #include <QString>
00007 #include <QDomElement>
00008 #include <QDomDocument>
00009 #include <QGLViewer/camera.h>
00010
00011 namespace apig {
00012
00016 class ProjTransfo {
00017 public:
00018 ProjTransfo(float d = 1);
00019 ProjTransfo(float m11, float m12, float m13, float m14,
00020 float m21, float m22, float m23, float m24,
00021 float m31, float m32, float m33, float m34,
00022 float m41, float m42, float m43, float m44);
00023 ProjTransfo(const float M[16], bool deleteArray = false);
00024 ProjTransfo(const double M[16], bool deleteArray = false);
00025 ProjTransfo(Vec4 O, Vec4 X, Vec4 Y, Vec4 Z, bool relative=false);
00026 ProjTransfo(Vec3 O, Vec3 X, Vec3 Y, Vec3 Z, bool relative=false);
00027 ProjTransfo(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax);
00028
00029
00030
00031 static ProjTransfo scaling(float sx, float sy, float sz);
00032 static ProjTransfo scaling(Vec3 s);
00033 static ProjTransfo scaling(float s);
00034 static ProjTransfo translation(float tx, float ty, float tz);
00035 static ProjTransfo translation(Vec3 t);
00036 static ProjTransfo translation(float t);
00037 static ProjTransfo translationAndScaling(float tx, float ty, float tz, float sx, float sy, float sz);
00038 static ProjTransfo translationAndScaling(Vec3 t, Vec3 s);
00039 static ProjTransfo translationAndScaling(float t, float s);
00040 static ProjTransfo scalingAndTranslation(float sx, float sy, float sz, float tx, float ty, float tz);
00041 static ProjTransfo scalingAndTranslation(Vec3 s, Vec3 t);
00042 static ProjTransfo scalingAndTranslation(float s, float t);
00043 static ProjTransfo rotation(float theta, Vec3 n, bool isNormed = false);
00044 static ProjTransfo rotation(Vec3 d);
00045
00046 static ProjTransfo rotation(Vec3 src, Vec3 dst, bool normalized = true);
00047
00048
00049
00050 ProjTransfo operator*(ProjTransfo P) const;
00051 Vec4 operator*(Vec4 v) const;
00052 Vec3 operator*(Vec3 v) const;
00053
00054 ProjTransfo inv() const;
00055 ProjTransfo transposed() const;
00056 void transpose();
00057
00058
00059
00060 inline const float* coefs() const { return M; }
00061
00062 inline float& coef(int i, int j) { return M[i + 4*j]; }
00063 inline float coef(int i, int j) const { return M[i + 4*j]; }
00064 inline float& operator()(int i, int j) { return coef(i,j); }
00065 inline float operator()(int i, int j) const { return coef(i,j); }
00066
00067 Vec4 column(int j) const;
00068 void setColumn(int j, Vec4 c);
00069
00070
00071
00072 static ProjTransfo getGLModelView();
00073 static ProjTransfo getGLProjection();
00074 static ProjTransfo getGLTransform();
00075 void glLoadMatrix() const;
00076 void glLoadModelView() const;
00077 void glLoadProjection() const;
00078 void glMultMatrix() const;
00079 void glMultModelView() const;
00080 void glMultProjection() const;
00081
00082
00083
00084 void getModelViewFrom(const qglviewer::Camera &camera);
00085 void getProjectionFrom(const qglviewer::Camera &camera);
00086
00087
00088
00089
00090 float screenRatio(float xMin = -1, float xMax = 1, float yMin = -1, float yMax = 1, float z = 0) const;
00091
00092 void drawBox(float xMin = 0, float xMax = 1, float yMin = 0, float yMax = 1, float zMin = 0, float zMax = 1) const;
00093
00094
00095
00096 ProjTransfo(const QDomElement &element);
00097 QDomElement domElement(const QString &name, QDomDocument &document) const;
00098 void initFromDOMElement(const QDomElement &element);
00099
00100 private:
00101 float M[16];
00102
00103
00104
00105
00106
00107 };
00108
00109 }
00110
00111 #endif
00112