K3dMatrixWork.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K3dMatrixWork.h"
00034 
00035 K3dMatrixWork::K3dMatrixWork ( K3dGameData *_pGameData )
00036 {
00037         m_pGameData = _pGameData;
00038         // Set this pointer to the game data
00039         m_pGameData->SetMatrixWork ( this );
00040         m_pVector3Work = m_pGameData->GetVector3Work();
00041 }
00042 
00043 K3dMatrixWork::~K3dMatrixWork ( void )
00044 {}
00045 
00047 void K3dMatrixWork::RotationUpVector ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00048 {
00049         K3dVector3Obj kV;
00050         K3dVector3Obj kUp ( 0,1,0 );
00051         K3dVector3Obj kCross;
00052         float fAngle;
00053 
00054         kV = _rV;
00055         kV = m_pVector3Work->Normalize ( kV );
00056         kCross = m_pVector3Work->Cross ( kUp, kV );
00057         kCross = m_pVector3Work->Normalize ( kCross );
00058         fAngle = m_pVector3Work->Dot ( kV, kUp );
00059         fAngle = acos ( fAngle );
00060         _rM.Rotation ( kCross, fAngle );
00061 }
00062 
00064 void K3dMatrixWork::RotationUpVectorGL ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00065 {
00066         // Slave vectors
00067         K3dVector3Obj kV;
00068         K3dVector3Obj kUp ( 0,1,0 );
00069         K3dVector3Obj kCross;
00070         float fAngle;
00071 
00072         kV = _rV;
00073         kV = m_pVector3Work->Normalize ( kV );
00074         kCross = m_pVector3Work->Cross ( kUp, kV );
00075         kCross = m_pVector3Work->Normalize ( kCross );
00076         fAngle = m_pVector3Work->Dot ( kV, kUp );
00077         fAngle = acos ( fAngle );
00078         _rM.RotationGL ( kCross, fAngle );
00079 }
00080 
00082 void K3dMatrixWork::RotationForwardVector ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00083 {
00084         // Slave vectors
00085         K3dVector3Obj kV;
00086         K3dVector3Obj kForward ( 0,0,1 );
00087         K3dVector3Obj kCross;
00088         float fAngle;
00089 
00090         kV = _rV;
00091         kV = m_pVector3Work->Normalize ( kV );
00092         kCross = m_pVector3Work->Cross ( kForward, kV );
00093         kCross = m_pVector3Work->Normalize ( kCross );
00094         fAngle = m_pVector3Work->Dot ( kV, kForward );
00095         fAngle = acos ( fAngle );
00096         _rM.Rotation ( kCross, fAngle );
00097 }
00098 
00099 
00100 
00102 void K3dMatrixWork::RotationForwardVectorGL ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00103 {
00104         // Slave vectors
00105         K3dVector3Obj kV;
00106         K3dVector3Obj kForward ( 0,0,1 );
00107         K3dVector3Obj kCross;
00108         float fAngle;
00109 
00110         kV = _rV;
00111         kV = m_pVector3Work->Normalize ( kV );
00112         kCross = m_pVector3Work->Cross ( kForward, kV );
00113         kCross = m_pVector3Work->Normalize ( kCross );
00114         fAngle = m_pVector3Work->Dot ( kV, kForward );
00115         fAngle = acos ( fAngle );
00116         _rM.RotationGL ( kCross, fAngle );
00117 }
00118 
00119 
00120 
00122 void K3dMatrixWork::RotationRightVector ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00123 {
00124         // Slave vectors
00125         K3dVector3Obj kV;
00126         K3dVector3Obj kRight ( 1,0,0 );
00127         K3dVector3Obj kCross;
00128         float fAngle;
00129 
00130         kV = _rV;
00131         kV = m_pVector3Work->Normalize ( kV );
00132         kCross = m_pVector3Work->Cross ( kRight, kV );
00133         kCross = m_pVector3Work->Normalize ( kCross );
00134         fAngle = m_pVector3Work->Dot ( kV, kRight );
00135         fAngle = acos ( fAngle );
00136         _rM.Rotation ( kCross, fAngle );
00137 }
00138 
00139 
00140 
00142 void K3dMatrixWork::RotationRightVectorGL ( K3dMatrix &_rM, const K3dVector3Obj &_rV )
00143 {
00144         // Slave vectors
00145         K3dVector3Obj kV;
00146         K3dVector3Obj kRight ( 1,0,0 );
00147         K3dVector3Obj kCross;
00148         float fAngle;
00149 
00150         kV = _rV;
00151         kV = m_pVector3Work->Normalize ( kV );
00152         kCross = m_pVector3Work->Cross ( kRight, kV );
00153         kCross = m_pVector3Work->Normalize ( kCross );
00154         fAngle = m_pVector3Work->Dot ( kV, kRight );
00155         fAngle = acos ( fAngle );
00156         _rM.RotationGL ( kCross, fAngle );
00157 }
00158 
00159 
00160 
00162 void K3dMatrixWork::RotationArbitraryVector ( K3dMatrix &_rM, const K3dVector3Obj &_rkVector,const  K3dVector3Obj &_rkArbitrary )
00163 {
00164         // Slave vectors
00165         K3dVector3Obj kV;
00166         K3dVector3Obj kArb;
00167         K3dVector3Obj kCross;
00168         float fAngle;
00169 
00170         kV = _rkVector;
00171         kArb = _rkArbitrary;
00172         kV = m_pVector3Work->Normalize ( kV );
00173         kArb = m_pVector3Work->Normalize ( kArb );
00174         kCross = m_pVector3Work->Cross ( kArb, kV );
00175         kCross = m_pVector3Work->Normalize ( kCross );
00176         fAngle = m_pVector3Work->Dot ( kV ,kArb );
00177         fAngle = acos ( fAngle );
00178         _rM.Rotation ( kCross, fAngle );
00179 }
00180 
00181 
00183 void K3dMatrixWork::RotationArbitraryVectorGL ( K3dMatrix &_rM, const K3dVector3Obj &_rkVector,const  K3dVector3Obj &_rkArbitrary )
00184 {
00185         // Slave vectors
00186         K3dVector3Obj kV;
00187         K3dVector3Obj kArb;
00188         K3dVector3Obj kCross;
00189         float fAngle;
00190 
00191         kV = _rkVector;
00192         kArb = _rkArbitrary;
00193         kV = m_pVector3Work->Normalize ( kV );
00194         kArb = m_pVector3Work->Normalize ( kArb );
00195         kCross = m_pVector3Work->Cross ( kArb, kV );
00196         kCross = m_pVector3Work->Normalize ( kCross );
00197         fAngle = m_pVector3Work->Dot ( kV, kArb );
00198         fAngle = acos ( fAngle );
00199         _rM.RotationGL ( kCross, fAngle );
00200 }
00201 
00202 

Generated on Thu Aug 16 23:53:28 2007 for K3dEngine by  doxygen 1.5.0