/// <summary> /// /// </summary> /// <param name="transform"></param> /// <param name="parentTransform"></param> private void RenderBone(JOBJCache jobj, bool selected) { Matrix4 transform = jobj.WorldTransform; var bonePosition = Vector3.TransformPosition(Vector3.Zero, transform); if (jobj.Parent != null) { Matrix4 parentTransform = jobj.Parent.WorldTransform; var parentPosition = Vector3.TransformPosition(Vector3.Zero, parentTransform); GL.LineWidth(1f); GL.Begin(PrimitiveType.Lines); GL.Color3(0f, 1f, 0f); GL.Vertex3(parentPosition); GL.Color3(0f, 0f, 1f); GL.Vertex3(bonePosition); GL.End(); } if (selected) { GL.Color3(1f, 1f, 0f); GL.PointSize(7f); } else { GL.Color3(1f, 0f, 0f); GL.PointSize(5f); } GL.Begin(PrimitiveType.Points); GL.Vertex3(bonePosition); GL.End(); }
/// <summary> /// Updates the transforms /// </summary> /// <param name="root"></param> private void UpdateTransforms(HSD_JOBJ root, JOBJCache parent = null) { if (root == null) { return; } var index = -1; if (jobjToCache.ContainsKey(root)) { index = jobjToCache[root].Index; } var local = CreateLocalTransform(root, index); var world = local; if (parent != null) { world = local * parent.WorldTransform; } if (!jobjToCache.ContainsKey(root)) { var jcache = new JOBJCache() { Parent = parent, Index = jobjToCache.Count, InvertedTransform = world.Inverted() }; jobjToCache.Add(root, jcache); } var cache = jobjToCache[root]; cache.LocalTransform = local; cache.WorldTransform = world; cache.BindTransform = cache.InvertedTransform * world; foreach (var child in root.Children) { UpdateTransforms(child, jobjToCache[root]); } }