Last active
February 15, 2016 13:42
-
-
Save lukpazera/1e2f6005c145c8b73cf9 to your computer and use it in GitHub Desktop.
Two ways to get item's inverted world transform matrix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This snippet demonstrates two of the ways to obtain item's inverted world transform matrix. | |
*/ | |
// --- METHOD 1 | |
CLxUser_Scene scene; | |
item.Context (scene); | |
CLxUser_ChannelRead chanRead; | |
CLxUser_SelectionService selSvc; | |
scene.Channels (NULL, selSvc.GetTime(), chanRead); | |
// Get world transform matrix via channel read. This matrix is not mutable. | |
CLxUserMatrix mtx; | |
chanRead.Object (item, "worldMatrix", mtx); | |
// Pull matrix array from the matrix object. | |
LXtMatrix4 xfrm; | |
mtx.Get4 (xfrm); | |
// Create new value of type matrix. We will copy the matrix array into it. | |
CLxUser_ValueService valSvc; | |
CLxUser_Value invMtxVal; | |
valSvc.NewValue (invMtxVal, LXsTYPE_MATRIX4); | |
// Create new matrix interface and set it to our mutable matrix value. | |
// Finally set the matrix array from the one copied from original matrix | |
// and call invert method. | |
CLxUser_Matrix invMtx; | |
invMtx.set (invMtxVal); | |
invMtx.Set4 (xfrm); | |
invMtx.Invert (); | |
// --- METHOD 2 | |
// This is similar to the above but we read value object from channel read | |
// directly, then create new user value and copy world transform value into it. | |
// Then, just like above, we create new matrix interface, cast it to the newly | |
// created value and use invert method. | |
CLxUser_Scene scene; | |
item.Context (scene); | |
CLxUser_ChannelRead chanRead; | |
CLxUser_SelectionService selSvc; | |
scene.Channels (NULL, selSvc.GetTime(), chanRead); | |
unsigned int wmtxChanIdx; | |
item.ChannelLookup ("worldMatrix", &wmtxChanIdx); | |
CLxUser_Value mtxVal; | |
chanRead.ValueObj (item, wmtxChanIdx, mtxVal); | |
CLxUser_ValueService valSvc; | |
CLxUser_Value invMtxVal; | |
valSvc.NewValue (invMtxVal, LXsTYPE_MATRIX4); | |
invMtxVal.Copy(mtxVal); // Copy FROM | |
CLxUser_Matrix invMtx; | |
invMtx.set (invMtxVal); | |
invMtx.Invert (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment