how to select an object

Has someone an idea about this purpose and an other for following the relief of a terrain (always for an object) ? It’s very important. Thanks.

I don’t understand, do you want to know how to do these things (selection etc.)? Don’t worry English is one of the hardest languages in the world to learn. If you mean what you said then the purpose of selcting an object is well for selecting it, this can be used to help in a game (sometimes you use a mouse to open a door, pick up an object.) but it is most useful for level editing and modeling so you can alter the properties of an object.

thanks tim,
what i would like to know is:

  • how to select an object : i have a scene with tanks (that I have created) … and i would select one of them but i don’t know how
  • and i would know how to make the tank follow the relief of the terrain
    Thanks

There are many ways to do selection, it all depends on what you want, what speed you need, compatibility etc.

You could use the selection buffer, I don’t know how to do this but there is a good example in the red book and I think I have a demo somewhere on it if you want. However this method porbably isn’t the best and I think will be slow and isn’t compatible with most peoples data sets without a lot of re-organisation.

One apparently easy way is to draw all objects a different colour: when the mouse (or pointer) is clicked keep the screen x,y position of the cursur, draw all the objects a seperate colour (cycle through adding red,then green and then blue making sure lighting and fog is turned off!), then use glReadPixels st to the colour buffer ( you will need to look up the exact configuration) making sure you are not drawing the cursur then with this colour you can just check what you clicked on. This method may produce a slight flicker when you select something because you are radicaly changing what is being drawn (for 1 frame), but if the frame rate is high enough it might not be visible.
My favourite method which I will soon use involves gluUnproject. This function takes your 2d screen coordinates of the cursur and will return the 3d coords which you can use to slect the nearest object. This is best for selecting faces and such like in 3d. Here is link to another simialr discussion where I briefly say how to implement it http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/003249.html

I wont put up any code since I havn’t YET done any of this, you should be able to do it your self if you look around (red book has a good example) or you can search this (and other) forums- it is a big subject.

As for moving over a terrain: well no time now, I will be back in a day or so to explain ( I need to figure this out for my self soon ). For starters you know your x,z position and this you can convert to your heightmap x,z (scaling might be needed) and thus get your y. How ever this will only give you the height at the vertices but if you make sure you are higher than the heighest vertex it will be ok, specialy if you have small triangles on the terrain compared to the tank. However a normal collision detection routine would be best using a quad tree- this is another huge area and the net is covered in c.d tutorials.

Salut Tim