Ejemplo n.º 1
0
        /// <summary>
        /// Gets a vector pointing out along a given pixel coordinate on the screen.
        /// </summary>
        /// <param name="point">The screen position in pixels.</param>
        public Vector3 ScreenPointToWorldDirection(Vector2 point)
        {
            ValidateDispose();
            Vector3 clipPoint = new Vector3(
                2.0f * ((point.X / m_resolutionX) - 0.5f),
                2.0f * (-((point.Y / m_resolutionY) - 0.5f)),
                1.0f
                );
            Vector3 worldPoint = Vector3.TransformPerspective(clipPoint, ProjectionMatrix.Inverted() * ViewMatrixInverse);

            return((worldPoint - Transform.Position).Normalized());
        }
Ejemplo n.º 2
0
        public Ray3d GetMouseRay()
        {
            var start = new Vector4d((Window.Mouse.X / (double)Window.Width - 0.5) * 2.0, ((Window.Height - Window.Mouse.Y) / (double)Window.Height - 0.5) * 2.0, 0.0, 1.0);
            var end   = new Vector4d((Window.Mouse.X / (double)Window.Width - 0.5) * 2.0, ((Window.Height - Window.Mouse.Y) / (double)Window.Height - 0.5) * 2.0, -1.0, 1.0);

            var IPV = ProjectionMatrix.Inverted() * ViewMatrix.Inverted();

            start  = Vector4d.Transform(start, IPV);
            start /= start.W;
            end    = Vector4d.Transform(end, IPV);
            end   /= end.W;
            end   -= start;

            return(new Ray3d(new Vector3d(start.X, start.Y, start.Z), new Vector3d(end.X, end.Y, end.Z).Normalized()));
        }