June 16, 2012

Rotation: pivot around a child prim

Given that an a object can pivot around any point, an object can pivot around a child prim by pivoting around the global position of the child prim.

Given these values:

vector gloVecObj    -- the global position of the root prim of an object
rotation gloRotObj -- the global rotation of the root prim of an object

vector locVecChild --  the local position of a child prim of an object

use this fundamental relation between positions and rotations represented in different frame of reference (cf. "Rotation: pivot around a point"):

(1)    gloVecA = gloVecObj + locVecA * gloRotObj 

where A will be the child prim.  Thus 

 (2)    gloVecChild = gloVecObj + locVecChild * gloRotObj

The calculation result of (2), gloVecChild, is the global vector of pivot point.

____________________________
To script this in the root prim, note that

      vector gloVecObj = llGetPos();
      rotation gloRotObj = llGetRot();

and that for the child with link number 'link'

      list a  = llGetLinkPrimitiveParams( link, [ PRIM_POS_LOCAL ] );
      vector locVecChild = llList2Vector( a, 0 );

The post "Rotation: pivot around a point" describes how to use this value to perform the pivoting.

[end]