Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MATH_GLMATH_H
00024 #define MATH_GLMATH_H
00025
00026 #include "common/rect.h"
00027
00028 #include "math/vector4d.h"
00029 #include "math/matrix4.h"
00030
00031 namespace Math {
00032
00033
00034 template<typename T, typename S>
00035 bool gluMathProject(Vector3d obj, const T model[16], const T proj[16], const S viewport[4], Vector3d &win) {
00036 Vector4d in, out;
00037 Matrix4 modelMatrix, projMatrix;
00038
00039 in.set(obj.x(), obj.y(), obj.z(), 1.0);
00040
00041 for (int i = 0; i < 4; i++) {
00042 modelMatrix(0, i) = model[0 * 4 + i];
00043 modelMatrix(1, i) = model[1 * 4 + i];
00044 modelMatrix(2, i) = model[2 * 4 + i];
00045 modelMatrix(3, i) = model[3 * 4 + i];
00046 projMatrix(0, i) = proj[0 * 4 + i];
00047 projMatrix(1, i) = proj[1 * 4 + i];
00048 projMatrix(2, i) = proj[2 * 4 + i];
00049 projMatrix(3, i) = proj[3 * 4 + i];
00050 }
00051
00052 out = modelMatrix.transform(in);
00053 in = projMatrix.transform(out);
00054 if (in.w() == 0.0)
00055 return false;
00056
00057 in.x() /= in.w();
00058 in.y() /= in.w();
00059 in.z() /= in.w();
00060
00061 win.x() = viewport[0] + (1 + in.x()) * viewport[2] / 2;
00062 win.y() = viewport[1] + (1 + in.y()) * viewport[3] / 2;
00063 win.z() = (1 + in.z()) / 2;
00064
00065 return true;
00066 }
00067
00068 bool gluMathUnProject(Vector3d win, const Matrix4 &mvpMatrix, const Common::Rect &viewport, Vector3d &obj);
00069
00070 Matrix4 makePerspectiveMatrix(double fovy, double aspect, double zNear, double zFar);
00071 Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, double zNear, double zFar);
00072 Matrix4 makeLookAtMatrix(const Vector3d &eye, const Vector3d ¢er, const Vector3d &up);
00073
00074 }
00075
00076 #endif