private HitPoint GetHitPointR(Vector3 d, Vector3 OP, BVHNode node) { if (node.Left != null && node.Right != null) { float lambdaLeft = Helper.VectorSphereHitPoint(d, OP, mSpheres[node.Left.SphereIndex]); float lambdaRight = Helper.VectorSphereHitPoint(d, OP, mSpheres[node.Right.SphereIndex]); if (lambdaLeft == HitPoint.NoHitPoint.Lambda && lambdaRight == HitPoint.NoHitPoint.Lambda) { return(HitPoint.NoHitPoint); } else if (lambdaLeft != HitPoint.NoHitPoint.Lambda && lambdaRight != HitPoint.NoHitPoint.Lambda) { HitPoint hpLeft = GetHitPointR(d, OP, node.Left); HitPoint hpRight = GetHitPointR(d, OP, node.Right); return((hpLeft.Lambda < hpRight.Lambda) ? hpLeft : hpRight); } else if (lambdaLeft != HitPoint.NoHitPoint.Lambda) { return(GetHitPointR(d, OP, node.Left)); } else // lambdaRight != HitPoint.NoHitPoint.Lambda { return(GetHitPointR(d, OP, node.Right)); } } else { Debug.Assert(node.SphereIndex < mNaturalSphereCount); float lambda = Helper.VectorSphereHitPoint(d, OP, mSpheres[node.SphereIndex]); if (lambda == HitPoint.NoHitPoint.Lambda) { return(HitPoint.NoHitPoint); } else { return(new HitPoint(OP, lambda, d, node.SphereIndex)); } } }
public BVHAccelerationStructure(List <Sphere> spheres) { mSpheres = new Sphere[spheres.Count * 2]; mNaturalSphereCount = spheres.Count; mRoot = Populate(spheres); }
public BVHNode(BVHNode l, BVHNode r, int sphere) { Left = l; Right = r; SphereIndex = sphere; }