Skip to content

Commit

Permalink
MATH: improve type support for viewport argument
Browse files Browse the repository at this point in the history
  • Loading branch information
aquadran committed Aug 15, 2014
1 parent 361eb89 commit e539b27
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions engines/grim/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void GfxOpenGL::getScreenBoundingBox(const Mesh *model, int *x1, int *y1, int *x
obj.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));

Math::Vector3d win;
Math::gluMathProject<GLdouble>(obj, modelView, projection, viewPort, win);
Math::gluMathProject<GLdouble, GLint>(obj, modelView, projection, viewPort, win);

if (win.x() > right)
right = win.x();
Expand Down Expand Up @@ -456,7 +456,7 @@ void GfxOpenGL::getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, in
int index = indices[j];
Math::Vector3d obj = model->_drawVertices[index];
Math::Vector3d win;
Math::gluMathProject<GLdouble>(obj, modelView, projection, viewPort, win);
Math::gluMathProject<GLdouble, GLint>(obj, modelView, projection, viewPort, win);

if (win.x() > right)
right = win.x();
Expand Down Expand Up @@ -533,7 +533,7 @@ void GfxOpenGL::getActorScreenBBox(const Actor *actor, Common::Point &p1, Common
Math::Vector3d added(bboxSize.x() * 0.5f * (x * 2 - 1), bboxSize.y() * 0.5f * (y * 2 - 1), bboxSize.z() * 0.5f * (z * 2 - 1));
m.transform(&added, false);
p = bboxPos + added;
Math::gluMathProject<GLdouble>(p, modelView, projection, viewPort, projected);
Math::gluMathProject<GLdouble, GLint>(p, modelView, projection, viewPort, projected);

// Find the points
if (projected.x() < p1.x)
Expand Down
6 changes: 3 additions & 3 deletions engines/grim/gfx_tinygl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void GfxTinyGL::getScreenBoundingBox(const Mesh *model, int *x1, int *y1, int *x
obj.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));

Math::Vector3d win;
Math::gluMathProject<TGLfloat>(obj, modelView, projection, viewPort, win);
Math::gluMathProject<TGLfloat, TGLint>(obj, modelView, projection, viewPort, win);

if (win.x() > right)
right = win.x();
Expand Down Expand Up @@ -470,7 +470,7 @@ void GfxTinyGL::getScreenBoundingBox(const EMIModel *model, int *x1, int *y1, in

Math::Vector3d obj = model->_drawVertices[index];
Math::Vector3d win;
Math::gluMathProject<TGLfloat>(obj, modelView, projection, viewPort, win);
Math::gluMathProject<TGLfloat, TGLint>(obj, modelView, projection, viewPort, win);

if (win.x() > right)
right = win.x();
Expand Down Expand Up @@ -549,7 +549,7 @@ void GfxTinyGL::getActorScreenBBox(const Actor *actor, Common::Point &p1, Common
Math::Vector3d added(bboxSize.x() * 0.5f * (x * 2 - 1), bboxSize.y() * 0.5f * (y * 2 - 1), bboxSize.z() * 0.5f * (z * 2 - 1));
m.transform(&added, false);
p = bboxPos + added;
Math::gluMathProject<TGLfloat>(p, modelView, projection, viewPort, projected);
Math::gluMathProject<TGLfloat, TGLint>(p, modelView, projection, viewPort, projected);

// Find the points
if (projected.x() < p1.x)
Expand Down
2 changes: 1 addition & 1 deletion engines/myst3/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Graphics::Surface *OpenGLRenderer::getScreenshot() {
void OpenGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) {
// Screen coords to 3D coords
Math::Vector3d obj;
Math::gluMathUnProject<double>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
Math::gluMathUnProject<double, int>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
_cubeModelViewMatrix, _cubeProjectionMatrix, _cubeViewport, obj);

// 3D coords to polar coords
Expand Down
2 changes: 1 addition & 1 deletion engines/myst3/gfx_tinygl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Graphics::Surface *TinyGLRenderer::getScreenshot() {
void TinyGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) {
// Screen coords to 3D coords
Math::Vector3d obj;
Math::gluMathUnProject<float>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
Math::gluMathUnProject<float, int>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
_cubeModelViewMatrix, _cubeProjectionMatrix, _cubeViewport, obj);

// 3D coords to polar coords
Expand Down
8 changes: 4 additions & 4 deletions math/glmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
namespace Math {

// function based on gluProject from Mesa 5.0 glu GPLv2+ licensed sources
template<typename T>
bool gluMathProject(Vector3d obj, const T model[16], const T proj[16], const int viewport[4], Vector3d &win) {
template<typename T, typename S>
bool gluMathProject(Vector3d obj, const T model[16], const T proj[16], const S viewport[4], Vector3d &win) {
Vector4d in, out;
Matrix4 modelMatrix, projMatrix;

Expand Down Expand Up @@ -64,8 +64,8 @@ bool gluMathProject(Vector3d obj, const T model[16], const T proj[16], const int
}

// function based on gluUnProject from Mesa 5.0 glu GPLv2+ licensed sources
template<typename T>
bool gluMathUnProject(Vector3d win, const T model[16], const T proj[16], const int viewport[4], Vector3d &obj) {
template<typename T, typename S>
bool gluMathUnProject(Vector3d win, const T model[16], const T proj[16], const S viewport[4], Vector3d &obj) {
Matrix4 A;
Matrix4 modelMatrix, projMatrix;
Vector4d in, out;
Expand Down

0 comments on commit e539b27

Please sign in to comment.