2009-09-16 10:29:30 +02:00
|
|
|
/* Residual - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/myst3/scene.h"
|
|
|
|
|
|
|
|
namespace Myst3 {
|
|
|
|
|
2011-09-03 17:33:14 +02:00
|
|
|
Scene::Scene():
|
|
|
|
_cameraPitch(0.0f), _cameraHeading(0.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:29:30 +02:00
|
|
|
void Scene::init(int width, int height) {
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2011-09-11 20:27:19 +02:00
|
|
|
|
2009-09-16 10:29:30 +02:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::clear() {
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glColor3f(1.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
2012-01-03 15:23:57 +01:00
|
|
|
void Scene::setupCameraOrtho2D() {
|
2012-01-03 15:00:34 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2012-01-03 15:23:57 +01:00
|
|
|
gluOrtho2D(0.0, _originalWidth, _originalHeight, 0.0);
|
2012-01-03 15:00:34 +01:00
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2011-09-05 20:13:48 +02:00
|
|
|
glLoadIdentity();
|
|
|
|
}
|
|
|
|
|
2012-01-03 15:23:57 +01:00
|
|
|
void Scene::setupCameraPerspective() {
|
2012-01-03 15:00:34 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glLoadIdentity();
|
2012-01-03 15:23:57 +01:00
|
|
|
gluPerspective(65.0, (GLfloat)_originalWidth /(GLfloat)_originalHeight, 0.1, 100.0);
|
2012-01-03 15:00:34 +01:00
|
|
|
|
2009-09-16 10:29:30 +02:00
|
|
|
// Rotate the model to simulate the rotation of the camera
|
2012-01-03 15:00:34 +01:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2009-09-16 10:29:30 +02:00
|
|
|
glLoadIdentity();
|
2011-08-28 18:45:35 +02:00
|
|
|
glRotatef(_cameraPitch, -1.0f, 0.0f, 0.0f);
|
|
|
|
glRotatef(_cameraHeading - 180.0f, 0.0f, 1.0f, 0.0f);
|
2009-09-16 20:48:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateCamera(Common::Point &mouse) {
|
2011-08-28 18:45:35 +02:00
|
|
|
_cameraPitch -= mouse.y / 3.0f;
|
|
|
|
_cameraHeading += mouse.x / 3.0f;
|
2009-09-16 20:48:32 +02:00
|
|
|
|
2011-08-28 18:45:35 +02:00
|
|
|
// Keep heading in 0..360 range
|
|
|
|
if (_cameraHeading > 360.0f)
|
|
|
|
_cameraHeading -= 360.0f;
|
|
|
|
else if (_cameraHeading < 0.0f)
|
|
|
|
_cameraHeading += 360.0f;
|
|
|
|
|
|
|
|
// Keep pitch within allowed values
|
|
|
|
_cameraPitch = CLIP(_cameraPitch, -60.0f, 80.0f);
|
2009-09-16 10:29:30 +02:00
|
|
|
}
|
|
|
|
|
2011-09-03 17:33:14 +02:00
|
|
|
void Scene::lookAt(float pitch, float heading) {
|
|
|
|
_cameraPitch = pitch;
|
|
|
|
_cameraHeading = heading;
|
|
|
|
}
|
|
|
|
|
2012-01-03 15:23:57 +01:00
|
|
|
void Scene::drawBlackRect(const Common::Rect &r) {
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glColor3f(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
2012-01-04 11:36:46 +01:00
|
|
|
glVertex3f( r.left, r.bottom, 0.0f);
|
|
|
|
glVertex3f( r.right, r.bottom, 0.0f);
|
|
|
|
glVertex3f( r.left, r.top, 0.0f);
|
|
|
|
glVertex3f( r.right, r.top, 0.0f);
|
2012-01-03 15:23:57 +01:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::drawBlackBorders() {
|
|
|
|
Common::Rect top = Common::Rect(_originalWidth, _topBorderHeight);
|
|
|
|
|
|
|
|
Common::Rect bottom = Common::Rect(_originalWidth, _bottomBorderHeight);
|
|
|
|
bottom.translate(0, _topBorderHeight + _frameHeight);
|
|
|
|
|
|
|
|
drawBlackRect(top);
|
|
|
|
drawBlackRect(bottom);
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:29:30 +02:00
|
|
|
} // end of namespace Myst3
|