Graphics Reference
In-Depth Information
class CRectangle2D {
public :
.
// constructor and destructor (not shown)
Source file.
Rectangle2D.h/cpp file
in the Primitives folders of
the D3D _ RectangleClass
project.
void SetCenter( float x, float y);
void SetSize( float width, float height);
void Draw( LPDIRECT3DDEVICE9 pDevice ) const ;
private :
float m _ center _ x, m _ center _ y; // Center of the rectangle
float m _ width, m _ height;
// Width and Height of the rectangle
};
This is the implementation of CRectangle2D class.
. // constructor and destructor (not shown)
void CRectangle2D::SetCenter( float x, float y){
... }
void CRectangle2D::SetSize( float width, float height) {
... }
Draw: This is the function that draws a rectangle to the graphics device.
void CRectangle2D:: Draw ( LPDIRECT3DDEVICE9 pDevice) const
{
if (pDevice) { // if device is defined
.
Compute vertex positions from the center/width/height representation.
v[0].m _ point = D3DXVECTOR3 (m _ center _ x-m _ width/2.0f, m _ center _ y+m _ height/2.0f, 0);
v[1].m _ point = D3DXVECTOR3 (m _ center _ x-m _ width/2.0f, m _ center _ y-m _ height/2.0f, 0);
v[2].m _ point = D3DXVECTOR3 (m _ center _ x+m _ width/2.0f, m _ center _ y-m _ height/2.0f, 0);
v[3].m _ point = D3DXVECTOR3 (m _ center _ x+m _ width/2.0f, m _ center _ y+m _ height/2.0f, 0);
pDevice->DrawPrimitiveUP(D3DPT _ TRIANGLEFAN, 2, (CONST void * )v,
... );
}
}
Listing 3.6. D3D Rectangle class (Tutorial 3.3).
interface methods of the CRectangle2D class are designed for straightforward
scene specification. The fact that data translation must occur before drawing is
completely hidden from the rest of the application.
Tutorial 3.3 implements the CRectangle2D class as shown in Listing 3.6,
and Tutorial 3.4 implements the same class based on the OpenGL API. For the
Search WWH ::




Custom Search