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 / Projectile.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-30  |  2.7 KB  |  109 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. See Projectile.cpp
  13. */
  14. #ifndef __PROJECTILE_H__
  15. #define __PROJECTILE_H__
  16.  
  17. #include "d3dfile.h"
  18.  
  19. #include "GameObject.h"
  20.  
  21. #include "_RO_Projectile.h"
  22.  
  23. class Projectile : _RO_DO_PUBLIC_RO(Projectile) , public GameObject
  24. {
  25. public:
  26.     Projectile();
  27.     virtual ~Projectile();
  28.  
  29.     void Render(void);
  30.  
  31.     void PollIt(void);
  32.  
  33.     bool GetPosition(D3DXVECTOR4 &input)
  34.     {
  35.         input = mPosition;
  36.         return true;
  37.     }
  38.  
  39.     D3DXVECTOR4 GetPosition(void)
  40.     {
  41.         return mPosition;
  42.     }
  43.  
  44.     void SetPosition(D3DXVECTOR4 pos)
  45.     {
  46.         mPosition = pos;
  47.         // Our position is being set by an outside class and since we don't know what out new velocity is yet we give the network layer a hint that it's changed
  48.         GiveDeltaHint(mPosition.x,0);
  49.         GiveDeltaHint(mPosition.y,0);
  50.         GiveDeltaHint(mPosition.z,0);
  51.     }
  52.  
  53.     D3DXVECTOR4 GetRotation(void)
  54.     {
  55.         return mRotation;
  56.         // Our position is being set by an outside class and since we don't know what out new velocity is yet we give the network layer a hint that it's changed
  57.     }
  58.  
  59.     void SetRotation(D3DXVECTOR4 rot)
  60.     {
  61.         mRotation = rot;
  62.         GiveDeltaHint(mRotation.x,0);
  63.         GiveDeltaHint(mRotation.y,0);
  64.         GiveDeltaHint(mRotation.z,0);
  65.  
  66.         D3DXVECTOR4 velocity = D3DXVECTOR4(0,0,-100.05f,0);
  67.  
  68.         // Calculate the velocity movement
  69.         D3DXMatrixRotationYawPitchRoll(&m_matObjectMatrix,mRotation.y,mRotation.x,mRotation.z);
  70.         D3DXVECTOR4 trans;
  71.         D3DXVec4Transform(&trans,&velocity,&m_matObjectMatrix);
  72.         GiveDeltaHint(mPosition.x,trans.x);
  73.         GiveDeltaHint(mPosition.y,trans.y);
  74.         GiveDeltaHint(mPosition.z,trans.z);
  75.     }
  76.  
  77.     CD3DMesh *mMesh;
  78.     D3DXMATRIX    m_matObjectMatrix;
  79.  
  80.     void OwnerChange(void)
  81.     {
  82.     }
  83.  
  84.     void *GetOpaquePointer(void *data = 0)
  85.     {
  86.         return (GameObject *)(this);
  87.     }
  88.  
  89.     /*
  90.     This callback is used by the distance based prediction to calculate the distance to another object in our game
  91.     */
  92.     float CalculateDistanceToObject(RNReplicaNet::ReplicaObject *object)
  93.     {
  94.         // Since the OpaquePointer is always the GameObject pointer for each object we can do this cast safely
  95.         GameObject *gameobject = (GameObject *) object->GetOpaquePointer();
  96.         return GameObject::CalculateDistanceToObject(gameobject);
  97.     }
  98.  
  99. /* These variables are defined in the ROL file for this object */
  100. private:
  101. _RO_DO_ALLOW_FRIEND_RO(Projectile);
  102.     D3DXVECTOR4 mPosition;
  103.     D3DXVECTOR4 mRotation;
  104.  
  105.     float mLifetime;
  106. };
  107.  
  108. #endif
  109.