override public void Query(MyAABB aabb, out List <MyCollider> output) { output = new List <MyCollider>(); foreach (var ab in m_aabbs) { if (ab.Collides(aabb)) { output.Add(ab.Collider()); } } }
public bool Collides(MyAABB other) { var lhsMin = min + transform.position; var lhsMax = max + transform.position; var rhsMin = other.min + other.transform.position; var rhsMax = other.max + other.transform.position; return((lhsMin.x < rhsMax.x && lhsMax.x > rhsMin.x) && (lhsMin.y < rhsMax.y && lhsMax.y > rhsMin.y) && (lhsMin.z < rhsMax.z && lhsMax.z > rhsMin.z)); }
override public bool TestRay(Ray3 ray, out float t, out Vector3 normal) { Vector3 min = transform.position + new Vector3(-width / 2, -height / 2, -depth / 2); Vector3 max = transform.position + new Vector3(width / 2, height / 2, depth / 2); Vector3 intersection; bool b = MyAABB.HitBoundingBox(min, max, ray.pos, ray.dir, out intersection); // hit point = ray.pos + t * ray.dir // t = (hit point - ray.pos)/ray.dir t = (intersection - ray.pos).magnitude / ray.dir.magnitude; normal = (ray.pos - intersection).normalized; Debug.DrawLine(intersection, intersection + Vector3.up, Color.red); Debug.DrawLine(intersection, intersection + Vector3.left, Color.red); Debug.DrawLine(intersection, intersection + Vector3.forward, Color.red); return(b); }
void DebugDraw(MyAABB aabb, Color color){ int i = 0; Vector3 [] points = new Vector3[8]; points[i++] = new Vector3(aabb.max.x, aabb.max.y, aabb.max.z) + aabb.transform.position; points[i++] = new Vector3(aabb.max.x, aabb.max.y, aabb.min.z) + aabb.transform.position; points[i++] = new Vector3(aabb.max.x, aabb.min.y, aabb.max.z) + aabb.transform.position; points[i++] = new Vector3(aabb.max.x, aabb.min.y, aabb.min.z) + aabb.transform.position; points[i++] = new Vector3(aabb.min.x, aabb.max.y, aabb.max.z) + aabb.transform.position; points[i++] = new Vector3(aabb.min.x, aabb.max.y, aabb.min.z) + aabb.transform.position; points[i++] = new Vector3(aabb.min.x, aabb.min.y, aabb.max.z) + aabb.transform.position; points[i++] = new Vector3(aabb.min.x, aabb.min.y, aabb.min.z) + aabb.transform.position; Debug.DrawLine(points[0], points[1], color); Debug.DrawLine(points[0], points[2], color); Debug.DrawLine(points[1], points[3], color); Debug.DrawLine(points[2], points[3], color); Debug.DrawLine(points[4], points[5], color); Debug.DrawLine(points[4], points[6], color); Debug.DrawLine(points[5], points[7], color); Debug.DrawLine(points[6], points[7], color); Debug.DrawLine(points[0], points[4], color); Debug.DrawLine(points[1], points[5], color); Debug.DrawLine(points[2], points[6], color); Debug.DrawLine(points[3], points[7], color); }
// returns a list of colliders whose AABBs collide // with a query AABB virtual public void Query(MyAABB aabb, out List <MyCollider> output) { output = null; }
virtual public void Remove(MyAABB aabb) { m_aabbs.Remove(aabb); }
// adds a new AABB to the broadphase virtual public void Add(MyAABB aabb) { m_aabbs.Add(aabb); }