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

Generated on Fri Dec 23 05:15:47 2005 for Constructive Solid Geometry by doxygen1.2.15