Tuesday, April 5, 2011

3D World to Local transformation

Hello. I am having a real headache trying to set a node's local position to match a given world position.

I was given a solution but, AFAICS, it only takes into account orientation and position but NOT scaling :

node_new_local_position = node_parent.derivedOrientation().Inverse() * ( world_position_to_match - node_parent.derivedPosition() );

The node in question is a child of node_parent; node_parent local and derived properties (orientation, position and scaling) are known, as well as its full matrix transform.

All the positions are 3d vectors; the orientation is a quaternion; the full transform is a 4x4 matrix.

Could someone please help me to modify the solution to support scaling in the node hierarchy?

Many thanks in advance,

Bill

From stackoverflow
  • I'm no expert in ogre3d but I guess you would need something like:

     node_new_local_position =  node_parent._getFullTransform ().inverse() * world_position_to_match;
    

    where _getFullTransform ().inverse() is a full 4 x 4 inverse of node_parents transform.

    EDIT: It looks like maybe you should just use _setDerivedPosition which does exactly what you're trying to accomplish.

    Bill Kotsias : I didn't imagine it would be that simple! Thanks!
    Andreas Brinck : @Bill Sometimes you get lucky ;)

0 comments:

Post a Comment