2014-09-21 18:19:07 +02:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2010-01-27 19:14:07 +01:00
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2010-01-27 19:14:07 +01:00
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
2010-01-27 19:14:07 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2014-09-21 18:19:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-01-27 19:14:07 +01:00
|
|
|
*
|
2014-09-21 18:19:07 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-01-27 19:14:07 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/scene.h"
|
|
|
|
|
2015-01-03 19:18:15 +01:00
|
|
|
#include "engines/stark/gfx/driver.h"
|
2015-01-02 16:07:55 +01:00
|
|
|
#include "engines/stark/gfx/renderentry.h"
|
2010-02-03 10:39:42 +01:00
|
|
|
|
2015-02-08 17:40:19 +01:00
|
|
|
#include "math/glmath.h"
|
|
|
|
|
2010-01-27 19:14:07 +01:00
|
|
|
namespace Stark {
|
|
|
|
|
2015-01-03 19:18:15 +01:00
|
|
|
Scene::Scene(GfxDriver *gfx) :
|
|
|
|
_gfx(gfx),
|
|
|
|
_fov(45.0),
|
|
|
|
_nearClipPlane(100.0),
|
2015-02-12 21:56:00 +01:00
|
|
|
_farClipPlane(64000.0) {
|
2010-01-27 19:14:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene() {
|
|
|
|
}
|
|
|
|
|
2015-01-04 08:21:02 +01:00
|
|
|
void Scene::initCamera(const Math::Vector3d &position, const Math::Vector3d &lookDirection,
|
2015-02-08 09:17:51 +01:00
|
|
|
float fov, Common::Rect viewSize, float nearClipPlane, float farClipPlane) {
|
2015-01-03 19:18:15 +01:00
|
|
|
_cameraPosition = position;
|
2015-01-04 08:21:02 +01:00
|
|
|
_cameraLookDirection = lookDirection;
|
2015-01-03 19:18:15 +01:00
|
|
|
_fov = fov;
|
2015-02-08 09:17:51 +01:00
|
|
|
_viewSize = viewSize;
|
2015-01-03 19:18:15 +01:00
|
|
|
_nearClipPlane = nearClipPlane;
|
|
|
|
_farClipPlane = farClipPlane;
|
2015-02-08 17:40:19 +01:00
|
|
|
|
|
|
|
_lookAtMatrix = Math::makeLookAtMatrix(_cameraPosition, _cameraPosition + _cameraLookDirection, Math::Vector3d(0.0, 0.0, 1.0));
|
2015-01-03 19:18:15 +01:00
|
|
|
}
|
|
|
|
|
2015-02-08 09:17:51 +01:00
|
|
|
void Scene::scrollCamera(const Common::Rect &viewport) {
|
|
|
|
_viewport = viewport;
|
2015-02-11 16:12:13 +01:00
|
|
|
|
|
|
|
float xmin, xmax, ymin, ymax;
|
2015-02-12 21:56:00 +01:00
|
|
|
computeClippingRect(&xmin, &xmax, &ymin, &ymax);
|
2015-02-11 16:12:13 +01:00
|
|
|
|
2015-02-12 21:56:00 +01:00
|
|
|
// The amounts by which translate to clipping planes to account for one pixel
|
|
|
|
// of camera scrolling movement
|
|
|
|
float scollXFactor = (xmax - xmin) / _viewport.width();
|
|
|
|
float scollYFactor = (ymax - ymin) / _viewport.height();
|
2015-02-11 16:12:13 +01:00
|
|
|
|
2015-02-12 21:56:00 +01:00
|
|
|
int32 distanceToRight = _viewport.right - _viewSize.width();
|
|
|
|
int32 distanceToBottom = _viewport.bottom - _viewSize.height();
|
|
|
|
|
|
|
|
xmin += distanceToRight * scollXFactor;
|
|
|
|
xmax += distanceToRight * scollXFactor;
|
|
|
|
ymin += distanceToBottom * scollYFactor;
|
|
|
|
ymax += distanceToBottom * scollYFactor;
|
2015-02-11 16:12:13 +01:00
|
|
|
|
|
|
|
_perspectiveMatrix = Math::makeFrustumMatrix(xmin, xmax, ymin, ymax, _nearClipPlane, _farClipPlane);
|
|
|
|
}
|
|
|
|
|
2015-02-12 21:56:00 +01:00
|
|
|
void Scene::computeClippingRect(float *xmin, float *xmax, float *ymin, float *ymax) {
|
|
|
|
float aspectRatio = _viewSize.width() / (float) _viewSize.height();
|
|
|
|
float xmaxValue = _nearClipPlane * tan(_fov * M_PI / 360.0);
|
|
|
|
float ymaxValue = xmaxValue / aspectRatio;
|
|
|
|
|
|
|
|
float xminValue = xmaxValue - 2 * xmaxValue * (_viewport.width() / (float) _viewSize.width());
|
|
|
|
float yminValue = ymaxValue - 2 * ymaxValue * (_viewport.height() / (float) _viewSize.height());
|
2015-02-11 16:12:13 +01:00
|
|
|
|
|
|
|
if (xmin) *xmin = xminValue;
|
|
|
|
if (xmax) *xmax = xmaxValue;
|
|
|
|
if (ymin) *ymin = yminValue;
|
|
|
|
if (ymax) *ymax = ymaxValue;
|
2015-02-08 09:17:51 +01:00
|
|
|
}
|
|
|
|
|
2015-01-10 10:27:32 +01:00
|
|
|
void Scene::render(RenderEntryArray renderEntries) {
|
2010-01-27 19:14:07 +01:00
|
|
|
// setup cam
|
2015-02-12 21:56:00 +01:00
|
|
|
_gfx->setGameViewport();
|
2015-02-08 17:40:19 +01:00
|
|
|
_gfx->setupPerspective(_perspectiveMatrix);
|
|
|
|
_gfx->setupCamera(_cameraPosition, _lookAtMatrix);
|
2010-09-09 18:23:52 +02:00
|
|
|
|
2010-01-27 19:14:07 +01:00
|
|
|
// Draw bg
|
|
|
|
|
|
|
|
// Draw other things
|
|
|
|
|
|
|
|
// Render all the scene elements
|
2015-01-04 20:01:17 +01:00
|
|
|
RenderEntryArray::iterator element = renderEntries.begin();
|
|
|
|
while (element != renderEntries.end()) {
|
2010-01-27 19:14:07 +01:00
|
|
|
// Draw the current element
|
|
|
|
(*element)->render(_gfx);
|
|
|
|
|
|
|
|
// Go for the next one
|
|
|
|
element++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//_gfx->set3DMode();
|
|
|
|
|
|
|
|
// setup lights
|
|
|
|
|
|
|
|
// draw actors
|
|
|
|
|
|
|
|
// draw overlay
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Stark
|