Sign in to follow this  
ocelot663

classes

Recommended Posts

ocelot663    122
Hi i currently have my entire directx scene (a crate in the center with a light source and some 2d HUD elements) all in the same .cpp file. i was wondering what would be the best way to separate my functions into classes and place them in different .cpp files in order to make things a little easier. im pretty new to c++. thanks in advance.

Share this post


Link to post
Share on other sites
shadowDragon    139
Well, a basic rule of thumb for splitting up a programming problem into classes is to look at the nouns (i.e. person, place, or thing) in the problem's description and make those your basic objects.

From your description you have: Crate, Light, and HUD. There's your start right there.

The only thing you might change is to make Crate be something more generic (i.e. StaticModel) so you can have other kinds of models (besides a Crate) in your scene.

You might also consider having them derive from a common base class, i.e. SceneObject or something. This way your Scene doesn't need to know it has 2 Lights and a Crate, it just knows it has 3 SceneObjects and can treat them all the same.

Also, try to make all of your objects responsible for themselves. I've had a lot of luck having a all of my objects inherit from a base class that has virtual Update() and Draw() functions.

This way each object can override the Update() or Draw() (or BOTH! :) ) and fill in the different code for how each object will update and draw itself.

So you can call Crate.Draw() and HUD.Draw() and your main.cpp doesn't need to know a thing about HOW those objects draw themselves it just knows THEY do and let's them handle it.

Hope this helps,

-SDX

Share this post


Link to post
Share on other sites
ocelot663    122
thanks dude yer thats very helpful

but now i know how to separate things into classes, how would i actually go about writing classes into it? like i think it has something to do with double colons (::) or something?

Share this post


Link to post
Share on other sites
ELFanatic    100
Quote:
Original post by ocelot663
thanks dude yer thats very helpful

but now i know how to separate things into classes, how would i actually go about writing classes into it? like i think it has something to do with double colons (::) or something?


oh my friend. I say deviate from your directx scene for a little bit and pick up a text and learn how to do classes, do simple classes, get the ideas down. they may confuse you otherwise. Then come back and impliment them in your directx scene.

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