public bool boundingBox(ref aabb box) { if (hitables.Count < 1) { return(false); } aabb tempBox = new aabb(); bool firstTrue = hitables[0].boundingBox(ref tempBox); if (!firstTrue) { return(false); } else { box = tempBox; for (int i = 1; i < hitables.Count; i++) { if (hitables[i].boundingBox(ref tempBox)) { box = aabb.surrounding_box(box, tempBox); } else { return(false); } } return(true); } }
public static aabb surrounding_box(aabb box0, aabb box1) { Vec3 small = new Vec3(Utils.min(box0.min.x, box1.min.x), Utils.min(box0.min.y, box1.min.y), Utils.min(box0.min.z, box1.min.z)); Vec3 big = new Vec3(Utils.max(box0.max.x, box1.max.x), Utils.max(box0.max.y, box1.max.y), Utils.max(box0.max.z, box1.max.z)); return(new aabb(small, big)); }
private int boxZCompare(Hitable a, Hitable b) { aabb boxLeft = new aabb(); aabb boxRight = new aabb(); if (!a.boundingBox(ref boxLeft) || !b.boundingBox(ref boxRight)) { throw new ArgumentException(""); } if (boxLeft.min.z - boxRight.min.z < 0.0) { return(-1); } else { return(1); } }
public bvh_node(List <Hitable> hitables, int n) { int axis = (int)Utils.rand(0, 3); if (axis == 0) { hitables.Sort(0, n, Comparer <Hitable> .Create(boxXCompare)); } else if (axis == 1) { hitables.Sort(0, n, Comparer <Hitable> .Create(boxYCompare)); } else { hitables.Sort(0, n, Comparer <Hitable> .Create(boxZCompare)); } if (n == 1) { left = hitables[0]; right = hitables[0]; } else if (n == 2) { left = hitables[0]; right = hitables[1]; } else { left = new bvh_node(hitables.GetRange(0, n / 2), n / 2); right = new bvh_node(hitables.GetRange(n / 2, n - n / 2), n - n / 2); } aabb boxLeft = new aabb(); aabb boxRight = new aabb(); if (!left.boundingBox(ref boxLeft) || !right.boundingBox(ref boxRight)) { throw new ArgumentException("No Bounding box in boh_node constructor"); } box = aabb.surrounding_box(boxLeft, boxRight); }
public bool boundingBox(ref aabb box) { box = new aabb(center - new Vec3(radius, radius, radius), center + new Vec3(radius, radius, radius)); return(true); }
public bool boundingBox(ref aabb box) { throw new NotImplementedException(); }
public bool boundingBox(ref aabb box) { box = this.box; return(true); }