Language:EN
Pages: 5
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
program describes system objects interacting

Program describes system objects inter-acting

14 direct3d AppB 6/19/03 5:34 PM Page 328

328 B.

This appendix covers a host of topics, including:

• A brief explanation of the uses and features of object-oriented programming

In an object-oriented view of programming, a program describes a system of objects inter-acting. This is contrary to a procedure-oriented view of programming, in which a program describes a series of steps to be performed.

Object-oriented programming involves a few key concepts. The most basic of these is abstraction, which simplifies writing large programs. Another is encapsulation, which makes it easier to change and maintain a program. The concept of class hierarchies is a powerful classification tool that can make a program easily extensible.

329
What Is Object-Oriented Programming?

All procedural languages support procedural abstraction, in which a piece of source code is put into a function and reused this way. For example, consider matrix multiplication:

FLOAT pM[16];
ZeroMemory( pM, sizeof(D3DXMATRIX) );
for( WORD i=0; i<4; i++ )
for( WORD j=0; j<4; j++ )
for( WORD k=0; k<4; k++ )
pM[4*i+j] += pM1[4*i+k] * pM2[4*k+j];
memcpy( pOut, pM, sizeof(D3DXMATRIX) );

14 direct3d AppB 6/19/03 5:34 PM Page 330

330 B.

// animation frames in mesh
// stores vertices per animation frame in // vertices[FrameNum][VertexNum]

int iNumTriangles; // Mesh triangles
TRIANGLEVERT *pTriangles;
int iNumTextures; // Mesh textures
TEXNAMES *pTexNames;
LPDIRECT3DTEXTURE8* pTexturesInterfaces;
TEXCOORDS *pfTextureCoords;
// Mesh tex coordinates TEXCOORDS *pfEnvTextureCoords; // not used here
};

int iMeshFrameNum;
VMESHFRAME *vMeshFrames;

// animation frames in mesh
// stores vertices per animation frame in\ // vertices[FrameNum][VertexNum]

331
What Is Object-Oriented Programming?

Now MD3MESH is an abstract data type that might be used in combination with functions as their parameter. These functions handle the details of filling the specific fields.

This traditional procedural approach lets you view data abstraction and procedural abstrac-tion as two distinct techniques. A more elegant way would be to link them. The following section describes the object-oriented programming approach, which uses classes.

long ReadLong(FILE* File); // file i/o helper
short ReadShort(FILE* File);
FLOAT ReadFloat(FILE* File);
void CreateVB(LPDIRECT3DDEVICE8 lpD3Ddevice); // vertex buffer system void DeleteVB();
void CreateTextures(LPDIRECT3DDEVICE8 lpD3Ddevice); // texture system void DeleteTextures();
public:
// class methods
BOOL CreateModel( char *fname, LPDIRECT3DDEVICE8 lpD3Ddevice);
void DeleteModel();
void InitDeviceObjects(LPDIRECT3DDEVICE8 lpD3Ddevice);
void DeleteDeviceObjects();
void Render(LPDIRECT3DDEVICE8 lpD3Ddevice);
CMD3Model();
// constructor/destructor ~CMD3Model();
};

332 B.

Encapsulation

Encapsulation is the process of hiding the

word-protected labe ake members visibl lasses but not to th give derived classes ion about your class users. nables to
user.
ore
han

A truly encapsulated class surrounds or hides its data with its functions so that you can access the data only by calling the func-tions. An illustration might look like Figure B.1. On the left are the public data mem-bers, and on the right are the private data members.

NOT

encapsulation does guarantee of safet r who is intent on u ivate data can alwa d * operators to gai ot
A pro- g a
use
access
Data Function Function Data
Function Funct Funct
Function Function

Data encapsulation with functions (public vs. private data
members)

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Ms June Murphy

PageId: ELI50F08E5