Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

Class Confusion

This topic is 4818 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

I have my main rendering class for OpenGL. Then that class spawns an instance of a class for each type of enemy, terrain, character etc. How can i access data from the Main rendering classes instance of terrain objects, from the main redering class's instance of character object, for example.

Share this post


Link to post
Share on other sites
Advertisement
Instance A
Instance B
Class X

I believe what you're saying is that you'd like for A (character instance) to reference information from B (terrain instance) since they are both X (Rendering Class). Based upon little to no knowledge of OpenGL, I'd have to say that my knowledge of classes tells me that you'd need a function that is a part of class that allows one instance to query another for the information you need. Since each instance is for lack of a better term, it's own instance, it is seperate and therefore unique, not sharing anything between A and B.

However, I may be way off base here and I'm sure the more experienced people will come along with code snippets and whatnot to set you in the right direction, but that's where I'm going on it.

Vopisk

Share this post


Link to post
Share on other sites
I think hes saying that the classes he spawns are of different types?

Is it something like this?


Class Engine
Class Terrain
Class Enemy
Class Renderer



etc?

Share this post


Link to post
Share on other sites
I was thinking that was also the case, however, my logical response is the same, inheritence does not allow an instance of a class to access the datamembers of another instance of the class. You have to write an accessor function if you want to do that, something like:

void GetTerrainHeight(terrain& ter);
{
if (ter.height <= player.elevation);
{
do crash_sequence();
}
}

Or something like that, I dunno, I'm not very good at the whole coding without my IDE yet... and it's 5:00am... so gimme a break. But yeah, pass whatever it is you want to access by reference or preferably constant reference and then manipulate the data that way.

Vopisk

Share this post


Link to post
Share on other sites
A more important question is, why is the renderer spawning these in the first place? Is it a renderer, or a game controller?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!