public AntiIntersection AntiIntersect(Ray ray, SphereBase parentSphere)
        {
            Vector3 l             = GetPosition() - ray.GetStart();     //Vector to sphere center (and direction)
            float   tc            = Vector3.Dot(l, ray.GetDirection()); //Length to ray hit-center
            float   els           = Vector3.Dot(l, l);
            float   radiusSquared = _radius * _radius;

            if (tc < 0 && els > radiusSquared)
            {
                return(AntiIntersection.CreateNullAntiIntersection());
            }
            float dSquared = els - tc * tc; //Squared perpendicular distance from spherecenter to ray (vinkelrätt)

            if (dSquared > radiusSquared)
            {
                return(AntiIntersection.CreateNullAntiIntersection());
            }
            float t1c = (float)Math.Sqrt(radiusSquared - dSquared);
            float tNear, tFar;

            tNear = tc - t1c;
            tFar  = tc + t1c;
            Vector3 pNear           = ray.GetStart() + Vector3.Multiply(ray.GetDirection(), tNear);
            Vector3 pFar            = ray.GetStart() + Vector3.Multiply(ray.GetDirection(), tFar);
            var     normNearTexture = Vector3.Normalize(Vector3.Divide(GetPosition() - pNear, _radius));
            var     normFarTexture  = Vector3.Normalize(Vector3.Divide(GetPosition() - pFar, _radius));

            return(new AntiIntersection(pNear, pFar, normNearTexture, normFarTexture, tNear, tFar, this));
        }
示例#2
0
 public Intersection(Vector3 positionFirstHit, Vector3 normalFirstHit, Vector3 normalFirstHitTexture, float tFirstHit, float tNear, float tFar, SphereBase sphereBase)
 {
     _hasValue              = true;
     _positionFirstHit      = positionFirstHit;
     _normalFirstHit        = normalFirstHit;
     _normalFirstHitTexture = normalFirstHitTexture;
     _tFirstHit             = tFirstHit;
     _tNear      = tNear;
     _tFar       = tFar;
     _sphereBase = sphereBase;
 }
示例#3
0
 public Intersection(bool isNull)
 {
     _hasValue              = !isNull;
     _positionFirstHit      = Vector3.Zero;
     _normalFirstHit        = Vector3.Zero;
     _normalFirstHitTexture = Vector3.Zero;
     _tFirstHit             = float.MaxValue;
     _tNear      = float.MaxValue;
     _tFar       = float.MaxValue;
     _sphereBase = null;
 }
 public AntiIntersection(Vector3 positionNear, Vector3 positionFar, Vector3 normalNearTexture, Vector3 normalFarTexture, float tNear, float tFar, SphereBase sphereBase)
 {
     _hasValue          = true;
     _isInfinite        = false;
     _positionNear      = positionNear;
     _positionFar       = positionFar;
     _normalNearTexture = normalNearTexture;
     _normalFarTexture  = normalFarTexture;
     _tNear             = tNear;
     _tFar       = tFar;
     _sphereBase = sphereBase;
 }
 public AntiIntersection(bool isNull, bool isInfinite)
 {
     _hasValue          = !isNull;
     _isInfinite        = isInfinite;
     _positionNear      = Vector3.Zero;
     _positionFar       = Vector3.Zero;
     _normalNearTexture = Vector3.Zero;
     _normalFarTexture  = Vector3.Zero;
     _tNear             = float.MaxValue;
     _tFar       = float.MaxValue;
     _sphereBase = null;
 }