public bool Intersects(_collider o) { if (o is CAABB) { return(aabb.Intersects((o as CAABB).aabb)); } return(false); }
internal static void Check(_collider a, _collider b) { if (a.Intersects(b)) { a.Parent().OnCollision(b.Parent()); b.Parent().OnCollision(a.Parent()); } }
//see in what child batch it should go public void Choose(_collider col) { for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) { if (col.Minmax().Intersects(childs[i, j].cbound.Minmax())) childs[i, j].Add(col); } }
internal void Add(_collider o, bool isStatic = false) { if (o == null) return; if (isStatic) { statics.Add(o); staticTree.Clear(); for (int i = 0; i < statics.Count; i++) staticTree.Add(statics[i]); staticTree.Build(); } else dynamics.Add(o); }
//run objects through the batches down public void CheckOther(_collider col) { if (!cbound.Intersects(col)) { return; } if(childs == null) { for(int i = 0; i < colliders.Count; i++) CollisionMath.Check(colliders[i], col); } else { for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) childs[i, j].CheckOther(col); } }
public void Add(_collider col) { if (col == null) return; cols.Add(col); AABB added = col.Minmax(); AABB old = new AABB(minmax); //find outerbound to cut float minx = Math.Min(added.x, old.x); float miny = Math.Min(added.y, old.y); float maxx = Math.Max(added.x + added.w, old.x + old.w); float maxy = Math.Max(added.y + added.h, old.y + old.h); minmax.x = minx; minmax.y = miny; minmax.w = maxx - minx; minmax.h = maxy - miny; root.MakeBound(minmax); counter++; }
//add a collider to this batch and see if it needs splitting public void Add(_collider element) { if (counter < 10 || depth >= 7) { colliders.Add(element); counter++; } else if (childs == null) { childs = new Node[2, 2]; AABB[,] splits = Split(); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) childs[i, j] = new Node(this, splits[i, j], depth + 1); Choose(element); for (int i = 0; i < colliders.Count; i++) Choose(colliders[i]); colliders.Clear(); } else Choose(element); }
public void AddComponent(Component com, string name = "") { com.gameObject = this; com.Init(); if (com is Renderer) { renderer = com as Renderer; } else if (com is _collider) { collider = com as _collider; context.collision.Add(collider, isStatic); } else { if (name == "") { name = MathH.random.NextDouble().ToString(); } components.Add(name, com); comparray = new Component[components.Count]; components.Values.CopyTo(comparray, 0); } }
set => SetProperty(ref _collider, value);