MYST3: Change frameViewport to be in screen coordinates rather than OpenGl coordinates

This commit is contained in:
Bastien Bouclet 2015-04-19 11:04:43 +02:00
parent 5bb96c937a
commit 1537ec2de2
6 changed files with 41 additions and 19 deletions

View file

@ -110,9 +110,6 @@ void OpenGLRenderer::setupCameraOrtho2D(bool noScaling) {
void OpenGLRenderer::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());
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(_projectionMatrix.getData());
@ -120,6 +117,10 @@ void OpenGLRenderer::setupCameraPerspective(float pitch, float heading, float fo
glLoadMatrixf(_modelViewMatrix.getData());
}
void OpenGLRenderer::setViewport(const Common::Rect &vp) {
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
}
void OpenGLRenderer::drawRect2D(const Common::Rect &rect, uint32 color) {
uint8 a, r, g, b;
Graphics::colorToARGB< Graphics::ColorMasks<8888> >(color, a, r, g, b);

View file

@ -41,6 +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;
Texture *createTexture(const Graphics::Surface *surface) override;
void freeTexture(Texture *texture) override;

View file

@ -177,7 +177,7 @@ void ShaderRenderer::setupCameraOrtho2D(bool noScaling) {
}
void ShaderRenderer::setViewport(const Common::Rect &vp) {
glViewport(vp.left, vp.top, vp.width(), vp.height());
glViewport(vp.left, _system->getHeight() - vp.top - vp.height(), vp.width(), vp.height());
}
void ShaderRenderer::drawRect2D(const Common::Rect &rect, uint32 color) {

View file

@ -397,14 +397,14 @@ Graphics::Surface *Menu::createThumbnail(Graphics::Surface *big) {
// The portion of the screenshot to keep
Common::Rect frame = _vm->_scene->frameViewport();
Common::Rect screen = _vm->_gfx->viewport();
Graphics::Surface frameSurface = big->getSubArea(frame);
uint32 *dst = (uint32 *)small->getPixels();
for (uint i = 0; i < small->h; i++) {
for (uint j = 0; j < small->w; j++) {
uint32 srcX = big->w * j / small->w;
uint32 srcY = screen.bottom - frame.bottom + frame.height() * i / small->h;
uint32 *src = (uint32 *)big->getBasePtr(srcX, srcY);
uint32 srcX = frameSurface.w * j / small->w;
uint32 srcY = frameSurface.h * i / small->h;
uint32 *src = (uint32 *)frameSurface.getBasePtr(srcX, srcY);
// Copy RGBA pixel
*dst++ = *src;

View file

@ -29,7 +29,6 @@
#include "graphics/colormasks.h"
#include "math/glmath.h"
#include "math/vector2d.h"
namespace Myst3 {
@ -139,30 +138,49 @@ 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);
frame.translate(screen.left, screen.top + screen.height() * Renderer::kTopBorderHeight / 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);
return Common::Point((frame.left + frame.right) / 2, (frame.top + frame.bottom) / 2);
}
Common::Point Scene::screenPosToWindowPos(const Common::Point &screen) const {
Common::Rect frame = frameViewport();
return Common::Point(screen.x - frame.left, screen.y - frame.top);
}
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);
Common::Rect frame = frameViewport();
// Screen coords to window coords
Common::Point pos = screenPosToWindowPos(screen);
// Window coords to normalized coords
Math::Vector4d in;
in.x() = pos.x * 2 / (float) frame.width() - 1.0;
in.y() = 1.0 - pos.y * 2 / (float) frame.height();
in.z() = 1.0;
in.w() = 1.0;
// Normalized coords to direction
Math::Matrix4 A = _vm->_gfx->getMvpMatrix();
A.inverse();
Math::Vector4d out = A.transform(in);
Math::Vector3d direction(out.x(), out.y(), out.z());
direction.normalize();
// 3D coords to polar coords
obj.normalize();
Math::Vector2d horizontalProjection = Math::Vector2d(obj.x(), obj.z());
Math::Vector2d horizontalProjection = Math::Vector2d(direction.x(), direction.z());
horizontalProjection.normalize();
pitch = 90 - Math::Angle::arcCosine(obj.y()).getDegrees();
pitch = 90 - Math::Angle::arcCosine(direction.y()).getDegrees();
heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees();
if (horizontalProjection.getX() > 0.0)

View file

@ -49,6 +49,8 @@ public:
void screenPosToDirection(const Common::Point screen, float &pitch, float &heading) const;
Common::Point screenPosToWindowPos(const Common::Point &screen) const;
void drawSunspotFlare(const SunSpot &s);
float distanceToZone(float spotHeading, float spotPitch, float spotRadius, float heading, float pitch);
};