Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00076 StarkScene->initCamera(_position, _lookDirection, _fov, _viewSize, _nearClipPlane, _farClipPlane);
00077
00078
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 }
00104 }