private static void addStaticObjectRecurs(ClientPhysicsQuadTreeNode node, IClientPhysicsObject obj) { if (obj.ContainedInNode(node) == ContainmentType.Disjoint) { return; } if (QuadTree.IsLeafNode(node)) { node.addPhysicsObject(obj); //TODO: need to enable physics right away? // This was said to be yes? if (node.dynamicObjectsCount > 0) { obj.EnablePhysics(); } } else { addStaticObjectRecurs(node.nodeData.UpperLeft, obj); addStaticObjectRecurs(node.nodeData.UpperRight, obj); addStaticObjectRecurs(node.nodeData.LowerLeft, obj); addStaticObjectRecurs(node.nodeData.LowerRight, obj); } }
public ClientPhysicsQuadTreeNode FindContainingNodeUpwards(IClientPhysicsObject obj) { if (obj.ContainedInNode(this) == Microsoft.Xna.Framework.ContainmentType.Contains) { return(this); //entity zit niet in deze node return(null); } if (nodeData.Parent == null) { return(null); } return(nodeData.Parent.FindContainingNodeUpwards(obj)); }
public void AddStaticObject(IClientPhysicsObject obj) { ClientPhysicsQuadTreeNode containingNode = findContainingNode(this, obj); if (containingNode == null) { containingNode = this; } // Now the obj.Node parameter is used, but it is possible to shift the removing from old node responsability // to the ICientPhysicsObject itself. This way, objects that never move do not have to store the Node field. if (obj.Node != null) { throw new InvalidOperationException("A Static Object can only be added once!!!"); } obj.Node = containingNode; addStaticObjectRecurs(containingNode, obj); }
private static void ordenObject(ClientPhysicsQuadTreeNode node, IClientPhysicsObject obj) { ClientPhysicsQuadTreeNode containingNode = findContainingNode(node, obj); if (containingNode == null) { containingNode = node; } // Now the obj.Node parameter is used, but it is possible to shift the removing from old node responsability // to the ICientPhysicsObject itself. This way, objects that never move do not have to store the Node field. if (obj.Node != null) { obj.Node.removePhysicsObject(obj); } containingNode.addPhysicsObject(obj); obj.Node = containingNode; }
private static void removeStaticObjectRecurs(ClientPhysicsQuadTreeNode node, IClientPhysicsObject obj) { if (obj.ContainedInNode(node) == ContainmentType.Disjoint) { return; } if (QuadTree.IsLeafNode(node)) { node.removePhysicsObject(obj); //TODO: need to enable physics right away? //if (node.dynamicObjectsCount > 0) node.enablePhysics(); else node.disablePhysics(); } else { removeStaticObjectRecurs(node.nodeData.UpperLeft, obj); removeStaticObjectRecurs(node.nodeData.UpperRight, obj); removeStaticObjectRecurs(node.nodeData.LowerLeft, obj); removeStaticObjectRecurs(node.nodeData.LowerRight, obj); } }
public void RemoveDynamicObject(IClientPhysicsObject obj) { dynamicObjectsCount--; }
/// <summary> /// This increases the DynamicObject count by one. Notice that this doesn't store the list of dynamic objects itself /// WARNING: this function is not really at the same level as AddStaticObject /// </summary> /// <param name="obj"></param> public void AddDynamicObject(IClientPhysicsObject obj) { dynamicObjectsCount++; }
/// <summary> /// Adds given obj to the tree, or updates its location in the tree /// This was previously/currently used for initially positioning static objects. This assigns the clientphysobject's node to its containing node and adds the object to this node. /// This has a a bad side-effect that the object's physics is enabled far to often. Better use AddStaticObject /// </summary> /// <param name="obj"></param> public void OrdenObject(IClientPhysicsObject obj) { ordenObject(this, obj); //return OrdenEntity( this, obj ); }
private void removePhysicsObject(IClientPhysicsObject obj) { physicsObjects.Remove(obj); }
/*public void FindCollisionNodes(ClientPhysicsQuadTreeNode node, IClientPhysicsObject entH, List<ClientPhysicsQuadTreeNode> collisionNodes) * { * if (entH.ContainedInNode(node) == ContainmentType.Disjoint) return; * if (QuadTree.IsLeafNode(node)) * { * collisionNodes.Add(node); * } * else * { * FindCollisionNodes(node.nodeData.UpperLeft, entH, collisionNodes); * FindCollisionNodes(node.nodeData.UpperRight, entH, collisionNodes); * FindCollisionNodes(node.nodeData.LowerLeft, entH, collisionNodes); * FindCollisionNodes(node.nodeData.LowerRight, entH, collisionNodes); * } * * * * }*/ private void addPhysicsObject(IClientPhysicsObject obj) { physicsObjects.Add(obj); }
/// <summary> /// This function adds 'change' to all the leaf nodes that intersect or contain given object /// </summary> /// <param name="node"></param> /// <param name="obj"></param> /// <param name="change"></param> private static void changeDynamicCountForIntersectingNodes(ClientPhysicsQuadTreeNode node, IClientPhysicsObject obj, int change) { if (obj.ContainedInNode(node) == ContainmentType.Disjoint) { return; } if (QuadTree.IsLeafNode(node)) { node.dynamicObjectsCount += change; if (node.dynamicObjectsCount < 0) { throw new InvalidOperationException("Invalid dynamicobjectscount. Cannot go below zero!"); } // update the physicsenabled flags if (node.dynamicObjectsCount > 0) { node.enablePhysics(); } else { node.disablePhysics(); } } else { changeDynamicCountForIntersectingNodes(node.nodeData.UpperLeft, obj, change); changeDynamicCountForIntersectingNodes(node.nodeData.UpperRight, obj, change); changeDynamicCountForIntersectingNodes(node.nodeData.LowerLeft, obj, change); changeDynamicCountForIntersectingNodes(node.nodeData.LowerRight, obj, change); } }
/// <summary> /// This function subtracts 1 to the dynamic object count of all leaf nodes intersecting or containing given obj /// </summary> /// <param name="obj"></param> public void RemoveDynamicObjectFromIntersectingNodes(IClientPhysicsObject obj) { changeDynamicCountForIntersectingNodes(this, obj, -1); }
/// <summary> /// This function adds 1 to the dynamic object count of all leaf nodes intersecting or containing given obj /// </summary> /// <param name="obj"></param> public void AddDynamicObjectToIntersectingNodes(IClientPhysicsObject obj) { changeDynamicCountForIntersectingNodes(this, obj, 1); }
private static ClientPhysicsQuadTreeNode findContainingNode(ClientPhysicsQuadTreeNode node, IClientPhysicsObject obj) { if (node == null) { return(null); } if (obj.ContainedInNode(node) != Microsoft.Xna.Framework.ContainmentType.Contains) { //entity zit niet in deze node return(null); } //Entity volledig zit in deze node. Check of hij volledig in een van de children zit. ClientPhysicsQuadTreeNode ret; if ((ret = findContainingNode(node.nodeData.UpperLeft, obj)) != null) { return(ret); } if ((ret = findContainingNode(node.nodeData.UpperRight, obj)) != null) { return(ret); } if ((ret = findContainingNode(node.nodeData.LowerLeft, obj)) != null) { return(ret); } if ((ret = findContainingNode(node.nodeData.LowerRight, obj)) != null) { return(ret); } //Zit niet volleidg in een van de children. return(node); }
public void RemoveStaticObject(IClientPhysicsObject obj) { removeStaticObjectRecurs(obj.Node, obj); obj.Node = null; }