コード例 #1
0
ファイル: MyCamera.cs プロジェクト: viktorius/Viktor
        /// <summary>
        /// Gets normalized world space line from screen space coordinates.
        /// </summary>
        /// <param name="screenCoords"></param>
        /// <returns></returns>
        public LineD WorldLineFromScreen(Vector2 screenCoords)
        {
            var matViewProjInv = MatrixD.Invert(ViewProjectionMatrix);

            // normalized screen space vector
            var raySource = new Vector4D(
                (2.0f * screenCoords.X) / Viewport.Width - 1.0f,
                1.0f - (2.0f * screenCoords.Y) / Viewport.Height,
                0.0f,
                1.0f
                );
            var rayTarget = new Vector4D(
                (2.0f * screenCoords.X) / Viewport.Width - 1.0f,
                1.0f - (2.0f * screenCoords.Y) / Viewport.Height,
                1.0f,
                1.0f
                );

            var raySourceWorld = Vector4D.Transform(raySource, matViewProjInv);
            var rayTargetWorld = Vector4D.Transform(rayTarget, matViewProjInv);

            raySourceWorld /= raySourceWorld.W;
            rayTargetWorld /= rayTargetWorld.W;

            return(new LineD(new Vector3D(raySourceWorld), new Vector3D(rayTargetWorld)));
        }
コード例 #2
0
ファイル: MyCamera.cs プロジェクト: viktorius/Viktor
        private void UpdatePropertiesInternal(MatrixD newViewMatrix)
        {
            ViewMatrix = newViewMatrix;
            MatrixD.Invert(ref ViewMatrix, out WorldMatrix);

            //  Projection matrix according to zoom level
            ProjectionMatrix = MatrixD.CreatePerspectiveFieldOfView(FovWithZoom, AspectRatio,
                                                                    GetSafeNear(),
                                                                    FarPlaneDistance);

            ProjectionMatrixFar = MatrixD.CreatePerspectiveFieldOfView(FovWithZoom, AspectRatio,
                                                                       GetSafeNear(),
                                                                       1000000);

            ViewProjectionMatrix    = ViewMatrix * ProjectionMatrix;
            ViewProjectionMatrixFar = ViewMatrix * ProjectionMatrixFar;

            //  Projection matrix according to zoom level
            // float near = System.Math.Min(NearPlaneDistance, NearForNearObjects); //minimum cockpit distance
            // ProjectionMatrixForNearObjects = MatrixD.CreatePerspectiveFieldOfView(FovWithZoomForNearObjects, ForwardAspectRatio,
            //    near,
            //    FarForNearObjects);

            UpdateBoundingFrustum();
        }