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

Generated on Fri Dec 23 05:19:34 2005 for OpenGL MDI 2 by doxygen1.2.15