C:/Users/Mike/Documents/Visual Studio Projects/GameEngine/src/Vector3.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 Copyright (C) 2006 Michael Harnetty
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 -----------------------------------------------------------------------------
00019 */
00020 
00021 #include "Vector3.h"
00022 
00023 namespace GameEngine {
00024 
00025         const Vector3 Vector3::ZERO( 0, 0, 0 );
00026         const Vector3 Vector3::UNIT_X( 1, 0, 0 );
00027         const Vector3 Vector3::UNIT_Y( 0, 1, 0 );
00028         const Vector3 Vector3::UNIT_Z( 0, 0, 1 );
00029 
00030         Vector3::Vector3() 
00031                 :       mX(0), 
00032                         mY(0), 
00033                         mZ(0)
00034         {
00035 
00036         }
00037 
00038         Vector3::Vector3(const Vector3& v) 
00039                 :       mX(v.mX), 
00040                         mY(v.mY), 
00041                         mZ(v.mZ)
00042         {
00043 
00044         }
00045 
00046 
00047         Vector3::Vector3(Real x, Real y, Real z)
00048                 :       mX(x), 
00049                         mY(y), 
00050                         mZ(z)
00051         {
00052 
00053         }
00054 
00055 
00056         Vector3::~Vector3()
00057         {
00058         }
00059 
00060 
00061         Real Vector3::length() const
00062         {
00063                 Real length = sqrt(mX*mX + mY*mY + mZ*mZ);
00064                 return length;
00065         }
00066 
00067 
00068         Real Vector3::dot(const Vector3& v) const
00069         {
00070                 return v.mX * mX + v.mY * mY + v.mZ * mZ;       
00071         }
00072 
00073 
00074         Vector3 Vector3::cross(const Vector3& v) const
00075     {
00076                 return Vector3( mY * v.mZ - mZ * v.mY, 
00077                                                 mZ * v.mX - mX * v.mZ, 
00078                                                 mX * v.mY - mY * v.mX
00079                                         );
00080         }
00081 
00082 
00083         Vector3& Vector3::normalise() {
00084 
00085                 Real vectorLength = length();
00086 
00087                 mX = mX / vectorLength;
00088                 mY = mY / vectorLength;
00089                 mZ = mZ / vectorLength;
00090 
00091 
00092                 return *this;
00093         }
00094 
00095 
00096         Vector3 Vector3::operator+(const Vector3& v) const {
00097         
00098                 Real x, y, z;
00099 
00100                 x = mX + v.mX;
00101                 y = mY + v.mY;
00102                 z = mZ + v.mZ;
00103                 
00104                 return Vector3(x,y,z);
00105         }
00106 
00107         
00108         Vector3 Vector3::operator*(const Real scalar) const
00109         {
00110                 return Vector3( mX * scalar, mY * scalar, mZ * scalar);
00111         }
00112 
00113         Vector3& Vector3::operator *=(Real scalar)
00114         {
00115                 mX *= scalar;
00116                 mY *= scalar;
00117                 mZ *= scalar;
00118 
00119                 return *this;
00120         }
00121 
00122 }

Generated on Thu Apr 19 09:47:02 2007 for GameEngine by  doxygen 1.5.2