/// <summary> /// Casts a ray against mesh /// </summary> /// <param name="ray">Ray to be cast</param> /// <param name="maxDistance">Maximum distance to trace ray</param> /// <param name="hitInfo">Will contain hit information if true is returned</param> /// <returns>Distance along the ray the hit was found</returns> public bool Raycast(Ray ray, float maxDistance, ref RaycastHit hitInfo) { #if DEBUG Interlocked.Increment(ref Counters.RaysCast); #endif var localRayDirection = ray.Direction.RotatedBy(_invRotation); var localRayOrigin = (ray.Origin - Position).RotatedBy(_invRotation); var localRay = new Ray(localRayOrigin, localRayDirection); var hit = new RayTriangleHit {Distance = maxDistance}; Triangle closestTriangle = null; bool hitFound = _octree.Raycast(localRay, ref hit, ref closestTriangle); if (!hitFound) return false; Vector3 normal = _normalSampler.Sample(closestTriangle, hit.U, hit.V).RotatedBy(_rotation); hitInfo = new RaycastHit(hit, closestTriangle, this, ray, normal); return true; }
public bool Raycast(Ray ray, float maxDistance, ref RaycastHit hitInfo) { float closestHitDistance = maxDistance; bool hitFound = false; foreach (Mesh mesh in _meshes) { #if DEBUG Interlocked.Increment(ref Counters.BoundingBoxHits); #endif RaycastHit meshHit = null; bool hit = mesh.Raycast(ray, closestHitDistance, ref meshHit); if (hit) { hitInfo = meshHit; closestHitDistance = meshHit.Distance; hitFound = true; } } return hitFound; }
public Vector3 SampleColor(Scene scene, RaycastHit raycastHit, int maxRecursiveRaycasts) { return Shader.Shade(scene, raycastHit, maxRecursiveRaycasts); }