PDA

View Full Version : Placing trees on Terrain with mouse?



ironduke
07-17-2000, 08: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.

anyone?

Eric
07-18-2000, 01: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.

Regards.

Eric

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

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

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