Esempio n. 1
0
        internal void ManipulateCamera()
        {
            if (_spaceMouseEventCount == 0)
            {
                return;
            }

            SharpDX.Vector3 viewDir;
            SharpDX.Vector3 sideDir;
            SharpDX.Vector3 upDir;
            _renderSetup.CalcDirections(out viewDir, out sideDir, out upDir);

            var viewDirLength = viewDir.Length();

            viewDir /= viewDirLength;

            float translationVelocity = _spaceMouseTranslateVector.Length() / 2000.0f;
            var   direction           = _spaceMouseTranslateVector;

            direction.Normalize();

            if (translationVelocity < _cameraInteraction.MaxMoveVelocity)
            {
                direction *= translationVelocity;
            }
            else
            {
                direction *= _cameraInteraction.MaxMoveVelocity;
            }

            var oldPosition = _renderSetup.CameraPosition;

            var moveDir = direction.X * sideDir - direction.Y * viewDir - direction.Z * upDir;

            var rotAroundX = Matrix.RotationAxis(sideDir, -_spaceMouseRotateVector.X / 8000.0f);
            var rotAroundY = Matrix.RotationAxis(upDir, -_spaceMouseRotateVector.Y / 8000.0f);
            var rot        = Matrix.Multiply(rotAroundX, rotAroundY);
            var newViewDir = Vector3.Transform(viewDir, rot);

            newViewDir.Normalize();

            _renderSetup.CameraPosition = oldPosition + moveDir;
            _renderSetup.CameraTarget   = oldPosition + moveDir + newViewDir.ToVector3() * viewDirLength;

            _spaceMouseEventCount      = 0;
            _spaceMouseTranslateVector = new Vector3(0, 0, 0);
            _spaceMouseRotateVector    = new Vector3(0, 0, 0);
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        private void UpdateLocalShownContent()
        {
            //if (_showSceneControl == null)
            //    return;
            //var op = _showSceneControl.Operator;
            //var d3DScene = _showSceneControl.RenderSetup;
            if (d3DScene == null || d3DScene.Operator == null || d3DScene.Operator.Outputs.Count <= 0)
            {
                return;
            }

            var op = d3DScene.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;

                Vector3 viewDir;
                Vector3 sideDir;
                Vector3 upDir;
                D3DRenderSetup.CalcDirections(d3DScene.CameraTarget, d3DScene.CameraPosition, d3DScene.CameraRoll, out viewDir, out sideDir, out upDir);
                var worldToCamera = Matrix.LookAtLH(d3DScene.CameraPosition, d3DScene.CameraTarget, upDir);

                d3DScene.Operator = op;

                switch (op.FunctionType)
                {
                case FunctionType.Scene:
                    context.Effect           = _renderer.SceneDefaultEffect;
                    context.InputLayout      = _renderer.SceneDefaultInputLayout;
                    context.DepthStencilView = _depthStencilView;

                    D3DRenderSetup.Setup(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.Setup(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());
            }
        }