Ejemplo n.º 1
0
        public SphereIntersectable(Sphere sphere)
            : base(sphere)
        {
            Vector3[] points = new Vector3[6];

            points[0] = Vector3.Transform(sphere.Center + Vector3.Up, sphere.Transform);
            points[1] = Vector3.Transform(sphere.Center + Vector3.Down, sphere.Transform);
            points[2] = Vector3.Transform(sphere.Center + Vector3.Left, sphere.Transform);
            points[3] = Vector3.Transform(sphere.Center + Vector3.Right, sphere.Transform);
            points[4] = Vector3.Transform(sphere.Center + Vector3.Forward, sphere.Transform);
            points[5] = Vector3.Transform(sphere.Center + Vector3.Backward, sphere.Transform);

            Center = sphere.Center;
            BoundingBox = BoundingBox.CreateFromPoints(points);
        }
Ejemplo n.º 2
0
        private void ProcessLine(string[] tokens)
        {
            string command = tokens[0];

            TargetedCamera camera = (TargetedCamera) _scene.Camera;
            switch (command)
            {
                case "size":
                    {
                        camera.Width = tokens.ToInt(1);
                        camera.Height = tokens.ToInt(2);
                        break;
                    }
                case "maxdepth ":
                    {
                        _scene.MaxDepth = tokens.ToInt(1);
                        break;
                    }
                case "output":
                    {
                        _scene.OutputFileName = tokens[1];
                        break;
                    }
                case "camera":
                    {
                        camera.Translation = Matrix.CreateTranslation(tokens.ToVec3(1));
                        camera.Target = tokens.ToVec3(4);
                        camera.Up = tokens.ToVec3(7);

                        float yFov = tokens.ToFloat(10);
                        camera.Fov = yFov;
                        camera.UseXFov = false;
                        break;
                    }
                case "sphere":
                    {
                        Sphere sphere = new Sphere(tokens.ToVec3(1), tokens.ToFloat(4))
                                            {
                                                Material = (Material) _material.Clone(),
                                                Transform = _transforms.Peek()
                                            };

                        _scene.Geomertries.Add(sphere);
                        break;
                    }
                case "maxverts":
                    {
                        _vertices = new List<Vector3>(tokens.ToInt(1));
                        break;
                    }
                case "maxvertnorms":
                    {
                        _vertices = new List<Vector3>(tokens.ToInt(1));
                        _verticesNormals = new List<Vector3>(tokens.ToInt(1));
                        break;
                    }
                case "vertex":
                    {
                        _vertices.Add(tokens.ToVec3(1));
                        break;
                    }
                case "vertexnormal":
                    {
                        _vertices.Add(tokens.ToVec3(1));
                        _verticesNormals.Add(tokens.ToVec3(4));
                        break;
                    }
                case "tri":
                    {
            //						Triangle triangle = new Triangle(_vertices[tokens.ToInt(1)], _vertices[tokens.ToInt(2)], _vertices[tokens.ToInt(3)])
            //						                    	{
            //						                    		Material = (Material) _material.Clone(),
            //						                    		Transform = _transforms.Peek()
            //						                    	};
                        CalculatedTriangle triangle = new CalculatedTriangle(_vertices[tokens.ToInt(1)], _vertices[tokens.ToInt(2)], _vertices[tokens.ToInt(3)],_transforms.Peek())
                                                {
                                                    Material = (Material) _material.Clone()
                                                };

                        _scene.Geomertries.Add(triangle);
                        break;
                    }
                case "trinormal":
                    {
                        Triangle triangle = new Triangle(_vertices[tokens.ToInt(1)], _vertices[tokens.ToInt(2)], _vertices[tokens.ToInt(3)])
                                                {
                                                    Na = _verticesNormals[tokens.ToInt(1)],
                                                    Nb = _verticesNormals[tokens.ToInt(2)],
                                                    Nc = _verticesNormals[tokens.ToInt(3)],
                                                    Material = (Material) _material.Clone(),
                                                    Transform = _transforms.Peek()
                                                };

                        _scene.Geomertries.Add(triangle);
                        break;
                    }
                case "translate":
                    {
                        Matrix matrix = Matrix.CreateTranslation(tokens.ToVec3(1));
                        RightMultiply(matrix);
                        break;
                    }
                case "rotate":
                    {
                        Matrix matrix = Transform.Rotate(tokens.ToFloat(4), tokens.ToVec3(1));
                        RightMultiply(matrix);
                        break;
                    }
                case "scale":
                    {
                        Matrix matrix = Matrix.CreateScale(tokens.ToVec3(1));
                        RightMultiply(matrix);
                        break;
                    }
                case "pushTransform":
                    {
                        Matrix matrix = _transforms.Peek();
                        _transforms.Push(matrix);
                        break;
                    }
                case "popTransform":
                    {
                        _transforms.Pop();
                        break;
                    }
                case "directional":
                    {
                        DirectionalLight light = new DirectionalLight
                                                 	{
                                                 		Color = tokens.ToVec3(4)
                                                 	};

                        Matrix rotation = Matrix.Identity;
                        rotation.Backward = tokens.ToVec3(1);
                        light.Rotation = rotation;

                        _scene.Lights.Add(light);
                        break;
                    }
                case "point":
                    {
                        PointLight light = new PointLight
                                           	{
                                           		Color = tokens.ToVec3(4),
                                           		Translation = Matrix.CreateTranslation(tokens.ToVec3(1)),
                                           		AttenuationConst = _attenuationConst,
                                           		AttenuationLinear = _attenuationLinear,
                                           		AttenuationQuadratic = _attenuationQuadratic
                                           	};

                        _scene.Lights.Add(light);
                        break;
                    }
                case "attenuation":
                    {
                        _attenuationConst = tokens.ToFloat(1);
                        _attenuationLinear = tokens.ToFloat(2);
                        _attenuationQuadratic = tokens.ToFloat(3);
                        break;
                    }
                case "ambient":
                    {
                        _material.AmbientColor = tokens.ToVec3(1);
                        break;
                    }
                case "diffuse":
                    {
                        _material.DiffuseColor = new PlaneColorSampler(tokens.ToVec3(1));
                        break;
                    }
                case "specular":
                    {
                        _material.SpecularColor = tokens.ToVec3(1);
                        _material.ReflectiveColor = tokens.ToVec3(1);
                        _material.Reflectivity = 1.0f;
                        break;
                    }
                case "shininess":
                    {
                        _material.Shininess = tokens.ToFloat(1);
                        break;
                    }
                case "emission":
                    {
                        _material.EmissionColor = tokens.ToVec3(1);
                        break;
                    }
            }
        }