From 9fde449c9ee576d83c09481d4fe860826c1f1220 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sun, 11 Sep 2011 20:27:19 +0200 Subject: [PATCH] MYST3: Draw a rect where the movies should be in the scene --- engines/myst3/detection.cpp | 3 -- engines/myst3/directorysubentry.cpp | 10 ++--- engines/myst3/directorysubentry.h | 36 ++++++++-------- engines/myst3/nodecube.cpp | 66 +++++++++++++++++++++++++++++ engines/myst3/nodecube.h | 12 ++++++ engines/myst3/scene.cpp | 2 +- engines/myst3/scene.h | 3 -- 7 files changed, 102 insertions(+), 30 deletions(-) diff --git a/engines/myst3/detection.cpp b/engines/myst3/detection.cpp index 2868c379976..695a194232a 100644 --- a/engines/myst3/detection.cpp +++ b/engines/myst3/detection.cpp @@ -18,9 +18,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - * $URL$ - * $Id$ - * */ #include "engines/advancedDetector.h" diff --git a/engines/myst3/directorysubentry.cpp b/engines/myst3/directorysubentry.cpp index 3a68f7e05de..1223b1bd1f8 100755 --- a/engines/myst3/directorysubentry.cpp +++ b/engines/myst3/directorysubentry.cpp @@ -33,7 +33,7 @@ void DirectorySubEntry::readFromStream(Common::SeekableReadStream &inStream) { _size = inStream.readUint32LE(); _metadataSize = inStream.readUint16LE(); _face = inStream.readByte(); - _type = inStream.readByte(); + _type = static_cast(inStream.readByte()); if (_metadataSize == 0) return; @@ -67,14 +67,14 @@ void DirectorySubEntry::dumpToFile(Common::SeekableReadStream &inStream, uint16 char fileName[255]; switch (_type) { - case 0: - case 5: + case kCubeFace: + case kSpotItem: sprintf(fileName, "dump/%d-%d.jpg", index, _face); break; - case 1: + case kFaceMask: sprintf(fileName, "dump/%d-%d.mask", index, _face); break; - case 8: + case kMovie: sprintf(fileName, "dump/%d.bik", index); break; default: diff --git a/engines/myst3/directorysubentry.h b/engines/myst3/directorysubentry.h index effef40e7e1..26fa3cca222 100755 --- a/engines/myst3/directorysubentry.h +++ b/engines/myst3/directorysubentry.h @@ -33,24 +33,13 @@ struct SpotItemData { struct VideoData { Graphics::Vector3d v1; Graphics::Vector3d v2; - uint32 u; - uint32 v; - uint32 width; - uint32 height; + int32 u; + int32 v; + int32 width; + int32 height; }; class DirectorySubEntry { - private: - uint32 _offset; - uint32 _size; - uint16 _metadataSize; - byte _face; - byte _type; - - // Metadata - SpotItemData _spotItemData; - VideoData _videoData; - public: enum ResourceType { kCubeFace = 0, @@ -65,9 +54,20 @@ class DirectorySubEntry { void dumpToFile(Common::SeekableReadStream &inStream, uint16 index); Common::MemoryReadStream *dumpToMemory(Common::SeekableReadStream &inStream) const; uint16 getFace() { return _face; } - ResourceType getType() { return static_cast(_type); } - const SpotItemData &getSpotItemData() { return _spotItemData; } - const VideoData &getVideoData() { return _videoData; } + ResourceType getType() { return _type; } + const SpotItemData &getSpotItemData() const { return _spotItemData; } + const VideoData &getVideoData() const { return _videoData; } + + private: + uint32 _offset; + uint32 _size; + uint16 _metadataSize; + byte _face; + ResourceType _type; + + // Metadata + SpotItemData _spotItemData; + VideoData _videoData; }; } // end of namespace Myst3 diff --git a/engines/myst3/nodecube.cpp b/engines/myst3/nodecube.cpp index f2f14055640..f75b186a437 100644 --- a/engines/myst3/nodecube.cpp +++ b/engines/myst3/nodecube.cpp @@ -45,8 +45,57 @@ void NodeCube::load(Archive &archive, uint16 index) { delete jpegStream; } } + + // HACK: To load some of the movies of a frame + loadMovie(archive, index + 10000); + loadMovie(archive, index + 11000); + loadMovie(archive, index + 20000); } +void NodeCube::loadMovie(Archive &archive, uint16 id) { + static const float scale = 50.0f; + + const DirectorySubEntry *binkDesc = archive.getDescription(id, 0, DirectorySubEntry::kMovie); + + if (!binkDesc) + return; + + Common::MemoryReadStream *binkStream = archive.getData(binkDesc); + const VideoData &videoData = binkDesc->getVideoData(); + + Graphics::Vector3d planeDirection = videoData.v1; + planeDirection.normalize(); + + Graphics::Vector3d u; + u.set(planeDirection.z(), 0.0f, -planeDirection.x()); + u.normalize(); + + Graphics::Vector3d v = Graphics::cross(planeDirection, u); + v.normalize(); + + Graphics::Vector3d planeOrigin = planeDirection * scale; + + float left = (videoData.u - 320) * 0.003125f; + float right = (videoData.u + videoData.width - 320) * 0.003125f; + float top = (320 - videoData.v) * 0.003125f; + float bottom = (320 - videoData.v - videoData.height) * 0.003125f; + + Graphics::Vector3d vLeft = scale * left * u; + Graphics::Vector3d vRight = scale * right * u; + Graphics::Vector3d vTop = scale * top * v; + Graphics::Vector3d vBottom = scale * bottom * v; + + Movie movie; + + movie.pTopLeft = planeOrigin + vTop + vLeft; + movie.pBottomLeft = planeOrigin + vBottom + vLeft; + movie.pBottomRight = planeOrigin + vBottom + vRight; + movie.pTopRight = planeOrigin + vTop + vRight; + + _movies.push_back(movie); + + delete binkStream; +} void NodeCube::draw() { // Size of the cube @@ -106,6 +155,23 @@ void NodeCube::draw() { glEnd(); glDepthMask(GL_TRUE); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + + for (uint i = 0; i < _movies.size(); i++) { + glBegin(GL_POLYGON); + glColor4f(0.0f, 0.5f, 0.0f, 0.2f); + glVertex3f(-_movies[i].pTopLeft.x(), _movies[i].pTopLeft.y(), _movies[i].pTopLeft.z()); + glVertex3f(-_movies[i].pBottomLeft.x(), _movies[i].pBottomLeft.y(), _movies[i].pBottomLeft.z()); + glVertex3f(-_movies[i].pBottomRight.x(), _movies[i].pBottomRight.y(), _movies[i].pBottomRight.z()); + glVertex3f(-_movies[i].pTopRight.x(), _movies[i].pTopRight.y(), _movies[i].pTopRight.z()); + glEnd(); + } + + glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); } } /* namespace Myst3 */ diff --git a/engines/myst3/nodecube.h b/engines/myst3/nodecube.h index 07889c6a4ab..975495fc25a 100644 --- a/engines/myst3/nodecube.h +++ b/engines/myst3/nodecube.h @@ -27,6 +27,13 @@ namespace Myst3 { +struct Movie { + Graphics::Vector3d pTopLeft; + Graphics::Vector3d pBottomLeft; + Graphics::Vector3d pBottomRight; + Graphics::Vector3d pTopRight; +}; + class NodeCube: public Myst3::Node { public: NodeCube(); @@ -34,6 +41,11 @@ public: void load(Archive &archive, uint16 id); void draw(); + + void loadMovie(Archive &archive, uint16 id); + +private: + Common::Array _movies; }; } /* namespace Myst3 */ diff --git a/engines/myst3/scene.cpp b/engines/myst3/scene.cpp index 3a5c28b7349..d0a60756cbc 100644 --- a/engines/myst3/scene.cpp +++ b/engines/myst3/scene.cpp @@ -36,7 +36,7 @@ void Scene::init(int width, int height) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - + glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); diff --git a/engines/myst3/scene.h b/engines/myst3/scene.h index a83360afa33..e3fc86f27df 100644 --- a/engines/myst3/scene.h +++ b/engines/myst3/scene.h @@ -18,9 +18,6 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * - * $URL$ - * $Id$ - * */ #ifndef MYST3_SCENE_H