GRIM/EMI/MYST3: drop usage for GLU functions for replacements

This commit is contained in:
Pawel Kolodziejski 2014-07-10 07:29:01 +02:00
parent 46a91377d8
commit 0db12d7062
5 changed files with 83 additions and 80 deletions

View file

@ -35,6 +35,8 @@
#include "graphics/surface.h" #include "graphics/surface.h"
#include "graphics/pixelbuffer.h" #include "graphics/pixelbuffer.h"
#include "math/glmath.h"
#include "engines/grim/actor.h" #include "engines/grim/actor.h"
#include "engines/grim/colormap.h" #include "engines/grim/colormap.h"
#include "engines/grim/font.h" #include "engines/grim/font.h"
@ -249,7 +251,9 @@ void GfxOpenGL::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &
if (pos.x() == interest.x() && pos.y() == interest.y()) if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Math::Vector3d(0, 1, 0); up_vec = Math::Vector3d(0, 1, 0);
gluLookAt(pos.x(), pos.y(), pos.z(), interest.x(), interest.y(), interest.z(), up_vec.x(), up_vec.y(), up_vec.z()); Math::Matrix4 lookMatrix = Math::makeLookAtMatrix(pos, interest, up_vec);
glMultMatrixf(lookMatrix.getData());
glTranslated(-pos.x(), -pos.y(), -pos.z());
} }
} }
@ -364,10 +368,9 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
GLdouble right = -1000; GLdouble right = -1000;
GLdouble left = 1000; GLdouble left = 1000;
GLdouble bottom = -1000; GLdouble bottom = -1000;
GLdouble winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) { for (int i = 0; i < model->_numFaces; i++) {
Math::Vector3d v; Math::Vector3d obj;
float *pVertices; float *pVertices;
for (int j = 0; j < model->_faces[i].getNumVertices(); j++) { for (int j = 0; j < model->_faces[i].getNumVertices(); j++) {
@ -380,18 +383,19 @@ void GfxOpenGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j); pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j);
v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2)); obj.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));
gluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ); Math::Vector3d win;
Math::gluMathProject<GLdouble>(obj, modelView, projection, viewPort, win);
if (winX > right) if (win.x() > right)
right = winX; right = win.x();
if (winX < left) if (win.x() < left)
left = winX; left = win.x();
if (winY < top) if (win.y() < top)
top = winY; top = win.y();
if (winY > bottom) if (win.y() > bottom)
bottom = winY; bottom = win.y();
} }
} }
@ -435,7 +439,6 @@ void GfxOpenGL::getBoundingBoxPos(const EMIModel *model, int *x1, int *y1, int *
GLdouble right = -1000; GLdouble right = -1000;
GLdouble left = 1000; GLdouble left = 1000;
GLdouble bottom = -1000; GLdouble bottom = -1000;
GLdouble winX, winY, winZ;
GLdouble modelView[16], projection[16]; GLdouble modelView[16], projection[16];
GLint viewPort[4]; GLint viewPort[4];
@ -449,18 +452,18 @@ void GfxOpenGL::getBoundingBoxPos(const EMIModel *model, int *x1, int *y1, int *
for (uint j = 0; j < model->_faces[i]._faceLength * 3; j++) { for (uint j = 0; j < model->_faces[i]._faceLength * 3; j++) {
int index = indices[j]; int index = indices[j];
Math::Vector3d v = model->_drawVertices[index]; Math::Vector3d obj = model->_drawVertices[index];
Math::Vector3d win;
Math::gluMathProject<GLdouble>(obj, modelView, projection, viewPort, win);
gluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ); if (win.x() > right)
right = win.x();
if (winX > right) if (win.x() < left)
right = winX; left = win.x();
if (winX < left) if (win.y() < top)
left = winX; top = win.y();
if (winY < top) if (win.y() > bottom)
top = winY; bottom = win.y();
if (winY > bottom)
bottom = winY;
} }
} }

View file

@ -26,6 +26,8 @@
#include "graphics/surface.h" #include "graphics/surface.h"
#include "graphics/colormasks.h" #include "graphics/colormasks.h"
#include "math/glmath.h"
#include "engines/grim/actor.h" #include "engines/grim/actor.h"
#include "engines/grim/colormap.h" #include "engines/grim/colormap.h"
#include "engines/grim/material.h" #include "engines/grim/material.h"
@ -317,7 +319,9 @@ void GfxTinyGL::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &
if (pos.x() == interest.x() && pos.y() == interest.y()) if (pos.x() == interest.x() && pos.y() == interest.y())
up_vec = Math::Vector3d(0, 1, 0); up_vec = Math::Vector3d(0, 1, 0);
lookAt(pos.x(), pos.y(), pos.z(), interest.x(), interest.y(), interest.z(), up_vec.x(), up_vec.y(), up_vec.z()); Math::Matrix4 lookMatrix = Math::makeLookAtMatrix(pos, interest, up_vec);
tglMultMatrixf(lookMatrix.getData());
tglTranslatef(-pos.x(), -pos.y(), -pos.z());
} }
} }
@ -480,10 +484,9 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
TGLfloat right = -1000; TGLfloat right = -1000;
TGLfloat left = 1000; TGLfloat left = 1000;
TGLfloat bottom = -1000; TGLfloat bottom = -1000;
TGLfloat winX, winY, winZ;
for (int i = 0; i < model->_numFaces; i++) { for (int i = 0; i < model->_numFaces; i++) {
Math::Vector3d v; Math::Vector3d obj;
float *pVertices; float *pVertices;
for (int j = 0; j < model->_faces[i].getNumVertices(); j++) { for (int j = 0; j < model->_faces[i].getNumVertices(); j++) {
@ -496,18 +499,19 @@ void GfxTinyGL::getBoundingBoxPos(const Mesh *model, int *x1, int *y1, int *x2,
pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j); pVertices = model->_vertices + 3 * model->_faces[i].getVertex(j);
v.set(*(pVertices), *(pVertices + 1), *(pVertices + 2)); obj.set(*(pVertices), *(pVertices + 1), *(pVertices + 2));
tgluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ); Math::Vector3d win;
Math::gluMathProject<TGLfloat>(obj, modelView, projection, viewPort, win);
if (winX > right) if (win.x() > right)
right = winX; right = win.x();
if (winX < left) if (win.x() < left)
left = winX; left = win.x();
if (winY < top) if (win.y() < top)
top = winY; top = win.y();
if (winY > bottom) if (win.y() > bottom)
bottom = winY; bottom = win.y();
} }
} }
@ -551,7 +555,6 @@ void GfxTinyGL::getBoundingBoxPos(const EMIModel *model, int *x1, int *y1, int *
TGLfloat right = -1000; TGLfloat right = -1000;
TGLfloat left = 1000; TGLfloat left = 1000;
TGLfloat bottom = -1000; TGLfloat bottom = -1000;
TGLfloat winX, winY, winZ;
TGLfloat modelView[16], projection[16]; TGLfloat modelView[16], projection[16];
TGLint viewPort[4]; TGLint viewPort[4];
@ -565,18 +568,19 @@ void GfxTinyGL::getBoundingBoxPos(const EMIModel *model, int *x1, int *y1, int *
for (uint j = 0; j < model->_faces[i]._faceLength * 3; j++) { for (uint j = 0; j < model->_faces[i]._faceLength * 3; j++) {
int index = indices[j]; int index = indices[j];
Math::Vector3d v = model->_drawVertices[index];
tgluProject(v.x(), v.y(), v.z(), modelView, projection, viewPort, &winX, &winY, &winZ); Math::Vector3d obj = model->_drawVertices[index];
Math::Vector3d win;
Math::gluMathProject<TGLfloat>(obj, modelView, projection, viewPort, win);
if (winX > right) if (win.x() > right)
right = winX; right = win.x();
if (winX < left) if (win.x() < left)
left = winX; left = win.x();
if (winY < top) if (win.y() < top)
top = winY; top = win.y();
if (winY > bottom) if (win.y() > bottom)
bottom = winY; bottom = win.y();
} }
} }

View file

@ -35,6 +35,7 @@
#include "graphics/surface.h" #include "graphics/surface.h"
#include "math/vector2d.h" #include "math/vector2d.h"
#include "math/glmath.h"
#include "engines/myst3/gfx.h" #include "engines/myst3/gfx.h"
#include "engines/myst3/gfx_opengl.h" #include "engines/myst3/gfx_opengl.h"
@ -134,7 +135,7 @@ void OpenGLRenderer::setupCameraOrtho2D() {
glViewport(0, 0, kOriginalWidth, kOriginalHeight); glViewport(0, 0, kOriginalWidth, kOriginalHeight);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluOrtho2D(0.0, kOriginalWidth, kOriginalHeight, 0.0); glOrtho(0.0, kOriginalWidth, kOriginalHeight, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
@ -151,7 +152,8 @@ void OpenGLRenderer::setupCameraPerspective(float pitch, float heading, float fo
glViewport(0, kBottomBorderHeight, kOriginalWidth, kFrameHeight); glViewport(0, kBottomBorderHeight, kOriginalWidth, kFrameHeight);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(glFOV, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0); Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (GLfloat)kOriginalWidth / (GLfloat)kFrameHeight, 1.0, 10000.0);
glMultMatrixf(m.getData());
// Rotate the model to simulate the rotation of the camera // Rotate the model to simulate the rotation of the camera
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
@ -353,19 +355,18 @@ Graphics::Surface *OpenGLRenderer::getScreenshot() {
} }
void OpenGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) { void OpenGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) {
double x, y, z;
// Screen coords to 3D coords // Screen coords to 3D coords
gluUnProject(screen.x, kOriginalHeight - screen.y, 0.9, _cubeModelViewMatrix, _cubeProjectionMatrix, (GLint *)_cubeViewport, &x, &y, &z); Math::Vector3d obj;
Math::gluMathUnProject<double>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
_cubeModelViewMatrix, _cubeProjectionMatrix, _cubeViewport, obj);
// 3D coords to polar coords // 3D coords to polar coords
Math::Vector3d v = Math::Vector3d(x, y, z); obj.normalize();
v.normalize();
Math::Vector2d horizontalProjection = Math::Vector2d(v.x(), v.z()); Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z());
horizontalProjection.normalize(); horizontalProjection.normalize();
pitch = 90 - Math::Angle::arcCosine(v.y()).getDegrees(); pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees();
heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees(); heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees();
if (horizontalProjection.getX() > 0.0) if (horizontalProjection.getX() > 0.0)

View file

@ -33,6 +33,7 @@
#include "graphics/surface.h" #include "graphics/surface.h"
#include "math/vector2d.h" #include "math/vector2d.h"
#include "math/glmath.h"
#include "engines/myst3/gfx.h" #include "engines/myst3/gfx.h"
#include "engines/myst3/gfx_tinygl.h" #include "engines/myst3/gfx_tinygl.h"
@ -131,7 +132,7 @@ void TinyGLRenderer::setupCameraOrtho2D() {
tglViewport(0, 0, kOriginalWidth, kOriginalHeight); tglViewport(0, 0, kOriginalWidth, kOriginalHeight);
tglMatrixMode(TGL_PROJECTION); tglMatrixMode(TGL_PROJECTION);
tglLoadIdentity(); tglLoadIdentity();
tgluOrtho2D(0.0, kOriginalWidth, kOriginalHeight, 0.0); tglOrtho(0.0, kOriginalWidth, kOriginalHeight, 0.0, -1.0, 1.0);
tglMatrixMode(TGL_MODELVIEW); tglMatrixMode(TGL_MODELVIEW);
tglLoadIdentity(); tglLoadIdentity();
@ -149,7 +150,8 @@ void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fo
tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight); tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight);
tglMatrixMode(TGL_PROJECTION); tglMatrixMode(TGL_PROJECTION);
tglLoadIdentity(); tglLoadIdentity();
tgluPerspective(glFOV, (TGLfloat)kOriginalWidth / (TGLfloat)kFrameHeight, 1.0, 10000.0); Math::Matrix4 m = Math::makePerspectiveMatrix(glFOV, (TGLfloat)kOriginalWidth / (TGLfloat)kFrameHeight, 1.0, 10000.0);
tglMultMatrixf(m.getData());
// Rotate the model to simulate the rotation of the camera // Rotate the model to simulate the rotation of the camera
tglMatrixMode(TGL_MODELVIEW); tglMatrixMode(TGL_MODELVIEW);
@ -157,14 +159,8 @@ void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fo
tglRotatef(pitch, -1.0f, 0.0f, 0.0f); tglRotatef(pitch, -1.0f, 0.0f, 0.0f);
tglRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f); tglRotatef(heading - 180.0f, 0.0f, 1.0f, 0.0f);
float modelView[16], projection[16]; tglGetFloatv(TGL_MODELVIEW_MATRIX, _cubeModelViewMatrix);
tglGetFloatv(TGL_MODELVIEW_MATRIX, modelView); tglGetFloatv(TGL_PROJECTION_MATRIX, _cubeProjectionMatrix);
tglGetFloatv(TGL_PROJECTION_MATRIX, projection);
for (int i = 0; i < 16; i++) {
_cubeModelViewMatrix[i] = modelView[i];
_cubeProjectionMatrix[i] = projection[i];
}
tglGetIntegerv(TGL_VIEWPORT, (TGLint *)_cubeViewport); tglGetIntegerv(TGL_VIEWPORT, (TGLint *)_cubeViewport);
} }
@ -328,19 +324,18 @@ Graphics::Surface *TinyGLRenderer::getScreenshot() {
} }
void TinyGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) { void TinyGLRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) {
double x, y, z;
// Screen coords to 3D coords // Screen coords to 3D coords
tgluUnProject(screen.x, kOriginalHeight - screen.y, 0.9, _cubeModelViewMatrix, _cubeProjectionMatrix, (TGLint *)_cubeViewport, &x, &y, &z); Math::Vector3d obj;
Math::gluMathUnProject<float>(Math::Vector3d(screen.x, kOriginalHeight - screen.y, 0.9),
_cubeModelViewMatrix, _cubeProjectionMatrix, _cubeViewport, obj);
// 3D coords to polar coords // 3D coords to polar coords
Math::Vector3d v = Math::Vector3d(x, y, z); obj.normalize();
v.normalize();
Math::Vector2d horizontalProjection = Math::Vector2d(v.x(), v.z()); Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z());
horizontalProjection.normalize(); horizontalProjection.normalize();
pitch = 90 - Math::Angle::arcCosine(v.y()).getDegrees(); pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees();
heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees(); heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees();
if (horizontalProjection.getX() > 0.0) if (horizontalProjection.getX() > 0.0)

View file

@ -66,8 +66,8 @@ private:
TinyGL::FrameBuffer *_fb; TinyGL::FrameBuffer *_fb;
int _cubeViewport[4]; int _cubeViewport[4];
double _cubeProjectionMatrix[16]; float _cubeProjectionMatrix[16];
double _cubeModelViewMatrix[16]; float _cubeModelViewMatrix[16];
bool _nonPowerOfTwoTexSupport; bool _nonPowerOfTwoTexSupport;
}; };