44 #include "quaternion.h"
47 #include "stringtool.h"
48 #include "MathTools/mathtools.h"
55 #include "btBulletDynamicsCommon.h"
71 case 0:
return this->
X;
72 case 1:
return this->
Y;
73 case 2:
return this->
Z;
85 case 0:
return this->
X;
86 case 1:
return this->
Y;
87 case 2:
return this->
Z;
162 if (1.0==this->
X && 0.0==this->
Y && 0.0==this->
Z)
165 }
else if (0.0==this->
X) {
166 if (1.0==this->
Y && 0.0==this->
Z)
169 }
else if (0.0==this->
Y && 1.0==this->
Z) {
207 {
return Vector3(this->
X * scalar, this->
Y * scalar, this->
Z * scalar); }
210 {
return Vector3(this->
X / scalar, this->
Y / scalar, this->
Z / scalar); }
235 {
return( Vec.
X == this->X && Vec.
Y == this->Y && Vec.
Z == this->Z ); }
238 {
return( Vec.getX() == this->
X && Vec.getY() == this->
Y && Vec.getZ() == this->
Z ); }
241 {
return ( Vec.x == this->X && Vec.y == this->Y && Vec.z == this->Z ); }
245 {
return ( Vec.
X != this->X || Vec.
Y != this->Y || Vec.
Z != this->Z ); }
248 {
return ( Vec.getX() != this->
X || Vec.getY() != this->
Y || Vec.getZ() != this->
Z ); }
251 {
return ( Vec.x != this->X || Vec.y != this->Y || Vec.z != this->Z ); }
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); }
309 {
return Vector3(
X+Vec.getX(),
Y+Vec.getY(),
Z+Vec.getZ()); }
312 {
return Vector3(
X-Vec.getX(),
Y-Vec.getY(),
Z-Vec.getZ()); }
315 {
return Vector3(
X*Vec.getX(),
Y*Vec.getY(),
Z*Vec.getZ()); }
318 {
return Vector3(
X/Vec.getX(),
Y/Vec.getY(),
Z/Vec.getZ()); }
324 {
return Vector3(
X+Vec.x,
Y+Vec.y,
Z+Vec.z); }
327 {
return Vector3(
X-Vec.x,
Y-Vec.y,
Z-Vec.z); }
330 {
return Vector3(
X*Vec.x,
Y*Vec.y,
Z*Vec.z); }
333 {
return Vector3(
X/Vec.x,
Y/Vec.y,
Z/Vec.z); }
341 this->
Y * Vec.
Z - this->Z * Vec.
Y,
342 this->Z * Vec.
X - this->X * Vec.
Z,
343 this->X * Vec.
Y - this->Y * Vec.
X
349 return this->
X * Vec.
X + this->
Y * Vec.
Y + this->
Z * Vec.
Z;
355 if( 0 != TempLength ) {
356 (*this) /= TempLength;
366 if( 0 != TempLength ) {
367 return (*
this) / TempLength;
377 if( LengthProduct < 1e-6f ) {
378 LengthProduct = 1e-6f;
383 Temp = MathTools::Clamp(Temp,
Real(-1.0),
Real(1.0) );
384 return MathTools::ACos(Temp);
411 return (Destination - *
this).
Normalize();
416 static const Real fSquareZero = (
Real)(1e-06 * 1e-06);
451 return (*
this - OtherVec).Length();
456 return (*
this - OtherVec).SquaredLength();
461 return MathTools::Sqrt(
X *
X +
Y *
Y +
Z *
Z);
466 return (
X *
X +
Y *
Y +
Z *
Z);
487 if( Dot < (1e-6 - 1.0) )
489 if( FallBackAxis !=
Vector3() )
500 Real Sqr = MathTools::Sqrt( (1+Dot)*2 );
501 Real InvSqr = 1 / Sqr;
505 Ret.
X = Cross.
X * InvSqr;
506 Ret.
Y = Cross.
Y * InvSqr;
507 Ret.
Z = Cross.
Z * InvSqr;
533 return ( this->
X == 0.0 && this->
Y == 0.0 && this->
Z == 0.0 );
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;
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;
558 Theirs.setX(this->
X);
559 Theirs.setY(this->
Y);
560 Theirs.setZ(this->
Z);
574 Ogre::Vector3 Theirs;
598 if( VersionAttr && XAttr && YAttr && ZAttr )
632 {
return String(
"Vector3"); }
634 const char* Vector3::__str__()
636 const Whole BufferSize=64;
637 static char buffer[BufferSize];
639 assert(Temp.size()<BufferSize);
640 strncpy(buffer,Temp.c_str(),BufferSize);
648 {
return lhs + Vec; }
652 {
return lhs * Vec; }
657 {
return lhs + Vec; }
661 {
return lhs * Vec; }
670 if( ( First - Second ).SquaredLength() < 1e-6 )
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 );
701 Ogre::Vector3&
operator << (Ogre::Vector3& VecTo,
const btVector3& VecFrom)
703 VecTo.x=VecFrom.getX();
704 VecTo.y=VecFrom.getY();
705 VecTo.z=VecFrom.getZ();
709 btVector3&
operator << (btVector3& VecTo,
const Ogre::Vector3& VecFrom)
711 VecTo.setX(VecFrom.x);
712 VecTo.setY(VecFrom.y);
713 VecTo.setZ(VecFrom.z);
Vector3 Reflect(const Vector3 &Normal)
Gets a reflection vector to the plane with the given normal.
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.
Vector3 Perpendicular() const
Gets a vector that is perpendicular to this one.
Vector3 CrossProduct(const Vector3 &Vec) const
This is used to calculate the crossproduct of this and another vector.
bool Boole
Generally acts a single bit, true or false.
Vector3 GetNormal() const
This returns the normal for this relative to the origin.
Vector3 & operator-=(const Vector3 &Vec)
Subraction Assignment Operator.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
String ToString(const T &Datum)
Converts whatever to a String as long as a streaming operator is available for it.
Vector3 operator+(const Vector3 &Vec) const
Addition Operator.
Real Length() const
Gets the length of this vector.
StandardAxis
Used to identify different Axis in a 3d coordinate system.
Boole IsPerpendicular(const Vector3 &Perp) const
Gets whether or not a vector is perpendicular to this one.
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...
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
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.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Not an axis, Don't pass this into functions or operator[] functions, it is intended as an error value...
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.
Mezzanine::Vector3 operator/(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Division Operator for Bullet Vectors with a Mezzanine::Vector3.
Quaternion GetRotationToAxis(const Vector3 &Axis, const Vector3 &FallBackAxis=Vector3()) const
Gets the rotation needed to rotate this vector as an axis to another axis.
Quaternion & Normalize()
Normalizes this Quaternion.
This implements the exception hiearchy for Mezzanine.
Boole operator<=(const Mezzanine::Vector3 &Vec) const
Less or Equal Comparison Operator.
Vector3 & operator+=(const Vector3 &Vec)
Addition Assignment Operator.
Real Distance(const Vector3 &OtherVec) const
Gets the distance between this and another vector.
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.
The interface for serialization.
Real SquaredDistance(const Vector3 &OtherVec) const
Gets the squared distance between this and another vector.
bool SetValue(const Char8 *rhs)
Set the value of this.
Vector3 & AntiPermute()
Shifts all of the components to the left.
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.
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
A light-weight handle for manipulating nodes in DOM tree.
Vector3 GetAntiPermute() const
Gets a anti-permuted copy of this vector.
Mezzanine::Vector3 operator*(const btVector3 &Vec, const Mezzanine::Vector3 &lhs)
Right Hand Multiplication Operator for Bullet Vectors with a Mezzanine::Vector3.
Vector3()
Default Constructor.
Real W
Rotation on the Axis X, Y and Z defined.
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.
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
Vector3 & Ceil(const Vector3 &Other)
Sets each member of this Vector3 to the higher value between the two vector3s.
void ExtractOgreVector3(const Ogre::Vector3 &temp)
Copies an existing Ogre vector3.
void ExtractBulletVector3(const btVector3 &temp)
Copies an existing Bullet vector3.
Vector3 & Normalize()
This will change this point into it's own normal relative to the origin.
Ogre::Vector3 GetOgreVector3() const
Gets a Ogre vector3.
static String GetSerializableName()
Get the name of the the XML tag this class will leave behind as its instances are serialized...
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.
Real GetAxisValue(const StandardAxis &Axis) const
Get The value associate with a certain Axis.
static Vector3 Neg_Unit_X()
Gets a vector representing the negative X unit of a Vector3.
void SetValues(const Real &X, const Real &Y, const Real &Z)
Manually sets all the members of this vector3.
std::istream & operator>>(std::istream &stream, Mezzanine::Vector3 &Vec)
Used to de-serialize an Mezzanine::Vector3 from a stream.
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.
Vector3 Inverse()
This will inverse the reals in the vector.
Thrown when parameters are checked at runtime and found invalid.
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
Real DotProduct(const Vector3 &Vec) const
This is used to calculate the dotproduct of this and another vector.
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
Vector3 & operator=(const btVector3 &Vec)
Assignment operator to convert from Bullet Vectors.
Boole operator>=(const Mezzanine::Vector3 &Vec) const
Greater than or Equal Comparison Operator.
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Thrown when the identity string wasn't valid at all.
Vector3 GetPermute() const
Gets a permuted copy of this vector.
Vector3 operator-()
Additive Inverse Operator.
Real SquaredLength() const
Gets the length of this vector squared.
This is used to represent a point in space, or a vector through space.
Thrown when Math has failed.
void Zero()
Sets all the members of this vector3 to zero.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
static Vector3 UnitOnAxis(StandardAxis Axis)
Get a Unit Vector along the given Axis.
Boole operator==(const Mezzanine::Vector3 &Vec) const
Equality Comparison Operator.
Boole IsZeroLength() const
Checks to see if the length of this vector is zero.
Vector3 GetDirection(const Vector3 &Destination) const
This will get the direction between two points.
Boole operator()(const Vector3 &First, const Vector3 &Second) const
Compares two Vector3's to determine which has the greater length/magnitude.
Vector3 operator*(const Real &scalar) const
Scaling by multiplication.
Real X
The X component of the Axis.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
Vector3 & operator*=(const Real &scalar)
Scaling by multiplication.
This is used to store information about rotation in 3d space.
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.
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.
Real Z
The Z component of the Axis.
std::string String
A datatype used to a series of characters.
Real AngleBetween(const Vector3 &Direction) const
Gets the angle between this and another vector assuming both are directional vectors.
Boole operator!=(const Mezzanine::Vector3 &Vec) const
Inequality Comparison Operator.
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.
static Vector3 Neg_Unit_Y()
Gets a vector representing the negative Y unit of a Vector3.
StandardAxis IsStandardUnitAxis() const
Get a Unit Vector along the given Axis.
Vector3 operator/(const Real &scalar) const
Scaling by Division.