MezzanineEngine March 18, 2012

vector3.cpp

00001 //© Copyright 2010 - 2011 BlackTopp Studios Inc.
00002 /* This file is part of The Mezzanine Engine.
00003 
00004     The Mezzanine Engine is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     The Mezzanine Engine is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with The Mezzanine Engine.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 /* The original authors have included a copy of the license specified above in the
00018    'Docs' folder. See 'gpl.txt'
00019 */
00020 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
00021    Build professional software and charge for their product.
00022 
00023    However there are some practical restrictions, so if your project involves
00024    any of the following you should contact us and we will try to work something
00025    out:
00026     - DRM or Copy Protection of any kind(except Copyrights)
00027     - Software Patents You Do Not Wish to Freely License
00028     - Any Kind of Linking to Non-GPL licensed Works
00029     - Are Currently In Violation of Another Copyright Holder's GPL License
00030     - If You want to change our code and not add a few hundred MB of stuff to
00031         your distribution
00032 
00033    These and other limitations could cause serious legal problems if you ignore
00034    them, so it is best to simply contact us or the Free Software Foundation, if
00035    you have any questions.
00036 
00037    Joseph Toppi - toppij@gmail.com
00038    John Blackwood - makoenergy02@gmail.com
00039 */
00040 #ifndef _vector3_cpp
00041 #define _vector3_cpp
00042 
00043 #include "vector3.h"
00044 #include "quaternion.h"
00045 #include "exception.h"
00046 #include "serialization.h"
00047 #include "stringtool.h"
00048 #include "mathtool.h"
00049 #include "world.h"          // Needed for Error logging in streaming
00050 #include "xml.h"            // Needed for streaming to xml
00051 
00052 #include <Ogre.h>
00053 #include "btBulletDynamicsCommon.h"
00054 #include <cAudio.h>
00055 
00056 #include <memory>
00057 
00058 //remove this
00059 #include <iostream>
00060 
00061 namespace Mezzanine
00062 {
00063 
00064     //remove this too
00065     void PrintHello() // Function to call from Lua
00066     {
00067         std::cout << "Hello world! From PrintHello()" << std::endl;
00068     }
00069 
00070     ///////////////////////////////////////////////////////////////////////////////
00071     // The Essentials
00072 
00073     Real Vector3::GetAxisValue(const StandardAxis& Axis) const
00074     {
00075         switch(Axis)
00076         {
00077             case 0: return this->X;
00078             case 1: return this->Y;
00079             case 2: return this->Z;
00080             default: throw(Exception("Cannot retrieve invalid StandardAxis in Vector3::GetAxisValue"));
00081         }
00082     }
00083 
00084     Real Vector3::GetAxisValue(const Whole& Axis) const
00085         { return this->GetAxisValue((StandardAxis)Axis); }
00086 
00087     Real& Vector3::GetAxisValue(const StandardAxis& Axis)
00088     {
00089         switch(Axis)
00090         {
00091             case 0: return this->X;
00092             case 1: return this->Y;
00093             case 2: return this->Z;
00094             default: throw(Exception("Cannot retrieve invalid StandardAxis in Vector3::GetAxisValue"));
00095         }
00096     }
00097 
00098     Real& Vector3::GetAxisValue(const Whole& Axis)
00099         { return this->GetAxisValue((StandardAxis)Axis); }
00100 
00101     Real Vector3::operator[] (const StandardAxis& Axis) const
00102         { return this->GetAxisValue(Axis); }
00103 
00104     Real Vector3::operator[] (const Whole& Axis) const
00105         { return this->GetAxisValue((StandardAxis)Axis); }
00106 
00107     Real& Vector3::operator[] (const StandardAxis& Axis)
00108         { return this->GetAxisValue(Axis); }
00109 
00110     Real& Vector3::operator[] (const Whole& Axis)
00111         { return this->GetAxisValue((StandardAxis)Axis); }
00112     ///////////////////////////////////////////////////////////////////////////////
00113     // Constructors
00114     Vector3::Vector3()
00115     {
00116         Zero();
00117     }
00118 
00119     Vector3::Vector3(const Real& x, const Real& y, const Real& z)
00120     {
00121         SetValues(x,y,z);
00122     }
00123 
00124     Vector3::Vector3(const Ogre::Vector3& Vec)
00125         { this->ExtractOgreVector3(Vec); }
00126 
00127     Vector3::Vector3(const btVector3& Vec)
00128         { this->ExtractBulletVector3(Vec); }
00129 
00130     Vector3::Vector3(const cAudio::cVector3& Vec)
00131         { this->ExtractcAudioVector3(Vec); }
00132 
00133     Vector3::Vector3(const Mezzanine::Vector3& Vec)
00134         { *this = Vec; }
00135 
00136 #ifdef MEZZXML
00137     Vector3::Vector3(xml::Node OneNode)
00138         { this->ProtoDeSerialize(OneNode); }
00139 #endif
00140 
00141     ///////////////////////////////////////////////////////////////////////////////
00142     // Prebuilt Vectors
00143 
00144     Vector3 Vector3::Unit_X()
00145         { return Vector3(1,0,0); }
00146 
00147     Vector3 Vector3::Unit_Y()
00148         { return Vector3(0,1,0);}
00149 
00150     Vector3 Vector3::Unit_Z()
00151         { return Vector3(0,0,1); }
00152 
00153     Vector3 Vector3::Neg_Unit_X()
00154         { return Vector3(-1,0,0); }
00155 
00156     Vector3 Vector3::Neg_Unit_Y()
00157         { return Vector3(0,-1,0); }
00158 
00159     Vector3 Vector3::Neg_Unit_Z()
00160         { return Vector3(0,0,-1); }
00161 
00162     Vector3 Vector3::UnitOnAxis(StandardAxis Axis)
00163     {
00164         switch(Axis)
00165         {
00166             case 0: return Vector3::Unit_X();
00167             case 1: return Vector3::Unit_Y();
00168             case 2: return Vector3::Unit_Z();
00169             default: throw(Exception("Cannot convert invalid StandardAxis in Vector3::UnitOnAxis"));
00170         }
00171     }
00172 
00173     StandardAxis Vector3::IsStandardUnitAxis() const
00174     {
00175         if (1.0==this->X && 0.0==this->Y && 0.0==this->Z)
00176         {
00177             return Axis_X;
00178         } else if (0.0==this->X) {                                         // Not Unit_X
00179             if (1.0==this->Y && 0.0==this->Z)
00180             {
00181                 return Axis_Y;
00182             } else if (0.0==this->Y && 1.0==this->Z) {                                     // Not Unit_Y so hopefully it is Z
00183                 return Axis_Y;
00184             }
00185         }
00186         throw(Exception("Cannot convert Vector3 to StandardAxis in Vector3::IsStandardUnitAxis, Vector3 may not be Axis Aligned or may not be Unit Length."));
00187     }
00188 
00189 
00190     ///////////////////////////////////////////////////////////////////////////////
00191     // Assignment Operators
00192     Vector3& Vector3::operator= (const btVector3 &Vec)
00193     {
00194         this->X=Vec.getX();
00195         this->Y=Vec.getY();
00196         this->Z=Vec.getZ();
00197     }
00198 
00199     Vector3& Vector3::operator= (const Ogre::Vector3 &Vec)
00200     {
00201         this->X=Vec.x;
00202         this->Y=Vec.y;
00203         this->Z=Vec.z;
00204     }
00205 
00206     Vector3& Vector3::operator= (const cAudio::cVector3 &Vec)
00207     {
00208         this->X=Vec.x;
00209         this->Y=Vec.y;
00210         this->Z=Vec.z;
00211     }
00212 
00213     ///////////////////////////////////////////////////////////////////////////////
00214     // Unary Operators
00215     Vector3 Vector3::operator- ()
00216         { return Vector3(-X,-Y,-Z); }
00217 
00218     ///////////////////////////////////////////////////////////////////////////////
00219     // Vector3 Arithmetic with Real
00220     Vector3 Vector3::operator* (const Real &scalar) const
00221         { return Vector3(this->X * scalar, this->Y * scalar, this->Z * scalar); }
00222 
00223     Vector3 Vector3::operator/ (const Real &scalar) const
00224         { return Vector3(this->X / scalar, this->Y / scalar, this->Z / scalar); }
00225 
00226     ///////////////////////////////////////////////////////////////////////////////
00227     // Vector3 Arithmetic and assignment with Real
00228     Vector3& Vector3::operator*= (const Real &scalar)
00229     {
00230         this->X *= scalar;
00231         this->Y *= scalar;
00232         this->Z *= scalar;
00233         return *this;
00234     }
00235 
00236     Vector3& Vector3::operator/= (const Real &scalar)
00237     {
00238         this->X /= scalar;
00239         this->Y /= scalar;
00240         this->Z /= scalar;
00241         return *this;
00242     }
00243 
00244     ///////////////////////////////////////////////////////////////////////////////
00245     // Equality Comparison operators
00246     bool Vector3::operator== (const Vector3 &Vec) const
00247         { return( Vec.X == this->X && Vec.Y == this->Y && Vec.Z == this->Z ); }
00248 
00249     bool Vector3::operator== (const btVector3 &Vec) const
00250         { return( Vec.getX() == this->X && Vec.getY() == this->Y && Vec.getZ() == this->Z ); }
00251 
00252     bool Vector3::operator== (const Ogre::Vector3 &Vec) const
00253         { return ( Vec.x == this->X && Vec.y == this->Y && Vec.z == this->Z ); }
00254 
00255     bool Vector3::operator== (const cAudio::cVector3 &Vec) const
00256         { return ( Vec.x == this->X && Vec.y == this->Y && Vec.z == this->Z ); }
00257 
00258 
00259     bool Vector3::operator!= (const Vector3 &Vec) const
00260         { return ( Vec.X != this->X || Vec.Y != this->Y || Vec.Z != this->Z ); }
00261 
00262     bool Vector3::operator!= (const btVector3 &Vec) const
00263         { return ( Vec.getX() != this->X || Vec.getY() != this->Y || Vec.getZ() != this->Z ); }
00264 
00265     bool Vector3::operator!= (const Ogre::Vector3 &Vec) const
00266         { return ( Vec.x != this->X || Vec.y != this->Y || Vec.z != this->Z ); }
00267 
00268     bool Vector3::operator!= (const cAudio::cVector3 &Vec) const
00269         { return ( Vec.x != this->X || Vec.y != this->Y || Vec.z != this->Z ); }
00270 
00271     ///////////////////////////////////////////////////////////////////////////////
00272     // Arithmetic Operators
00273 
00274     Vector3 Vector3::operator+ (const Vector3 &Vec) const
00275         { return Vector3(X+Vec.X, Y+Vec.Y, Z+Vec.Z ); }
00276 
00277     Vector3 Vector3::operator- (const Vector3 &Vec) const
00278         { return Vector3(X-Vec.X, Y-Vec.Y, Z-Vec.Z ); }
00279 
00280     Vector3 Vector3::operator* (const Vector3 &Vec) const
00281         { return Vector3(X*Vec.X, Y*Vec.Y, Z*Vec.Z ); }
00282 
00283     Vector3 Vector3::operator/ (const Vector3 &Vec) const
00284         { return Vector3(X/Vec.X, Y/Vec.Y, Z/Vec.Z ); }
00285 
00286     ///////////////////////////////////////////////////////////////////////////////
00287     // Arithmetic Operators with btVector3
00288 
00289     Vector3 Vector3::operator+ (const btVector3  &Vec) const
00290         { return Vector3(X+Vec.getX(), Y+Vec.getY(), Z+Vec.getZ()); }
00291 
00292     Vector3 Vector3::operator- (const btVector3  &Vec) const
00293         { return Vector3(X-Vec.getX(), Y-Vec.getY(), Z-Vec.getZ()); }
00294 
00295     Vector3 Vector3::operator* (const btVector3  &Vec) const
00296         { return Vector3(X*Vec.getX(), Y*Vec.getY(), Z*Vec.getZ()); }
00297 
00298     Vector3 Vector3::operator/ (const btVector3  &Vec) const
00299         { return Vector3(X/Vec.getX(), Y/Vec.getY(), Z/Vec.getZ()); }
00300 
00301     ///////////////////////////////////////////////////////////////////////////////
00302     // Arithmetic Operators with Ogre::Vector3
00303 
00304     Vector3 Vector3::operator+ (const Ogre::Vector3 &Vec) const
00305         { return Vector3(X+Vec.x, Y+Vec.y, Z+Vec.z); }
00306 
00307     Vector3 Vector3::operator- (const Ogre::Vector3 &Vec) const
00308         { return Vector3(X-Vec.x, Y-Vec.y, Z-Vec.z); }
00309 
00310     Vector3 Vector3::operator* (const Ogre::Vector3 &Vec) const
00311         { return Vector3(X*Vec.x, Y*Vec.y, Z*Vec.z); }
00312 
00313     Vector3 Vector3::operator/ (const Ogre::Vector3 &Vec) const
00314         { return Vector3(X/Vec.x, Y/Vec.y, Z/Vec.z); }
00315 
00316     ///////////////////////////////////////////////////////////////////////////////
00317     // Arithmetic Operators with cAudio::cVector3
00318 
00319     Vector3 Vector3::operator+ (const cAudio::cVector3 &Vec) const
00320         { return Vector3(X+Vec.x, Y+Vec.y, Z+Vec.z); }
00321 
00322     Vector3 Vector3::operator- (const cAudio::cVector3 &Vec) const
00323         { return Vector3(X-Vec.x, Y-Vec.y, Z-Vec.z); }
00324 
00325     Vector3 Vector3::operator* (const cAudio::cVector3 &Vec) const
00326         { return Vector3(X*Vec.x, Y*Vec.y, Z*Vec.z); }
00327 
00328     Vector3 Vector3::operator/ (const cAudio::cVector3 &Vec)  const
00329         { return Vector3(X/Vec.x, Y/Vec.y, Z/Vec.z); }
00330 
00331     ///////////////////////////////////////////////////////////////////////////////
00332     // Fancy Math
00333 
00334     Vector3 Vector3::CrossProduct( const Vector3& Vec ) const
00335     {
00336         return Vector3(                                        // 1,2,3 . 4,5,6
00337                 this->Y * Vec.Z - this->Z * Vec.Y,             // 2*6-3*5 = -3
00338                 this->Z * Vec.X - this->X * Vec.Z,             // 3*4-1*6 = 6
00339                 this->X * Vec.Y - this->Y * Vec.X              // 1*5-2*4 = -3
00340             );
00341     }
00342 
00343     Real Vector3::DotProduct(const Vector3& Vec) const
00344     {
00345         return this->X * Vec.X + this->Y * Vec.Y + this->Z * Vec.Z;
00346     }
00347 
00348     Vector3& Vector3::Normalize()
00349     {
00350         Real TempLength = this->Distance(Vector3(0.0f,0.0f,0.0f));
00351         if (0!=TempLength)
00352         {
00353              (*this) /= TempLength;
00354         }else{
00355             throw (Mezzanine::Exception ("Cannot Normalize Vector3(0,0,0)"));
00356         }
00357         return *this;
00358     }
00359 
00360     Vector3 Vector3::GetNormal() const
00361     {
00362         Real TempLength = this->Distance(Vector3(0.0f,0.0f,0.0f));
00363         if (0!=TempLength)
00364         {
00365             return (*this) / TempLength;
00366         }else{
00367             throw (Mezzanine::Exception ("Cannot Get the Normal of Vector3(0,0,0)"));
00368         }
00369     }
00370 
00371     Vector3 Vector3::GetDirection(const Vector3& Destination) const
00372     {
00373         Vector3 Dir = Destination - *this;
00374         Dir.Normalize();
00375         return Dir;
00376     }
00377 
00378     Vector3 Vector3::Inverse()
00379     {
00380         if (X!=0)
00381             X=1/X;
00382         if (Y!=0)
00383             Y=1/Y;
00384         if (Z!=0)
00385             Z=1/Z;
00386         return *this;
00387     }
00388 
00389     Real Vector3::Distance(const Vector3& OtherVec) const
00390     {
00391         return (*this - OtherVec).Length();
00392     }
00393 
00394     Real Vector3::SquaredDistance(const Vector3& OtherVec) const
00395     {
00396         return (*this - OtherVec).SquaredLength();
00397     }
00398 
00399     Real Vector3::Length() const
00400     {
00401         return MathTool::Sqrt(X * X + Y * Y + Z * Z);
00402     }
00403 
00404     Real Vector3::SquaredLength() const
00405     {
00406         return X * X + Y * Y + Z * Z;
00407     }
00408 
00409     bool Vector3::IsZeroLength() const
00410     {
00411         return SquaredLength() < (1e-06 * 1e-06);
00412     }
00413 
00414     Quaternion Vector3::GetRotationToAxis(const Vector3& Axis, const Vector3& FallBackAxis) const
00415     {
00416         Quaternion Ret;
00417         Vector3 Vec1 = *this;
00418         Vector3 Vec2 = Axis;
00419         Vec1.Normalize();
00420         Vec2.Normalize();
00421 
00422         Real Dot = Vec1.DotProduct(Vec2);
00423         if( Dot >= 1.0 )
00424         {
00425             return Ret;
00426         }
00427         if( Dot < (1e-6 - 1.0) )
00428         {
00429             if( FallBackAxis != Vector3() )
00430             {
00431                 Ret.SetFromAxisAngle(MathTool::GetPi(),FallBackAxis);
00432             }else{
00433                 Vector3 CrossAxis = Vector3::Unit_X().CrossProduct(*this);
00434                 if(CrossAxis.IsZeroLength())
00435                     CrossAxis = Vector3::Unit_Y().CrossProduct(*this);
00436                 CrossAxis.Normalize();
00437                 Ret.SetFromAxisAngle(MathTool::GetPi(),CrossAxis);
00438             }
00439         }else{
00440             Real Sqr = MathTool::Sqrt( (1+Dot)*2 );
00441             Real InvSqr = 1 / Sqr;
00442 
00443             Vector3 Cross = Vec1.CrossProduct(Vec2);
00444 
00445             Ret.X = Cross.X * InvSqr;
00446             Ret.Y = Cross.Y * InvSqr;
00447             Ret.Z = Cross.Z * InvSqr;
00448             Ret.W = Sqr * 0.5f;
00449             Ret.Normalize();
00450         }
00451         return Ret;
00452     }
00453 
00454     ///////////////////////////////////////////////////////////////////////////////
00455     // Utility Functions
00456     void Vector3::Zero()
00457     {
00458         this->X = 0;
00459         this->Y = 0;
00460         this->Z = 0;
00461     }
00462 
00463     void Vector3::SetValues(const Real& X, const Real& Y, const Real& Z)
00464     {
00465         this->X = X;
00466         this->Y = Y;
00467         this->Z = Z;
00468     }
00469 
00470     ///////////////////////////////////////////////////////////////////////////////
00471     // Manual Conversions
00472     btVector3 Vector3::GetBulletVector3() const
00473     {
00474         btVector3 Theirs;
00475         Theirs.setX(this->X);
00476         Theirs.setY(this->Y);
00477         Theirs.setZ(this->Z);
00478         Theirs.setW(0);
00479         return Theirs;
00480     }
00481 
00482     void Vector3::ExtractBulletVector3(const btVector3& Ours)
00483     {
00484         this->X=Ours.getX();
00485         this->Y=Ours.getY();
00486         this->Z=Ours.getZ();
00487     }
00488 
00489     Ogre::Vector3 Vector3::GetOgreVector3() const
00490     {
00491         Ogre::Vector3 Theirs;
00492         Theirs.x=this->X;
00493         Theirs.y=this->Y;
00494         Theirs.z=this->Z;
00495         return Theirs;
00496     }
00497 
00498     void Vector3::ExtractOgreVector3(const Ogre::Vector3& Ours)
00499     {
00500         this->X=Ours.x;
00501         this->Y=Ours.y;
00502         this->Z=Ours.z;
00503     }
00504 
00505     cAudio::cVector3 Vector3::GetcAudioVector3() const
00506     {
00507         cAudio::cVector3 Theirs;
00508         Theirs.x=this->X;
00509         Theirs.y=this->Y;
00510         Theirs.z=this->Z;
00511         return Theirs;
00512     }
00513 
00514     void Vector3::ExtractcAudioVector3(const cAudio::cVector3& Ours)
00515     {
00516         this->X=Ours.x;
00517         this->Y=Ours.y;
00518         this->Z=Ours.z;
00519     }
00520 
00521 #ifdef MEZZXML
00522         // Serializable
00523         void Vector3::ProtoSerialize(xml::Node& CurrentRoot) const
00524         {
00525             Mezzanine::xml::Node VecNode = CurrentRoot.AppendChild(SerializableName());
00526             VecNode.SetName(SerializableName());
00527 
00528             Mezzanine::xml::Attribute VersionAttr = VecNode.AppendAttribute("Version");
00529             Mezzanine::xml::Attribute XAttr = VecNode.AppendAttribute("X");
00530             Mezzanine::xml::Attribute YAttr = VecNode.AppendAttribute("Y");
00531             Mezzanine::xml::Attribute ZAttr = VecNode.AppendAttribute("Z");
00532             if( VersionAttr && XAttr && YAttr && ZAttr )
00533             {
00534                 if( VersionAttr.SetValue("1") && XAttr.SetValue(this->X) && YAttr.SetValue(this->Y) && ZAttr.SetValue(this->Z))
00535                 {
00536                     return;
00537                 }else{
00538                     SerializeError("Create XML Attribute Values", SerializableName(),true);
00539                 }
00540             }else{
00541                 SerializeError("Create XML Attributes", SerializableName(),true);
00542             }
00543         }
00544 
00545         // DeSerializable
00546         void Vector3::ProtoDeSerialize(const xml::Node& OneNode)
00547         {
00548             if ( Mezzanine::String(OneNode.Name())==Mezzanine::String(SerializableName()) )
00549             {
00550                 if(OneNode.GetAttribute("Version").AsInt() == 1)
00551                 {
00552                     this->X=OneNode.GetAttribute("X").AsReal();
00553                     this->Y=OneNode.GetAttribute("Y").AsReal();
00554                     this->Z=OneNode.GetAttribute("Z").AsReal();
00555                 }else{
00556                     throw( Mezzanine::Exception(StringTool::StringCat("Incompatible XML Version for ",SerializableName(),": Not Version 1")) );
00557                 }
00558             }else{
00559                 throw( Mezzanine::Exception(Mezzanine::StringTool::StringCat("Attempting to deserialize a ",SerializableName(),", found a ", OneNode.Name())));
00560             }
00561         }
00562 
00563         String Vector3::SerializableName()
00564             { return String("Vector3"); }
00565 #endif
00566 
00567 }
00568 
00569 Mezzanine::Vector3 operator+ (const btVector3  &Vec, const Mezzanine::Vector3& lhs)
00570     { return lhs + Vec; }
00571 Mezzanine::Vector3 operator- (const btVector3  &Vec, const Mezzanine::Vector3& lhs)
00572     { return Mezzanine::Vector3(Vec.getX()-lhs.X, Vec.getY()-lhs.Y, Vec.getZ()-lhs.Z); }
00573 Mezzanine::Vector3 operator* (const btVector3  &Vec, const Mezzanine::Vector3& lhs)
00574     { return lhs * Vec; }
00575 Mezzanine::Vector3 operator/ (const btVector3  &Vec, const Mezzanine::Vector3& lhs)
00576     { return Mezzanine::Vector3(Vec.getX()/lhs.X, Vec.getY()/lhs.Y, Vec.getZ()/lhs.Z); }
00577 
00578 Mezzanine::Vector3 operator+ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
00579     { return lhs + Vec; }
00580 Mezzanine::Vector3 operator- (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
00581     { return Mezzanine::Vector3(Vec.x-lhs.X, Vec.y-lhs.Y, Vec.z-lhs.Z); }
00582 Mezzanine::Vector3 operator* (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
00583     { return lhs * Vec; }
00584 Mezzanine::Vector3 operator/ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
00585     { return Mezzanine::Vector3(Vec.x/lhs.X, Vec.y/lhs.Y, Vec.z/lhs.Z); }
00586 
00587 Mezzanine::Vector3 operator+ (const cAudio::cVector3 &Vec, const Mezzanine::Vector3& lhs)
00588     { return lhs + Vec; }
00589 Mezzanine::Vector3 operator- (const cAudio::cVector3 &Vec, const Mezzanine::Vector3& lhs)
00590     { return Mezzanine::Vector3(Vec.x-lhs.X, Vec.y-lhs.Y, Vec.z-lhs.Z); }
00591 Mezzanine::Vector3 operator* (const cAudio::cVector3 &Vec, const Mezzanine::Vector3& lhs)
00592     { return lhs * Vec; }
00593 Mezzanine::Vector3 operator/ (const cAudio::cVector3 &Vec, const Mezzanine::Vector3& lhs)
00594     { return Mezzanine::Vector3(Vec.x/lhs.X, Vec.y/lhs.Y, Vec.z/lhs.Z); }
00595 
00596 ///////////////////////////////////////////////////////////////////////////////
00597 // Class External << Operators for streaming or assignment
00598 std::ostream& operator << (std::ostream& stream, const Mezzanine::Vector3& x)
00599 {
00600     #ifdef MEZZXML
00601         //stream << "<Vector3 Version=\"1\" X=\"" << x.X << "\" Y=\"" << x.Y << "\" Z=\"" << x.Z << "\"/>";
00602         Serialize(stream,x);
00603     #else
00604         stream << "[" << x.X << "," << x.Y << "," << x.Z << "]";
00605     #endif // \MEZZXML
00606     return stream;
00607 }
00608 
00609 #ifdef MEZZXML
00610 std::istream& operator >> (std::istream& stream, Mezzanine::Vector3& Vec)
00611     { return DeSerialize(stream, Vec); }
00612 
00613 void operator >> (const Mezzanine::xml::Node& OneNode, Mezzanine::Vector3& Vec)
00614     { Vec.ProtoDeSerialize(OneNode); }
00615 #endif // \MEZZXML
00616 
00617 Ogre::Vector3& operator << (Ogre::Vector3& VecTo, const Mezzanine::Vector3& VecFrom)
00618 {
00619     VecTo = VecFrom.GetOgreVector3();
00620     return VecTo;
00621 }
00622 
00623 Ogre::Vector3& operator << (Ogre::Vector3& VecTo, const btVector3& VecFrom)
00624 {
00625     VecTo.x=VecFrom.getX();
00626     VecTo.y=VecFrom.getY();
00627     VecTo.z=VecFrom.getZ();
00628     return VecTo;
00629 }
00630 
00631 Ogre::Vector3&  operator << (Ogre::Vector3& VecTo, const cAudio::cVector3& VecFrom)
00632 {
00633     VecTo.x=VecFrom.x;
00634     VecTo.y=VecFrom.y;
00635     VecTo.z=VecFrom.z;
00636     return VecTo;
00637 }
00638 
00639 
00640 btVector3& operator << (btVector3& VecTo, const Ogre::Vector3& VecFrom)
00641 {
00642     VecTo.setX(VecFrom.x);
00643     VecTo.setY(VecFrom.y);
00644     VecTo.setZ(VecFrom.z);
00645     VecTo.setW(0);
00646     return VecTo;
00647 }
00648 
00649 btVector3& operator << (btVector3& VecTo, const Mezzanine::Vector3& VecFrom)
00650 {
00651     VecTo=VecFrom.GetBulletVector3();
00652     return VecTo;
00653 }
00654 
00655 btVector3&  operator << (btVector3& VecTo, const cAudio::cVector3& VecFrom)
00656 {
00657     VecTo.setX(VecFrom.x);
00658     VecTo.setY(VecFrom.y);
00659     VecTo.setZ(VecFrom.z);
00660     return VecTo;
00661 }
00662 
00663 Mezzanine::Vector3& operator << (Mezzanine::Vector3& VecTo, const Ogre::Vector3& VecFrom)
00664 {
00665     VecTo=VecFrom;
00666     return VecTo;
00667 }
00668 
00669 Mezzanine::Vector3& operator << (Mezzanine::Vector3& VecTo, const btVector3& VecFrom)
00670 {
00671     VecTo=VecFrom;
00672     return VecTo;
00673 }
00674 
00675 Mezzanine::Vector3&  operator << (Mezzanine::Vector3& VecTo, const cAudio::cVector3& VecFrom)
00676 {
00677     VecTo=VecFrom;
00678     return VecTo;
00679 }
00680 
00681 cAudio::cVector3&  operator << (cAudio::cVector3& VecTo, const Ogre::Vector3& VecFrom)
00682 {
00683     VecTo.x=VecFrom.x;
00684     VecTo.y=VecFrom.y;
00685     VecTo.z=VecFrom.z;
00686     return VecTo;
00687 }
00688 
00689 cAudio::cVector3&  operator << (cAudio::cVector3& VecTo, const btVector3& VecFrom)
00690 {
00691     VecTo.x=VecFrom.getX();
00692     VecTo.y=VecFrom.getY();
00693     VecTo.z=VecFrom.getZ();
00694     return VecTo;
00695 }
00696 
00697 cAudio::cVector3&  operator << (cAudio::cVector3& VecTo, const Mezzanine::Vector3& VecFrom)
00698 {
00699     VecTo=VecFrom.GetcAudioVector3();
00700     return VecTo;
00701 }
00702 
00703 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines