Esempio n. 1
0
    public static rtAABB surrounding_box(rtAABB box0, rtAABB box1)
    {
        Vector3 small = Vector3.Min(box0._min, box1._min);
        Vector3 big   = Vector3.Max(box0._max, box1._max);

        return(new rtAABB(small, big));
    }
Esempio n. 2
0
    public override bool bounding_box(float t0, float t1, ref rtAABB box)
    {
        if (list.Count < 1)
        {
            return(false);
        }

        rtAABB temp_box   = new rtAABB();
        bool   first_true = list[0].bounding_box(t0, t1, ref temp_box);

        if (!first_true)
        {
            return(false);
        }
        else
        {
            box = temp_box;
        }

        for (int i = 0; i < list.Count; i++)
        {
            if (list[0].bounding_box(t0, t1, ref temp_box))
            {
                box = rtAABB.surrounding_box(box, temp_box);
            }
            else
            {
                return(false);
            }
        }
        return(true);
    }
Esempio n. 3
0
    public override bool bounding_box(float t0, float t1, ref rtAABB box)
    {
        Vector3 min = Vector3.Min(Vector3.Min(a, b), c);
        Vector3 max = Vector3.Max(Vector3.Max(a, b), c);

        box = new rtAABB(min, max);
        return(true);
    }
Esempio n. 4
0
    public override bool bounding_box(float t0, float t1, ref rtAABB box)
    {
        Vector3 radiuVec = Vector3.one * radius;
        rtAABB  box0     = new rtAABB(center0 - radiuVec, center0 + radiuVec);
        rtAABB  box1     = new rtAABB(center1 - radiuVec, center1 + radiuVec);

        box = rtAABB.surrounding_box(box0, box1);
        return(true);
    }
Esempio n. 5
0
    public quad(zMaterial mat, Transform transform, int instanceID = 0)
    {
        k = 0;
        //Vector3 worldmin = transform.localToWorldMatrix.MultiplyPoint(new Vector3(-0.5f, -0.5f, 0f));
        //Vector3 worldmax = transform.localToWorldMatrix.MultiplyPoint(new Vector3(0.5f, 0.5f, 0f));
        //x0 = Mathf.Min(worldmin.x, worldmax.x);
        //x1 = Mathf.Max(worldmin.x, worldmax.x);
        //z0 = Mathf.Min(worldmin.z, worldmax.z);
        //z1 = Mathf.Max(worldmin.z, worldmax.z);
        x0       = -0.5f;
        x1       = 0.5f;
        y0       = -0.5f;
        y1       = 0.5f;
        material = mat;
        normal   = -transform.forward;
        id       = instanceID;
        trans    = transform;
        Bounds bd = trans.GetComponent <Renderer>().bounds;

        aabb = new rtAABB(bd.min, bd.max);
    }
Esempio n. 6
0
 public override bool bounding_box(float t0, float t1, ref rtAABB box)
 {
     box = new rtAABB(center - Vector3.one * radius, center + Vector3.one * radius);
     return(true);
 }
Esempio n. 7
0
 public abstract bool bounding_box(float t0, float t1, ref rtAABB box);
 public triangle_list(List <triangle> list, Bounds bd, int instanceID = 0)
 {
     this.list = list;
     aabb      = new rtAABB(bd.min, bd.max);
     id        = instanceID;
 }
 public override bool bounding_box(float t0, float t1, ref rtAABB box)
 {
     box = aabb;
     return(true);
 }
Esempio n. 10
0
    public BVH_Node(List <Hitable> list, float time0, float time1)
    {
        Objlist = list;
        int axis = Mathf.FloorToInt(zRandom.drand() * 3f);

        if (axis == 0)
        {
            list.Sort((a, b) =>
            {
                rtAABB box_left = new rtAABB(), box_right = new rtAABB();
                if (!a.bounding_box(0, 0, ref box_left) || !b.bounding_box(0, 0, ref box_right))
                {
                    Debug.LogError(" no bounding box in bvh_node constructor");
                }
                if (box_left._min.x - box_right._min.x < 0f)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            });
        }
        else if (axis == 1)
        {
            list.Sort((a, b) =>
            {
                rtAABB box_left = new rtAABB(), box_right = new rtAABB();
                if (!a.bounding_box(0, 0, ref box_left) || !b.bounding_box(0, 0, ref box_right))
                {
                    Debug.LogError(" no bounding box in bvh_node constructor");
                }
                if (box_left._min.y - box_right._min.y < 0f)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            });
        }
        else
        {
            list.Sort((a, b) =>
            {
                rtAABB box_left = new rtAABB(), box_right = new rtAABB();
                if (!a.bounding_box(0, 0, ref box_left) || !b.bounding_box(0, 0, ref box_right))
                {
                    Debug.LogError(" no bounding box in bvh_node constructor");
                }
                if (box_left._min.z - box_right._min.z < 0f)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            });
        }

        int n = list.Count;

        if (n == 1)
        {
            left = right = list[0];
        }
        else if (n == 2)
        {
            left  = list[0];
            right = list[1];
        }
        else
        {
            left  = new BVH_Node(list.GetRange(0, n / 2), time0, time1);
            right = new BVH_Node(list.GetRange(n / 2, n - n / 2), time0, time1);
        }
        rtAABB box_l = new rtAABB(), box_r = new rtAABB();

        if (!left.bounding_box(time0, time1, ref box_l) || !right.bounding_box(time0, time1, ref box_r))
        {
            Debug.LogError(" no bounding box in bvh_node constructor");
        }
        box = rtAABB.surrounding_box(box_l, box_r);
    }