00001 #include <windows.h> 00002 #include "vector.h" 00003 #include "mmgr.h" 00004 00005 VECTOR::VECTOR(float sx, float sy, float sz) 00006 : 00007 x(sx), 00008 y(sy), 00009 z(sz) 00010 { 00011 } 00012 00013 VECTOR::~VECTOR() 00014 { 00015 } 00016 00017 void VECTOR::Reset() 00018 { 00019 x = 0; 00020 y = 0; 00021 z = 0; 00022 } 00023 00024 float VECTOR::DotProduct(VECTOR vect) 00025 { 00026 float dot; 00027 dot = vect.x * x + vect.y * y + vect.z * z; 00028 return dot; 00029 } 00030 00031 void VECTOR::CrossVector(VECTOR vect) 00032 { 00033 VECTOR temp = *this; 00034 x = vect.y * temp.z - vect.z * temp.y; 00035 y = vect.z * temp.x - vect.x * temp.z; 00036 z = vect.x * temp.y - vect.y * temp.x; 00037 } 00038 00039 float VECTOR::GetMagnitude() 00040 { 00041 float magnitude = (float)sqrt(x * x + y * y + z * z); 00042 if (magnitude != 0.0f) 00043 return magnitude; 00044 else 00045 return 1.0; 00046 } 00047 00048 void VECTOR::Normalize() 00049 { 00050 float magnitude = this->GetMagnitude(); 00051 x /= magnitude; 00052 y /= magnitude; 00053 z /= magnitude; 00054 }