Spinning Topp Logo BlackTopp Studios
inc
vector3.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _vector3_cpp
41 #define _vector3_cpp
42 
43 #include "vector3.h"
44 #include "quaternion.h"
45 #include "exception.h"
46 #include "serialization.h"
47 #include "stringtool.h"
48 #include "MathTools/mathtools.h"
49 #ifndef SWIG
50  #include "XML/xml.h"
51 #endif
52 #include "XML/xml.h" // Needed for streaming to xml
53 
54 #include <Ogre.h>
55 #include "btBulletDynamicsCommon.h"
56 
57 #include <memory>
58 
59 //remove this
60 #include <iostream>
61 
62 namespace Mezzanine
63 {
64  ///////////////////////////////////////////////////////////////////////////////
65  // The Essentials
66 
68  {
69  switch(Axis)
70  {
71  case 0: return this->X;
72  case 1: return this->Y;
73  case 2: return this->Z;
74  default: { MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Cannot retrieve invalid StandardAxis."); }
75  }
76  }
77 
78  Real Vector3::GetAxisValue(const Whole& Axis) const
79  { return this->GetAxisValue((StandardAxis)Axis); }
80 
82  {
83  switch(Axis)
84  {
85  case 0: return this->X;
86  case 1: return this->Y;
87  case 2: return this->Z;
88  default: { MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Cannot retrieve invalid StandardAxis."); }
89  }
90  }
91 
93  { return this->GetAxisValue((StandardAxis)Axis); }
94 
96  { return this->GetAxisValue(Axis); }
97 
98  Real Vector3::operator[] (const Whole& Axis) const
99  { return this->GetAxisValue((StandardAxis)Axis); }
100 
102  { return this->GetAxisValue(Axis); }
103 
105  { return this->GetAxisValue((StandardAxis)Axis); }
106 
107  ///////////////////////////////////////////////////////////////////////////////
108  // Constructors
109 
111  { this->Zero(); }
112 
113  Vector3::Vector3(const Real& x, const Real& y, const Real& z)
114  { this->SetValues(x,y,z); }
115 
116  Vector3::Vector3(const Ogre::Vector3& Vec)
117  { this->ExtractOgreVector3(Vec); }
118 
119  Vector3::Vector3(const btVector3& Vec)
120  { this->ExtractBulletVector3(Vec); }
121 
123  { *this = Vec; }
124 
126  { this->ProtoDeSerialize(OneNode); }
127 
128  ///////////////////////////////////////////////////////////////////////////////
129  // Prebuilt Vectors
130 
132  { return Vector3(1,0,0); }
133 
135  { return Vector3(0,1,0);}
136 
138  { return Vector3(0,0,1); }
139 
141  { return Vector3(-1,0,0); }
142 
144  { return Vector3(0,-1,0); }
145 
147  { return Vector3(0,0,-1); }
148 
150  {
151  switch(Axis)
152  {
153  case 0: return Vector3::Unit_X();
154  case 1: return Vector3::Unit_Y();
155  case 2: return Vector3::Unit_Z();
156  default: { MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Cannot convert invalid StandardAxis."); }
157  }
158  }
159 
161  {
162  if (1.0==this->X && 0.0==this->Y && 0.0==this->Z)
163  {
164  return Axis_X;
165  } else if (0.0==this->X) { // Not Unit_X
166  if (1.0==this->Y && 0.0==this->Z)
167  {
168  return Axis_Y;
169  } else if (0.0==this->Y && 1.0==this->Z) { // Not Unit_Y so hopefully it is Z
170  return Axis_Z;
171  }
172  }
173  return Axis_Invalid;
174  //MEZZ_EXCEPTION(ExceptionBase::INVALID_STATE_EXCEPTION,"Cannot convert Vector3 to StandardAxis, Vector3 may not be Axis Aligned or may not be Unit Length.");
175  }
176 
177 
178  ///////////////////////////////////////////////////////////////////////////////
179  // Assignment Operators
180 
181  Vector3& Vector3::operator= (const btVector3 &Vec)
182  {
183  this->X=Vec.getX();
184  this->Y=Vec.getY();
185  this->Z=Vec.getZ();
186  return *this;
187  }
188 
189  Vector3& Vector3::operator= (const Ogre::Vector3 &Vec)
190  {
191  this->X=Vec.x;
192  this->Y=Vec.y;
193  this->Z=Vec.z;
194  return *this;
195  }
196 
197  ///////////////////////////////////////////////////////////////////////////////
198  // Unary Operators
199 
201  { return Vector3(-X,-Y,-Z); }
202 
203  ///////////////////////////////////////////////////////////////////////////////
204  // Vector3 Arithmetic with Real
205 
206  Vector3 Vector3::operator* (const Real &scalar) const
207  { return Vector3(this->X * scalar, this->Y * scalar, this->Z * scalar); }
208 
209  Vector3 Vector3::operator/ (const Real &scalar) const
210  { return Vector3(this->X / scalar, this->Y / scalar, this->Z / scalar); }
211 
212  ///////////////////////////////////////////////////////////////////////////////
213  // Vector3 Arithmetic and assignment with Real
214 
216  {
217  this->X *= scalar;
218  this->Y *= scalar;
219  this->Z *= scalar;
220  return *this;
221  }
222 
224  {
225  this->X /= scalar;
226  this->Y /= scalar;
227  this->Z /= scalar;
228  return *this;
229  }
230 
231  ///////////////////////////////////////////////////////////////////////////////
232  // Equality Comparison operators
233 
235  { return( Vec.X == this->X && Vec.Y == this->Y && Vec.Z == this->Z ); }
236 
237  Boole Vector3::operator== (const btVector3 &Vec) const
238  { return( Vec.getX() == this->X && Vec.getY() == this->Y && Vec.getZ() == this->Z ); }
239 
240  Boole Vector3::operator== (const Ogre::Vector3 &Vec) const
241  { return ( Vec.x == this->X && Vec.y == this->Y && Vec.z == this->Z ); }
242 
243 
245  { return ( Vec.X != this->X || Vec.Y != this->Y || Vec.Z != this->Z ); }
246 
247  Boole Vector3::operator!= (const btVector3 &Vec) const
248  { return ( Vec.getX() != this->X || Vec.getY() != this->Y || Vec.getZ() != this->Z ); }
249 
250  Boole Vector3::operator!= (const Ogre::Vector3 &Vec) const
251  { return ( Vec.x != this->X || Vec.y != this->Y || Vec.z != this->Z ); }
252 
254  { return ( this->X <= Vec.X && this->Y <= Vec.Y && this->Z <= Vec.Z); }
256  { return ( this->X >= Vec.X && this->Y >= Vec.Y && this->Z >= Vec.Z); }
257 
258  ///////////////////////////////////////////////////////////////////////////////
259  // Arithmetic Operators
260 
262  { return Vector3(X+Vec.X, Y+Vec.Y, Z+Vec.Z ); }
263 
265  { return Vector3(X-Vec.X, Y-Vec.Y, Z-Vec.Z ); }
266 
268  { return Vector3(X*Vec.X, Y*Vec.Y, Z*Vec.Z ); }
269 
271  { return Vector3(X/Vec.X, Y/Vec.Y, Z/Vec.Z ); }
272 
274  {
275  this->X += Vec.X;
276  this->Y += Vec.Y;
277  this->Z += Vec.Z;
278  return *this;
279  }
280 
282  {
283  this->X -= Vec.X;
284  this->Y -= Vec.Y;
285  this->Z -= Vec.Z;
286  return *this;
287  }
288 
290  {
291  this->X *= Vec.X;
292  this->Y *= Vec.Y;
293  this->Z *= Vec.Z;
294  return *this;
295  }
296 
298  {
299  this->X /= Vec.X;
300  this->Y /= Vec.Y;
301  this->Z /= Vec.Z;
302  return *this;
303  }
304 
305  ///////////////////////////////////////////////////////////////////////////////
306  // Arithmetic Operators with btVector3
307 
308  Vector3 Vector3::operator+ (const btVector3 &Vec) const
309  { return Vector3(X+Vec.getX(), Y+Vec.getY(), Z+Vec.getZ()); }
310 
311  Vector3 Vector3::operator- (const btVector3 &Vec) const
312  { return Vector3(X-Vec.getX(), Y-Vec.getY(), Z-Vec.getZ()); }
313 
314  Vector3 Vector3::operator* (const btVector3 &Vec) const
315  { return Vector3(X*Vec.getX(), Y*Vec.getY(), Z*Vec.getZ()); }
316 
317  Vector3 Vector3::operator/ (const btVector3 &Vec) const
318  { return Vector3(X/Vec.getX(), Y/Vec.getY(), Z/Vec.getZ()); }
319 
320  ///////////////////////////////////////////////////////////////////////////////
321  // Arithmetic Operators with Ogre::Vector3
322 
323  Vector3 Vector3::operator+ (const Ogre::Vector3 &Vec) const
324  { return Vector3(X+Vec.x, Y+Vec.y, Z+Vec.z); }
325 
326  Vector3 Vector3::operator- (const Ogre::Vector3 &Vec) const
327  { return Vector3(X-Vec.x, Y-Vec.y, Z-Vec.z); }
328 
329  Vector3 Vector3::operator* (const Ogre::Vector3 &Vec) const
330  { return Vector3(X*Vec.x, Y*Vec.y, Z*Vec.z); }
331 
332  Vector3 Vector3::operator/ (const Ogre::Vector3 &Vec) const
333  { return Vector3(X/Vec.x, Y/Vec.y, Z/Vec.z); }
334 
335  ///////////////////////////////////////////////////////////////////////////////
336  // Fancy Math
337 
339  {
340  return Vector3( // 1,2,3 . 4,5,6
341  this->Y * Vec.Z - this->Z * Vec.Y, // 2*6-3*5 = -3
342  this->Z * Vec.X - this->X * Vec.Z, // 3*4-1*6 = 6
343  this->X * Vec.Y - this->Y * Vec.X // 1*5-2*4 = -3
344  );
345  }
346 
347  Real Vector3::DotProduct(const Vector3& Vec) const
348  {
349  return this->X * Vec.X + this->Y * Vec.Y + this->Z * Vec.Z;
350  }
351 
353  {
354  Real TempLength = this->Distance( Vector3(0.0f,0.0f,0.0f) );
355  if( 0 != TempLength ) {
356  (*this) /= TempLength;
357  }else{
358  MEZZ_EXCEPTION(ExceptionBase::ARITHMETIC_EXCEPTION,"Cannot Normalize Vector3(0,0,0).");
359  }
360  return *this;
361  }
362 
364  {
365  Real TempLength = this->Distance( Vector3(0.0f,0.0f,0.0f) );
366  if( 0 != TempLength ) {
367  return (*this) / TempLength;
368  }else{
369  MEZZ_EXCEPTION(ExceptionBase::ARITHMETIC_EXCEPTION,"Cannot Get the Normal of Vector3(0,0,0).");
370  }
371  }
372 
373  Real Vector3::AngleBetween(const Vector3& Direction) const
374  {
375  Real LengthProduct = this->Length() * Direction.Length();
376  // Divide by zero check
377  if( LengthProduct < 1e-6f ) {
378  LengthProduct = 1e-6f;
379  }
380 
381  // Sorry about the variable name. :(
382  Real Temp = this->DotProduct(Direction) / LengthProduct;
383  Temp = MathTools::Clamp(Temp, Real(-1.0), Real(1.0) );
384  return MathTools::ACos(Temp);
385  }
386 
388  {
389  *this = this->GetPermute();
390  return *this;
391  }
392 
394  {
395  return Vector3(this->Z,this->X,this->Y);
396  }
397 
399  {
400  *this = this->GetAntiPermute();
401  return *this;
402  }
403 
405  {
406  return Vector3(this->Y,this->Z,this->X);
407  }
408 
409  Vector3 Vector3::GetDirection(const Vector3& Destination) const
410  {
411  return (Destination - *this).Normalize();
412  }
413 
415  {
416  static const Real fSquareZero = (Real)(1e-06 * 1e-06);
417 
418  Vector3 Perp = this->CrossProduct( Vector3::Unit_X() );
419  if( Perp.SquaredLength() < fSquareZero ) {
420  // If we're here, then this is vector is on the X axis already. Use another axis.
421  Perp = this->CrossProduct( Vector3::Unit_Y() );
422  }
423  Perp.Normalize();
424 
425  return Perp;
426  }
427 
429  {
430  return ( this->DotProduct(Perp) == 0 );
431  }
432 
434  {
435  if( X != 0 )
436  X = 1 / X;
437  if( Y != 0 )
438  Y = 1 / Y;
439  if( Z != 0 )
440  Z = 1 / Z;
441  return *this;
442  }
443 
445  {
446  return Vector3( *this - ( Normal * (2 * this->DotProduct(Normal) ) ) );
447  }
448 
449  Real Vector3::Distance(const Vector3& OtherVec) const
450  {
451  return (*this - OtherVec).Length();
452  }
453 
454  Real Vector3::SquaredDistance(const Vector3& OtherVec) const
455  {
456  return (*this - OtherVec).SquaredLength();
457  }
458 
460  {
461  return MathTools::Sqrt(X * X + Y * Y + Z * Z);
462  }
463 
465  {
466  return (X * X + Y * Y + Z * Z);
467  }
468 
470  {
471  return SquaredLength() < (1e-06 * 1e-06);
472  }
473 
474  Quaternion Vector3::GetRotationToAxis(const Vector3& Axis, const Vector3& FallBackAxis) const
475  {
476  Quaternion Ret;
477  Vector3 Vec1 = *this;
478  Vector3 Vec2 = Axis;
479  Vec1.Normalize();
480  Vec2.Normalize();
481 
482  Real Dot = Vec1.DotProduct(Vec2);
483  if( Dot >= 1.0 )
484  {
485  return Ret;
486  }
487  if( Dot < (1e-6 - 1.0) )
488  {
489  if( FallBackAxis != Vector3() )
490  {
491  Ret.SetFromAxisAngle(MathTools::GetPi(),FallBackAxis);
492  }else{
493  Vector3 CrossAxis = Vector3::Unit_X().CrossProduct(*this);
494  if(CrossAxis.IsZeroLength())
495  CrossAxis = Vector3::Unit_Y().CrossProduct(*this);
496  CrossAxis.Normalize();
497  Ret.SetFromAxisAngle(MathTools::GetPi(),CrossAxis);
498  }
499  }else{
500  Real Sqr = MathTools::Sqrt( (1+Dot)*2 );
501  Real InvSqr = 1 / Sqr;
502 
503  Vector3 Cross = Vec1.CrossProduct(Vec2);
504 
505  Ret.X = Cross.X * InvSqr;
506  Ret.Y = Cross.Y * InvSqr;
507  Ret.Z = Cross.Z * InvSqr;
508  Ret.W = Sqr * 0.5f;
509  Ret.Normalize();
510  }
511  return Ret;
512  }
513 
514  ///////////////////////////////////////////////////////////////////////////////
515  // Utility Functions
516 
518  {
519  this->X = 0;
520  this->Y = 0;
521  this->Z = 0;
522  }
523 
524  void Vector3::SetValues(const Real& X, const Real& Y, const Real& Z)
525  {
526  this->X = X;
527  this->Y = Y;
528  this->Z = Z;
529  }
530 
532  {
533  return ( this->X == 0.0 && this->Y == 0.0 && this->Z == 0.0 );
534  }
535 
537  {
538  if( Other.X > this->X ) this->X = Other.X;
539  if( Other.Y > this->Y ) this->Y = Other.Y;
540  if( Other.Z > this->Z ) this->Z = Other.Z;
541  return *this;
542  }
543 
545  {
546  if( Other.X < this->X ) this->X = Other.X;
547  if( Other.Y < this->Y ) this->Y = Other.Y;
548  if( Other.Z < this->Z ) this->Z = Other.Z;
549  return *this;
550  }
551 
552  ///////////////////////////////////////////////////////////////////////////////
553  // Manual Conversions
554 
555  btVector3 Vector3::GetBulletVector3() const
556  {
557  btVector3 Theirs;
558  Theirs.setX(this->X);
559  Theirs.setY(this->Y);
560  Theirs.setZ(this->Z);
561  Theirs.setW(0);
562  return Theirs;
563  }
564 
565  void Vector3::ExtractBulletVector3(const btVector3& Ours)
566  {
567  this->X=Ours.getX();
568  this->Y=Ours.getY();
569  this->Z=Ours.getZ();
570  }
571 
572  Ogre::Vector3 Vector3::GetOgreVector3() const
573  {
574  Ogre::Vector3 Theirs;
575  Theirs.x=this->X;
576  Theirs.y=this->Y;
577  Theirs.z=this->Z;
578  return Theirs;
579  }
580 
581  void Vector3::ExtractOgreVector3(const Ogre::Vector3& Ours)
582  {
583  this->X=Ours.x;
584  this->Y=Ours.y;
585  this->Z=Ours.z;
586  }
587 
588  void Vector3::ProtoSerialize(XML::Node& CurrentRoot) const
589  {
590  Mezzanine::XML::Node VecNode = CurrentRoot.AppendChild(GetSerializableName());
591 
592  if(VecNode)
593  {
594  Mezzanine::XML::Attribute VersionAttr = VecNode.AppendAttribute("Version");
595  Mezzanine::XML::Attribute XAttr = VecNode.AppendAttribute("X");
596  Mezzanine::XML::Attribute YAttr = VecNode.AppendAttribute("Y");
597  Mezzanine::XML::Attribute ZAttr = VecNode.AppendAttribute("Z");
598  if( VersionAttr && XAttr && YAttr && ZAttr )
599  {
600  if( VersionAttr.SetValue("1") && XAttr.SetValue(this->X) && YAttr.SetValue(this->Y) && ZAttr.SetValue(this->Z))
601  {
602  return;
603  }else{
604  SerializeError("Create XML Attribute Values", GetSerializableName(),true);
605  }
606  }else{
607  SerializeError("Create XML Attributes", GetSerializableName(),true);
608  }
609  }else{
610  SerializeError("Create XML Serialization Node", GetSerializableName(),true);
611  }
612  }
613 
615  {
617  {
618  if(OneNode.GetAttribute("Version").AsInt() == 1)
619  {
620  this->X=OneNode.GetAttribute("X").AsReal();
621  this->Y=OneNode.GetAttribute("Y").AsReal();
622  this->Z=OneNode.GetAttribute("Z").AsReal();
623  }else{
624  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + GetSerializableName() + ": Not Version 1.");
625  }
626  }else{
627  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a " + GetSerializableName() + ", found a " + String(OneNode.Name()) + ".");
628  }
629  }
630 
632  { return String("Vector3"); }
633 
634  const char* Vector3::__str__()
635  {
636  const Whole BufferSize=64; // longest possible vector3 is 59: <Vector3 Version="1" X="1.33333" Y="2.33333" Z="3.33333" />
637  static char buffer[BufferSize];
638  String Temp(ToString(*this));
639  assert(Temp.size()<BufferSize);
640  strncpy(buffer,Temp.c_str(),BufferSize);
641  return buffer;
642  }
643 
644  ///////////////////////////////////////////////////////////////////////////////
645  // Right Hand Arithmetic Operators
646 
647  Mezzanine::Vector3 operator+ (const btVector3 &Vec, const Mezzanine::Vector3& lhs)
648  { return lhs + Vec; }
649  Mezzanine::Vector3 operator- (const btVector3 &Vec, const Mezzanine::Vector3& lhs)
650  { return Mezzanine::Vector3(Vec.getX()-lhs.X, Vec.getY()-lhs.Y, Vec.getZ()-lhs.Z); }
651  Mezzanine::Vector3 operator* (const btVector3 &Vec, const Mezzanine::Vector3& lhs)
652  { return lhs * Vec; }
653  Mezzanine::Vector3 operator/ (const btVector3 &Vec, const Mezzanine::Vector3& lhs)
654  { return Mezzanine::Vector3(Vec.getX()/lhs.X, Vec.getY()/lhs.Y, Vec.getZ()/lhs.Z); }
655 
656  Mezzanine::Vector3 operator+ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
657  { return lhs + Vec; }
658  Mezzanine::Vector3 operator- (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
659  { return Mezzanine::Vector3(Vec.x-lhs.X, Vec.y-lhs.Y, Vec.z-lhs.Z); }
660  Mezzanine::Vector3 operator* (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
661  { return lhs * Vec; }
662  Mezzanine::Vector3 operator/ (const Ogre::Vector3 &Vec, const Mezzanine::Vector3& lhs)
663  { return Mezzanine::Vector3(Vec.x/lhs.X, Vec.y/lhs.Y, Vec.z/lhs.Z); }
664 
665  ///////////////////////////////////////////////////////////////////////////////
666  // Vector2LengthCompare methods
667 
668  Boole Vector3LengthCompare::operator()(const Vector3& First, const Vector3& Second) const
669  {
670  if( ( First - Second ).SquaredLength() < 1e-6 )
671  return false;
672  if( MathTools::Abs( First.X - Second.X ) > 1e-3 )
673  return ( First.X < Second.X );
674  if( MathTools::Abs( First.Y - Second.Y ) > 1e-3 )
675  return ( First.Y < Second.Y );
676  return ( First.Z < Second.Z );
677  }
678 
679  ///////////////////////////////////////////////////////////////////////////////
680  // Class External << Operators for streaming or assignment
681 
682  std::ostream& operator << (std::ostream& stream, const Mezzanine::Vector3& x)
683  {
684  //stream << "<Vector3 Version=\"1\" X=\"" << x.X << "\" Y=\"" << x.Y << "\" Z=\"" << x.Z << "\"/>";
685  Serialize(stream,x);
686  return stream;
687  }
688 
689  std::istream& operator >> (std::istream& stream, Mezzanine::Vector3& Vec)
690  { return DeSerialize(stream, Vec); }
691 
693  { Vec.ProtoDeSerialize(OneNode); }
694 
695  Ogre::Vector3& operator << (Ogre::Vector3& VecTo, const Mezzanine::Vector3& VecFrom)
696  {
697  VecTo = VecFrom.GetOgreVector3();
698  return VecTo;
699  }
700 
701  Ogre::Vector3& operator << (Ogre::Vector3& VecTo, const btVector3& VecFrom)
702  {
703  VecTo.x=VecFrom.getX();
704  VecTo.y=VecFrom.getY();
705  VecTo.z=VecFrom.getZ();
706  return VecTo;
707  }
708 
709  btVector3& operator << (btVector3& VecTo, const Ogre::Vector3& VecFrom)
710  {
711  VecTo.setX(VecFrom.x);
712  VecTo.setY(VecFrom.y);
713  VecTo.setZ(VecFrom.z);
714  VecTo.setW(0);
715  return VecTo;
716  }
717 
718  btVector3& operator << (btVector3& VecTo, const Mezzanine::Vector3& VecFrom)
719  {
720  VecTo=VecFrom.GetBulletVector3();
721  return VecTo;
722  }
723 
724  Mezzanine::Vector3& operator << (Mezzanine::Vector3& VecTo, const Ogre::Vector3& VecFrom)
725  {
726  VecTo=VecFrom;
727  return VecTo;
728  }
729 
730  Mezzanine::Vector3& operator << (Mezzanine::Vector3& VecTo, const btVector3& VecFrom)
731  {
732  VecTo=VecFrom;
733  return VecTo;
734  }
735 }
736 
737 #endif
Vector3 Reflect(const Vector3 &Normal)
Gets a reflection vector to the plane with the given normal.
Definition: vector3.cpp:444
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
Vector3 Perpendicular() const
Gets a vector that is perpendicular to this one.
Definition: vector3.cpp:414
Vector3 CrossProduct(const Vector3 &Vec) const
This is used to calculate the crossproduct of this and another vector.
Definition: vector3.cpp:338
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Vector3 GetNormal() const
This returns the normal for this relative to the origin.
Definition: vector3.cpp:363
Vector3 & operator-=(const Vector3 &Vec)
Subraction Assignment Operator.
Definition: vector3.cpp:281
Real X
Coordinate on the X vector.
Definition: vector3.h:85
Real Z
Coordinate on the Z vector.
Definition: vector3.h:89
String ToString(const T &Datum)
Converts whatever to a String as long as a streaming operator is available for it.
Definition: datatypes.h:242
Vector3 operator+(const Vector3 &Vec) const
Addition Operator.
Definition: vector3.cpp:261
Real Length() const
Gets the length of this vector.
Definition: vector3.cpp:459
StandardAxis
Used to identify different Axis in a 3d coordinate system.
Definition: enumerations.h:119
Boole IsPerpendicular(const Vector3 &Perp) const
Gets whether or not a vector is perpendicular to this one.
Definition: vector3.cpp:428
void SetFromAxisAngle(const Real &Angle, const Vector3 &Axis)
Generates and sets the values of this quaternion to describe a rotation from an axis and angle on tha...
Definition: quaternion.cpp:115
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
std::ostream & Serialize(std::ostream &Stream, const T &Converted, const String &Indent=String(""))
Convert any class that supports serialization or has a serializer to a string of chars in a stream...
Real Y
The Y component of the Axis.
Definition: quaternion.h:77
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
Not an axis, Don't pass this into functions or operator[] functions, it is intended as an error value...
Definition: enumerations.h:121
SmoothTrackIterator< InterpolatableType > & operator+(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for addition with and an Integer on the Left hand side, such as: 2 + Iter.
Vector3 & operator/=(const Real &scalar)
Scaling by Division.
Definition: vector3.cpp:223
Mezzanine::Vector3 operator/(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Division Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:653
Quaternion GetRotationToAxis(const Vector3 &Axis, const Vector3 &FallBackAxis=Vector3()) const
Gets the rotation needed to rotate this vector as an axis to another axis.
Definition: vector3.cpp:474
Quaternion & Normalize()
Normalizes this Quaternion.
Definition: quaternion.cpp:218
This implements the exception hiearchy for Mezzanine.
Boole operator<=(const Mezzanine::Vector3 &Vec) const
Less or Equal Comparison Operator.
Definition: vector3.cpp:253
Vector3 & operator+=(const Vector3 &Vec)
Addition Assignment Operator.
Definition: vector3.cpp:273
Real Distance(const Vector3 &OtherVec) const
Gets the distance between this and another vector.
Definition: vector3.cpp:449
std::ostream & operator<<(std::ostream &stream, const Mezzanine::HashedString32 &x)
Send a HashedString32 down a stream serialized.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
The interface for serialization.
Real SquaredDistance(const Vector3 &OtherVec) const
Gets the squared distance between this and another vector.
Definition: vector3.cpp:454
bool SetValue(const Char8 *rhs)
Set the value of this.
Vector3 & AntiPermute()
Shifts all of the components to the left.
Definition: vector3.cpp:398
SmoothTrackIterator< InterpolatableType > & operator-(Integer Steps, SmoothTrackIterator< InterpolatableType > &Iter)
This allows for subtraction with and an Integer on the Left hand side, such as: 2 + Iter...
Vector3 & Floor(const Vector3 &Other)
Sets each member of this Vector3 to the lower value between the two vector3s.
Definition: vector3.cpp:544
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
Definition: vector3.cpp:555
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
Vector3 GetAntiPermute() const
Gets a anti-permuted copy of this vector.
Definition: vector3.cpp:404
Mezzanine::Vector3 operator*(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
Definition: vector3.cpp:651
Vector3()
Default Constructor.
Definition: vector3.cpp:110
Real W
Rotation on the Axis X, Y and Z defined.
Definition: quaternion.h:81
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
Boole IsZero() const
Checks to see if the values of this vector are all zero.
Definition: vector3.cpp:531
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
Definition: vector3.cpp:134
Vector3 & Ceil(const Vector3 &Other)
Sets each member of this Vector3 to the higher value between the two vector3s.
Definition: vector3.cpp:536
void ExtractOgreVector3(const Ogre::Vector3 &temp)
Copies an existing Ogre vector3.
Definition: vector3.cpp:581
void ExtractBulletVector3(const btVector3 &temp)
Copies an existing Bullet vector3.
Definition: vector3.cpp:565
Vector3 & Normalize()
This will change this point into it's own normal relative to the origin.
Definition: vector3.cpp:352
Ogre::Vector3 GetOgreVector3() const
Gets a Ogre vector3.
Definition: vector3.cpp:572
static String GetSerializableName()
Get the name of the the XML tag this class will leave behind as its instances are serialized...
Definition: vector3.cpp:631
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
Real Y
Coordinate on the Y vector.
Definition: vector3.h:87
Real GetAxisValue(const StandardAxis &Axis) const
Get The value associate with a certain Axis.
Definition: vector3.cpp:67
static Vector3 Neg_Unit_X()
Gets a vector representing the negative X unit of a Vector3.
Definition: vector3.cpp:140
void SetValues(const Real &X, const Real &Y, const Real &Z)
Manually sets all the members of this vector3.
Definition: vector3.cpp:524
std::istream & operator>>(std::istream &stream, Mezzanine::Vector3 &Vec)
Used to de-serialize an Mezzanine::Vector3 from a stream.
Definition: vector3.cpp:689
std::istream & DeSerialize(std::istream &Stream, T &Converted)
Deserialize the next xml tag in the stream into a specific in memory class instance.
Vector3 & Permute()
Shifts all of the components to the right.
Definition: vector3.cpp:387
Vector3 Inverse()
This will inverse the reals in the vector.
Definition: vector3.cpp:433
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Definition: vector3.cpp:131
Real DotProduct(const Vector3 &Vec) const
This is used to calculate the dotproduct of this and another vector.
Definition: vector3.cpp:347
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
Definition: vector3.cpp:614
Vector3 & operator=(const btVector3 &Vec)
Assignment operator to convert from Bullet Vectors.
Definition: vector3.cpp:181
Boole operator>=(const Mezzanine::Vector3 &Vec) const
Greater than or Equal Comparison Operator.
Definition: vector3.cpp:255
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Definition: vector3.cpp:137
Thrown when the identity string wasn't valid at all.
Definition: exception.h:93
Vector3 GetPermute() const
Gets a permuted copy of this vector.
Definition: vector3.cpp:393
Vector3 operator-()
Additive Inverse Operator.
Definition: vector3.cpp:200
Real SquaredLength() const
Gets the length of this vector squared.
Definition: vector3.cpp:464
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
Thrown when Math has failed.
Definition: exception.h:111
void Zero()
Sets all the members of this vector3 to zero.
Definition: vector3.cpp:517
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
static Vector3 UnitOnAxis(StandardAxis Axis)
Get a Unit Vector along the given Axis.
Definition: vector3.cpp:149
Boole operator==(const Mezzanine::Vector3 &Vec) const
Equality Comparison Operator.
Definition: vector3.cpp:234
Boole IsZeroLength() const
Checks to see if the length of this vector is zero.
Definition: vector3.cpp:469
Vector3 GetDirection(const Vector3 &Destination) const
This will get the direction between two points.
Definition: vector3.cpp:409
Boole operator()(const Vector3 &First, const Vector3 &Second) const
Compares two Vector3's to determine which has the greater length/magnitude.
Definition: vector3.cpp:668
Vector3 operator*(const Real &scalar) const
Scaling by multiplication.
Definition: vector3.cpp:206
Real X
The X component of the Axis.
Definition: quaternion.h:75
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Vector3 & operator*=(const Real &scalar)
Scaling by multiplication.
Definition: vector3.cpp:215
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Real operator[](const StandardAxis &Axis) const
Get The value associate with a certain Axis.
Definition: vector3.cpp:95
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
static Vector3 Neg_Unit_Z()
Gets a vector representing the negative Z unit of a Vector3.
Definition: vector3.cpp:146
Real Z
The Z component of the Axis.
Definition: quaternion.h:79
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Real AngleBetween(const Vector3 &Direction) const
Gets the angle between this and another vector assuming both are directional vectors.
Definition: vector3.cpp:373
Boole operator!=(const Mezzanine::Vector3 &Vec) const
Inequality Comparison Operator.
Definition: vector3.cpp:244
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Definition: vector3.cpp:588
static Vector3 Neg_Unit_Y()
Gets a vector representing the negative Y unit of a Vector3.
Definition: vector3.cpp:143
StandardAxis IsStandardUnitAxis() const
Get a Unit Vector along the given Axis.
Definition: vector3.cpp:160
Vector3 operator/(const Real &scalar) const
Scaling by Division.
Definition: vector3.cpp:209