Besway to create a ground under some objects


I have a problem, i create random starting poistions for my objects and i also have a quad which i have set up as my ground, but more often than not some of my objects are under the ground.

How can i get it so the objects always draw ontop of it.

Here is the coords for the ground:


Heres how i draw something, i translate to the same place i tranlstae the ground to and draw, before it was working ok, but i have just improved the random generator and the objects are uner the ground.

Also if the way i am drawing my ground is not the best could someone mention a better way, eventually i would like to do hightmapping but not sure yet.

The ground is a bit of an angle i.e. its as if you are looking down on a plato from a hill and i’d like the objects to draw on it.

Cheers for any help.

It all depends on your implementation and on what you want to achieve.

If you have only one ground plane. Define the groundvertices of the objects to lie in the same plane as the vertices of your ground plane and apply the same transformation matrix you use for your ground plane to transform the object.

If you don’t know which vertices of the object will touch the ground, you can perform some kind of collision detection. Transform the vertices of your object to the coordinate frame of your groundplane so that the plane corresponds to the XY plane. Check the Z-values of these transformed vertices. Compute the minimum of these values and translate your object by that amount. Finally, put the object back by using the inverse transform.

There’s a caveat here. Suppose you want to place a horizontal cube on a sloped plane, then the result will be a cube that touches the plane with only one corner, which is not very realistic. Here you will have to introduce some gravity and use Newton’s laws of physics to iterate to the equilibrium state of the cube.
A shortcut: Just take the three vertices with the smallest Z-coordinates (as defined in the previous paragraph). These define a plane themselves, and allign that plane with the groundplane.

If you’re using terrains, I strongly suggest you use heightmaps.