/// <summary>
        /// World Space to View Space
        /// </summary>
        public void Execute()
        {
            var cameraPosition    = RenderingPipelineRegister.Instance.Camera.Position;
            var cameraRotation    = RenderingPipelineRegister.Instance.Camera.Rotation;
            var translationMatrix = MatrixTool.CreateTranslationMatrix(-cameraPosition.X, -cameraPosition.Y, -cameraPosition.Z);
            var rotationMatrix    = MatrixTool.CreateRotationMatrix(-cameraRotation.X, -cameraRotation.Y, -cameraRotation.Z);
            var projectionMatrix  = RenderingPipelineRegister.Instance.Camera.GetProjectionMatrix();

            foreach (var vertex in RenderingPipelineRegister.Instance.VertexList)
            {
                var position = MatrixTool.VectorToMatrix(vertex.WorldPosition);

                if (MatrixTool.TryMul(translationMatrix, position, out position))
                {
                    if (MatrixTool.TryMul(rotationMatrix, position, out position))
                    {
                        if (MatrixTool.TryMul(projectionMatrix, position, out position))
                        {
                            position.TryGetValue(0, 0, out vertex.WorldPosition.X);
                            position.TryGetValue(0, 1, out vertex.WorldPosition.Y);
                            position.TryGetValue(0, 2, out vertex.WorldPosition.Z);
                        }
                    }
                }
            }
        }
        public void Execute()
        {
            var screenMappingMatrix = MatrixTool.CreateScreenMappingMatrix(RenderingPipelineRegister.Instance.Width, RenderingPipelineRegister.Instance.Height);

            foreach (var vertex in RenderingPipelineRegister.Instance.VertexList)
            {
                var position = MatrixTool.VectorToMatrix(vertex.WorldPosition);
                if (MatrixTool.TryMul(screenMappingMatrix, position, out position))
                {
                    position.TryGetValue(0, 0, out vertex.WorldPosition.X);
                    position.TryGetValue(0, 1, out vertex.WorldPosition.Y);
                    position.TryGetValue(0, 2, out vertex.WorldPosition.Z);
                }
            }
        }
Exemple #3
0
        public Matrix GetProjectionMatrix()
        {
            switch (Type)
            {
            case CameraType.Orthogonal:
                float r = OrthogonalSetting.Size * Screen.Width * 0.5f;
                float l = -OrthogonalSetting.Size * Screen.Width * 0.5f;
                float t = OrthogonalSetting.Size * Screen.Height * 0.5f;
                float b = -OrthogonalSetting.Size * Screen.Height * 0.5f;
                float n = OrthogonalSetting.Near;
                float f = OrthogonalSetting.Far;
                return(MatrixTool.CreateOrthogonalProjectionMatrix(r, l, t, b, n, f));

            case CameraType.Perspective:
                return(new Matrix());
            }

            return(new Matrix());
        }