コード例 #1
0
        public Ray RayForPixel(int px, int py)
        {
            float xOffset = (px + 0.5f) * PixelSize;
            float yOffset = (py + 0.5f) * PixelSize;

            float worldX = HalfWidth - xOffset;
            float worldY = HalfHeight - yOffset;

            Tuple pixel  = Transform.Inverse() * Tuple.Point(worldX, worldY, -1);
            Tuple origin = Transform.Inverse() * Tuple.Point(0, 0, 0);

            return(new Ray(origin, (pixel - origin).Normalize()));
        }
コード例 #2
0
        public DefaultWorld()
        {
            Lights.Add(new PointLight(Tuple.Point(-10, 10, -10), Tuple.Color(1, 1, 1)));

            Shape s1 = new Sphere();

            s1.Material.Color    = Tuple.Color(0.8f, 1, 0.6f);
            s1.Material.Diffuse  = 0.7f;
            s1.Material.Specular = 0.2f;

            Shapes.Add(s1);

            Shape s2 = new Sphere();

            s2.Transform = Transformation.Scaling(0.5f, 0.5f, 0.5f);

            Shapes.Add(s2);
        }
コード例 #3
0
        private void ReadVertex(char[] contents)
        {
            var vertex = Tuple.Point(0, 0, 0);

            for (int i = 0; i < 3; ++i)
            {
                Token token = GetNextToken(contents);
                if (token.Type == TokenType.Number)
                {
                    vertex[i] = float.Parse(token.Value);
                }
                else
                {
                    throw new FormatException($"{token.Value} is not a Number");
                }
            }

            Vertices.Add(vertex);
        }
コード例 #4
0
        protected override List <Intersection> LocalIntersect(Ray localRay)
        {
            Tuple sphereToRay = localRay.Origin - Tuple.Point(0, 0, 0);

            float a = localRay.Direction.Dot(localRay.Direction);
            float b = localRay.Direction.Dot(sphereToRay);
            float c = sphereToRay.Dot(sphereToRay) - 1;

            float discriminant = b * b - a * c;

            if (discriminant >= 0)
            {
                float sqrtDisc = System.MathF.Sqrt(discriminant);
                return(Intersection.Aggregate(
                           new Intersection((-b - sqrtDisc) / a, this),
                           new Intersection((-b + sqrtDisc) / a, this)));
            }

            return(Intersection.Aggregate());
        }
コード例 #5
0
 private static Tuple ReadPoint(JToken jToken)
 {
     return(Tuple.Point((float)jToken[0], (float)jToken[1], (float)jToken[2]));
 }
コード例 #6
0
 protected override Tuple LocalNormalAt(Tuple localPoint, Intersection hit)
 {
     return(localPoint - Tuple.Point(0, 0, 0));
 }