MYST3: Start moving some of the frame viewport code the the Scene class

This commit is contained in:
Bastien Bouclet 2015-04-19 10:15:10 +02:00
parent bb896d23bc
commit 5bb96c937a
11 changed files with 59 additions and 50 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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();

View File

@ -624,6 +624,7 @@ void Myst3Engine::drawFrame(bool noSwap) {
}
_gfx->setupCameraPerspective(pitch, heading, fov);
_gfx->setViewport(_scene->frameViewport());
} else {
_gfx->setupCameraOrtho2D(false);
}

View File

@ -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

View File

@ -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);
};