return null;\r
}\r
\r
- void PrimPosAndRot(SceneObject prim, out Vector3 pos, out Quaternion rot)\r
+ /// <summary>\r
+ /// Calculates finar rendering position for objects on the scene\r
+ /// </summary>\r
+ /// <param name="obj">SceneObject whose position is calculated</param>\r
+ /// <param name="pos">Rendering position</param>\r
+ /// <param name="rot">Rendering rotation</param>\r
+ void PrimPosAndRot(SceneObject obj, out Vector3 pos, out Quaternion rot)\r
{\r
- if (prim == null)\r
+ // Sanity check\r
+ if (obj == null)\r
{\r
pos = RHelp.InvalidPosition;\r
rot = Quaternion.Identity;\r
return;\r
}\r
\r
- if (prim.BasePrim.ParentID == 0)\r
+ if (obj.BasePrim.ParentID == 0)\r
{\r
- pos = prim.InterpolatedPosition;\r
- rot = prim.InterpolatedRotation;\r
+ // We are the root prim, return our interpolated position\r
+ pos = obj.InterpolatedPosition;\r
+ rot = obj.InterpolatedRotation;\r
return;\r
}\r
else\r
pos = RHelp.InvalidPosition;\r
rot = Quaternion.Identity;\r
\r
- SceneObject p = GetSceneObject(prim.BasePrim.ParentID);\r
+ // Not root, find our parent\r
+ SceneObject p = GetSceneObject(obj.BasePrim.ParentID);\r
if (p == null) return;\r
\r
+ // If we don't know parent position, recursively find out\r
if (!p.PositionCalculated)\r
{\r
PrimPosAndRot(p, out p.RenderPosition, out p.RenderRotation);\r
\r
if (p is RenderPrimitive)\r
{\r
- pos = parentPos + prim.InterpolatedPosition * parentRot;\r
- rot = parentRot * prim.InterpolatedRotation;\r
+ // Child prim (our parent is another prim here)\r
+ pos = parentPos + obj.InterpolatedPosition * parentRot;\r
+ rot = parentRot * obj.InterpolatedRotation;\r
}\r
else if (p is RenderAvatar)\r
{\r
+ // Calculating position and rotation of the root prim of an attachment here\r
+ // (our parent is an avatar here)\r
RenderAvatar parentav = (RenderAvatar)p;\r
\r
- int attachment_index = (int)prim.BasePrim.PrimData.AttachmentPoint;\r
- // Check for invalid LL attachment point\r
+ // Check for invalid attachment point\r
+ int attachment_index = (int)obj.BasePrim.PrimData.AttachmentPoint;\r
if (attachment_index > GLAvatar.attachment_points.Count()) return;\r
-\r
attachment_point apoint = GLAvatar.attachment_points[attachment_index];\r
- Vector3 point = parentav.glavatar.skel.getOffset(apoint.joint) + apoint.position;\r
- Quaternion qrot = apoint.rotation * parentav.glavatar.skel.getRotation(apoint.joint);\r
-\r
- pos = parentPos + point * parentRot + prim.InterpolatedPosition * (parentRot * qrot);\r
- rot = qrot * parentRot * prim.InterpolatedRotation;\r
+ skeleton skel = parentav.glavatar.skel;\r
+ if (!skel.mBones.ContainsKey(apoint.joint)) return;\r
+\r
+ // Bone position and rotation\r
+ Bone bone = skel.mBones[apoint.joint];\r
+ Vector3 bpos = bone.getTotalOffset();\r
+ Quaternion brot = bone.getTotalRotation();\r
+\r
+ // Start with avatar positon\r
+ pos = parentPos;\r
+ rot = parentRot;\r
+\r
+ // Translate and rotate to the joint calculated position\r
+ pos += bpos * rot;\r
+ rot *= brot;\r
+\r
+ // Translate and rotate built in joint offset\r
+ pos += apoint.position * rot;\r
+ rot *= apoint.rotation;\r
+\r
+ // Translate and rotate from the offset from the attachment point\r
+ // set in teh appearance editor\r
+ pos += obj.BasePrim.Position * rot;\r
+ rot *= obj.BasePrim.Rotation;\r
}\r
return;\r
}\r