private TriggerRangeEvent(CollisionBody collisionBody, IEntity triggerEntity, bool isInRange) : base(collisionBody.Owner, isInRange ? EventType.TRIGGER_IN_RANGE_EVENT : EventType.TRIGGER_OUT_RANGE_EVENT) { this.triggerEntity = triggerEntity; this.collisionBody = collisionBody; this.isInRange = isInRange; }
public virtual void addBody(CollisionBody shape) { if (!this.bodyList.Contains(shape)) { this.bodyList.Add(shape); CollisionManager.Instance.addContainer(shape); } }
public static TriggerRangeEvent Create(CollisionBody collisionBody, IEntity triggerEntity, bool isInRange) { TriggerRangeEvent returningEvent = EventManager.Instance.GetEventFromType<TriggerRangeEvent>(isInRange ? EventType.TRIGGER_IN_RANGE_EVENT : EventType.TRIGGER_OUT_RANGE_EVENT); if (returningEvent == null) { returningEvent = EventManager.Instance.AddEventToPool(new TriggerRangeEvent(collisionBody, triggerEntity, isInRange)); } else { returningEvent.collisionBody = collisionBody; returningEvent.triggerEntity = triggerEntity; returningEvent.isInRange = isInRange; returningEvent.origin = collisionBody.Owner; } return returningEvent; }
public void AddObject(CollisionBody obj, float minX, float minY, float maxX, float maxY) { this.items.Add(obj); if (this.depth == 1) { obj.lastBigNode = this; } if (children == null) { if (this.items.Count > this.maxBodyCount && this.depth < this.maxDepth) { this.SubDivide(); } } else { for (int i = 0; i < 4; i++) { bool inside = true; QuadTreeNode child = this.children[i]; if (child.x1 > maxX || child.x2 < minX || child.y1 > maxY || child.y2 < minY) inside = false; if (inside) { if (child.x2 >= maxX && child.x1 <= minX && child.y2 >= maxY && child.y1 <= minY) { obj.lastBigNode = child; } this.children[i].AddObject(obj, minX, minY, maxX, maxY); } } } }
public void GetCollidableObjects(XboxHashSet<CollisionBody> list, CollisionBody container, ref Rectangle boundingBox) { float minX = boundingBox.X, minY = boundingBox.Y, maxX = boundingBox.X + boundingBox.Width, maxY = boundingBox.Y + boundingBox.Height; this.GetCollidableObjects(list, container, minX, minY, maxX, maxY); }
public void GetCollidableObjects(XboxHashSet<CollisionBody> list, CollisionBody container) { float minX = 0, minY = 0, maxX = 0, maxY = 0; container.BuildAABB(out minX, out minY, out maxX, out maxY); this.GetCollidableObjects(list, container, minX, minY, maxX, maxY); }
public void GetCollidableObjects(XboxHashSet<CollisionBody> list, CollisionBody container, float minX, float minY, float maxX, float maxY) { if (children == null) { //if (this.containerList.Contains(container)) //{ /*foreach (CollisionBody bodyFromList in this.items) { list.Add(bodyFromList); }*/ list.MergeInto(this.items); //} } else { for (int i = 0; i < 4; i++) { bool inside = true; QuadTreeNode child = this.children[i]; if (child.x1 > maxX || child.x2 < minX || child.y1 > maxY || child.y2 < minY) inside = false; if (inside) { if (child.children == null) { /*foreach (CollisionBody bodyFromList in child.items) { list.Add(bodyFromList); }*/ list.MergeInto(child.items); } else { child.GetCollidableObjects(list, container); } } } } }
public AnimatedCollisionComponent(IEntity owner, CollisionBody shape) : base(owner, shape) { this.initialize(); }
/// <summary> /// Obtiene todos los CollisionBody que se encuentren en rango /// de un CollisionBody especifico para así poder minimizar /// los calculos de colisión /// </summary> /// <param name="body">Body utilizado para la busqueda</param> /// <returns>Lista de bodies en rango</returns> public XboxHashSet<CollisionBody> GetBodyGroup(CollisionBody body) { //this.bodyGroupList.Clear(); this.bodyGroupHashSet.Clear(); QuadTreeNode root; if (this.layersRoots.TryGetValue(body.Layer, out root)) { float minX = 0, minY = 0, maxX = 0, maxY = 0; body.BuildAABB(out minX, out minY, out maxX, out maxY); if (body.lastBigNode.depth == 0) { root.GetCollidableObjects(this.bodyGroupHashSet, body, minX, minY, maxX, maxY); } else { body.lastBigNode.GetCollidableObjects(this.bodyGroupHashSet, body, minX, minY, maxX, maxY); } } return this.bodyGroupHashSet; }
public void AddObject(CollisionBody obj, ref Rectangle boundingBox) { float minX = boundingBox.X, minY = boundingBox.Y, maxX = boundingBox.X + boundingBox.Width, maxY = boundingBox.Y + boundingBox.Height; this.AddObject(obj, minX, minY, maxX, maxY); }
/// <summary> /// Especifica la zona de una vez ya que el owner de sa zona sera la entidad /// a la que este trigger se quiere adaptar y no el trigger como tal (a diferencia de BaseTrigger) /// </summary> /// <param name="zone"></param> public AttachableTrigger(CollisionBody zone) { // no zone yet! coz zone necesita owner que es esto mismo, acomodar! this.zone = zone; initialize(); }
/// <summary> /// Verifica si este cuerpo esta colisionando o va a colisionar /// con otro cuerpo dado /// </summary> /// <param name="polygon">Cuerpo con el cual se hará la verificacion</param> /// <param name="distance">Distancia por la cual se movera este cuerpo</param> /// <param name="result">Referencia del objeto que contendrá la información necesaria sobre /// si se esta intersectando, si se intersectará y la distancia necesaria /// para evitar una intersección</param> public CollisionResult Intersect(CollisionBody secondBody, ref Vector2 distance) { bool intersect = true; bool willIntersect = true; float minX = 0, minY = 0, maxX = 0, maxY = 0; this.BuildAABB(out minX, out minY, out maxX, out maxY); float minSecondX = 0, minSecondY = 0, maxSecondX = 0, maxSecondY = 0; secondBody.BuildAABB(out minSecondX, out minSecondY, out maxSecondX, out maxSecondY); if (minX > maxSecondX || maxX < minSecondX || minY > maxSecondY || maxY < minSecondY) intersect = false; minX += distance.X; maxX += distance.X; minY += distance.Y; maxY += distance.Y; if (minX > maxSecondX || maxX < minSecondX || minY > maxSecondY ||maxY < minSecondY) willIntersect = false; if (!intersect && !willIntersect) { CollisionResult result = new CollisionResult(); result.triggeringBody = this; result.affectedBody = secondBody; return result; } if (secondBody.GetType() == typeof(Box)) { return this.IntersectWithBox((Box)secondBody, ref distance); } else if (secondBody.GetType() == typeof(Polygon)) { return this.IntersectWithPolygon((Polygon)secondBody, ref distance); } else { return this.IntersectWithSphere((Sphere)secondBody, ref distance); } }
public void addBody(CollisionBody body) { wrapperList.Add(new AreaCollisionBodyWrapper(owner, body)); CollisionManager.Instance.addContainer(body); }
/// <summary> /// Remueve un CollisionBody tanto de la lista global de bodies /// como de su capa respectiva /// </summary> /// <param name="body">CollisionBody a remover</param> public void removeContainer(CollisionBody body) { QuadTreeNode root; if (this.layersRoots.TryGetValue(body.Layer, out root)) { float minX = 0, minY = 0, maxX = 0, maxY = 0; body.BuildAABB(out minX, out minY, out maxX, out maxY); root.RemoveObject(body, minX, minY, maxX, maxY); } this.bodyGlobalSet.Remove(body); }
public void RemoveObject(CollisionBody obj, float minX, float minY, float maxX, float maxY) { this.items.Remove(obj); if (children != null) { if (this.items.Count < maxBodyCount - 1) { for (int i = 0; i < 4; i++) { this.children[i].Delete(); } foreach (CollisionBody body in this.items) { if (body.lastBigNode.depth > this.depth) body.lastBigNode = this; } Program.GAME.CollisionManager.redeemNodeArray(this.children); this.children = null; return; } for (int i = 0; i < 4; i++) { bool inside = true; QuadTreeNode child = this.children[i]; if (child.x1 > maxX || child.x2 < minX || child.y1 > maxY || child.y2 < minY) inside = false; if (inside) { child.RemoveObject(obj, minX, minY, maxX, maxY); } } } }
public override void removeBody(CollisionBody shape) { if (this.BodyList.Remove(shape)) { CollisionManager.Instance.removeContainer(shape); } }
public PlatformCollisionComponent(IEntity owner, CollisionBody shape) : base(owner, shape) { this.initialize(); }
public AbstractCollisionComponent(IEntity owner, CollisionBody body) : base(owner) { this.bodyList = new List<CollisionBody>(); this.bodyList.Add(body); }
public ActiveBody(CollisionBody body, int time) { this.Body = body; this.timeAlive = time; }
public virtual void removeBody(CollisionBody shape) { if (this.bodyList.Remove(shape)) { CollisionManager.Instance.removeContainer(shape); } }
/// <summary> /// Agrega un CollisionBody tanto a la lista global de bodies /// como a su capa respectiva /// </summary> /// <param name="body">CollisionBody a agregar</param> public void addContainer(CollisionBody body) { if (!this.layersRoots.ContainsKey(body.Layer)) { QuadTreeNode root = new QuadTreeNode(); root.reset(/*null, */layerX, layerY, layerWidth, layerHeight, 1, this.maxNodeCapacity, this.nodeDepth); this.layersRoots.Add(body.Layer, root); } float minX = 0, minY = 0, maxX = 0, maxY = 0; body.BuildAABB(out minX, out minY, out maxX, out maxY); this.layersRoots[body.Layer].AddObject(body, minX, minY, maxX, maxY); this.bodyGlobalSet.Add(body); }