home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 11 / Engine / SceneObject.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  4.4 KB  |  120 lines

  1. //-----------------------------------------------------------------------------
  2. // The minimum requirements for an object to exist in a 3D scene. Application
  3. // specific objects must derive from this class.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #ifndef SCENE_OBJECT_H
  9. #define SCENE_OBJECT_H
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Scene Object Type Define
  13. //-----------------------------------------------------------------------------
  14. #define TYPE_SCENE_OBJECT 0
  15.  
  16. //-----------------------------------------------------------------------------
  17. // Scene Object Class
  18. //-----------------------------------------------------------------------------
  19. class SceneObject : public BoundingVolume
  20. {
  21. public:
  22.     SceneObject( unsigned long type = TYPE_SCENE_OBJECT, char *meshName = NULL, char *meshPath = "./", bool sharedMesh = true );
  23.     virtual ~SceneObject();
  24.  
  25.     virtual void Update( float elapsed, bool addVelocity = true );
  26.     virtual void Render( D3DXMATRIX *world = NULL );
  27.  
  28.     virtual void CollisionOccurred( SceneObject *object, unsigned long collisionStamp );
  29.  
  30.     void Drive( float force, bool lockYAxis = true );
  31.     void Strafe( float force, bool lockYAxis = true );
  32.     void Stop();
  33.  
  34.     void SetTranslation( float x, float y, float z );
  35.     void SetTranslation( D3DXVECTOR3 translation );
  36.     void AddTranslation( float x, float y, float z );
  37.     void AddTranslation( D3DXVECTOR3 translation );
  38.     D3DXVECTOR3 GetTranslation();
  39.  
  40.     void SetRotation( float x, float y, float z );
  41.     void SetRotation( D3DXVECTOR3 rotation );
  42.     void AddRotation( float x, float y, float z );
  43.     void AddRotation( D3DXVECTOR3 rotation );
  44.     D3DXVECTOR3 GetRotation();
  45.  
  46.     void SetVelocity( float x, float y, float z );
  47.     void SetVelocity( D3DXVECTOR3 velocity );
  48.     void AddVelocity( float x, float y, float z );
  49.     void AddVelocity( D3DXVECTOR3 velocity );
  50.     D3DXVECTOR3 GetVelocity();
  51.  
  52.     void SetSpin( float x, float y, float z );
  53.     void SetSpin( D3DXVECTOR3 spin );
  54.     void AddSpin( float x, float y, float z );
  55.     void AddSpin( D3DXVECTOR3 spin );
  56.     D3DXVECTOR3 GetSpin();
  57.  
  58.     D3DXVECTOR3 GetForwardVector();
  59.     D3DXVECTOR3 GetRightVector();
  60.  
  61.     D3DXMATRIX *GetTranslationMatrix();
  62.     D3DXMATRIX *GetRotationMatrix();
  63.     D3DXMATRIX *GetWorldMatrix();
  64.     D3DXMATRIX *GetViewMatrix();
  65.  
  66.     void SetType( unsigned long type );
  67.     unsigned long GetType();
  68.  
  69.     void SetFriction( float friction );
  70.  
  71.     unsigned long GetCollisionStamp();
  72.  
  73.     void SetVisible( bool visible );
  74.     bool GetVisible();
  75.  
  76.     void SetEnabled( bool enabled );
  77.     bool GetEnabled();
  78.  
  79.     void SetGhost( bool ghost );
  80.     bool GetGhost();
  81.  
  82.     void SetIgnoreCollisions( bool ignoreCollisions );
  83.     bool GetIgnoreCollisions();
  84.  
  85.     void SetTouchingGroundFlag( bool touchingGround );
  86.     bool IsTouchingGround();
  87.  
  88.     void SetMesh( char *meshName = NULL, char *meshPath = "./", bool sharedMesh = true );
  89.     Mesh *GetMesh();
  90.  
  91. protected:
  92.     D3DXVECTOR3 m_forward; // Object's forward vector.
  93.     D3DXVECTOR3 m_right; // Object's right vector.
  94.  
  95.     D3DXMATRIX m_worldMatrix; // World matrix.
  96.     D3DXMATRIX m_viewMatrix; // View matrix.
  97.  
  98. private:
  99.     D3DXVECTOR3 m_translation; // Object's translation in 3D space.
  100.     D3DXVECTOR3 m_rotation; // Object's rotation in radians.
  101.  
  102.     D3DXVECTOR3 m_velocity; // Object's velocity in units/second.
  103.     D3DXVECTOR3 m_spin; // Object's spin in radians/second.
  104.  
  105.     D3DXMATRIX m_translationMatrix; // Translation matrix.
  106.     D3DXMATRIX m_rotationMatrix; // Rotation matrix.
  107.  
  108.     unsigned long m_type; // Identifies the scene object's parent class.
  109.     float m_friction; // Friction applied to the object's velocity and spin.
  110.     unsigned long m_collisionStamp; // Indicates the last frame when a collision occurred.
  111.     bool m_visible; // Indicates it the object is visible. Invisible objects are not rendered.
  112.     bool m_enabled; // Indicates if the object is enabled. Disabled objects are not updated.
  113.     bool m_ghost; // Indicates if the object is a ghost. Ghost objects cannot physically collide with anything.
  114.     bool m_ignoreCollisions; // Indicates if the object is to ignore collisions. Physical collisions can still occur, they're just not registered.
  115.     bool m_touchingGround; // Indicates if the object is touching the ground.
  116.     bool m_sharedMesh; // Indicates if the object is sharing the mesh or has exclusive access.
  117.     Mesh *m_mesh; // Pointer to the object's mesh.
  118. };
  119.  
  120. #endif