3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
33 #include "MT_CmMatrix4x4.h"
34 #include "MT_Vector3.h"
35 #include "MT_Point3.h"
38 MT_CmMatrix4x4::MT_CmMatrix4x4()
45 MT_CmMatrix4x4::MT_CmMatrix4x4(const float value[4][4])
50 m_V[i][j] = value[i][j];
56 MT_CmMatrix4x4::MT_CmMatrix4x4(const double value[16])
58 for (int i=0;i<16;i++)
59 m_Vflat[i] = value[i];
64 MT_CmMatrix4x4::MT_CmMatrix4x4(const MT_CmMatrix4x4& other)
71 MT_CmMatrix4x4::MT_CmMatrix4x4(const MT_Point3& orig,
72 const MT_Vector3& dir,
75 MT_Vector3 z = -(dir.normalized());
76 MT_Vector3 x = (up.cross(z)).normalized();
77 MT_Vector3 y = (z.cross(x));
94 m_V[3][0] = orig.x();//0.0f;
95 m_V[3][1] = orig.y();//0.0f;
96 m_V[3][2] = orig.z();//0.0f;
104 MT_Vector3 MT_CmMatrix4x4::GetRight() const
106 return MT_Vector3(m_V[0][0], m_V[0][1], m_V[0][2]);
111 MT_Vector3 MT_CmMatrix4x4::GetUp() const
113 return MT_Vector3(m_V[1][0], m_V[1][1], m_V[1][2]);
118 MT_Vector3 MT_CmMatrix4x4::GetDir() const
120 return MT_Vector3(m_V[2][0], m_V[2][1], m_V[2][2]);
125 MT_Point3 MT_CmMatrix4x4::GetPos() const
127 return MT_Point3(m_V[3][0], m_V[3][1], m_V[3][2]);
132 void MT_CmMatrix4x4::Identity()
134 for (int i=0; i<4; i++)
136 for (int j=0; j<4; j++)
137 m_V[i][j] = (i==j?1.0f:0.0f);
143 void MT_CmMatrix4x4::SetMatrix(const MT_CmMatrix4x4& other)
145 for (int i=0; i<16; i++)
146 m_Vflat[i] = other.m_Vflat[i];
151 double* MT_CmMatrix4x4::getPointer()
158 const double* MT_CmMatrix4x4::getPointer() const
165 void MT_CmMatrix4x4::setElem(int pos,double newvalue)
167 m_Vflat[pos] = newvalue;
170 MT_CmMatrix4x4 MT_CmMatrix4x4::Perspective(
182 mat(0, 0) = -(2.0*inNear) / (inRight-inLeft);
189 mat(1, 1) = (2.0*inNear) / (inTop-inBottom);
194 mat(0, 2) = (inRight+inLeft) / (inRight-inLeft);
195 mat(1, 2) = (inTop+inBottom) / (inTop-inBottom);
196 mat(2, 2) = -(inFar+inNear) / (inFar-inNear);
202 mat(2, 3) = -(2.0*inFar*inNear) / (inFar-inNear);