\r
Vector3 PrimPos(Primitive prim)\r
{\r
+ Vector3 pos;\r
+ Quaternion rot;\r
+ PrimPosAndRot(prim, out pos, out rot);\r
+ return pos;\r
+ }\r
+\r
+ object GetParent(uint localID)\r
+ {\r
+ RenderPrimitive parent;\r
+ RenderAvatar avi;\r
+ if (Prims.TryGetValue(localID, out parent))\r
+ {\r
+ return parent;\r
+ }\r
+ else if (Avatars.TryGetValue(localID, out avi))\r
+ {\r
+ return avi;\r
+ }\r
+ return null;\r
+ }\r
+\r
+ void PrimPosAndRot(Primitive prim, out Vector3 pos, out Quaternion rot)\r
+ {\r
if (prim.ParentID == 0)\r
{\r
- return prim.Position;\r
+ pos = prim.Position;\r
+ rot = prim.Rotation;\r
+ return;\r
}\r
else\r
{\r
- RenderPrimitive parent;\r
- RenderAvatar parentav;\r
- if (Prims.TryGetValue(prim.ParentID, out parent))\r
+ pos = new Vector3(99999f, 99999f, 99999f);\r
+ rot = Quaternion.Identity;\r
+\r
+ object p = GetParent(prim.ParentID);\r
+ if (p == null) return;\r
+\r
+ Primitive parentPrim = null;\r
+ if (p is RenderPrimitive)\r
{\r
- if (parent.Prim.ParentID == 0)\r
- {\r
- return parent.Prim.Position + prim.Position * Matrix4.CreateFromQuaternion(parent.Prim.Rotation);\r
- }\r
- else\r
- {\r
- // This is an child prim of an attachment\r
- if (Avatars.TryGetValue(parent.Prim.ParentID, out parentav))\r
- {\r
- var avPos = PrimPos(parentav.avatar);\r
- return avPos;\r
- }\r
- else\r
- {\r
- return new Vector3(99999f, 99999f, 99999f);\r
- }\r
- }\r
+ parentPrim = ((RenderPrimitive)p).Prim;\r
}\r
- else if (Avatars.TryGetValue(prim.ParentID, out parentav))\r
+ else if (p is RenderAvatar)\r
{\r
- var avPos = PrimPos(parentav.avatar);\r
+ parentPrim = ((RenderAvatar)p).avatar;\r
+ }\r
+\r
+ Vector3 parentPos;\r
+ Quaternion parentRot;\r
+ PrimPosAndRot(parentPrim, out parentPos, out parentRot);\r
\r
- return avPos + prim.Position * Matrix4.CreateFromQuaternion(parentav.avatar.Rotation);\r
+ if (p is RenderPrimitive)\r
+ {\r
+ pos = parentPos + prim.Position * parentRot;\r
+ rot = parentRot * prim.Rotation;\r
}\r
- else\r
+ else if (p is RenderAvatar)\r
{\r
- return new Vector3(99999f, 99999f, 99999f);\r
+ RenderAvatar parentav = (RenderAvatar)p;\r
+\r
+ int attachment_index = (int)prim.PrimData.AttachmentPoint;\r
+ // Check for invalid LL attachment point\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 = parentav.glavatar.skel.getRotation(apoint.joint) * apoint.rotation;\r
+\r
+ pos = parentPos + point * parentRot + prim.Position * (parentRot * qrot);\r
+ rot = qrot * parentRot * prim.Rotation;\r
}\r
+ return;\r
}\r
}\r
\r
}\r
\r
\r
- void RenderBoundingBox(BoundingVolume bbox)\r
+ void RenderBoundingBox(RenderPrimitive prim)\r
{\r
+ BoundingVolume bbox = prim.BoundingVolume;\r
GL.PushAttrib(AttribMask.AllAttribBits);\r
GL.Disable(EnableCap.Fog);\r
GL.Disable(EnableCap.Texture2D);\r
GL.Disable(EnableCap.Blend);\r
GL.Disable(EnableCap.AlphaTest);\r
\r
+ GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);\r
+ GL.PushMatrix();\r
+ GL.MultMatrix(Math3D.CreateTranslationMatrix(prim.SimPosition));\r
+ GL.MultMatrix(Math3D.CreateRotationMatrix(prim.SimRotation));\r
+ GL.Scale(prim.Prim.Scale.X, prim.Prim.Scale.Y, prim.Prim.Scale.Z);\r
+ GL.Color3(1f, 0f, 0f);\r
GL.Begin(BeginMode.Quads);\r
var bmin = bbox.Min;\r
var bmax = bbox.Max;\r
GL.Vertex3(bmax.X, bmin.Y, bmin.Z);\r
\r
GL.End();\r
+ GL.PopMatrix();\r
+ GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);\r
GL.PopAttrib();\r
}\r
\r
SortedPrims = new List<RenderPrimitive>(Prims.Count);\r
foreach (RenderPrimitive prim in Prims.Values)\r
{\r
- prim.SimPosition = PrimPos(prim.Prim);\r
+ PrimPosAndRot(prim.Prim, out prim.SimPosition, out prim.SimRotation);\r
prim.DistanceSquared = Vector3.DistanceSquared(Camera.RenderPosition, prim.SimPosition);\r
SortedPrims.Add(prim);\r
}\r
{\r
for (int i = 0; i < nrPrims; i++)\r
{\r
+ //RenderBoundingBox(SortedPrims[i]);\r
RenderPrim(SortedPrims[i], pass, i);\r
}\r
}\r