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

matrix3.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 COPYRIGHT
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 "math/matrix3.h"
00024 
00025 namespace Math {
00026 
00027 Matrix<3, 3>::Matrix() :
00028     MatrixType<3, 3>(), Rotation3D<Matrix<3, 3> >() {
00029 
00030 }
00031 
00032 Matrix<3, 3>::Matrix(const MatrixBase<3, 3> &m) :
00033     MatrixType<3, 3>(m), Rotation3D<Matrix<3, 3> >() {
00034 
00035 }
00036 
00037 void swap (float &a, float &b) {
00038     float c=a; a=b; b=c;
00039 }
00040 
00041 void Matrix<3, 3>::transpose() {
00042     swap(operator()(0,1), operator()(1,0));
00043     swap(operator()(0,2), operator()(2,0));
00044     swap(operator()(1,2), operator()(2,1));
00045 }
00046 
00051 void Matrix<3, 3>::buildFromTargetDir(const Math::Vector3d &modelForward, const Math::Vector3d &targetDirection, 
00052                            const Math::Vector3d &modelUp, const Math::Vector3d &worldUp)
00053 {
00054     Math::Vector3d modelRight = Math::Vector3d::crossProduct(modelUp, modelForward);
00055     modelRight.normalize();
00056     Math::Vector3d worldRight = Math::Vector3d::crossProduct(worldUp, targetDirection);
00057     worldRight.normalize();
00058     Math::Vector3d perpWorldUp = Math::Vector3d::crossProduct(targetDirection, worldRight);
00059     perpWorldUp.normalize();
00060     
00061     Math::Matrix3 m1;
00062     m1.getRow(0) << worldRight.x() << worldRight.y() << worldRight.z();
00063     m1.getRow(1) << perpWorldUp.x() << perpWorldUp.y() << perpWorldUp.z();
00064     m1.getRow(2) << targetDirection.x() << targetDirection.y() << targetDirection.z();
00065     m1.transpose();
00066     
00067     Math::Matrix3 m2;
00068     m2.getRow(0) << modelRight.x() << modelRight.y() << modelRight.z();
00069     m2.getRow(1) << modelUp.x() << modelUp.y() << modelUp.z();
00070     m2.getRow(2) << modelForward.x() << modelForward.y() << modelForward.z();
00071     
00072     this->operator=(m1 * m2);
00073 }
00074 
00075 
00076 } // end of namespace Math


Generated on Sat May 25 2019 05:00:49 for ResidualVM by doxygen 1.7.1
curved edge   curved edge