View Full Version : Placing trees on Terrain with mouse?

07-17-2000, 07:01 PM
I have created a height field editor, I now wish to select a tree button in the app then when I click the mouse button on the terrain it places a tree exactly on the x,y,z of that piece of terrain.


07-18-2000, 12:31 AM
Hi IronDuke !

I think you could do it using the depth buffer : I assume you know the X,Y coordinates of the point that has been clicked !

1) Use glReadPixels with GL_DEPTH_COMPONENT to retrieve the depth Z of the pixel that has been clicked. Be aware that the OpenGL Y Axis is reversed compared to the window Y axis.
2) Use gluUnProject(X,Y,Z,modelMat,projMat,viewPort,&spaceX,&spaceY,&spaceZ);
You obtain the matrices with glGetDoublev ang glGetIntegerv.

Then, spaceX,spaceY and spaceZ contain the coordinates of the point clicked on the landscape !

I use this method in most of my programs for picking and transforming objects (translations/rotations).

Hope it helps.



07-18-2000, 06:43 AM
I understand what you mean, if you have the time perhaps you could go into a little more detail?

05-09-2002, 02:18 PM
thanks !!!!!! it works fine !!!

07-09-2003, 06:27 AM
hey im try to make the same thing but im realy dont understend.