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 / Example9 / Plane.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  3.1 KB  |  102 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 "Dolphin.h"
  19.  
  20. using namespace RNReplicaNet;
  21.  
  22. extern CD3DMesh*     gpAirplaneMesh;
  23.  
  24. Plane::Plane()
  25. {
  26.     mReplica = this;        // Setup our forward reference pointer
  27.     mMesh = gpAirplaneMesh;
  28.     mPosition = D3DXVECTOR4(0,0,0,0);
  29.     mRotation = D3DXVECTOR4(0,0,0,0);
  30.  
  31.     // Enable the session propagation mechanism for this object
  32.     SetSessionPropagationFilter(true);
  33.  
  34. //    mShadow = new ShadowVolume();
  35. }
  36.  
  37. Plane::~Plane()
  38. {
  39. }
  40.  
  41. void Plane::PollIt(void)
  42. {
  43.     // Only run the "physics" if we are a master object
  44.     if (!IsMaster())
  45.     {
  46.         return;
  47.     }
  48.  
  49.     D3DXVECTOR4 velocity = D3DXVECTOR4(0,0,-0.05f,0);
  50.     mRotation.y += D3DXToRadian(0.1f);
  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.     // Now look for dolphin classes and update if we are to propagate to these
  60.     int i;
  61.     for (i=0;i<(int)gGameObjects.size();i++)
  62.     {
  63.         ReplicaObject *robject;
  64.  
  65.         // Get the derived class object pointer that contains a base class type of ReplicaObject from the GameObject class
  66.         robject = gGameObjects[i]->mReplica;
  67.         // If there is an object pointer
  68.         if (robject)
  69.         {
  70.             // Compare the class id of the ReplicaObject with the class ID of the ReplicaObject Dolphin object
  71.             if (robject->GetClassID() == _MAKE_RO(Dolphin)::StaticGetClassID())
  72.             {
  73.                 D3DXVECTOR4 temp = GetPosition() - gGameObjects[i]->GetPosition();
  74.                 float distance = D3DXVec4Length(&temp);
  75.                 // Check the distance
  76.                 if (distance < 30.0f)
  77.                 {
  78.                     // It is within the distance so we try to propagate to the object's sessionID
  79.                     int sessionID = robject->GetSessionID();
  80.                     if (SessionPropagationAddSession(sessionID))
  81.                     {
  82.                         char buffer[256];
  83.                         sprintf(buffer,"Added %d:%d to %d\n",GetSessionID(),GetUniqueID(),sessionID);
  84.                         OutputDebugString(buffer);
  85.                     }
  86.                 }
  87.                 else
  88.                 {
  89.                     // It is outside the distance so we remove the propagate using object's sessionID
  90.                     int sessionID = robject->GetSessionID();
  91.                     if (SessionPropagationRemoveSession(sessionID))
  92.                     {
  93.                         char buffer[256];
  94.                         sprintf(buffer,"Removed %d:%d from %d\n",GetSessionID(),GetUniqueID(),sessionID);
  95.                         OutputDebugString(buffer);
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.     }
  101. }
  102.