Need help understanding picking concept

Started by
4 comments, last by empirical2 13 years ago
I've created a terrain editor for a strategy game I'm creating. You can find the alpha here:

ThoriumBREED terrain editor


Now that you can see what I'm going for, how do I go about linking each drawn hexagon to another class that contains data about that hexagon? For example, the mountain hexagons will provide a defensive bonus to the units occupying that hex. This is my first game project so I'm just not sure of the way this is usually implemented.

how do I link a hexagon to a class containing information about that hexagon (terrain type, units placed there, etc).
Advertisement
I'm not sure what you are asking for. Are you asking how picking an object can be done with a mouse click?
http://www.opengl.org/wiki/Common_Mistakes#Selection_and_Picking_and_Feedback_Mode
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

I'm not sure what you are asking for. Are you asking how picking an object can be done with a mouse click?
http://www.opengl.or...d_Feedback_Mode


Sorry for not being more clear. Perhaps I'll explain the end result I'm looking for...

I'd like to be able to click on a hexagon and have the information about that hexagon appear. For example, when the user clicks on a grass hex it would display the following:

Hex number (row, column)
Hex type (rock, dirt, grass, water)
Any units on that tile (an array of a class called Unit)

I have read that picking can provide you a 'name' for the selected hexagon. What is an effective method of linking the 'name' with the other information?


I have read that picking can provide you a 'name' for the selected hexagon. What is an effective method of linking the 'name' with the other information?


I believe this 'name' you mean is related to the (old) OpenGL picking system. It is based on re-rendering the whole scene when you click but on a 1x1 viewport around the mouse click position, and OpenGL puts the "name" of every object which was clicked on some stack. I don't remember well how you assign a 'name' (which is just a number) for each object though.

You could just assign an index for each hexagon and have an array containing all the hexagon informations. When you have detected which hexagon was clicked, get the index and get the information from the array at that index. That's usually how I solve this kind of stuff. It also allows you to get hexagon indexes/references from somewhere else without having to copy all the hexagon information.
I've just read through your link V-man and found this interesting tidbit:

"[font=sans-serif][size=2]A modern OpenGL program should not use the selection buffer or feedback mode. These are not 3D graphics rendering features yet they have been added to GL since version 1.0. Selection and feedback runs in software (CPU side). On some implementations, when used along with VBOs, it has been reported that performance is lousy."[/font]
[font=sans-serif][size=2]
[/font]
[font=sans-serif][size=2]That being said, I started to look into color picking as my method of selection. I found a good article on one implementation here:[/font]
[font=sans-serif][size=2]
[/font]
[font=sans-serif][size=2]Color Picking
[/font]

This example created a separate class that handles the color assignment. Using that idea, I can build on the class to contain all the information and references I need for my game. I'm going to try this method and see where I get. Thank for your help!
Using glUnproject is much better than picking (IMO). At the end of the drawing you use it to get the point the mouse is over in 3D X,Y,Z coords.

Then on the next frame you just check each tile to see if it falls with in those cords. Its always one frame behind but this is not noticeable to the user.(IMO) and saves rendering everything again. Also If your tile coords are regular its trivial to work out which tile from the XYZ.

Here is some info http://www.opengl.org/resources/faq/technical/selection.htm

This topic is closed to new replies.

Advertisement