# Skinning Bone Attachments

**URL:** <https://forums.imgtec.com/t/skinning-bone-attachments/419>\
**Category:** PowerVR Insider\
**Created:** [July 26, 2009, 8:47am UTC](https://forums.imgtec.com/t/skinning-bone-attachments/419 "2009-07-26T08:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zibba](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@zibba](https://forums.imgtec.com/u/zibba)\
**Post date:** [July 26, 2009, 8:47am UTC](https://forums.imgtec.com/t/skinning-bone-attachments/419/1 "2009-07-26T08:47:53Z")

</div>

Hi  
  
  
  
  
  
I’m using the training course OGLESSkinning to render an animating character using the matrix palette and bone batches. I’m trying to figure out how to attach another object to the character’s hand. I thought inside the render loop, I could grab the world matrix and use that to transform the attached object, but it’s not working how I imagined, thus:

Code:

  
//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterate through all the bones in the batch  
for (int j = 0; j \< pMesh-\>sBoneBatches.pnBatchBoneCnt[i32Batch]; ++j)  
{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/\*  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set the current matrix palette that we wish to change. An error  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;will be returned if the index (j) is not between 0 and  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GL\_MAX\_PALETTE\_MATRICES\_OES. The value of GL\_MAX\_PALETTE\_MATRICES\_OES  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;can be retrieved using glGetIntegerv, the initial value is 9.  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GL\_MAX\_PALETTE\_MATRICES\_OES does not mean you need to limit  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;your character to 9 bones as you can overcome this limitation  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by using bone batching which splits the mesh up into sub-meshes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;which use only a subset of the bones.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\*/  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extensions.glCurrentPaletteMatrixOES(j);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Generates the world matrix for the given bone in this batch.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i32NodeID = pMesh-\>sBoneBatches.pnBatches[i32Batch \* pMesh-\>sBoneBatches.nBatchBoneMax + j];  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scene.GetBoneWorldMatrix(mBoneWorld, \*pNode, scene.pNode[i32NodeID]);  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Multiply the bone's world matrix by the view matrix to put it in view space  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mBoneWorld = viewmat \* mBoneWorld;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // here we'd set the transform matrix on the attached object, e.g.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i32Batch == boneBatch && j == boneAttach)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (attached)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attached-\>setParentMatrix(mBoneWorld);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Load the bone matrix into the current palette matrix.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myglLoadMatrix(mBoneWorld.f);  

  
  
  
Is this the correct matrix to pull out, or do I have to do a further transform?  
  
  
  
regards

---

<div class="post-metadata">

**Author:** ![zibba](https://avatars.discourse-cdn.com/v4/letter/z/898d66/32.png) [@zibba](https://forums.imgtec.com/u/zibba)\
**Post date:** [July 26, 2009, 10:42pm UTC](https://forums.imgtec.com/t/skinning-bone-attachments/419/2 "2009-07-26T22:42:22Z")

</div>

Ah this is wrong. What do is get the matrix from the node e.g

Code:

  
PVRTMat4 mat;  
scene.GetWorldMatrix(mat, scene.pNode[some\_node\_eg\_hand]);  

  
  
  
Then transform the attachment object by the parent's position and rotation, and mat.

---

<div class="post-metadata">

**Author:** ![GordonMaclachlan](https://avatars.discourse-cdn.com/v4/letter/g/c68b51/32.png) [@GordonMaclachlan](https://forums.imgtec.com/u/GordonMaclachlan)\
**Post date:** [September 4, 2009, 10:37am UTC](https://forums.imgtec.com/t/skinning-bone-attachments/419/3 "2009-09-04T10:37:28Z")

</div>

We’re hoping to improve the documentation for the POD format (amongst other things) for a future release so this should be more clear for others - glad you worked it out.
