Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

object.cpp

Go to the documentation of this file.
00001 #include <windows.h>
00002 #include "object.h"
00003 
00004 extern bool freeCamera;
00005 extern float radian;
00006 extern float pi;
00007 
00008 OBJECT::OBJECT()
00009 {
00010     Delta_x = 0.0;
00011     Delta_y = 0.0;
00012     Delta_z = 0.0;
00013     Movement_x = 0.0;
00014     Movement_y = 0.0;
00015     Movement_z = 0.0;
00016 }
00017 
00018 OBJECT::~OBJECT()
00019 {
00020 }
00021 
00022 void OBJECT::Reset()
00023 {
00024     Orientation.Reset();
00025     Position.Reset();
00026         Delta_x = 0.0;
00027         Delta_y = 0.0;
00028         Delta_z = 0.0;
00029         Movement_x = 0.0;
00030         Movement_y = 0.0;
00031         Movement_z = 0.0;
00032 }
00033 
00034 void OBJECT::Rotate()
00035 {
00036     QUAT temp_quat;
00037     temp_quat.EulerToQuat(Delta_x * radian * Multiplier, Delta_y * radian * Multiplier, Delta_z * radian * Multiplier);
00038     Orientation.MultQuat(temp_quat);
00039 }
00040 
00041 void OBJECT::Draw()
00042 {
00043   // Should probably be a pure virtual 
00044 }
00045 
00046 void OBJECT::UpdatePosition()
00047 {
00048     if (Movement_x != 0)
00049         MoveX();
00050     if (Movement_y != 0)
00051         MoveY();
00052     if (Movement_z != 0)
00053         MoveZ();
00054 
00055     Movement_x = 0.0;
00056     Movement_y = 0.0;
00057     Movement_z = 0.0;
00058 }
00059 
00060 void OBJECT::UpdatePosition(float x, float y, float z)
00061 {
00062     if (x != 0)
00063         MoveX(x);
00064     if (y != 0)
00065         MoveY(y);
00066     if (z != 0)
00067         MoveZ(z);
00068 }
00069 
00070 void OBJECT::MoveX()
00071 {
00072     float DirX;
00073     float DirY;
00074     float DirZ;
00075     float W;
00076     float X;
00077     float Y;
00078     float Z;
00079     QUAT TempQuat;
00080     QUAT TempQuat2;
00081     TempQuat = Orientation;
00082     TempQuat2.EulerToQuat(0.0, -90.0*(pi/180), 0.0);
00083     TempQuat.MultQuat(TempQuat2);
00084     W = TempQuat.w;
00085     X = TempQuat.x;
00086     Y = TempQuat.y;
00087     Z = TempQuat.z;
00088     DirX = 2.0 * ( X * Z - W * Y );
00089     DirY = 2.0 * ( Y * Z + W * X );
00090     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00091     Position.x += DirX * Movement_x * Multiplier;
00092     Position.y += DirY * Movement_x * Multiplier;
00093     Position.z += DirZ * Movement_x * Multiplier;
00094 }
00095 
00096 void OBJECT::MoveY()
00097 {
00098     float DirX;
00099     float DirY;
00100     float DirZ;
00101     float W;
00102     float X;
00103     float Y;
00104     float Z;
00105     QUAT TempQuat;
00106     QUAT TempQuat2;
00107     TempQuat = Orientation;
00108     TempQuat2.EulerToQuat(90.0*(pi/180), 0.0, 0.0);
00109     TempQuat.MultQuat(TempQuat2);
00110     W = TempQuat.w;
00111     X = TempQuat.x;
00112     Y = TempQuat.y;
00113     Z = TempQuat.z;
00114     DirX = 2.0 * ( X * Z - W * Y );
00115     DirY = 2.0 * ( Y * Z + W * X );
00116     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00117     Position.x += DirX * Movement_y * Multiplier;
00118     Position.y += DirY * Movement_y * Multiplier;
00119     Position.z += DirZ * Movement_y * Multiplier;
00120 }
00121 
00122 void OBJECT::MoveZ()
00123 {
00124     float DirX;
00125     float DirY;
00126     float DirZ;
00127     float W = Orientation.w;
00128     float X = Orientation.x;
00129     float Y = Orientation.y;
00130     float Z = Orientation.z;
00131     DirX = 2.0 * ( X * Z - W * Y );
00132     DirY = 2.0 * ( Y * Z + W * X );
00133     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00134     Position.x += DirX * Movement_z * Multiplier;
00135     Position.y += DirY * Movement_z * Multiplier;
00136     Position.z += DirZ * Movement_z * Multiplier;
00137 }
00138 
00139 void OBJECT::MoveX(float x)
00140 {
00141     float DirX;
00142     float DirY;
00143     float DirZ;
00144     float W;
00145     float X;
00146     float Y;
00147     float Z;
00148     QUAT TempQuat;
00149     QUAT TempQuat2;
00150     TempQuat = Orientation;
00151     TempQuat2.EulerToQuat(0.0, -90.0*(pi/180), 0.0);
00152     TempQuat.MultQuat(TempQuat2);
00153     W = TempQuat.w;
00154     X = TempQuat.x;
00155     Y = TempQuat.y;
00156     Z = TempQuat.z;
00157     DirX = 2.0 * ( X * Z - W * Y );
00158     DirY = 2.0 * ( Y * Z + W * X );
00159     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00160     Position.x += DirX * x;
00161     Position.y += DirY * x;
00162     Position.z += DirZ * x;
00163 }
00164 
00165 void OBJECT::MoveY(float y)
00166 {
00167     float DirX;
00168     float DirY;
00169     float DirZ;
00170     float W;
00171     float X;
00172     float Y;
00173     float Z;
00174     QUAT TempQuat;
00175     QUAT TempQuat2;
00176     TempQuat = Orientation;
00177     TempQuat2.EulerToQuat(90.0*(pi/180), 0.0, 0.0);
00178     TempQuat.MultQuat(TempQuat2);
00179     W = TempQuat.w;
00180     X = TempQuat.x;
00181     Y = TempQuat.y;
00182     Z = TempQuat.z;
00183     DirX = 2.0 * ( X * Z - W * Y );
00184     DirY = 2.0 * ( Y * Z + W * X );
00185     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00186     Position.x += DirX * y;
00187     Position.y += DirY * y;
00188     Position.z += DirZ * y;
00189 }
00190 
00191 void OBJECT::MoveZ(float z)
00192 {
00193     float DirX;
00194     float DirY;
00195     float DirZ;
00196     float W = Orientation.w;
00197     float X = Orientation.x;
00198     float Y = Orientation.y;
00199     float Z = Orientation.z;
00200     DirX = 2.0 * ( X * Z - W * Y );
00201     DirY = 2.0 * ( Y * Z + W * X );
00202     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00203     Position.x += DirX * z;
00204     Position.y += DirY * z;
00205     Position.z += DirZ * z;
00206 }
00207 
00208 VECTOR OBJECT::GetXUnit()
00209 {
00210     float DirX;
00211     float DirY;
00212     float DirZ;
00213     float W;
00214     float X;
00215     float Y;
00216     float Z;
00217     QUAT TempQuat;
00218     QUAT TempQuat2;
00219     TempQuat = Orientation;
00220     TempQuat2.EulerToQuat(0.0, -90.0*(pi/180), 0.0);
00221     TempQuat.MultQuat(TempQuat2);
00222     W = TempQuat.w;
00223     X = TempQuat.x;
00224     Y = TempQuat.y;
00225     Z = TempQuat.z;
00226     DirX = 2.0 * ( X * Z - W * Y );
00227     DirY = 2.0 * ( Y * Z + W * X );
00228     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00229     VECTOR Unit;
00230     Unit.x += DirX * 1;
00231     Unit.y += DirY * 1;
00232     Unit.z += DirZ * 1;
00233     return Unit;
00234 }
00235 
00236 VECTOR OBJECT::GetYUnit()
00237 {
00238     float DirX;
00239     float DirY;
00240     float DirZ;
00241     float W;
00242     float X;
00243     float Y;
00244     float Z;
00245     QUAT TempQuat;
00246     QUAT TempQuat2;
00247     TempQuat = Orientation;
00248     TempQuat2.EulerToQuat(90.0*(pi/180), 0.0, 0.0);
00249     TempQuat.MultQuat(TempQuat2);
00250     W = TempQuat.w;
00251     X = TempQuat.x;
00252     Y = TempQuat.y;
00253     Z = TempQuat.z;
00254     DirX = 2.0 * ( X * Z - W * Y );
00255     DirY = 2.0 * ( Y * Z + W * X );
00256     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00257     VECTOR Unit;
00258     Unit.x += DirX * 1;
00259     Unit.y += DirY * 1;
00260     Unit.z += DirZ * 1;
00261     return Unit;
00262 }
00263 
00264 VECTOR OBJECT::GetZUnit()
00265 {
00266     float DirX;
00267     float DirY;
00268     float DirZ;
00269     float W = Orientation.w;
00270     float X = Orientation.x;
00271     float Y = Orientation.y;
00272     float Z = Orientation.z;
00273     DirX = 2.0 * ( X * Z - W * Y );
00274     DirY = 2.0 * ( Y * Z + W * X );
00275     DirZ = 1.0 - 2.0 * ( X * X + Y * Y );
00276     VECTOR Unit;
00277     Unit.x += DirX * 1;
00278     Unit.y += DirY * 1;
00279     Unit.z += DirZ * 1;
00280     return Unit;
00281 }
00282 

Generated on Fri Dec 23 05:21:20 2005 for Skybox by doxygen1.2.15