My Project
SpriteObject.h
1 #pragma once
2 #include "TileObject.h"
3 
4 namespace ParaEngine
5 {
6 struct D3DXSpriteEntity;
7 
17 #define SPRITE_HORIZONTAL_PLANE 0
20 #define SPRITE_Y_FACINGCAMERA 1
22 #define SPRITE_FREETRANSFORM 2
24 #define SPRITE_FACINGCAMERA 3
26 #define SPRITE_3D_SCREEN 4
28 #define SPRITE_2D 5
30 #define SPRITE_END1 7
32 
35 #define SPRITE_RENDER_ALPHA 8
36 #define SPRITE_RENDER_ZBUFFER 16
38 #define SPRITE_RENDER_BATCH 32
40 
41 
42 struct TextureEntity;
58 class CSpriteObject : public CTileObject
59 {
60 public:
61  virtual CBaseObject::_SceneObjectType GetType(){return CBaseObject::SpriteObject;};
62 
64  FLOAT m_fWidth, m_fHeight;
68  D3DXSpriteEntity* m_pSprite;
69 
70  //-- info in the animation texture
76  UINT m_num_frames;
77 
78  //-- rendering attributes
81  BOOL CheckSpriteStyleField(DWORD dwType){
82  if(dwType<=SPRITE_END1)
83  return (m_sprite_style&SPRITE_END1) == dwType;
84  else
85  return ((m_sprite_style & dwType)>0);};
88 
89  //-- frames to play in the texture
94  UINT m_nEndFrame;
96  bool m_bLoop;
98  bool m_bAnimate;
101 
102 protected:
103  double m_dTimeSinceLastUpdate;
104 
106  void AdvanceFrame(double fTimeDelta)
107  {
108  if(m_bAnimate)
109  {
110  m_dTimeSinceLastUpdate+=fTimeDelta;
111  if(m_dTimeSinceLastUpdate > m_dTimeInterval*m_num_frames)
112  {
113  m_nCurrentFrameOffset = m_nStartFrame;
114  m_dTimeSinceLastUpdate = 0;
115  }
116  else if(m_dTimeSinceLastUpdate > m_dTimeInterval)
117  {
118  m_nCurrentFrameOffset++;
119  m_dTimeSinceLastUpdate = 0;
120  }
121 
122  if((m_nStartFrame+m_nCurrentFrameOffset) > m_nEndFrame)
123  {
124  if(m_bLoop)
125  m_nCurrentFrameOffset = m_nStartFrame;
126  else
127  m_nCurrentFrameOffset = m_nEndFrame;
128  }
129  }
130  };
131 public:
133  virtual HRESULT Draw( SceneState * sceneState);
137  HRESULT InitObject(D3DXSpriteEntity* pSprite,TextureEntity* ppTexture, Vector3 vPos,
138  FLOAT fWidth=1.0f, FLOAT fHeight=1.0f, DWORD sprite_style=0);
139  void SetRenderState(LPDIRECT3DDEVICE9 pd3dDevice);
140  void RestoreRenderState(LPDIRECT3DDEVICE9 pd3dDevice);
141 
142 public:
143  CSpriteObject(void);
144  virtual ~CSpriteObject(void);
145 };
146 }
UINT m_nStartFrame
animation is looped between m_nStartFrame and m_nEndFrame
Definition: SpriteObject.h:93
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
DWORD m_sprite_style
see above macro definitions
Definition: SpriteObject.h:80
It&#39;s used as parameter to Draw method of each scene object.
Definition: SceneState.h:284
virtual AssetEntity * GetPrimaryAsset()
used as KEY for batch rendering
Definition: SpriteObject.h:135
RECT m_rcFirstImageRect
rect of the first image in the texture
Definition: SpriteObject.h:74
different physics engine has different winding order.
Definition: EventBinding.h:32
double m_dTimeInterval
the time to change to next frame
Definition: SpriteObject.h:100
Color m_colorkey
The ref transparent key.
Definition: SpriteObject.h:85
Definition: ManagedDef.h:18
UINT m_num_frames
how many frames are there.
Definition: SpriteObject.h:76
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
void AdvanceFrame(double fTimeDelta)
always loop between m_nStartFrame and m_nEndFrame(inclusive).
Definition: SpriteObject.h:106
bool m_bAnimate
whether to play animation
Definition: SpriteObject.h:98
HRESULT InitObject(D3DXSpriteEntity *pSprite, TextureEntity *ppTexture, Vector3 vPos, FLOAT fWidth=1.0f, FLOAT fHeight=1.0f, DWORD sprite_style=0)
– for init and delete
Definition: SpriteObject.cpp:168
UINT m_nCurrentFrameOffset
m_nStartFrame+m_nCurrentFrameOffset => current frame
Definition: SpriteObject.h:91
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
Matrix4 m_mxWorldMatrix
used in free transform style only to specify world tranform,it can be set by the user ...
Definition: SpriteObject.h:66
TextureEntity * m_ppTexture
texture
Definition: SpriteObject.h:72
Tile Object have position and bounding rect and can usually be attached to quad-tree terrain tile...
Definition: TileObject.h:10
bool m_bLoop
whether to loop the animation
Definition: SpriteObject.h:96
Definition: ParaColor.h:275
OBSOLETED Sprite object can either be used in the 3D space or 2D screen ordinates.
Definition: SpriteObject.h:58
D3DXSpriteEntity * m_pSprite
Sprite.
Definition: SpriteObject.h:68
FLOAT m_fWidth
size of the object in the world coordinates
Definition: SpriteObject.h:61
virtual HRESULT Draw(SceneState *sceneState)
– for rendering
Definition: SpriteObject.cpp:48
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25