Ejemplo n.º 1
0
 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());
         }
     }
 }
Ejemplo n.º 2
0
    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));
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
	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);
	}
Ejemplo n.º 5
0
 // returns a list of colliders whose AABBs collide
 // with a query AABB
 virtual public void Query(MyAABB aabb, out List <MyCollider> output)
 {
     output = null;
 }
Ejemplo n.º 6
0
 virtual public void Remove(MyAABB aabb)
 {
     m_aabbs.Remove(aabb);
 }
Ejemplo n.º 7
0
 // adds a new AABB to the broadphase
 virtual public void Add(MyAABB aabb)
 {
     m_aabbs.Add(aabb);
 }