Bonzai Engine Forum

Bonzai Engine & Tools => Bonzai Engine => Topic started by: chrychoo on July 04, 2013, 09:48:10 PM

Title: Model positioning and rotating. Centering the model. How to??
Post by: chrychoo on July 04, 2013, 09:48:10 PM
Hello!

I have started coding with Bonzai recently. It's great!

I'm dealing now with model rotating. I have a window with the loaded model in the center. In my situation there is some data coming with information about x, y, z rotation (signed float, degrees) and I would like my model to behave exactly in that way.

I have read two topics about this on the forum: "Model rotating when projection matrix and model view matrices are used" and "How to get the center of a mesh".

I get my Model object by calling instance.getModel().

We can position a model using a Transform object (which can be created from a matrix if needed). And the code is:
How to set up those "pos" and "rot" Quats??

Unfortunately the model origin is not always it's center, so we have to use it's bounding box to find it's center and rotate from that point. How to do this??
We have a code:
I tried to do something with this code but I couldn't. I have Bonzai version 1.3.1 and I discovered that there is something different there. For example Model.getBoundingVolume() method accepts IBoundingVolume.BoundingVolumeOptions type and returns IBoundingVolume<?>. How to deal with that??

Thanks!
Title: Re: Model positioning and rotating. Centering the model. How to??
Post by: jerome_j on July 08, 2013, 10:05:02 AM
Hello,

If you have a model instance, you can position the instance directly with:

To initialize a Transform object, you can do as follow:

For centering the model, there is two way, either get the bounding box like this:
and use the box position to move the model or instance.
Or you can use the utility:

For your question about the generic interface IBoundingVolume<?>, the type returned by getBoundingVolume methods is of the type of the volume requested.
Meaning, Box.BoundingBox_AABB_Visible request a box so you can safely cast the result to a Box (which extends IBoundingVolume<Box>). Similarly with sphere, cylinder and capsule volume.

Ps: I've edited you post to use code tag and replaced BoundingBox (1.2.8 ) to Box (1.3.1).
Title: Re: Model positioning and rotating. Centering the model. How to??
Post by: chrychoo on September 21, 2013, 10:15:05 PM
Thank you very much for your help !