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

prop.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/visual/prop.h"
00024 
00025 #include "engines/stark/formats/biffmesh.h"
00026 #include "engines/stark/gfx/driver.h"
00027 #include "engines/stark/gfx/texture.h"
00028 
00029 namespace Stark {
00030 
00031 VisualProp::VisualProp() :
00032         Visual(TYPE),
00033         _model(nullptr),
00034         _texture(nullptr) {
00035 }
00036 
00037 VisualProp::~VisualProp() {
00038     delete _model;
00039     delete _texture;
00040 }
00041 
00042 void VisualProp::setModel(Formats::BiffMesh *model) {
00043     assert(!_model);
00044 
00045     _model = model;
00046 
00047     const Common::Array<Formats::BiffMesh::Vertex> &vertices = _model->getVertices();
00048     for (uint i = 0; i < vertices.size(); i++) {
00049         _boundingBox.expand(vertices[i].position);
00050     }
00051 }
00052 
00053 void VisualProp::setTexture(Gfx::TextureSet *texture) {
00054     assert(!_texture);
00055 
00056     _texture = texture;
00057 }
00058 
00059 Math::Matrix4 VisualProp::getModelMatrix(const Math::Vector3d& position, float direction) {
00060     Math::Matrix4 posMatrix;
00061     posMatrix.setPosition(position);
00062 
00063     Math::Matrix4 rot1;
00064     rot1.buildAroundX(90);
00065 
00066     Math::Matrix4 rot2;
00067     rot2.buildAroundY(270 - direction);
00068 
00069     Math::Matrix4 modelTransform = _model->getTransform();
00070 
00071     return posMatrix * rot1 * rot2 * modelTransform;
00072 }
00073 
00074 bool VisualProp::intersectRay(const Math::Ray &ray, const Math::Vector3d &position, float direction) {
00075     Math::Matrix4 inverseModelMatrix = getModelMatrix(position, direction);
00076     inverseModelMatrix.inverse();
00077 
00078     // Build an object local ray from the world ray
00079     Math::Ray localRay = ray;
00080     localRay.transform(inverseModelMatrix);
00081 
00082     return localRay.intersectAABB(_boundingBox);
00083 }
00084 
00085 } // End of namespace Stark


Generated on Sat Feb 23 2019 05:01:14 for ResidualVM by doxygen 1.7.1
curved edge   curved edge