private static RenderedNode NewRenderedObject(string meshName, int id, int index, Vector3 position, float scale) { RenderedNode n = UnscaledRenderedObject(meshName, id, index, position); n.node.ScaleFactor = Vector3.UnitScale * scale; return(n); }
private static RenderedNode NewRenderedObject(string meshName, int id, int index, Vector3 position, float scale, Quaternion orientation) { RenderedNode n = NewRenderedObject(meshName, id, index, position, scale); n.node.Orientation = orientation; return(n); }
private static RenderedNode NewRenderedObject(string meshName, int id, int index, Vector3 position, Vector3 scale, Quaternion orientation) { RenderedNode n = UnscaledRenderedObject(meshName, id, index, position); n.node.ScaleFactor = scale; n.node.Orientation = orientation; return(n); }
public MovingPart(CollisionAPI api, CollisionShape shape) { this.shape = shape; this.api = api; constantShape = shape; id = api.SphereTree.GetId(); renderedNodes = null; RenderedNode.MaybeCreateRenderedNodes(false, shape, id, ref renderedNodes); sphere = null; }
public static void AddDisplacement(Vector3 displacement, ref List <RenderedNode> renderedNodes) { if (renderedNodes != null) { for (int i = 0; i < renderedNodes.Count; i++) { RenderedNode n = renderedNodes[i]; n.node.Position += displacement; } } }
private static RenderedNode NewRenderedBox(int id, int index, CollisionOBB box) { RenderedNode n = UnscaledRenderedObject("unit_box.mesh", id, index, box.center); n.node.ScaleFactor = 2 * box.extents * MO.DivMeter; Quaternion q = Quaternion.Identity; q.FromAxes(box.axes[0], box.axes[1], box.axes[2]); n.node.Orientation = q; return(n); }
public static void ChangeRendering(bool render, CollisionShape shape, int id, ref List <RenderedNode> renderedNodes) { if (!render) { RenderedNode.RemoveNodeRendering(id, ref renderedNodes); } else { RenderedNode.CreateRenderedNodes(shape, id, ref renderedNodes); } }
public void Transform(Vector3 scale, Quaternion rotate, Vector3 translate) { // TODO: This is a temporary solution, and terribly inefficient. // I need to update the transforms on the node properly, without // the remove/add. RenderedNode.RemoveNodeRendering(id, ref renderedNodes); shape = constantShape.Clone(); shape.Transform(scale, rotate, translate); id = api.SphereTree.GetId(); renderedNodes = null; RenderedNode.MaybeCreateRenderedNodes(false, shape, id, ref renderedNodes); sphere = null; }
// Create a SphereTreeNode leaf node public SphereTreeNode(CollisionShape shape, SphereTree sphereTree) : base(shape.center, shape.radius) { this.sphereTree = sphereTree; this.containedShape = shape; parent = null; children = new SphereTreeNode[childCount]; intersectingShapes = new List <CollisionShape>(); leafNode = true; sphereTree.idCounter++; id = sphereTree.idCounter; sphereTree.nodeCount++; RenderedNode.MaybeCreateRenderedNodes(true, shape, id, ref renderedNodes); }
public void ChangeRendering(bool render) { if (leafNode) { RenderedNode.ChangeRendering(render, containedShape, id, ref renderedNodes); } else { for (int i = 0; i < childCount; i++) { SphereTreeNode child = children[i]; if (child != null) { child.ChangeRendering(render); } } } }
private static RenderedNode UnscaledRenderedObject(string meshName, int id, int index, Vector3 position) { string name = RenderedNodeName(id, index); if (MO.DoLog) { MO.Log(string.Format(" Creating rendering for node {0}", name)); } Entity entity = scene.CreateEntity(name, meshName); SceneNode node = scene.RootSceneNode.CreateChildSceneNode(name); node.AttachObject(entity); node.Position = position; node.ScaleFactor = Vector3.UnitScale; node.Orientation = Quaternion.Identity; RenderedNode n = new RenderedNode(entity, node); return(n); }
public static void RemoveNodeRendering(int id, ref List <RenderedNode> renderedNodes) { if (renderedNodes != null) { for (int i = 0; i < renderedNodes.Count; i++) { string name = RenderedNodeName(id, i); if (MO.DoLog) { MO.Log(string.Format(" Removing rendering for node {0}", name)); } RenderedNode n = renderedNodes[i]; n.node.Creator.DestroySceneNode(name); // remove the entity from the scene scene.RemoveEntity(n.entity); // clean up any unmanaged resources n.entity.Dispose(); } renderedNodes.Clear(); } }
public void AddDisplacement(Vector3 displacement) { shape.AddDisplacement(displacement); RenderedNode.AddDisplacement(displacement, ref renderedNodes); }
public void RemoveNodeRendering() { RenderedNode.RemoveNodeRendering(id, ref renderedNodes); }
public void ChangeRendering(bool render) { RenderedNode.ChangeRendering(render, shape, id, ref renderedNodes); }
public void AddDisplacementToRenderedNodes(Vector3 displacement) { RenderedNode.AddDisplacement(displacement, ref renderedNodes); }
public void ToggleRenderCollisionVolumes(SceneManager scene, bool movingObjects) { RenderedNode.ToggleRenderCollisionVolumes(this, scene, movingObjects); }
public int RemoveCollisionShapesWithHandleInternal(long handle) { // The dumb version: iterate over all containment spheres // looking for obstacles with the given handle, returning true // if a child changed. (The smarter version would maintain an // index mapping handles to SphereTreeNodes whose // containedShape or intersectingShapes have a shape with // that handle.) // // This runs bottom-up, to provide an opportunity to coalesce // the sphere tree. // intersectingShapes are easy - - just remove if they have a // matching handle, since their removal doesn't change the tree int removeCount = 0; for (int i = 0; i < intersectingShapes.Count; i++) { CollisionShape obstacle = intersectingShapes[i]; if (obstacle.handle == handle) { if (MO.DoLog) { MO.Log(" Removing intersecting shape {0} of {1}", obstacle, this); } intersectingShapes.RemoveAt(i); i--; sphereTree.intersectingShapeCount--; Debug.Assert(sphereTree.intersectingShapeCount >= 0, "intersectingShapeCount < 0!"); } } // Now handle the children for (int i = 0; i < childCount; i++) { SphereTreeNode child = children[i]; if (child != null) { if (child.leafNode && child.containedShape.handle == handle) { if (MO.DoLog) { MO.Log(" Removing child leaf {0} of {1}", child, this); } children[i] = null; child.parent = null; RenderedNode.RemoveNodeRendering(child.id, ref child.renderedNodes); sphereTree.shapesRemoved++; sphereTree.nodeCount--; removeCount++; } else if (!child.leafNode) { removeCount += child.RemoveCollisionShapesWithHandleInternal(handle); } } } int count = CountChildren(); if (count == 0 && containedShape == null) { // This is now a truly pointless node - - remove from its // parent. Parent will only be null for the root node if (parent != null) { if (MO.DoLog) { MO.Log(" Removing branch with no kids {0} of {1}", this, parent); } parent.RemoveChild(this); sphereTree.nodeCount--; Debug.Assert(sphereTree.nodeCount > 0, "nodeCount <= 0"); return(removeCount); } } else if (count == 1) { if (parent != null) { // Make my child the child of my parent if (MO.DoLog) { MO.Log(" Replacing 1-child node {0} in parent {1}", this, parent); } parent.ReplaceChild(this, FindFirstChild()); sphereTree.nodeCount--; Debug.Assert(sphereTree.nodeCount > 0, "nodeCount <= 0"); return(removeCount); } } if (removeCount > 0) { RecalculateCenterAndRadius(); } return(removeCount); }