Sign in to follow this  

Simple Inheritance

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, Im looking at using some inheritance in my game for the first time. What i have is a scene which contains a number of similar objects. These objects all have similar properties. My question is how would i go about laying these classes out? for example say i have 2 objects sphere1: mass = 5kg; - Static to sphere1 class radius = 10; - Static to sphere1 class position; sphere2 mass = 1kg; - Static to sphere2 class radius = 2; - Static to sphere2 class position; How would i go about designing these classes in respect to the following code? I have included a pure virtual draw method as each sphere will need its own draw()
Class SceneObj
{
public:
virtual void Draw() = 0;
protected:
// Would the position go here?
private:
}

Class Sphere1 : public SceneObj
{
public:
void Draw();
private:
// static const float radius; - here??
// static const float mass; - here??
}

Class Sphere2 : public SceneObj
{
public:
void Draw();
private:
// static const float radius; - here??
// static const float mass; - here??
}
What i would later like to do is pass a SceneObj to a collision method if that makes sence, such as
SomeCollisionMethod(SceneObj * someObj)
{
if(someObj->position.........)
{
// do something ........
}
}
Any help would be apprechiated. Cheers.

Share this post


Link to post
Share on other sites
The only difference between these two spheres are some values. They're both spheres with the exact same characteristics, so there's absolutely no need to create both a Sphere1 and Sphere2 class. It will only lead to code duplication. Instead, write a Sphere class that can properly deal with different weights and sizes.

Personally I think that the term SceneObj is a bit too generic. It seems that you want to make them drawable and collidable, but will every SceneObject be visible and physically solid? Anyway, if you could give some more information about the purpose of this system, I or someone else could give some more specific help.

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain P
It seems that you want to make them drawable and collidable


Thats correct, i want to think of each object (be it a sphere, cube, cylinder etc)as a scene object and be able to make them drawable and collideable

Quote:
Original post by Captain P
but will every SceneObject be visible and physically solid?


Yes this is my intention

Share this post


Link to post
Share on other sites

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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