Example #1
0
        /// <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)));
        }
Example #2
0
        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();
        }
        void IMyClipmapCell.UpdateWorldMatrix(ref VRageMath.MatrixD worldMatrix, bool sortIntoCullObjects)
        {
            m_worldMatrix = worldMatrix;

            Matrix m = m_worldMatrix * Matrix.CreateScale(m_scale) * Matrix.CreateTranslation(m_translation);

            m_actor.SetMatrix(ref m);
        }
Example #4
0
        void IMyClipmapCell.UpdateWorldMatrix(ref VRageMath.MatrixD worldMatrix, bool sortIntoCullObjects)
        {
            m_worldMatrix = worldMatrix;

            MatrixD m = MatrixD.CreateScale(m_scale) * MatrixD.CreateTranslation(m_translation) * m_worldMatrix;

            m_actor.SetMatrix(ref m);
            m_actor.SetAabb((BoundingBoxD)m_localAabb.Transform(m_worldMatrix));
        }
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);
            m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
Example #6
0
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            //m_mesh = new MyVoxelMesh(cellCoord.CoordInLod, cellCoord.Lod, "");
            //m_actor.GetRenderable().SetModel(m_mesh);
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory <MyFoliageComponent> .Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);

            m_discardingOn = false;
        }
Example #7
0
        public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix)
        {
            var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix);

            cell.SetVisibility(false);
            cell.ScaleGroup = scaleGroup;
            return(cell);
        }
Example #8
0
 internal static float AddAndInterpolateObjectMatrix(MyInterpolationQueue <VRageMath.MatrixD> queue, ref VRageMath.MatrixD matrix)
 {
     if (Settings.EnableObjectInterpolation)
     {
         queue.AddSample(ref matrix, MyRender.CurrentUpdateTime);
         return(queue.Interpolate(MyRender.InterpolationTime, out matrix));
     }
     return(0.0f);
 }
Example #9
0
        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();
        }
Example #10
0
 public void SetViewMatrix(MatrixD newViewMatrix)
 {
     PreviousPosition = Position;
     UpdatePropertiesInternal(newViewMatrix);
 }
Example #11
0
 public void SetViewMatrix(MatrixD newViewMatrix)
 {
     PreviousPosition = Position;
     UpdatePropertiesInternal(newViewMatrix);
 }
Example #12
0
 void IMyEntity.SetWorldMatrix(VRageMath.MatrixD worldMatrix, object source)
 {
     PositionComp.SetWorldMatrix(worldMatrix, source);
 }