private void Update(EvaluationContext context) { SharpDX.Matrix camToWorld = context.WorldToCamera; camToWorld.Invert(); var pos = SharpDX.Vector4.Transform(new SharpDX.Vector4(0f, 0f, 0f, 1f), camToWorld); Position.Value = new Vector3(pos.X, pos.Y, pos.Z); var dir = SharpDX.Vector4.Transform(new SharpDX.Vector4(0f, 0f, 1f, 1f), camToWorld) - pos; Direction.Value = new Vector3(dir.X, dir.Y, dir.Z); float aspect = context.CameraToClipSpace.M22 / context.CameraToClipSpace.M11; AspectRatio.Value = aspect; Position.DirtyFlag.Clear(); Direction.DirtyFlag.Clear(); AspectRatio.DirtyFlag.Clear(); }
/// <summary> /// Returns a render view matrix for Direct3D. /// </summary> internal void GetViewMatrix(out DxMatrix4 result) { var m = (DxMatrix4)this; DxMatrix4.Invert(ref m, out result); }
// ** Begin public static void DrawMPC3D(RenderContext11 renderContext, float opacity, Vector3d centerPoint) { double zoom = Earth3d.MainWindow.ZoomFactor; double distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90; int alpha = Math.Min(255, Math.Max(0, (int)distAlpha)); if (alpha > 254) { return; } if (mpcVertexBuffer == null) { for (int i = 0; i < 7; i++) { mpcBlendStates[i] = new BlendState(false, 1000, 0); } if (!initBegun) { MethodInvoker initDelegate = new MethodInvoker(StartInit); initDelegate.BeginInvoke(null, null); initBegun = true; } return; } renderContext.DepthStencilMode = DepthStencilMode.Off; renderContext.setRasterizerState(TriangleCullMode.Off); Matrix3d offset = Matrix3d.Translation(-centerPoint); Matrix3d world = renderContext.World * offset; Matrix matrixWVP = (world * renderContext.View * renderContext.Projection).Matrix11; matrixWVP.Transpose(); Vector3 cam = Vector3.TransformCoordinate(renderContext.CameraPosition.Vector311, Matrix.Invert(renderContext.World.Matrix11)); renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView); renderContext.BlendMode = BlendMode.Additive; if (mpcVertexBuffer != null) { for (int i = 0; i < 7; i++) { mpcBlendStates[i].TargetState = ((Properties.Settings.Default.MinorPlanetsFilter & (int)Math.Pow(2, i)) != 0); if (mpcBlendStates[i].State) { if (mpcVertexBuffer[i].Downlevel) { DownlevelKeplerPointSpriteShader11.Constants.JNow = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate); DownlevelKeplerPointSpriteShader11.Constants.Opacity = opacity * mpcBlendStates[i].Opacity; DownlevelKeplerPointSpriteShader11.Constants.MM = 0; DownlevelKeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP; DownlevelKeplerPointSpriteShader11.Constants.Scale = new SharpDX.Vector2(100f, 100f); DownlevelKeplerPointSpriteShader11.Constants.ViewportScale = new SharpDX.Vector2(2f / renderContext.ViewPort.Width, 2f / renderContext.ViewPort.Height); DownlevelKeplerPointSpriteShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1); DownlevelKeplerPointSpriteShader11.Use(renderContext.devContext, mpcVertexBuffer[i].Instanced); } else { KeplerPointSpriteShader11.Constants.JNow = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate); KeplerPointSpriteShader11.Constants.Opacity = opacity * mpcBlendStates[i].Opacity; KeplerPointSpriteShader11.Constants.MM = 0; KeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP; KeplerPointSpriteShader11.Constants.Scale = new SharpDX.Vector2(100f, 100f); KeplerPointSpriteShader11.Constants.ViewportScale = new SharpDX.Vector2(2f / renderContext.ViewPort.Width, 2 / renderContext.ViewPort.Height); KeplerPointSpriteShader11.Constants.CameraPosition = new SharpDX.Vector4(cam, 1); KeplerPointSpriteShader11.Use(renderContext.devContext); } mpcVertexBuffer[i].Draw(renderContext, mpcVertexBuffer[i].Count, null, opacity); } } } renderContext.BlendMode = BlendMode.Alpha; renderContext.Device.ImmediateContext.GeometryShader.Set(null); }