ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

camera.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/resources/camera.h"
00024 
00025 #include "engines/stark/debug.h"
00026 #include "engines/stark/formats/xrc.h"
00027 #include "engines/stark/resources/location.h"
00028 #include "engines/stark/scene.h"
00029 #include "engines/stark/services/services.h"
00030 
00031 namespace Stark {
00032 namespace Resources {
00033 
00034 Camera::~Camera() {
00035 }
00036 
00037 Camera::Camera(Object *parent, byte subType, uint16 index, const Common::String &name) :
00038         Object(parent, subType, index, name),
00039         _f1(0),
00040         _fov(45),
00041         _nearClipPlane(100.0),
00042         _farClipPlane(64000.0) {
00043     _type = TYPE;
00044 }
00045 
00046 void Camera::setClipPlanes(float near, float far) {
00047     _nearClipPlane = near;
00048     _farClipPlane = far;
00049 }
00050 
00051 void Camera::readData(Formats::XRCReadStream *stream) {
00052     _position = stream->readVector3();
00053     _lookDirection = stream->readVector3();
00054     _f1 = stream->readFloatLE();
00055     _fov = stream->readFloatLE();
00056     _viewSize = stream->readRect();
00057     _v4 = stream->readVector3();
00058 }
00059 
00060 void Camera::onAllLoaded() {
00061     Object::onAllLoaded();
00062 
00063     // Compute scroll coordinates bounds
00064     Common::Point maxScroll;
00065     maxScroll.x = _viewSize.width() - 640;
00066     maxScroll.y = _viewSize.height() - 365;
00067 
00068     Location *location = findParent<Location>();
00069     location->initScroll(maxScroll);
00070 }
00071 
00072 void Camera::onEnterLocation() {
00073     Object::onEnterLocation();
00074 
00075     // Setup the camera
00076     StarkScene->initCamera(_position, _lookDirection, _fov, _viewSize, _nearClipPlane, _farClipPlane);
00077 
00078     // Scroll the camera to its initial position
00079     Location *location = findParent<Location>();
00080     location->setScrollPosition(location->getScrollPosition());
00081 }
00082 
00083 Math::Angle Camera::getHorizontalAngle() const {
00084     Math::Angle lookDirectionAngle = Math::Vector3d::angle(_lookDirection, Math::Vector3d(1.0, 0.0, 0.0));
00085     Math::Vector3d cross = Math::Vector3d::crossProduct(_lookDirection, Math::Vector3d(1.0, 0.0, 0.0));
00086     if (cross.z() < 0) {
00087         return -lookDirectionAngle;
00088     } else {
00089         return lookDirectionAngle;
00090     }
00091 }
00092 
00093 void Camera::printData() {
00094     Common::Debug debug = streamDbg();
00095     debug << "position: " << _position << "\n";
00096     debug << "lookDirection: " << _lookDirection << "\n";
00097     debug << "f1: " << _f1 << "\n";
00098     debug << "fov: " << _fov << "\n";
00099     debug << "viewSize:" << _viewSize.left << _viewSize.top << _viewSize.right << _viewSize.bottom << "\n";
00100     debug << "v4: " << _v4 << "\n";
00101 }
00102 
00103 } // End of namespace Resources
00104 } // End of namespace Stark


Generated on Sat May 18 2019 05:00:56 for ResidualVM by doxygen 1.7.1
curved edge   curved edge