ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

glmath.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 // function based on gluProject from Mesa 5.0 glu GPLv2+ licensed sources
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 &center, const Vector3d &up);
00073 
00074 }
00075 
00076 #endif


Generated on Sat Feb 16 2019 05:00:51 for ResidualVM by doxygen 1.7.1
curved edge   curved edge