Author Topic: Model positioning and rotating. Centering the model. How to??  (Read 8929 times)

chrychoo

  • Jr. Member
  • **
  • Posts: 2
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!
« Last Edit: July 08, 2013, 09:58:23 AM by jerome_j »

jerome_j

  • Administrator
  • *****
  • Posts: 116
    • Bonzai Engine
Re: Model positioning and rotating. Centering the model. How to??
« Reply #1 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).
« Last Edit: July 08, 2013, 10:18:12 AM by jerome_j »

chrychoo

  • Jr. Member
  • **
  • Posts: 2
Re: Model positioning and rotating. Centering the model. How to??
« Reply #2 on: September 21, 2013, 10:15:05 PM »
Thank you very much for your help !