2
\$\begingroup\$

I'm trying to rotate a model around some axes, but this rotates it around the world origin. I understand that I need to translate the object relative to its own size before rotating it, but I don't know by how much.

I've done it by trial and error until now. How can I automatically read a model's width, height and position?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ It's not really clear what you're asking here. Are you asking how to get an object's properties(such as width, height, position), or how to rotate an object? \$\endgroup\$
    – Alex
    May 1, 2015 at 14:41
  • \$\begingroup\$ @Alex the properties. I edited my question. \$\endgroup\$ May 1, 2015 at 14:49
  • \$\begingroup\$ Is this 2D or 3D? \$\endgroup\$ May 1, 2015 at 19:44

1 Answer 1

3
\$\begingroup\$

There are a couple ways.

This way shows how you can do it at runtime by grabbing out all the vertices to build the BoundingBox around the model.

The first answer on this page is super old but the basic idea applies to use a custom processor for your model in the content pipeline so you can compute the BoundingBox and store it in the Tag property of the model.

Generally it's better to do it in the content pipeline and store the data with the model that way your users don't have to wait for those redundant calculations each time they boot the game, but either approach should work.

\$\endgroup\$
2
  • \$\begingroup\$ I'm using your second link. This works fine for .X files but not for .fbx files. All values are double.MaxValue or double.MinValue. Can you help me? \$\endgroup\$ May 12, 2015 at 12:37
  • \$\begingroup\$ I can't provide much more advice. That approach should be agnostic to the input format as it operates entirely on the imported model vertices. If your meshes draw correctly, there's no reason a process like that shouldn't work. I'd recommend just double checking that all the comparisons are correct. You can also debug the content pipeline using things like this or this. \$\endgroup\$ May 12, 2015 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .