diff --git a/engines/myst3/cursor.cpp b/engines/myst3/cursor.cpp index b741dceaefc..6816a7c03e0 100644 --- a/engines/myst3/cursor.cpp +++ b/engines/myst3/cursor.cpp @@ -57,7 +57,7 @@ static const CursorData availableCursors[] = { Cursor::Cursor(Myst3Engine *vm) : _vm(vm), - _position(vm->_gfx->frameCenter()), + _position(vm->_scene->frameCenter()), _hideLevel(0), _lockedAtCenter(false) { @@ -146,7 +146,7 @@ void Cursor::lockPosition(bool lock) { g_system->lockMouse(lock); - Common::Point center = _vm->_gfx->frameCenter(); + Common::Point center = _vm->_scene->frameCenter(); if (_lockedAtCenter) { // Locking, just move the cursor at the center of the screen _position = center; @@ -223,7 +223,7 @@ void Cursor::getDirection(float &pitch, float &heading) { pitch = _vm->_state->getLookAtPitch(); heading = _vm->_state->getLookAtHeading(); } else { - _vm->_gfx->screenPosToDirection(_position, pitch, heading); + _vm->_scene->screenPosToDirection(_position, pitch, heading); } } diff --git a/engines/myst3/gfx.cpp b/engines/myst3/gfx.cpp index 67da8abd1e1..d73c126579e 100644 --- a/engines/myst3/gfx.cpp +++ b/engines/myst3/gfx.cpp @@ -118,15 +118,6 @@ Common::Rect Renderer::viewport() const { return _screenViewport; } -Common::Rect Renderer::frameViewport() const { - Common::Rect screen = viewport(); - - Common::Rect frame = Common::Rect(screen.width(), screen.height() * kFrameHeight / kOriginalHeight); - frame.translate(screen.left, screen.top + screen.height() * kBottomBorderHeight / kOriginalHeight); - - return frame; -} - void Renderer::computeScreenViewport() { int32 screenWidth = _system->getWidth(); int32 screenHeight = _system->getHeight(); @@ -146,12 +137,6 @@ void Renderer::computeScreenViewport() { } } -Common::Point Renderer::frameCenter() const { - Common::Rect screen = viewport(); - Common::Rect frame = frameViewport(); - return Common::Point((frame.left + frame.right) / 2, screen.top + screen.bottom - (frame.top + frame.bottom) / 2); -} - Math::Matrix4 Renderer::makeProjectionMatrix(float fov) const { static const float nearClipPlane = 1.0; static const float farClipPlane = 10000.0; @@ -180,24 +165,6 @@ void Renderer::setupCameraPerspective(float pitch, float heading, float fov) { _mvpMatrix.transpose(); } -void Renderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) { - // Screen coords to 3D coords - Math::Vector3d obj; - Math::gluMathUnProject(Math::Vector3d(screen.x, _system->getHeight() - screen.y, 0.9f), _mvpMatrix, frameViewport(), obj); - - // 3D coords to polar coords - obj.normalize(); - - Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z()); - horizontalProjection.normalize(); - - pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees(); - heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees(); - - if (horizontalProjection.getX() > 0.0) - heading = 360 - heading; -} - bool Renderer::isCubeFaceVisible(uint face) { assert(face < 6); diff --git a/engines/myst3/gfx.h b/engines/myst3/gfx.h index a08b59b92e9..b257c5c6ec1 100644 --- a/engines/myst3/gfx.h +++ b/engines/myst3/gfx.h @@ -84,18 +84,17 @@ public: virtual Graphics::Surface *getScreenshot() = 0; Common::Rect viewport() const; - Common::Rect frameViewport() const; - Common::Point frameCenter() const; Math::Matrix4 makeProjectionMatrix(float fov) const; virtual void setupCameraOrtho2D(bool noScaling) = 0; virtual void setupCameraPerspective(float pitch, float heading, float fov); - - void screenPosToDirection(const Common::Point screen, float &pitch, float &heading); + virtual void setViewport(const Common::Rect &vp) = 0; bool isCubeFaceVisible(uint face); + Math::Matrix4 getMvpMatrix() const { return _mvpMatrix; } + void flipVertical(Graphics::Surface *s); static const int kOriginalWidth = 640; diff --git a/engines/myst3/gfx_opengl_shaders.cpp b/engines/myst3/gfx_opengl_shaders.cpp index 37653ef7342..7a46b9fe901 100644 --- a/engines/myst3/gfx_opengl_shaders.cpp +++ b/engines/myst3/gfx_opengl_shaders.cpp @@ -176,11 +176,8 @@ void ShaderRenderer::setupCameraOrtho2D(bool noScaling) { } } -void ShaderRenderer::setupCameraPerspective(float pitch, float heading, float fov) { - Renderer::setupCameraPerspective(pitch, heading, fov); - - Common::Rect frame = frameViewport(); - glViewport(frame.left, frame.top, frame.width(), frame.height()); +void ShaderRenderer::setViewport(const Common::Rect &vp) { + glViewport(vp.left, vp.top, vp.width(), vp.height()); } void ShaderRenderer::drawRect2D(const Common::Rect &rect, uint32 color) { diff --git a/engines/myst3/gfx_opengl_shaders.h b/engines/myst3/gfx_opengl_shaders.h index 47afde5b4cc..6e5985d9c5d 100644 --- a/engines/myst3/gfx_opengl_shaders.h +++ b/engines/myst3/gfx_opengl_shaders.h @@ -41,7 +41,7 @@ public: virtual void clear() override; virtual void setupCameraOrtho2D(bool noScaling) override; - virtual void setupCameraPerspective(float pitch, float heading, float fov) override; + virtual void setViewport(const Common::Rect &vp) override; virtual Texture *createTexture(const Graphics::Surface *surface) override; virtual void freeTexture(Texture *texture) override; diff --git a/engines/myst3/gfx_tinygl.cpp b/engines/myst3/gfx_tinygl.cpp index 5c5a8bb8c55..a8fd3de3946 100644 --- a/engines/myst3/gfx_tinygl.cpp +++ b/engines/myst3/gfx_tinygl.cpp @@ -101,9 +101,6 @@ void TinyGLRenderer::setupCameraOrtho2D(bool noScaling) { void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fov) { Renderer::setupCameraPerspective(pitch, heading, fov); - // NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL - tglViewport(0, kTopBorderHeight, kOriginalWidth, kFrameHeight); - tglMatrixMode(TGL_PROJECTION); tglLoadMatrixf(_projectionMatrix.getData()); @@ -111,6 +108,11 @@ void TinyGLRenderer::setupCameraPerspective(float pitch, float heading, float fo tglLoadMatrixf(_modelViewMatrix.getData()); } +void TinyGLRenderer::setViewport(const Common::Rect &vp) { + // NOTE: tinyGL viewport implementation needs to be checked as it doesn't behave the same as openGL + tglViewport(vp.left, vp.top, vp.width(), vp.height()); +} + void TinyGLRenderer::drawRect2D(const Common::Rect &rect, uint32 color) { uint8 a, r, g, b; Graphics::colorToARGB< Graphics::ColorMasks<8888> >(color, a, r, g, b); diff --git a/engines/myst3/gfx_tinygl.h b/engines/myst3/gfx_tinygl.h index b1ea1a1a764..60b0b320cb5 100644 --- a/engines/myst3/gfx_tinygl.h +++ b/engines/myst3/gfx_tinygl.h @@ -42,6 +42,7 @@ public: virtual void clear() override; virtual void setupCameraOrtho2D(bool noScaling) override; virtual void setupCameraPerspective(float pitch, float heading, float fov) override; + virtual void setViewport(const Common::Rect &vp) override; Texture *createTexture(const Graphics::Surface *surface) override; void freeTexture(Texture *texture) override; diff --git a/engines/myst3/menu.cpp b/engines/myst3/menu.cpp index c9f2869cd9e..5d09fd32f73 100644 --- a/engines/myst3/menu.cpp +++ b/engines/myst3/menu.cpp @@ -396,7 +396,7 @@ Graphics::Surface *Menu::createThumbnail(Graphics::Surface *big) { Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24)); // The portion of the screenshot to keep - Common::Rect frame = _vm->_gfx->frameViewport(); + Common::Rect frame = _vm->_scene->frameViewport(); Common::Rect screen = _vm->_gfx->viewport(); uint32 *dst = (uint32 *)small->getPixels(); diff --git a/engines/myst3/myst3.cpp b/engines/myst3/myst3.cpp index d683804b90f..779f6eb902a 100644 --- a/engines/myst3/myst3.cpp +++ b/engines/myst3/myst3.cpp @@ -624,6 +624,7 @@ void Myst3Engine::drawFrame(bool noSwap) { } _gfx->setupCameraPerspective(pitch, heading, fov); + _gfx->setViewport(_scene->frameViewport()); } else { _gfx->setupCameraOrtho2D(false); } diff --git a/engines/myst3/scene.cpp b/engines/myst3/scene.cpp index cfc1eb6d792..6610ccf2e9f 100644 --- a/engines/myst3/scene.cpp +++ b/engines/myst3/scene.cpp @@ -29,6 +29,9 @@ #include "graphics/colormasks.h" +#include "math/glmath.h" +#include "math/vector2d.h" + namespace Myst3 { Scene::Scene(Myst3Engine *vm) : @@ -132,4 +135,38 @@ void Scene::updateMouseSpeed() { _mouseSpeed = ConfMan.getInt("mouse_speed"); } +Common::Rect Scene::frameViewport() const { + Common::Rect screen = _vm->_gfx->viewport(); + + Common::Rect frame = Common::Rect(screen.width(), screen.height() * Renderer::kFrameHeight / Renderer::kOriginalHeight); + frame.translate(screen.left, screen.top + screen.height() * Renderer::kBottomBorderHeight / Renderer::kOriginalHeight); + + return frame; +} + +Common::Point Scene::frameCenter() const { + Common::Rect screen = _vm->_gfx->viewport(); + Common::Rect frame = frameViewport(); + + return Common::Point((frame.left + frame.right) / 2, screen.top + screen.bottom - (frame.top + frame.bottom) / 2); +} + +void Scene::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) const { + // Screen coords to 3D coords + Math::Vector3d obj; + Math::gluMathUnProject(Math::Vector3d(screen.x, g_system->getHeight() - screen.y, 0.9f), _vm->_gfx->getMvpMatrix(), frameViewport(), obj); + + // 3D coords to polar coords + obj.normalize(); + + Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z()); + horizontalProjection.normalize(); + + pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees(); + heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees(); + + if (horizontalProjection.getX() > 0.0) + heading = 360 - heading; +} + } // end of namespace Myst3 diff --git a/engines/myst3/scene.h b/engines/myst3/scene.h index 59f1ea20a38..e1148dbcb72 100644 --- a/engines/myst3/scene.h +++ b/engines/myst3/scene.h @@ -44,6 +44,11 @@ public: void updateMouseSpeed(); + Common::Rect frameViewport() const; + Common::Point frameCenter() const; + + void screenPosToDirection(const Common::Point screen, float &pitch, float &heading) const; + void drawSunspotFlare(const SunSpot &s); float distanceToZone(float spotHeading, float spotPitch, float spotRadius, float heading, float pitch); };