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 / Example4 / Plane.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  3.2 KB  |  120 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. #include "GameDatabase.h"
  20. #include "Network.h"
  21. #include "GameClass.h"
  22.  
  23. extern CD3DMesh*     gpAirplaneMesh;
  24.  
  25. Plane::Plane()
  26. {
  27.     SetReplicaObject(this);        // Setup our forward reference pointer
  28.     mMesh = gpAirplaneMesh;
  29.     mPosition = D3DXVECTOR4(0,0,0,0);
  30.     mRotation = D3DXVECTOR4(0,0,0,0);
  31.  
  32.     mPlayerNumber = rand() & 7;
  33.     mPlayerColour = rand() & 7;
  34.     mPlayerEnergy = 1.0f;
  35.  
  36.     mSpeed = 40.0f;
  37. //    mSpeed = 10.0f;
  38. //    mSpeed = 0.0f;
  39. }
  40.  
  41. Plane::~Plane()
  42. {
  43.     // If this plane is being deleted and it is being used as the camera plane then
  44.     // disconnect it from the application so the camera does not use a hanging pointer.
  45.     if (CMyD3DApplication::GetCMyD3DApplication()->mPlayerConrolledPlane == this)
  46.     {
  47.         CMyD3DApplication::GetCMyD3DApplication()->mPlayerConrolledPlane = 0;
  48.     }
  49. }
  50.  
  51. void Plane::PostObjectCreate(void)
  52. {
  53.     // If we are playing back a recording and the plane sessionID matches with the recorded sessionID
  54.     // then set the controlled plane pointer so the camera can use it to render with.
  55.     if (Network::mNetwork->GetSessionPlayback() && GetSessionID() == Network::mNetwork->GetSessionID())
  56.     {
  57.         CMyD3DApplication::GetCMyD3DApplication()->mPlayerConrolledPlane = this;
  58.     }
  59. }
  60.  
  61. void Plane::PollIt(void)
  62. {
  63.     // Only run the "physics" if we are a master object
  64.     if (!IsMaster())
  65.     {
  66.         return;
  67.     }
  68.  
  69.     if (mSpeed > 0.1f)
  70.     {
  71.     D3DXVECTOR4 velocity = D3DXVECTOR4(0,0,-mSpeed,0);
  72. //    mRotation.y += D3DXToRadian(0.1f);
  73.  
  74.     // Calculate the velocity movement
  75.     D3DXMatrixRotationYawPitchRoll(&m_matObjectMatrix,mRotation.y,mRotation.x,mRotation.z);
  76.     D3DXVECTOR4 trans;
  77.     D3DXVec4Transform(&trans,&velocity,&m_matObjectMatrix);
  78.  
  79.     mPosition += trans * GameDatabase::mGameFrameTick;
  80.     GiveDeltaHint(mPosition.x,trans.x);
  81.     GiveDeltaHint(mPosition.y,trans.y);
  82.     GiveDeltaHint(mPosition.z,trans.z);
  83.     }
  84.  
  85. #define LIMIT (140.0f)
  86.  
  87.     if (mPosition.x < -LIMIT)
  88.     {
  89.         mPosition.x = -LIMIT;
  90.         GiveDeltaHint(mPosition.x,0);
  91.     }
  92.     if (mPosition.z < -LIMIT)
  93.     {
  94.         mPosition.z = -LIMIT;
  95.         GiveDeltaHint(mPosition.z,0);
  96.     }
  97.     if (mPosition.x > LIMIT)
  98.     {
  99.         mPosition.x = LIMIT;
  100.         GiveDeltaHint(mPosition.x,0);
  101.     }
  102.     if (mPosition.z > LIMIT)
  103.     {
  104.         mPosition.z = LIMIT;
  105.         GiveDeltaHint(mPosition.z,0);
  106.     }
  107.     if (mPosition.y < -6.0f)
  108.     {
  109.         mPosition.y = -6.0f;
  110.         GiveDeltaHint(mPosition.y,0);
  111.     }
  112.     if (mPosition.y > 500.0f)
  113.     {
  114.         mPosition.y = 500.0f;
  115.         GiveDeltaHint(mPosition.y,0);
  116.     }
  117.  
  118. }
  119.  
  120.