private void SetProxyIdForEntity(AABBEntity entity, int newId) { if (entity.ProxyIdsByTree == null) { entity.ProxyIdsByTree = new Dictionary <long, int>(); } entity.ProxyIdsByTree[TreeId] = newId; }
public void Remove(AABBEntity entity) { int proxyId = GetProxyIdForEntity(entity); Log.Trace("Remove entity " + proxyId, "Remove"); if (proxyId != PROXY_ID_UNITIALIZED) { MathTree.RemoveProxy(proxyId); SetProxyIdForEntity(entity, PROXY_ID_UNITIALIZED); } Log.Trace("Finished Remove entity " + proxyId, "Remove"); }
public BoundingBoxD GetEntityAABB(AABBEntity entity) { BoundingBoxD bbox = entity.BoundingBox; //Include entity velocity to be able to hit fast moving objects if (entity.WorldTranslation != null && entity.LinearVelocity != null) { bbox = bbox.Include( entity.WorldTranslation + entity.LinearVelocity * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 5 ); } return(bbox); }
// We define these here because AABBEntity is an interface private int GetProxyIdForEntity(AABBEntity entity) { if (entity.ProxyIdsByTree == null) { entity.ProxyIdsByTree = new Dictionary <long, int>(); } if (!entity.ProxyIdsByTree.ContainsKey(TreeId)) { return(PROXY_ID_UNITIALIZED); } else { return(entity.ProxyIdsByTree[TreeId]); } }
public void Move(AABBEntity entity) { int proxyId = GetProxyIdForEntity(entity); if (proxyId != PROXY_ID_UNITIALIZED) { BoundingBoxD bbox = GetEntityAABB(entity); if (bbox.Size == Vector3D.Zero) // remove entities with zero bounding boxes { Remove(entity); return; } MathTree.MoveProxy(proxyId, ref bbox, Vector3D.Zero); } }
public void Add(AABBEntity entity) { int proxyId = GetProxyIdForEntity(entity); Log.Trace("Add entity " + proxyId, "Add"); BoundingBoxD bbox = GetEntityAABB(entity); if (bbox.Size == Vector3D.Zero) { return; // don't add entities with zero bounding boxes } int newProxyId = MathTree.AddProxy(ref bbox, entity, 0); SetProxyIdForEntity(entity, newProxyId); Log.Trace("Finished Add entity " + newProxyId, "Add"); }