public override RtColor PatternAt(RtPoint point)
        {
            var distance = ColorB - ColorA;
            var fraction = point.X - Math.Floor(point.X);

            return(ColorA + distance * fraction);
        }
示例#2
0
 public bool Equals(RtPoint other)
 {
     return(other.X.ApproximateEquals(X) &&
            other.Y.ApproximateEquals(Y) &&
            other.Z.ApproximateEquals(Z) &&
            other.W.ApproximateEquals(W));
 }
示例#3
0
        public RtVector NormalAt(RtPoint worldPoint, Intersection hit)
        {
            var localPoint  = WorldToShape(worldPoint);
            var localNormal = LocalNormalAt(localPoint, hit);
            var worldNormal = NormalToWorld(localNormal);

            return(worldNormal);
        }
        public RtPoint Perturb(RtPoint localPoint)
        {
            var noise = new OpenSimplexNoise();
            var newX  = localPoint.X + noise.Evaluate(localPoint.X, localPoint.Y, localPoint.Z) * _factor;
            var newY  = localPoint.Y + noise.Evaluate(localPoint.X, localPoint.Y, localPoint.Z + 1) * _factor;
            var newZ  = localPoint.Z + noise.Evaluate(localPoint.X, localPoint.Y, localPoint.Z + 2) * _factor;

            return(new RtPoint(newX, newY, newZ));
        }
示例#5
0
 public Triangle(RtPoint point1, RtPoint point2, RtPoint point3, RtVector normal1, RtVector normal2, RtVector normal3)
 {
     Point1  = point1;
     Point2  = point2;
     Point3  = point3;
     Normal1 = normal1;
     Normal2 = normal2;
     Normal3 = normal3;
 }
示例#6
0
        public RtPoint WorldToShape(RtPoint worldPoint)
        {
            if (Parent != null)
            {
                worldPoint = Parent.WorldToShape(worldPoint);
            }

            return(Transform.Inverse() * worldPoint);
        }
示例#7
0
        public override RtColor PatternAt(RtPoint point)
        {
            if (Math.Floor(point.X) % 2 == 0)
            {
                return(ColorA);
            }

            return(ColorB);
        }
示例#8
0
        public override RtColor PatternAt(RtPoint point)
        {
            if (Math.Floor(Math.Sqrt(Math.Pow(point.X, 2.0) + Math.Pow(point.Z, 2.0))) % 2 == 0)
            {
                return(ColorA);
            }

            return(ColorB);
        }
示例#9
0
 public override RtVector LocalNormalAt(RtPoint point, Intersection hit)
 {
     if (hit == null)
     {
         return(Normal);
     }
     else
     {
         return(Normal2 * hit.U + Normal3 * hit.V + Normal1 * (1 - hit.U - hit.V));
     }
 }
示例#10
0
 public override double IntensityAt(RtPoint point, World world)
 {
     if (world.IsShadowed(Position, point))
     {
         return(0.0);
     }
     else
     {
         return(1.0);
     }
 }
示例#11
0
        public RtColor PatternAtShape(Shape shape, RtPoint worldPoint)
        {
            var shapePoint  = shape.Transform.Inverse() * worldPoint;
            var patterPoint = Transform.Inverse() * shapePoint;

            if (IsPerturbed && PerturbBy != null)
            {
                patterPoint = PerturbBy.Perturb(patterPoint);
            }

            return(PatternAt(patterPoint));
        }
示例#12
0
        public AreaLight(RtPoint corner, RtVector uVector, int uSteps, RtVector vVector, int vSteps, RtColor intensity)
        {
            Corner    = corner;
            UVector   = uVector / uSteps;
            USteps    = uSteps;
            VVector   = vVector / vSteps;
            VSteps    = vSteps;
            Intensity = intensity;

            var middle = (uVector / 2) + (vVector / 2);

            Position = new RtPoint(middle.X, middle.Y, middle.Z);
            Samples  = uSteps * vSteps;
        }
示例#13
0
        public override RtVector LocalNormalAt(RtPoint point, Intersection hit)
        {
            var maxC = (new double[] { Math.Abs(point.X), Math.Abs(point.Y), Math.Abs(point.Z) }).Max();

            if (maxC == Math.Abs(point.X))
            {
                return(new RtVector(point.X, 0, 0));
            }
            else if (maxC == Math.Abs(point.Y))
            {
                return(new RtVector(0, point.Y, 0));
            }

            return(new RtVector(0, 0, point.Z));
        }
示例#14
0
        public override RtVector LocalNormalAt(RtPoint point, Intersection hit)
        {
            var distance = Math.Pow(point.X, 2) + Math.Pow(point.Z, 2);

            if (distance < 1 && point.Y >= Maximum - DoubleExtensions.EPSILON)
            {
                return(new RtVector(0, 1, 0));
            }
            else if (distance < 1 && point.Y <= Minimum + DoubleExtensions.EPSILON)
            {
                return(new RtVector(0, -1, 0));
            }
            else
            {
                return(new RtVector(point.X, 0, point.Z));
            }
        }
示例#15
0
        public override double IntensityAt(RtPoint point, World world)
        {
            var total = 0.0;

            for (int v = 0; v < VSteps; v++)
            {
                for (int u = 0; u < USteps; u++)
                {
                    var lightPosition = PointOnLight(u, v);
                    if (!world.IsShadowed(lightPosition, point))
                    {
                        total += 1.0;
                    }
                }
            }

            var results = total / Samples;

            return(results);
        }
示例#16
0
        public bool IsShadowed(RtPoint lightPosition, RtPoint point)
        {
            var vector    = lightPosition - point;
            var distance  = vector.Magnitude();
            var direction = vector.Normalize();

            var ray          = new Ray(point, direction);
            var intersetions = Intersect(ray);

            var hit = intersetions.ShadowHit();

            if (hit != null && hit.Time < distance)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override RtColor PatternAt(RtPoint point)
        {
            if (Math.Floor(Math.Sqrt(Math.Pow(point.X, 2.0) + Math.Pow(point.Z, 2.0))) % 2 == 0)
            {
                var distance  = ColorA2 - ColorA1;
                var distance1 = (ColorA2 - ColorA1) / 2;

                var t = Math.Atan2(point.Z, point.X);

                var fraction = Math.Abs(t) / Math.PI * 2;

                if (t >= 0)
                {
                    return(ColorA2 - distance * fraction);
                }
                else
                {
                    return(ColorA2 + distance * fraction);
                }
            }

            return(ColorB);
        }
示例#18
0
 public PointLight(RtPoint position, RtColor color)
 {
     Position  = position;
     Intensity = color;
     Samples   = 1;
 }
 public void AddVertex(RtPoint rtPoint)
 {
     _vertices.Add(rtPoint);
 }
示例#20
0
 public abstract RtVector LocalNormalAt(RtPoint point, Intersection hit);
示例#21
0
 public override RtVector LocalNormalAt(RtPoint point, Intersection hit)
 {
     throw new System.NotImplementedException();
 }
示例#22
0
 public abstract RtColor PatternAt(RtPoint point);
示例#23
0
 public Transform Translation(RtPoint location)
 {
     return(Translation(location.X, location.Y, location.Z));
 }
示例#24
0
 public Triangle(RtPoint point1, RtPoint point2, RtPoint point3)
 {
     Point1 = point1;
     Point2 = point2;
     Point3 = point3;
 }
 public double Perlin(RtPoint point)
 {
     return(Perlin(point.X, point.Y, point.Z));
 }
示例#26
0
 public abstract double IntensityAt(RtPoint point, World world);
示例#27
0
 public override RtVector LocalNormalAt(RtPoint point, Intersection hit)
 {
     return(new RtVector(0, 1, 0));
 }
示例#28
0
 public override RtVector LocalNormalAt(RtPoint shapePoint, Intersection hit)
 {
     return(shapePoint.DistanceFromZero());
 }
示例#29
0
 public Ray(RtPoint origin, RtVector direction)
 {
     Origin    = origin;
     Direction = direction;
 }