/// <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))); }
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); }
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); }
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; }
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); }
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); }
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(); }
public void SetViewMatrix(MatrixD newViewMatrix) { PreviousPosition = Position; UpdatePropertiesInternal(newViewMatrix); }
public void SetViewMatrix(MatrixD newViewMatrix) { PreviousPosition = Position; UpdatePropertiesInternal(newViewMatrix); }
void IMyEntity.SetWorldMatrix(VRageMath.MatrixD worldMatrix, object source) { PositionComp.SetWorldMatrix(worldMatrix, source); }