12 }
13
14 CDxSprite::CDxSprite(short _id, CDxTexture *_tex, UINT _type, UINT _tx, UINT _ty, UINT _tw, UINT _th)
15 {
16 m_id = _id;
17
18 m_tex = _tex;
19
20 m_type = _type;
21
22 m_rect.left = _tx;
23
24 m_rect.top = _ty;
25
26 m_rect.right = _tx + _tw;
27
28 m_rect.bottom = _ty + _th;
29
30 m_width = _tw;
31
32 m_hight = _th;
33
34 m_vcenter.x = 0;
35
36 m_vcenter.y = 0;
37
38 m_vcenter.z = 0;
39
40 m_position.x = 0;
41
42 m_position.y = 0;
43
44 m_position.z = 0;
45 }
46
47
48
49 void CDxSprite::Render(DFPOINT _pos)
50 {
51 //精灵的坐标x
52 m_position.x = _pos.x;
53
54 //精灵的左边y
55 m_position.y = _pos.y;
56
57 if(CDx9App::GetDx9App().GetD3dSprite())
58 {
59 CDx9App::GetDx9App().GetD3dSprite()->Draw(m_tex->GetTex(),&m_rect,
60 &m_vcenter,&m_position,-1);
61 }
62 }
63
64
65 void CDxSprite:: Render(DFPOINT _pos,DOUBLE _Angle)
66 {
67 //旋转,平移矩阵 www.2cto.com
68 D3DXMATRIX matWorld,matRotationZ,matWorld1;
69
70 CDx9App::GetDx9App().GetD3dSprite()->SetTransform(&matRotationZ);
71
72 //精灵的坐标x
73 m_position.x = _pos.x;
74
75 //精灵的左边y
76 m_position.y = _pos.y;
77
78 FLOAT x = (GetWidth()/2);
79
80 FLOAT y = (GetHight()/2);
82 D3DXMatrixTranslation(&matWorld, -x, -y,0);
83
84 D3DXMatrixRotationZ(&matRotationZ,(2*PAI) - _Angle);
85
86 D3DXMatrixTranslation(&matWorld1,m_position.x,m_position.y,0);
87
88 matWorld = matWorld*matRotationZ*matWorld1 ;
89
90 CDx9App::GetDx9App().GetD3dSprite()->SetTransform(&matWorld);
91
92 if(CDx9App::GetDx9App().GetD3dSprite())
93 {
94 CDx9App::GetDx9App().GetD3dSprite()->Draw(m_tex->GetTex(),&m_rect,&m_vcenter,&D3DXVECTOR3(0,0,0),-1);
95 }
96 }
97
98
99 void CDxSprite::Render(DFPOINT _pos,FLOAT _x,FLOAT _y)
100 {
101 //旋转,平移矩阵
102 D3DXMATRIX matScall, matMove, matMove1,matMove2,matResult;
103
104 //精灵的坐标x
105 m_position.x = _pos.x;
106
107 //精灵的左边y
108 m_position.y = _pos.y;
109
110 FLOAT x = (GetWidth()/2);
111
112 FLOAT y = (GetHight()/2);
113
114 //缩放
115 D3DXMatrixScaling(&matScall, _x ,_y, 0);
116
117 //为了让精灵在反转的时候坐标不改变做了平移处理
118 if(_x == -1)
119 D3DXMatrixTranslation(&matMove,GetWidth(),0, 0);
120
121 if(_y == -1)
122 D3DXMatrixTranslation(&matMove2,0,GetHight(), 0);
123
124 if(_x!=-1&&_y!=-1)
125 D3DXMatrixTranslation(&matMove,0,0, 0);
126
127 //平移
128 D3DXMatrixTranslation(&matMove1,m_position.x ,m_position.y, 0);
129
130 //计算结果
131 if(_x == -1)
132 matResult = matScall*matMove*matMove1 ;
133
134 if(_y == -1)
135 matResult = matScall*matMove2*matMove1 ;
136
137 if(_x!=-1&&_y!=-1)
138 matResult = matScall*matMove ;
139
140 if(_x ==-1&&_y == -1)
141 matResult = matScall*matMove*matMove2*matMove1 ;
142
143 if(_x == 1&&_y == 1)
144 matResult = matScall*matMove*matMove1;
145
146 if(_x>1)
147 matResult = matScall*matMove*matMove1;
148 if(_y>1)
149 matResult = matScall*matMove*matMove1;
150