public SpaceMouse(CameraInteraction cameraInteraction, D3DRenderSetup renderSetup) { App.Current.MainWindow.SpaceMouseHandlerWpf.Active3DxMouse.MotionEvent += SpaceMouseMotionHandler; App.Current.MainWindow.SpaceMouseHandlerWpf.Active3DxMouse.ButtonEvent += SpaceMouseButtonHandler; _cameraInteraction = cameraInteraction; _renderSetup = renderSetup; }
private Ray ComputeMouseViewRayInWorld(D3DRenderSetup renderSetup) { var windowPos = _showSceneControl.PointFromScreen(_mousePos); var x = (float)(2.0 * windowPos.X / _showSceneControl.ActualWidth - 1); var y = (float)-(2.0 * windowPos.Y / _showSceneControl.ActualHeight - 1); var rayNds = new Vector3(x, y, 1.0f); // Normalized Device coordinates var rayClip = new Vector4(rayNds.X, rayNds.Y, -1, 1); var inverseProjection = (renderSetup.LastContext.CameraProjection); inverseProjection.Invert(); var rayEye = Vector4.Transform(rayClip, inverseProjection); rayEye.Z = 1; rayEye.W = 0; var inverseViewMatrix = (renderSetup.LastContext.WorldToCamera); inverseViewMatrix.Invert(); var rayDirectionInWorld = Vector4.Transform(rayEye, inverseViewMatrix); Vector3 raySourceInWorld = renderSetup.CameraPosition; var rayInWorld = new Ray(raySourceInWorld, new Vector3(rayDirectionInWorld.X, rayDirectionInWorld.Y, rayDirectionInWorld.Z)); return(rayInWorld); }
public FullScreenView(D3DRenderSetup renderSetup) { d3DScene = renderSetup; App.Current.MainWindow.Hide(); System.Windows.Forms.Cursor.Hide(); KeyDown += KeyDownHandler; KeyUp += KeyUpHandler; MouseDown += MouseDownHandler; MouseUp += MouseUpHandler; MouseWheel += MouseWheelHandler; MouseMove += MouseMoveHandler; MouseDoubleClick += MouseDoubleClickHandler; CurrentTime = 0; PlaySpeed = 0; FormBorderStyle = FormBorderStyle.None; var settings = new ContextSettings(); settings.DisplayMode = new SharpDX.Direct3D9.DisplayMode() { Width = (int)App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.Resolution.Width", 1920), Height = (int)App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.Resolution.Height", 1080), RefreshRate = 60, Format = SharpDX.Direct3D9.Format.A8R8G8B8 }; settings.AspectRatio = settings.DisplayMode.AspectRatio; var displayNumber = int.Parse(App.Current.ProjectSettings.GetOrSetDefault("Tooll.FullScreen.DisplayNumber", "1")); displayNumber = Utilities.Clamp(displayNumber, 0, Screen.AllScreens.GetLength(0) - 1); Location = Screen.AllScreens[displayNumber].WorkingArea.Location; CurrentTime = App.Current.Model.GlobalTime; PlaySpeed = App.Current.MainWindow.CompositionView.PlaySpeed; App.Current.MainWindow.CompositionView.PlaySpeed = 0; Run(settings); App.Current.Model.GlobalTime = CurrentTime; App.Current.MainWindow.CompositionView.PlaySpeed = PlaySpeed; App.Current.MainWindow.Show(); App.Current.MainWindow.Activate(); App.Current.MainWindow.InvalidateVisual(); App.Current.MainWindow.XCompositionViewDock.Focus(); System.Windows.Forms.Cursor.Show(); }
/* This requires ShowSceneControl to have been loaded */ private void LateInit() { RenderConfiguration = new RenderViewConfiguration() { ShowGridAndGizmos = true, TransformGizmo = new TransformGizmo(), }; _camSetupProvider = new ViewCameraSetupProvider(RenderConfiguration); _renderSetup = new D3DRenderSetup(RenderConfiguration); SetupRenderer(); CameraInteraction = new CameraInteraction( RenderConfiguration, this); }
private void SetupRendering() { XSceneImage.Source = _D3DImageContainer; _renderSetup = new D3DRenderSetup((int)XGrid.ActualWidth, (int)XGrid.ActualHeight); _D3DImageContainer.SetBackBufferSharpDX(_renderSetup.SharedTexture); var contextSettings = new ContextSettings(); contextSettings.DisplayMode = new SharpDX.Direct3D9.DisplayMode() { Width = _renderSetup.WindowWidth, Height = _renderSetup.WindowHeight, RefreshRate = 60, Format = D3DImageSharpDX.TranslateFormat(_renderSetup.SharedTexture) }; contextSettings.AspectRatio = contextSettings.DisplayMode.AspectRatio; _defaultContext = OperatorPartContext.createDefault(contextSettings); }
private D3DRenderSetup CreateOrReuseRenderSetup(RenderViewConfiguration referenceConfig = null) { if (_renderSetupPool.Count > 0) { var setup = _renderSetupPool.Dequeue(); setup.RenderConfig.CameraSetup = referenceConfig.CameraSetup; setup.RenderConfig.Operator = referenceConfig.Operator; setup.RenderConfig.RenderWithGammaCorrection = referenceConfig.RenderWithGammaCorrection; return(setup); } Logger.Info("Creating new renderSetup of Preset-thumb"); var clonedRenderConfig = referenceConfig.Clone(); clonedRenderConfig.Width = THUMB_WIDTH; clonedRenderConfig.Height = THUMB_HEIGHT; var renderSetup = new D3DRenderSetup(clonedRenderConfig); return(renderSetup); }
private void OrbitByAngle(Vector2 rotationSpeed) { Vector3 viewDir, sideDir, upDir; var currentTarget = _showSceneControl.RenderSetup.CameraTarget; D3DRenderSetup.CalcDirections(currentTarget, _cameraPositionGoal, 0, out viewDir, out sideDir, out upDir); var viewDirLength = viewDir.Length(); viewDir /= viewDirLength; Matrix rotAroundX = Matrix.RotationAxis(sideDir, rotationSpeed.Y); Matrix rotAroundY = Matrix.RotationAxis(upDir, rotationSpeed.X); Matrix rot = Matrix.Multiply(rotAroundX, rotAroundY); Vector4 newViewDir = Vector3.Transform(viewDir, rot); newViewDir.Normalize(); // Set new position and freeze cam-target transitions _showSceneControl.RenderSetup.CameraPosition = _cameraPositionGoal = _showSceneControl.RenderSetup.CameraTarget - newViewDir.ToVector3() * viewDirLength; _cameraTargetGoal = currentTarget; }
private void UpdateLocalShownContent() { //if (_showSceneControl == null) // return; //var op = _showSceneControl.Operator; //var d3DScene = _showSceneControl.RenderSetup; if (_renderConfig == null || _renderConfig.Operator == null || _renderConfig.Operator.Outputs.Count <= 0) { return; } //var op = d3DScene.RenderedOperator; var op = _renderConfig.Operator; D3DDevice.WindowSize = new SharpDX.Size2(Size.Width, Size.Height); D3DDevice.TouchWidth = Size.Width; D3DDevice.TouchHeight = Size.Height; TimeLogger.BeginFrame(CurrentTime); D3DDevice.BeginFrame(); ProcessKeyEvents(); try { var context = new OperatorPartContext(_defaultContext, (float)CurrentTime); if (Math.Abs(context.Time - _previousTime) > Constants.Epsilon) { var invalidator = new OperatorPart.InvalidateInvalidatables(); op.Outputs[0].TraverseWithFunctionUseSpecificBehavior(null, invalidator); _previousTime = context.Time; } context.D3DDevice = D3DDevice.Device; context.RenderTargetView = _renderTargetView; context.DepthStencilState = _renderer.DefaultDepthStencilState; context.BlendState = _renderer.DefaultBlendState; context.RasterizerState = _renderer.DefaultRasterizerState; context.SamplerState = _renderer.DefaultSamplerState; context.Viewport = _viewport; context.Texture0 = _shaderResourceView; var worldToCamera = Matrix.LookAtLH(_renderConfig.CameraSetup.Position, _renderConfig.CameraSetup.Target, _renderConfig.CameraSetup.UpDir); switch (op.FunctionType) { case FunctionType.Scene: context.Effect = _renderer.SceneDefaultEffect; context.InputLayout = _renderer.SceneDefaultInputLayout; context.DepthStencilView = _depthStencilView; D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera); op.Outputs[0].Eval(context); break; case FunctionType.Image: context.Effect = _renderer.ScreenRenderEffect; context.InputLayout = _renderer.ScreenQuadInputLayout; context.DepthStencilView = null; D3DRenderSetup.SetupContextForRenderingCamToBuffer(context, op, _renderer, worldToCamera); var image = op.Outputs[0].Eval(new OperatorPartContext(context)).Image; if (image != null) { _renderer.SetupBaseEffectParameters(context); _renderer.RenderToScreen(image, context); } break; } _swapChain.Present(1, PresentFlags.None); D3DDevice.EndFrame(); TimeLogger.EndFrame(); } catch (Exception exception) { Logger.Error("Exception while in fullscreen:\n", exception.ToString()); } }