home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / ReplicaNetFreewareV5_4.exe / data1.cab / Program_Executable_Files / Example1 / Plane.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.5 KB  |  93 lines

  1. /* START_LICENSE_HEADER
  2.  
  3. Copyright (C) 2000 Martin Piper, original design and program code
  4. Copyright (C) 2001-2005 Replica Software
  5.  
  6. This program file is copyright (C) Replica Software and can only be used under license.
  7. For more information visit: http://www.replicanet.com/
  8. Or email: info@replicanet.com
  9.  
  10. END_LICENSE_HEADER */
  11. /*
  12. The Plane game object. Every tick the plane will move a little furthur around in a circle.
  13. This object have corresponding ROL files in the ROLFiles folder. The ROL files are compiled by the ROLCompiler.
  14. The CompiledGameObjects folder contains the compiled ROL definition file for this object. The member variables listed
  15. in the ROL file for this class are automatically updated when this object is allocated on another machine
  16. */
  17. #include "Plane.h"
  18. #include "Camera.h"
  19.  
  20. extern CD3DMesh*     gpAirplaneMesh;
  21.  
  22. Plane::Plane()
  23. {
  24.     mReplica = this;        // Setup our forward reference pointer
  25.     mMesh = gpAirplaneMesh;
  26.     mPosition = D3DXVECTOR4(0,0,0,0);
  27.     mRotation = D3DXVECTOR4(0,0,0,0);
  28.  
  29.     mPlayerNumber = rand() & 7;
  30.     mPlayerColour = rand() & 7;
  31.     mPlayerEnergy = 1.0f;
  32.  
  33. //    mShadow = new ShadowVolume();
  34. }
  35.  
  36. Plane::~Plane()
  37. {
  38. }
  39.  
  40. void Plane::PollIt(void)
  41. {
  42.     // Only run the "physics" if we are a master object
  43.     if (!IsMaster())
  44.     {
  45.         return;
  46.     }
  47.  
  48.     D3DXVECTOR4 velocity = D3DXVECTOR4(0,0,-0.05f,0);
  49.     mRotation.y += D3DXToRadian(0.05f);
  50.     mRotation.y += D3DXToRadian(0.05f);
  51.  
  52.     // Calculate the velocity movement
  53.     D3DXMatrixRotationYawPitchRoll(&m_matObjectMatrix,mRotation.y,mRotation.x,mRotation.z);
  54.     D3DXVECTOR4 trans;
  55.     D3DXVec4Transform(&trans,&velocity,&m_matObjectMatrix);
  56.     mPosition += trans;
  57. }
  58.  
  59. /*
  60. This callback is used by the distance based prediction to calculate the distance to another object in our game
  61. */
  62. float Plane::CalculateDistanceToObject(ReplicaObject *object)
  63. {
  64.     if (object->GetClassID() == _RO_Camera::StaticGetClassID())
  65.     {
  66.         Camera *gameobject = (Camera *) object;
  67.  
  68.         D3DXVECTOR4 pos = gameobject->GetPosition();
  69.  
  70.         pos.x = mPosition.x - pos.x;
  71.         pos.y = mPosition.y - pos.y;
  72.         pos.z = mPosition.z - pos.z;
  73.         return sqrtf( (pos.x*pos.x) + (pos.y*pos.y) + (pos.z*pos.z));
  74.     }
  75.     return kReplicaObject_InfiniteDistance;
  76. }
  77.  
  78. /*
  79. This callback returns true which means if a session quits then the fault tolerant
  80. mechanism makes the plane get transfered from the session that left to another session
  81. */
  82. bool Plane::ApproveFault(void)
  83. {
  84.     return true;
  85. }
  86.  
  87. /*
  88. This callback lets us know if the plane object changes who owns the object
  89. */
  90. void Plane::OwnerChange(void)
  91. {
  92. }
  93.