I thought calling rotate directly on a Spatial would rotate it around “itself” as in around its geometric center. However, I’m working on an imported model now trying to rotate “sub-spatials” of a larger model, and find that a call to Spatial.rotate(0.1f, 0, 0) for a x-axis rotation for example makes the Spatial move in a circle in the XY-plane, indicating that the origin for the axis system that the spatial is rotating around is somewhere off in space, and away from the object itself.
How did this happen? Does Spatial.rotate in the end rotate around the origin defined by the model it “belongs” to as a whole, not the geometric origin of the spatial?
There might be another rotation applied to spatial, try calling setLocalRotation
That just caused the Spatial to move and rotate in the XZ-plane instead. I want it to spin on it’s own axis.
It IS rotating around its local origin. It’s just that the model’s local origin is somewhere strange.
Look at the spatial’s world bound and compare it to its local translation… you will see that the center is probably way off somewhere.
Yeah, the BoundingBox center is at (0.12681948, 0.042627037, 0.8830446) while the local translation is (0, 0, 0). I thought the two would match up given that no transforms has been applied to it yet but the bounding volume might be determined at import time to something different?
Either find which child is moved and fix it… or add it to another node and offset it under that node… then rotate the node.
ie: make sure the local origin is whare you want it.
Well, the Spatial has no children.
The problem with attaching it to it’s own node is that it need to stay attached to the larger object for when that object moves. Think wheels on a moving car. I want so spin the wheel on it’s own axis while the car is moving and rotating.
There’s probably an easy way to design a node hierarchy here that will work, I’m just unfamiliar with this.
I don’t understand why that’s an issue.
Node node = new Node();
wheel = node;
…or fix the model to be centered properly in whatever tool you used to create it.
I’ve tried this - attaching the wheel to it’s own wheelnode, then attaching the wheelnode to the car, then rotating the car and the wheelnode. It seemed like the logical thing to do but I can’t get it to work.
The car rotates, but the wheel does not.
Look at the FancyCar example, it does a similar thing to rotate the wheels which also have their center outside of the geometry itself.
I’ll just have to work with a simple experiment until I figure this out, thanks. I am however perplexed as to why the method suggested by pspeed leads to no rotation at all for the spatial once it is attached to the larger body.
Well, we can’t see the code from here and it’s a code problem, so…