home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / GameObject.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-23  |  1.9 KB  |  75 lines

  1. #include "GameObject.h"
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. GameObject::GameObject(){
  7.     vectorInit3d(0.0, 0.0, 0.0, pos);
  8.     vectorInit3d(0.0, 0.0, 1.0, dir);
  9.     vectorInit3d(0.0, 1.0, 0.0, up);
  10.     vectorInit3d(1.0, 0.0, 0.0, left);
  11.     vectorInit3d(0.0, 0.0, 0.0, vel);
  12.     yaw=0.0f;
  13.     pitch=PI*0.5f;
  14.     turnSpeed=0.0f;
  15.     moveSpeed=0.0f;
  16.  
  17.     attachedDlpcs.clear();
  18. }
  19.  
  20. GameObject::~GameObject(){
  21. //    list<DynamicLightParticleCluster*>::iterator iter = attachedDlpcs.begin();
  22.     while( !attachedDlpcs.empty() ){
  23.         Renderer::particleSystem.unlinkParticleCluster( attachedDlpcs.front() );
  24.         delete attachedDlpcs.front();    // this will result in a call to detachDLPC() and remove the item
  25.     }
  26. }
  27.  
  28. void GameObject::reconstructVectors(){
  29.     vectorCrossP3d(up, dir, left);
  30.     vectorCrossP3d(dir, left, up);
  31.  
  32.     vectorNormalize3d(dir, dir);
  33.     vectorNormalize3d(up, up);
  34.     vectorNormalize3d(left, left);
  35. }
  36.  
  37. void GameObject::vectorsFromAngles(){
  38.     vectorInit3d((float)(cos(yaw)*sin(pitch)), (float)(cos(pitch)), (float)(sin(yaw)*sin(pitch)), dir);
  39.     float upPitch=pitch - PI*0.5f;
  40.     vectorInit3d((float)(cos(yaw)*sin(upPitch)), (float)(cos(upPitch)), (float)(sin(yaw)*sin(upPitch)), up);
  41.     vectorCrossP3d(up, dir, left);
  42. }
  43.  
  44. void GameObject::anglesFromVectors(){
  45.     pitch = (float)acos( dir[1] );
  46. //    yaw = vectorAngle3d( left
  47.     if( left[0] < 0.0f ){
  48.         yaw = PI + (float)acos(left[2]);
  49.     }else{
  50.         yaw = /*PI*0.5f + */(float)acos(-left[2]);
  51.     }
  52. }
  53.  
  54.  
  55. /*
  56. void GameObject::move(float deltaT){
  57.     if(vectorLengthSquared3d(vel)<0.0001f)
  58.         return;
  59.  
  60.     vectorNormalize3d(vel, vel);
  61.     vectorScale3d(deltaT*moveSpeed, vel, vel);
  62.     if(noclip || collisionDetection(vel))        // check if move is save
  63.         vectorAdd3d(pos, vel, pos);    // ...and move
  64. }
  65. */
  66.  
  67.  
  68. void GameObject::attachDynamicLightParticleCluster(DynamicLightParticleCluster* dlpc){
  69.     attachedDlpcs.push_back(dlpc);
  70. }
  71.  
  72. void GameObject::detachDynamicLightParticleCluster(DynamicLightParticleCluster* dlpc){
  73.     attachedDlpcs.remove(dlpc);
  74. }
  75.