Vector3.cpp
Go to the documentation of this file.
00001 #include "Vector3.h"
00002 #include "math.h"
00003 
00004 Vector3::Vector3()
00005 { this->x = 0; this->y = 0; this->z = 0; }
00006 
00007 Vector3::Vector3(float x, float y, float z)
00008 { this->x = x; this->y = y; this->z = z; }
00009 
00010 Vector3::~Vector3()
00011 {}
00012 
00013 Vector3::Vector3(const Vector3 &vec) :
00014 x(vec.x), y(vec.y), z(vec.z)
00015 {}
00016 
00017 Vector3 Vector3::operator+(const Vector3 &vec) const
00018 {
00019     Vector3 newVec;
00020     newVec.x = this->x + vec.x;
00021     newVec.y = this->y + vec.y;
00022     newVec.z = this->z + vec.z;
00023     return newVec;
00024 }
00025 
00026 Vector3 Vector3::operator-(const Vector3 &vec) const
00027 {
00028     Vector3 newVec;
00029     newVec.x = this->x - vec.x;
00030     newVec.y = this->y - vec.y;
00031     newVec.z = this->z - vec.z;
00032     return newVec;
00033 }
00034 
00035 Vector3 Vector3::operator*(const float k) const
00036 {
00037     Vector3 newVec;
00038     newVec.x = this->x * k;
00039     newVec.y = this->y * k;
00040     newVec.z = this->z * k;
00041     return newVec;
00042 }
00043 
00044 void Vector3::Normalize()
00045 {
00046     float length = Length();
00047     this->x /= length;
00048     this->y /= length;
00049     this->z /= length;
00050 }
00051 
00052 float Vector3::Dot(const Vector3 &vec) const
00053 {
00054     return ( this->x * vec.x + this->y * vec.y + this->z * vec.z );
00055 }
00056 
00057 Vector3 Vector3::Cross(const Vector3 &vec) const
00058 {
00059     Vector3 newVec;
00060     newVec.x = this->y * vec.z - vec.y * this->z;
00061     newVec.y = this->z * vec.x - vec.z * this->x;
00062     newVec.z = this->x * vec.y - vec.x * this->y;
00063     return newVec;
00064 }
00065 
00066 float Vector3::Length()
00067 {
00068     return sqrt(this->x * this->x + this->y * this->y + this->z * this->z);
00069 }
00070 
00071 bool Vector3::IsEqual(const Vector3 &vec) const
00072 {
00073     if (fabs(this->x - vec.x)<0.001f && fabs(this->y - vec.y)<0.001f && fabs(this->z - vec.z)<0.001f)
00074         return true;
00075     return false;
00076 }


clearpath_tools
Author(s): Sean Anderson
autogenerated on Sun Oct 5 2014 22:52:30