Sign in to follow this  
GRoss

OOP DX9 game question

Recommended Posts

Hi everybody!

I've been working on my programming assignment using C++ and DX9 and got the VERY basics working. However, for now, everything is just in 1 .cpp file.

I would like to have my objects for the game to be represented by separate classes. Here's the structure that was advices for the assignment:

GameWindow GameObject ---------------------PhysicsObject
| | |
GameController - GameObjectManager -----------CMesh
|
InputSystem

As far as I understand PhysicsObject will contain all the physical properties of the object and CMesh will handle the visual representation of it.

Now what I don't understand is what should I have in the CMesh class and what should I be able to get from it in the GameController to the render it to screen.

I have this to load the mesh:

if( FAILED( D3DXLoadMeshFromX( "Mesh1.x", D3DXMESH_SYSTEMMEM,
D3D_Device, NULL,
&MaterialBuffer, NULL, &numMaterials,
&Mesh1 ) ) )
{
MessageBox(NULL, "Error loading Mesh1.x model file...", "Error!", MB_OK);
return false;
}


..and this to render the mesh:

for(DWORD i = 0; i < numMaterials; i++)
{
D3D_Device->SetMaterial(&MaterialList[i]);
D3D_Device->SetTexture(0, TextureList[i]);

Mesh1->DrawSubset(i);
}


If you can point out a tutorial/example where this is discussed or an explanation that would be much appreciated!

Share this post


Link to post
Share on other sites
Quote:
Original post by GRoss
Here's the structure that was advices for the assignment:


I'm not sure where the lines mean inheritance and where they mean composition.

But if this was the suggested structure, was there also an explanation of what each class is for?

What's a GameController? What does it control? (the game, probably, but what does that mean?)

What's a GameObjectManager? What does it manage? (game objects, probably, but what does that mean?)

And what is the assignment?

Share this post


Link to post
Share on other sites
Thanks for your reply!

It seems that auto-formatting broke the structure..

Here's what I wrote up from what was explained in class:

http://i.imgur.com/Ht0W9.png

As far as I understand GameWindow class will handle all of the windows window and DX9 setting up. The actual game will be run from the SpaceInvadersGameController class. GameObjectManager will have a number of vectors with different objects in them - projectiles, space invaders, player ship, other.. GameObject is the actual object in the game - all objects are gameObjects. GameObject will have a physical representation in PhysicsObject class and a visual representation in the CMesh class.

The CMesh class is the one I'm having problems with...

Share this post


Link to post
Share on other sites
From the drawing and your code listings, the mesh should have a pointer to a D3D device, ID3DXMesh, and should also store the materials and textures. It should have a constructor and destructor that load/free the mesh and its textures, and a Render function that renders the mesh.

Tutorial 6 from the SDK shows how to load and render meshes, if you need more info on that.

Share this post


Link to post
Share on other sites
Thanks!!

I don't know why, but I just couldn't get my head around that class... It's all good now - its working! And it worked out to be quite a bit simpler that I though

8D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this