Jump to content
  • Advertisement
Sign in to follow this  
OpenGL_Guru

OpenGL OPenGL and C++ classes related...

This topic is 5032 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 am trying to figure out how to implement part of my class or rather how i call the call from main to do something specific. i have rendered out some terrain and have the code in my class that returns back the xyz position whenever i click on the terrain with the mouse and then i draw a white sphere at that location in 3D. this is all well and work flawlessly. i have more than one set of terrain data sets so i am tryingto figure out a generic way to call these class routines from main. for example i declare my data sets as: myClass *terrain1 = new myClass(...); myClass *terrain2 - new myClass(...); when i pick on the terrain with the left mouse button, i then check to see where i picked. the code is here using glut.
void myGlutMouse(int button, int button_state, int x, int y)
{
  if ( button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN ) 
  {
    last_x = x;
    last_y = y;
  
  if(terrain1->world_coords(x, y, world_pick))
     terrain1->get_world(world_pick[0], world_pick[1], world_pick[2]);
  }
                        
   glutPostRedisplay();
} 
so world_coords receives x & y and returns true if i picked on the terrain itself and not just anywhere in space and stores where i picked in 3D space and stores this into an array world_pick. get_world send this (x,y,z) pair into the class so i can either print out on the screen what that was and/or where to draw the solid sphere on the terrain to act as a probe. here is my problem: you notice that i use terrain1.. but how would i use something generic so i can get the pick values from terrain2 or any other terrain that i am rendering? thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
just have a pointer to the current terrain and set it to the value of the terrain you want to test.


... somwhere in code ...
currentterrain = terrain2;

void myGlutMouse(int button, int button_state, int x, int y)
{
if ( button == GLUT_LEFT_BUTTON && button_state == GLUT_DOWN )
{
last_x = x;
last_y = y;

if(currentterrain->world_coords(x, y, world_pick))
currentterrain->get_world(world_pick[0], world_pick[1], world_pick[2]);
}

glutPostRedisplay();
}



So when you want to swap terrains you just assign a pointer to the terrain to the global 'currentterrain' pointer and it works.

I am ofcourse assuming I'm understanding what you want todo correctly [smile]

Share this post


Link to post
Share on other sites
so if i have 6 different terrains then i could just say..

myClass *current_terrain = terrain1;
myClass *current_terrain = terrain2;
myClass *current_terrain = terrain3;
myClass *current_terrain = terrain4;
myClass *current_terrain = terrain5;
myClass *current_terrain = terrain6;

????

what if i want to render more than 1 terrain at one time?

Share this post


Link to post
Share on other sites
well, you'd declare 'currentterrain' once and then assign the correct terrain to the varible to you can query it.

If you need to have more than one terrain current at a time then just maintin a list of the active terrains to query.

However, I dont see why you would need more than one terrain current at once, heck i'm not sure why you'd want to load more than one at once [wink]

Share this post


Link to post
Share on other sites
i still dont get what you mean. if i have 6 different terrains and want to probe either of them at any time i have to assign this some way. the person i am writing this for wants to compare 2 terrains together to see the differences...:)

anyway im gonna have to have something like this i am guessing...

if(drawing terrain1)
current_terrain = terrain1;
else if(drawing_terrain2)
????current_terr..............;

Share this post


Link to post
Share on other sites
if he wants to query both terrains at once then just query them, otherwise yes you'll basically do as you said

... somewhere...
myClass * currentterrain;

... main loop ...
if(terrain1 == current)
currentterrain = terrain1;
else if(terrain2 == current)
currentterrain = terrain2;
.. etc etc ..



then in your msg handler just query it via the currentterrain pointer as I showed.

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!