diff options
author | Thomas Fach-Pedersen | 2014-06-05 23:16:50 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-09-29 22:33:37 +0200 |
commit | d9453057abff91a30ff4fb427cadc21b5666c350 (patch) | |
tree | 4cdcdbc920f42edfede4c53a7112fa04665479e1 /engines | |
parent | 7ab0985ca8526d29c0d7f076746045b39267a23c (diff) | |
download | scummvm-rg350-d9453057abff91a30ff4fb427cadc21b5666c350.tar.gz scummvm-rg350-d9453057abff91a30ff4fb427cadc21b5666c350.tar.bz2 scummvm-rg350-d9453057abff91a30ff4fb427cadc21b5666c350.zip |
BLADERUNNER: Add View matrix loading
Diffstat (limited to 'engines')
-rw-r--r-- | engines/bladerunner/module.mk | 1 | ||||
-rw-r--r-- | engines/bladerunner/scene.cpp | 1 | ||||
-rw-r--r-- | engines/bladerunner/scene.h | 2 | ||||
-rw-r--r-- | engines/bladerunner/view.cpp | 82 | ||||
-rw-r--r-- | engines/bladerunner/view.h | 57 | ||||
-rw-r--r-- | engines/bladerunner/vqa_decoder.cpp | 3 | ||||
-rw-r--r-- | engines/bladerunner/vqa_decoder.h | 6 | ||||
-rw-r--r-- | engines/bladerunner/vqa_player.cpp | 2 | ||||
-rw-r--r-- | engines/bladerunner/vqa_player.h | 3 |
9 files changed, 156 insertions, 1 deletions
diff --git a/engines/bladerunner/module.mk b/engines/bladerunner/module.mk index 3d014483cf..eae0d950c7 100644 --- a/engines/bladerunner/module.mk +++ b/engines/bladerunner/module.mk @@ -17,6 +17,7 @@ MODULE_OBJS = \ script/script.o \ set.o \ settings.o \ + view.o \ vqa_decoder.o \ vqa_player.o diff --git a/engines/bladerunner/scene.cpp b/engines/bladerunner/scene.cpp index 7cb3b017f2..2f357e2860 100644 --- a/engines/bladerunner/scene.cpp +++ b/engines/bladerunner/scene.cpp @@ -105,6 +105,7 @@ int Scene::advanceFrame(Graphics::Surface &surface) { int frame = _vqaPlayer.update(); if (frame >= 0) { surface.copyFrom(*_vqaPlayer.getSurface()); + _view = _vqaPlayer.getView(); } return frame; } diff --git a/engines/bladerunner/scene.h b/engines/bladerunner/scene.h index b69d99decb..d7904f2190 100644 --- a/engines/bladerunner/scene.h +++ b/engines/bladerunner/scene.h @@ -23,6 +23,7 @@ #ifndef BLADERUNNER_SCENE_H #define BLADERUNNER_SCENE_H +#include "bladerunner/view.h" #include "bladerunner/vqa_player.h" namespace BladeRunner { @@ -41,6 +42,7 @@ public: int _nextSceneId; int _frame; bool _playerWalkedIn; + View _view; public: Scene(BladeRunnerEngine *vm) diff --git a/engines/bladerunner/view.cpp b/engines/bladerunner/view.cpp new file mode 100644 index 0000000000..b3b6ad8ad2 --- /dev/null +++ b/engines/bladerunner/view.cpp @@ -0,0 +1,82 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + * + */ + +#include "bladerunner/view.h" + +#include "common/debug.h" +#include "common/stream.h" + +namespace BladeRunner { + +bool View::read(Common::ReadStream *stream) { + uint32 frame; + frame = stream->readUint32LE(); + + float d[12]; + for (int i = 0; i != 12; ++i) + d[i] = stream->readFloatLE(); + + _frameViewMatrix = Matrix4x3(d); + + float fovX = stream->readFloatLE(); + + setFovX(fovX); + calculateSliceViewMatrix(); + calculateCameraPosition(); + + return true; +} + +void View::setFovX(float fovX) { + _fovX = fovX; + + _viewportHalfWidth = 320.0f; + _viewportHalfHeight = 240.0f; + + _viewportDistance = 320.0f / tanf(_fovX / 2.0f); +} + +void View::calculateSliceViewMatrix() { + Matrix4x3 m = _frameViewMatrix; + + m = m * rotationMatrixX(float(M_PI) / 2.0f); + + Matrix4x3 a( -1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, -1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f); + + m = a * m; + + _sliceViewMatrix = m; +} + +void View::calculateCameraPosition() +{ + Matrix4x3 invertedMatrix = invertMatrix(_sliceViewMatrix); + + _cameraPosition.x = invertedMatrix(0, 3); + _cameraPosition.y = invertedMatrix(1, 3); + _cameraPosition.z = invertedMatrix(2, 3); +} + + +} // End of namespace BladeRunner diff --git a/engines/bladerunner/view.h b/engines/bladerunner/view.h new file mode 100644 index 0000000000..511ea66d1b --- /dev/null +++ b/engines/bladerunner/view.h @@ -0,0 +1,57 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + * + */ + +#ifndef BLADERUNNER_VIEW_H +#define BLADERUNNER_VIEW_H + +#include "matrix.h" + +namespace Common { + class ReadStream; +} + +namespace BladeRunner { + +class View { +public: + float _fovX; + Matrix4x3 _frameViewMatrix; + Matrix4x3 _sliceViewMatrix; + uint32 _frame; + + Vector3 _cameraPosition; + + float _viewportHalfWidth; + float _viewportHalfHeight; + float _viewportDistance; + + bool read(Common::ReadStream *stream); + +private: + void setFovX(float fovX); + void calculateSliceViewMatrix(); + void calculateCameraPosition(); +}; + +} // End of namespace BladeRunner + +#endif diff --git a/engines/bladerunner/vqa_decoder.cpp b/engines/bladerunner/vqa_decoder.cpp index f2aee5dd33..f5b8c80037 100644 --- a/engines/bladerunner/vqa_decoder.cpp +++ b/engines/bladerunner/vqa_decoder.cpp @@ -754,7 +754,8 @@ bool VQADecoder::VQAVideoTrack::readVIEW(Common::SeekableReadStream *s, uint32 s if (size != 56) return false; - s->skip(size); + _view.read(s); + return true; } diff --git a/engines/bladerunner/vqa_decoder.h b/engines/bladerunner/vqa_decoder.h index ca7e067305..132c18ace2 100644 --- a/engines/bladerunner/vqa_decoder.h +++ b/engines/bladerunner/vqa_decoder.h @@ -24,6 +24,7 @@ #define BLADERUNNER_VQA_DECODER_H #include "bladerunner/aud_decoder.h" +#include "bladerunner/view.h" #include "audio/audiostream.h" @@ -51,6 +52,8 @@ public: const Graphics::Surface *decodeVideoFrame(); Audio::SeekableAudioStream *decodeAudioFrame(); + const View &getView() { return _videoTrack->getView(); } + uint16 numFrames() const { return _header.numFrames; } uint8 frameRate() const { return _header.frameRate; } @@ -158,6 +161,7 @@ private: int getCurFrame() const; int getFrameCount() const; const Graphics::Surface *decodeVideoFrame(); + const View &getView() { return _view; } bool readVQFR(Common::SeekableReadStream *s, uint32 size); bool readVPTR(Common::SeekableReadStream *s, uint32 size); @@ -198,6 +202,8 @@ private: int _curFrame; + View _view; + void VPTRWriteBlock(uint16 *frame, unsigned int dstBlock, unsigned int srcBlock, int count, bool alpha = false); bool decodeFrame(uint16 *frame); }; diff --git a/engines/bladerunner/vqa_player.cpp b/engines/bladerunner/vqa_player.cpp index 9d96154e5c..2b79ac7eec 100644 --- a/engines/bladerunner/vqa_player.cpp +++ b/engines/bladerunner/vqa_player.cpp @@ -64,6 +64,7 @@ int VQAPlayer::update() { if (_hasAudio) queueAudioFrame(_decoder.decodeAudioFrame()); _surface = _decoder.decodeVideoFrame(); + _view = _decoder.getView(); } _decodedFrame = calcNextFrame(_curFrame); @@ -86,6 +87,7 @@ int VQAPlayer::update() { _curFrame = _decodedFrame; if (_curFrame >= 0) { _surface = _decoder.decodeVideoFrame(); + _view = _decoder.getView(); } _decodedFrame = calcNextFrame(_curFrame); diff --git a/engines/bladerunner/vqa_player.h b/engines/bladerunner/vqa_player.h index 9e9266ed45..4d87b59dee 100644 --- a/engines/bladerunner/vqa_player.h +++ b/engines/bladerunner/vqa_player.h @@ -47,6 +47,8 @@ class VQAPlayer { int _loopSpecial; int _loopDefault; + View _view; + uint32 _nextFrameTime; bool _hasAudio; bool _audioStarted; @@ -78,6 +80,7 @@ public: int update(); const Graphics::Surface *getSurface() const; + const View &getView() const { return _view; } void setLoopSpecial(int loop, bool wait); void setLoopDefault(int loop); |