views:

40

answers:

2

I'm new to graphics. I'm experimenting with OpenGL / JOGL.

I have a .obj file that I'm rendering. I'm having difficulty placing it exactly where I want it in the world. I have a plane that I want it to rest on, taking into account the model's runtime-set size. Just doing a transformation isn't quite enough, because I need to take into account the model's dimensions.

Even then, I'm not sure how to translate 0 in the .obj's frame of reference to the world coordinate system.

What is the idiomatic pattern for dealing with this?

+1  A: 

For a simple translation (in steps):

Take the position of the object's origin in world coordinates and create a translation matrix from this by first multiplying the origin by -1:

1 0 0 -xo
0 1 0 -yo
0 0 1 -zo
0 0 0  1

This will move the object so its origin coincides with the world origin. So take the y value of the plane you want the object to rest on (assuming that y is "up") and add that to the vector calculated above so your matrix becomes:

1 0 0 -xo
0 1 0 (-yo + yp)
0 0 1 -zo
0 0 0  1

This will mean that the plane intersects the object (assuming that the origin is somewhere inside the object). Now find the bounding box of the object and take the minimum y value from the object's origin:

+------+ ymax
|      |
|      |
|   o  |
|      |
+------+ ymin

where "o" is the origin.

Include this in the matrix:

1 0 0 -xo
0 1 0 (-yo + yp + (yo - min))
0 0 1 -zo
0 0 0  1

I think this should put your object resting on the plane. It's been a while since I did this sort of stuff so I might have some signs the wrong way round - so double check the numbers and be prepared to experiment.

ChrisF
A: 

You should set your model's origin at its feet, and approx. under its gravity center. This way, when you scale it, its position (relatively to the ground) won't change.

Then, simply translate it where you want it to be, then rotate, then scale (in this order) - you're done.

Calvin1602