Ejemplo n.º 1
0
        /// <summary>
        /// Creates the cornell box.
        /// </summary>
        /// <param name="roomSize">Size of the room.</param>
        /// <param name="sphereRadius">The sphere radius.</param>
        /// <param name="cubeSize">Size of the cube.</param>
        /// <returns></returns>
        public static DefaultMesh CreateCornellBox(float roomSize = 2, float sphereRadius = 0.3f, float cubeSize = 0.6f)
        {
            var mesh = new DefaultMesh();
            //off-center plane
            var plane = CreatePlane(roomSize, roomSize, 2, 2).Transform(new Translation3D(0, -roomSize / 2, 0));

            plane.SetConstantUV(new Vector2(0, 0));
            mesh.Add(plane);                                         //bottom
                                                                     //rotate plane repeatedly to create box
            mesh.Add(plane.Transform(new Rotation3D(Axis.X, 90f)));  //front
            mesh.Add(plane.Transform(new Rotation3D(Axis.X, -90f))); //back
            plane.SetConstantUV(new Vector2(1, 0));
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 90f)));  //right
            plane.SetConstantUV(new Vector2(2, 0));
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 270f))); //left
            plane.SetConstantUV(new Vector2(0, 0));
            mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 180f))); //top

            var sphere = CreateSphere(sphereRadius, 4);

            sphere.SetConstantUV(new Vector2(3, 0));
            mesh.Add(sphere.Transform(new Translation3D(0.4f, -1 + sphereRadius, -0.2f)));

            var cube             = CreateCubeWithNormals(cubeSize);
            var trans            = new Translation3D(-0.5f, -1 + 0.5f * cubeSize, 0.1f);
            var translateAndRotY = new Rotation3D(Axis.Y, 35f, trans);

            cube.SetConstantUV(new Vector2(3, 0));
            mesh.Add(cube.Transform(translateAndRotY));
            return(mesh);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the view matrix.
        /// </summary>
        /// <returns></returns>
        public Matrix4x4 CalcViewMatrix()
        {
            var t            = new Translation3D(-Position);
            var mtxTranslate = Matrix4x4.Transpose(Matrix4x4.CreateTranslation(-Position));
            var mtxRotate    = CalcRotationMatrix();

            return(mtxRotate * mtxTranslate);
        }