/// <summary>
        /// Picks at the mouse position and traverses the picked objects components.
        /// If a corresponding component is found the suitable visit method is called which invokes the event.
        /// </summary>
        /// <param name="mousePos">The current mouse position.</param>
        /// <param name="canvasWidth">Canvas width - needed to determine the mouse position in clip space.</param>
        /// <param name="canvasHeight">Canvas height - needed to determine the mouse position in clip space.</param>
        public void CheckForInteractiveObjects(RenderContext rc, float2 mousePos, int canvasWidth, int canvasHeight)
        {
            var pickPosClip = mousePos * new float2(2.0f / canvasWidth, -2.0f / canvasHeight) + new float2(-1, 1);

            var pickResults  = _scenePicker.Pick(rc, pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).ToList();
            var pickResNodes = pickResults.Select(x => x.Node).ToList();
            var firstPickRes = pickResults.FirstOrDefault();

            _pickRes = null;

            if (firstPickRes != null)
            {
                _pickRes = FindLeafNodeInPickRes(firstPickRes?.Node, pickResNodes);
            }

            if (_pickRes != _pickResCache)
            {
                Traverse(_pickResCache);
            }

            _pickResCache = _pickRes;

            if (_pickRes != null)
            {
                Traverse(_pickRes);
            }
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColour;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColour        = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);
                    }
                    _currentPick = newPick;
                }
            }
            float cabinRot = _cabinTransform.Rotation.y;

            cabinRot += 0.1f * Keyboard.ADAxis;
            _cabinTransform.Rotation = new float3(0, cabinRot, 0);

            if (_currentPick != null)
            {
                _pickTransform = _currentPick.Node.GetTransform();
                float zRot = _pickTransform.Rotation.z;
                zRot += 0.1f * Keyboard.WSAxis;
                _pickTransform.Rotation = new float3(0, 0, zRot);
            }
            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#3
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            _baseTransform.Rotation = new float3(0, _baseTransform.Rotation.y + Keyboard.ADAxis * DeltaTime * 3, 0);
            canon.Rotation          = new float3(0, canon.Rotation.y + Keyboard.LeftRightAxis * DeltaTime * 3, 0);
            vr.Rotation             = new float3(vr.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            hr.Rotation             = new float3(hr.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            vl.Rotation             = new float3(vl.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);
            hl.Rotation             = new float3(hl.Rotation.x + Keyboard.WSAxis * DeltaTime * 3, 0, 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-0.7f) * float4x4.CreateRotationY(1.3f);

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();

                PickResult newPick = null;

                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColor         = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            _rightRearTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float4)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float4(1, 0.4f, 0.4f, 1));
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#5
0
        // RenderAFrame is called once a frame
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            _rightRearTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Math.Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.OrangeRed;
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);
            // _WheelVLTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0);



            // _SchaufelTransform.Scale = new float3(0.5f, 2f, 2f);



            if (Mouse.MiddleButton == true)
            {
                _camAngle = _camAngle + Mouse.Velocity.x / 500;
            }
            ;

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);



            // Setup the camera
            //RC.View = float4x4.CreateTranslation(0, -10, 50) * float4x4.CreateRotationY(_camAngle);
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationY(_camAngle);


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0f, 1f, 0.1f));
                    }
                    _currentPick = newPick;
                }
            }

            //Wheel
            if (_currentPick?.Node.Name == "WheelVL" || _currentPick?.Node.Name == "WheelHL" || _currentPick?.Node.Name == "WheelVR" || _currentPick?.Node.Name == "WheelHR")
            {
                float VL = _WheelVLTransform.Rotation.z;
                VL += 0.1f * Keyboard.LeftRightAxis;
                _WheelVLTransform.Rotation = new float3(0, 0, VL);
                float HL = _WheelHLTransform.Rotation.z;
                HL += 0.1f * Keyboard.LeftRightAxis;
                _WheelHLTransform.Rotation = new float3(0, 0, HL);
                float VR = _WheelVRTransform.Rotation.z;
                VR += 0.1f * Keyboard.LeftRightAxis;
                _WheelVRTransform.Rotation = new float3(0, 0, VR);
                float HR = _WheelHRTransform.Rotation.z;
                HR += 0.1f * Keyboard.LeftRightAxis;
                _WheelHRTransform.Rotation = new float3(0, 0, HR);
            }

            //Body
            if (_currentPick?.Node.Name == "Body")
            {
                float Body = _BodyTransform.Rotation.y;
                Body += 0.1f * Keyboard.LeftRightAxis;
                _BodyTransform.Rotation = new float3(0, Body, 0);
            }

            //Arm
            if (_currentPick?.Node.Name == "Arm")
            {
                float Arm = _ArmTransform.Rotation.z;
                Arm += 0.1f * Keyboard.LeftRightAxis;
                _ArmTransform.Rotation = new float3(0, 0, Arm);
            }

            //Schaufel
            if (_currentPick?.Node.Name == "Schaufel")
            {
                float Schaufel = _SchaufelTransform.Rotation.z;
                Schaufel += 0.1f * Keyboard.UpDownAxis;
                _SchaufelTransform.Rotation = new float3(0, 0, Schaufel);
            }



            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#7
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (_camAngleVelocity > 0)
            {
                _camAngleVelocity -= 0.03f;
                if (_camAngleVelocity < 0)
                {
                    _camAngleVelocity = 0;
                }
            }
            ;
            if (_camAngleVelocity < 0)
            {
                _camAngleVelocity += 0.03f;
                if (_camAngleVelocity > 0)
                {
                    _camAngleVelocity = 0;
                }
            }
            ;

            if (Mouse.RightButton)
            {
                _camAngleVelocity = Mouse.Velocity.x / 10000;
            }
            ;

            _camAngle -= _camAngleVelocity;


            // Setup the camera
            RC.View = float4x4.CreateRotationX(-M.Pi / 7.3f) * float4x4.CreateRotationY(M.Pi - _TrailerTransform.Rotation.y) * float4x4.CreateTranslation(-_TrailerTransform.Translation.x, -6, -_TrailerTransform.Translation.z);


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                if (pickResults.Count > 0)
                {
                    //Diagnostics.Log(pickResults[0].Node.Name);

                    PickResult newPick = null;
                    if (pickResults.Count > 0)
                    {
                        pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                        newPick = pickResults[0];
                        if (!newPick.Node.Name.StartsWith("Cube"))
                        {
                            newPick = null;
                        }
                    }
                    if (newPick?.Node != _currentPick?.Node)
                    {
                        if (_currentPick != null)
                        {
                            _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                        }
                        if (newPick != null)
                        {
                            var mat = newPick.Node.GetMaterial();
                            _oldColor         = mat.Diffuse.Color;
                            mat.Diffuse.Color = new float3(1, 0, 0);

                            _targetHeight = newPick.Node.GetTransform().Translation.y - .8f;
                        }
                        _currentPick = newPick;
                    }
                }
                else
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                        _currentPick = null;
                    }
                }
            }

            float xRadVL = _RadVLTransform.Rotation.x;

            xRadVL += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadVLTransform.Rotation = new float3(xRadVL, 0, 0);

            float xRadVR = _RadVRTransform.Rotation.x;

            xRadVR += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadVRTransform.Rotation = new float3(xRadVR, 0, 0);

            float xRadHL = _RadHLTransform.Rotation.x;
            float yRadHL = _RadHLTransform.Rotation.y;

            xRadHL += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            yRadHL  = Keyboard.ADAxis * -0.35f;
            _RadHLTransform.Rotation = new float3(xRadHL, yRadHL, 0);

            float xRadHR = _RadHRTransform.Rotation.x;
            float yRadHR = _RadHRTransform.Rotation.y;

            xRadHR += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            yRadHR  = Keyboard.ADAxis * -.35f;
            _RadHRTransform.Rotation = new float3(xRadHR, yRadHR, 0);

            float yGabel = _GabelTransform.Translation.y;

            if (_targetHeight < yGabel)
            {
                yGabel -= DeltaTime;
                if (_targetHeight > yGabel)
                {
                    yGabel = _targetHeight;
                }
            }

            if (_targetHeight > yGabel)
            {
                yGabel += DeltaTime;
                if (_targetHeight < yGabel)
                {
                    yGabel = _targetHeight;
                }
            }
            _GabelTransform.Translation = new float3(_GabelTransform.Translation.x, yGabel, _GabelTransform.Translation.z);

            /*float xLift = _LiftTransform.Rotation.x;
             * xLift += Keyboard.LeftRightAxis * -0.005f * (DeltaTime / 16 * 1000);
             * if (xLift < -0.22f) xLift = -0.22f;
             * if (xLift > 0) xLift = 0;
             * _LiftTransform.Rotation = new float3(xLift, 0, 0);
             *
             *
             *
             * float yGabel = _GabelTransform.Translation.y;
             * yGabel += Keyboard.UpDownAxis * 0.05f * (DeltaTime / 16 * 1000);
             * if (yGabel < 0.03f) yGabel = 0.03f;
             * if (yGabel > 4) yGabel = 4;
             * _GabelTransform.Translation = new float3(_GabelTransform.Translation.x, yGabel, _GabelTransform.Translation.z);
             */


            float3 pAalt = _BaseTransform.Translation;
            float3 pBalt = _TrailerTransform.Translation;

            float posVel = Keyboard.WSAxis * Time.DeltaTime;
            float rotVel = Keyboard.ADAxis * Time.DeltaTime;

            float newRot = _BaseTransform.Rotation.y + (rotVel * Keyboard.WSAxis * Time.DeltaTime * 30);

            _BaseTransform.Rotation = new float3(0, newRot, 0);

            float3 pAneu = _BaseTransform.Translation + new float3(posVel * M.Sin(newRot) * 10, 0, posVel * M.Cos(newRot) * 10);

            _BaseTransform.Translation = pAneu;

            float3 pBneu = pAneu + (float3.Normalize(pBalt - pAneu) * _d);

            _TrailerTransform.Translation = pBneu;

            _TrailerTransform.Rotation = new float3(0, (float)System.Math.Atan2(float3.Normalize(pBalt - pAneu).x, float3.Normalize(pBalt - pAneu).z), 0);

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#8
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            _wheel_front_right_transform = _scene.Children.FindNodes(node => node.Name == "RightFrontWheel")?.FirstOrDefault()?.GetTransform();
            float wheel_front_right_rotation_y = _wheel_front_right_transform.Rotation.y;

            wheel_front_right_rotation_y         += 2 * Keyboard.UpDownAxis * DeltaTime;
            _wheel_front_right_transform.Rotation = new float3(0, wheel_front_right_rotation_y, 0);

            _wheel_front_left_transform = _scene.Children.FindNodes(node => node.Name == "LeftFrontWheel")?.FirstOrDefault()?.GetTransform();
            float wheel_front_left_rotation_y = _wheel_front_left_transform.Rotation.y;

            wheel_front_left_rotation_y         += 2 * Keyboard.UpDownAxis * DeltaTime;
            _wheel_front_left_transform.Rotation = new float3(0, wheel_front_left_rotation_y, 0);


            if (_allow_arm_movement)
            {
                _jib_arm_transform = _scene.Children.FindNodes(node => node.Name == "jib_arm")?.FirstOrDefault()?.GetTransform();
                float jib_arm_rotation_y = _jib_arm_transform.Rotation.y;
                jib_arm_rotation_y         += 1.5f * Keyboard.LeftRightAxis * DeltaTime;
                _jib_arm_transform.Rotation = new float3(0, jib_arm_rotation_y, 0);
            }


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, -1, 50) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_camAngle);

            if (Mouse.RightButton)
            {
                _camSpeed = Mouse.Velocity.x;
            }
            else
            {
                _camSpeed = _camSpeed * 0.9f;
            }

            _camAngle = _camAngle + 0.005f * _camSpeed * Time.DeltaTime;


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        _oldColor = (float3)newPick.Node.GetComponent <ShaderEffectComponent>().Effect.GetEffectParam("DiffuseColor");
                        newPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", new float3(0.4f, 0.6f, 0.4f));

                        if (newPick.Node.Name == "jib_arm" || newPick.Node.Name == "jib_arm_base")
                        {
                            _allow_arm_movement = true;
                        }
                        else
                        {
                            _allow_arm_movement = false;
                        }
                    }
                    else
                    {
                        _allow_arm_movement = false;
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#9
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            RC.Viewport(0, 0, Width, Height);

            #region Controls

            // Mouse and keyboard movement
            if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            if (Input.Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f;
            }
            else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _keys = false;
                float2 touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime;
                    _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime;
                }
                else
                {
                    float curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime);
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            _angleHorz += _angleVelHorz;
            _angleVert += _angleVelVert;

            // Create the camera matrix and set it as the current ModelView transformation
            float4x4 mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            float4x4 mtxCam = float4x4.LookAt(0, 0, -5, 0, 0, 0, 0, 1, 0);

            float4x4 view         = mtxCam * mtxRot;
            float4x4 perspective  = float4x4.CreatePerspectiveFieldOfView(_fovy, (float)Width / Height, ZNear, ZFar);
            float4x4 orthographic = float4x4.CreateOrthographic(Width, Height, ZNear, ZFar);

            #endregion Controls

            //Annotations will be updated according to circle positions.
            //Lines will be updated according to circle and annotation positions.
            RC.View       = view;
            RC.Projection = perspective;
            SceneNode canvas = _gui.Children[0];

            foreach (SceneNode child in canvas.Children)
            {
                if (!child.Name.Contains("MarkModelContainer"))
                {
                    continue;
                }

                //1. Calculate the circles canvas position.
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode container = child.Children[k];

                    SceneNode          circle  = container.Children[0];
                    UserInterfaceInput uiInput = _uiInput[k];

                    //the monkey's matrices
                    SceneNode monkey     = _scene.Children[0];
                    float4x4  model      = monkey.GetGlobalTransformation();
                    float4x4  projection = perspective;

                    float4x4 mvpMonkey = projection * view * model;

                    float3 clipPos         = float4x4.TransformPerspective(mvpMonkey, uiInput.Position); //divides by 2
                    float2 canvasPosCircle = new float2(clipPos.x, clipPos.y) * 0.5f + 0.5f;

                    canvasPosCircle.x      *= _canvasWidth;
                    canvasPosCircle.y      *= _canvasHeight;
                    uiInput.CircleCanvasPos = canvasPosCircle;

                    var pos = new float2(uiInput.CircleCanvasPos.x - (uiInput.Size.x / 2), uiInput.CircleCanvasPos.y - (uiInput.Size.y / 2)); //we want the lower left point of the rect that encloses the
                    circle.GetComponent <RectTransform>().Offsets = GuiElementPosition.CalcOffsets(AnchorPos.Middle, pos, _canvasHeight, _canvasWidth, uiInput.Size);

                    //1.1   Check if circle is visible

                    PickResult newPick = _scenePicker.Pick(RC, new float2(clipPos.x, clipPos.y)).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                    if (newPick != null && uiInput.AffectedTriangles[0] == newPick.Triangle) //VISIBLE
                    {
                        uiInput.IsVisible = true;

                        var effect = circle.GetComponent <SurfaceEffect>();
                        effect.SetDiffuseAlphaInShaderEffect(UserInterfaceHelper.alphaVis);
                    }
                    else
                    {
                        uiInput.IsVisible = false;
                        var effect = circle.GetComponent <SurfaceEffect>();
                        effect.SetDiffuseAlphaInShaderEffect(UserInterfaceHelper.alphaInv);
                    }

                    //1.2   Calculate annotation positions without intersections.
                    if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                    {
                        float yPosScale = uiInput.CircleCanvasPos.y / _canvasHeight;
                        yPosScale = (yPosScale - 0.5f) * 2f;
                        uiInput.AnnotationCanvasPos.y = uiInput.CircleCanvasPos.y - (UserInterfaceHelper.AnnotationDim.y / 2) + (2 * UserInterfaceHelper.AnnotationDim.y * yPosScale);

                        if (uiInput.CircleCanvasPos.x > _canvasWidth / 2) //RIGHT
                        {
                            uiInput.AnnotationCanvasPos.x = UserInterfaceHelper.CanvasWidthInit - UserInterfaceHelper.AnnotationDim.x - UserInterfaceHelper.AnnotationDistToLeftOrRightEdge;
                        }
                        else
                        {
                            uiInput.AnnotationCanvasPos.x = UserInterfaceHelper.AnnotationDistToLeftOrRightEdge;
                        }
                    }
                    _uiInput[k] = uiInput;
                }

                // 2.   Find intersecting annotations and correct their position in _uiInput.
                //      Disable rendering of annotation if its corresponding circle is not visible.
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode          container  = child.Children[k];
                    SceneNode          annotation = container.Children[1];
                    UserInterfaceInput uiInput    = _uiInput[k];

                    if (uiInput.IsVisible)
                    {
                        if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                        {
                            Dictionary <int, float2> intersectedAnnotations = new();
                            int iterations = 0;
                            CalculateNonIntersectingAnnotationPositions(ref uiInput, ref intersectedAnnotations, ref iterations);
                        }

                        annotation.GetComponent <NineSlicePlane>().Active = true;
                        foreach (Mesh comp in annotation.GetComponentsInChildren <Mesh>())
                        {
                            comp.Active = true;
                        }
                    }
                    else
                    {
                        annotation.GetComponent <NineSlicePlane>().Active = false;
                        foreach (Mesh comp in annotation.GetComponentsInChildren <Mesh>())
                        {
                            comp.Active = false;
                        }
                    }
                }

                // 3.   Update annotation positions on canvas and draw line
                for (int k = 0; k < child.Children.Count; k++)
                {
                    SceneNode container = child.Children[k];

                    SceneNode          line    = container.Children[2];
                    UserInterfaceInput uiInput = _uiInput[k];

                    if (uiInput.IsVisible)
                    {
                        if (!uiInput.CircleCanvasPos.Equals(uiInput.CircleCanvasPosCache))
                        {
                            UpdateAnnotationOffsets(child.Children[uiInput.Identifier].Children[1], uiInput);
                            DrawLine(child.Children[uiInput.Identifier].Children[2], uiInput);
                        }
                    }

                    DrawLine(line, uiInput);

                    uiInput.CircleCanvasPosCache = uiInput.CircleCanvasPos;
                    _uiInput[k] = uiInput;
                }
            }

            _sceneRenderer.Render(RC);
            RC.Projection = _canvasRenderMode == CanvasRenderMode.Screen ? orthographic : perspective;
            // Constantly check for interactive objects.
            if (!Input.Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(RC, Input.Mouse.Position, Width, Height);
            }

            if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(RC, Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height);
            }
            _guiRenderer.Render(RC);

            Present();
        }
示例#10
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

                      
            
            float speed = Keyboard.UpDownAxis * 15.0f;
            float rotSpeed = Keyboard.LeftRightAxis * 3.0f;
            float wheelRotSpeed = speed * Time.DeltaTime * 0.3f;
            float wheelRotSpeedDelta = rotSpeed * Time.DeltaTime * 0.3f;
            float yRot = _bodyTransform.Rotation.y + rotSpeed * Time.DeltaTime;
            float3 speed3d = new float3(speed * M.Sin(yRot), 0, speed * M.Cos(yRot));

            _bodyTransform.Translation = _bodyTransform.Translation + speed3d * Time.DeltaTime;
            _bodyTransform.Rotation = new float3(_bodyTransform.Rotation.x, yRot, _bodyTransform.Rotation.z);
            
        
            _rightRearWheelTransform.Rotation = new float3(_rightFrontWheelTransform.Rotation.x + wheelRotSpeed - wheelRotSpeedDelta, 0, 0);
            _leftRearWheelTransform.Rotation = new float3(_leftRearWheelTransform.Rotation.x + wheelRotSpeed + wheelRotSpeedDelta, 0, 0);
            _rightFrontWheelTransform.Rotation = new float3(_rightFrontWheelTransform.Rotation.x +wheelRotSpeed - wheelRotSpeedDelta, 0, 0);
            _leftFrontWheelTransform.Rotation = new float3(_leftFrontWheelTransform.Rotation.x + wheelRotSpeed + wheelRotSpeedDelta, 0, 0);
          

            // Setup the camera 
            RC.View = float4x4.CreateTranslation(0, -10, 50) * float4x4.CreateRotationY(_camAngle);
            
       

            
            if(Mouse.RightButton == true){
                _camAngle += Mouse.Velocity.x * 0.01f * DeltaTime;
            }

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                
                _scenePicker.View = RC.View;
                _scenePicker.Projection = RC.Projection;
                
                List<PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                
                PickResult newPick = null;
               
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent<ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                        
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent<ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0.5f, 1, 0.4f));
                    }
                   
                    _currentPick = newPick;
                }

                
            }

            if(_currentPick?.Node.Name == "Schaufel"){
                float schaufelTransform = _schaufelTransform.Rotation.x;
                schaufelTransform -= 0.01f * Keyboard.WSAxis;
               
                if(schaufelTransform >= 0.8f){
                    schaufelTransform = 0.8f;
                }else if(schaufelTransform <= -1.0f){
                    schaufelTransform = -1.0f;
                }
                _schaufelTransform.Rotation = new float3(schaufelTransform, 0, 0);
            }else if(_currentPick?.Node.Name == "Oberarm"){
                float oberarmTransform = _oberarmTransform.Rotation.x;
                oberarmTransform -= 0.01f * Keyboard.WSAxis;
                
                if(oberarmTransform >= 1.0f){
                    oberarmTransform = 1.0f;
                }else if(oberarmTransform <= -0.5f){
                    oberarmTransform = -0.5f;
                }
                _oberarmTransform.Rotation = new float3(oberarmTransform, 0, 0);
            }else if(_currentPick?.Node.Name == "Arm"){
                float unterarmTransform = _unterarmTransform.Rotation.x;
                unterarmTransform -= 0.01f * Keyboard.WSAxis;
                 if(unterarmTransform >= 1.5f){
                    unterarmTransform = 1.5f;
                }else if(unterarmTransform <= -0.01f){
                    unterarmTransform = -0.01f;
                }
                _unterarmTransform.Rotation = new float3(unterarmTransform, 0, 0);
            } 

            // if(_currentPick?.Node.Name == "LeftFrontWheel" || _currentPick?.Node.Name == "RightFrontWheel" || _currentPick?.Node.Name == "LeftRearWheel" || _currentPick?.Node.Name == "RightRearWheel"){
            //     float leftFrontWheelTransform = _leftFrontWheelTransform.Rotation.x;
            //     leftFrontWheelTransform -= 0.08f * Keyboard.UpDownAxis;
            //     _leftFrontWheelTransform.Rotation = new float3(leftFrontWheelTransform, 0, 0);

            //     float rightFrontWheelTransform = _rightFrontWheelTransform.Rotation.x;
            //     rightFrontWheelTransform -= 0.08f * Keyboard.UpDownAxis;
            //     _rightFrontWheelTransform.Rotation = new float3(rightFrontWheelTransform, 0, 0);

            //     float leftRearWheelTransform = _leftRearWheelTransform.Rotation.x;
            //     leftRearWheelTransform -= 0.08f * Keyboard.UpDownAxis;
            //     _leftRearWheelTransform.Rotation = new float3(leftRearWheelTransform, 0, 0);

            //     float rightRearWheelTransform = _rightRearWheelTransform.Rotation.x;
            //     rightRearWheelTransform -= 0.08f * Keyboard.UpDownAxis;
            //     _rightRearWheelTransform.Rotation = new float3(rightRearWheelTransform, 0, 0);
            // }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#11
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //   _rightRearTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 10) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0));


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColor         = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(0, 1f, 1f);
                    }
                    _currentPick = newPick;
                }
            }

            //   _gunTransform.Rotation = new float3(0,0,1.5f);
            //  _leftFrontTransform.Rotation = new float3(5,0,0);

            if (_currentPick != null)
            {
                if (_currentPick.Node.Name == "hull")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _tankTransform.Translation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radvl.Rotation            += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radvr.Rotation            += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);

                        _radhl.Rotation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                        _radhr.Rotation += new float3(-3 * Keyboard.UpDownAxis * DeltaTime, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "hull")
                {
                    if (Keyboard.LeftRightAxis != 0)
                    {
                        _tankTransform.Rotation += new float3(0, -3f * Keyboard.LeftRightAxis * DeltaTime, 0);
                        _radvl.Rotation         += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                        _radvr.Rotation         += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);

                        _radhl.Rotation += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                        _radhr.Rotation += new float3(-3f * Keyboard.LeftRightAxis * DeltaTime, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "turm")
                {
                    if (Keyboard.LeftRightAxis != 0)
                    {
                        _turretTransform.Rotation += new float3(0, 0.9f * Keyboard.LeftRightAxis * DeltaTime, 0);
                    }
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform1.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                        _gunTransform2.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                        _gunTransform3.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "gun1")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform1.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "gun2")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform2.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }
                if (_currentPick.Node.Name == "gun3")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _gunTransform3.Rotation += new float3(0, 0, -1 * Keyboard.UpDownAxis * DeltaTime);
                    }
                }

                if (_currentPick.Node.Name == "rad_vr")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radvr.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "rad_vl")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radvl.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }

                if (_currentPick.Node.Name == "rad_hl")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radhl.Rotation += new float3(-0.02f * Keyboard.UpDownAxis, 0, 0);
                    }
                }
                if (_currentPick.Node.Name == "rad_hr")
                {
                    if (Keyboard.UpDownAxis != 0)
                    {
                        _radhr.Rotation += new float3(-0.025f * Keyboard.UpDownAxis, 0, 0);
                    }
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#12
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            //Rotation Drehsteuerung
            _DSShader   = _scene.Children.FindNodes(node => node.Name == "Drehsteuerung")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>();
            _oldColorDS = (float3)_DSShader.Effect.GetEffectParam("DiffuseColor");
            if (_oldColorDS == _newColor)
            {
                _DS = _scene.Children.FindNodes(node => node.Name == "Drehsteuerung")?.FirstOrDefault()?.GetTransform();
                float DSRot = _DS.Rotation.y;
                DSRot       += 0.4f * Keyboard.ADAxis * Time.DeltaTime;
                _DS.Rotation = new float3(0, DSRot, 0);
            }

            //Rotation hintere Leiter
            _leiterBackShader = _scene.Children.FindNodes(node => node.Name == "LeiterHinten")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>();
            _oldColorLB       = (float3)_leiterBackShader.Effect.GetEffectParam("DiffuseColor");
            if (_oldColorLB == _newColor)
            {
                _leiterBack    = _scene.Children.FindNodes(node => node.Name == "LeiterHinten")?.FirstOrDefault()?.GetTransform();
                leiterBackRot  = _leiterBack.Rotation.x;
                leiterBackRot += 0.4f * Keyboard.WSAxis * Time.DeltaTime;

                if (leiterBackRot <= 0)
                {
                    _leiterBack.Rotation = new float3(0, 0, 0);
                }

                else if (leiterBackRot <= 60 * M.Pi / 180)
                {
                    _leiterBack.Rotation = new float3(leiterBackRot, 0, 0);
                }

                else if (leiterBackRot >= 60 * M.Pi / 180)
                {
                    leiterBackRot        = 60 * M.Pi / 180;
                    _leiterBack.Rotation = new float3(leiterBackRot, 0, 0);
                }
            }

            //Rotation vordere Leiter
            _leiterFrontShader = _scene.Children.FindNodes(node => node.Name == "LeiterVorne")?.FirstOrDefault()?.GetComponent <ShaderEffectComponent>();
            _oldColorLF        = (float3)_leiterFrontShader.Effect.GetEffectParam("DiffuseColor");
            if (_oldColorLF == _newColor)
            {
                _leiterFront = _scene.Children.FindNodes(node => node.Name == "LeiterVorne")?.FirstOrDefault()?.GetTransform();
                float leiterFrontRot = _leiterFront.Rotation.x;
                leiterFrontRot += 0.4f * Keyboard.WSAxis * Time.DeltaTime;

                if (leiterBackRot == 0)
                {
                    if (leiterFrontRot <= 0)
                    {
                        _leiterFront.Rotation = new float3(0, 0, 0);
                    }
                }

                else if (leiterFrontRot <= -30 * M.Pi / 180)
                {
                    leiterFrontRot        = -30 * M.Pi / 180;
                    _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0);
                }

                else if (leiterFrontRot <= 30 * M.Pi / 180)
                {
                    _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0);
                }

                else if (leiterFrontRot >= 30 * M.Pi / 180)
                {
                    leiterFrontRot        = 30 * M.Pi / 180;
                    _leiterFront.Rotation = new float3(leiterFrontRot, 0, 0);
                }
            }

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 20) * float4x4.CreateRotationX(-(float)Atan(10.0 / 40.0)) * float4x4.CreateRotationY(-(float)Acos(0));

            //Scene Picker
            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.19f, 0.29f));
                        _newColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#13
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_cam);
            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var mat = newPick.Node.GetMaterial();
                        _oldColor         = mat.Diffuse.Color;
                        mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);
                    }
                    _currentPick = newPick;
                }
            }
            if (_currentPick != null)
            {
                switch (_currentPick.Node.Name)
                {
                case "Grabble":
                    _grabbleTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;

                case "UpperGrabble":
                    _upperGrabbleTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;

                case "LeftRearWheel":
                    _leftRearTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;

                case "RightRearWheel":
                    _rightRearTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;

                case "LeftFrontWheel":
                    _leftFrontTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;

                case "RightFrontWheel":
                    _rightFrontTransform.Rotation.x += 0.1f * Keyboard.WSAxis * DeltaTime * 20;
                    break;
                }
            }

            if (Mouse.RightButton)
            {
                _cam += .01f * DeltaTime * Mouse.Velocity.x;
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#14
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Mouse and keyboard movement
            if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            if (Input.Mouse.LeftButton)
            {
                _pick         = true;
                _pickPos      = Input.Mouse.Position;
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f;
            }
            else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _pick    = true;
                _pickPos = Input.Touch.GetPosition(TouchPoints.Touchpoint_0);
                var touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f;
            }
            else
            {
                _pick = false;
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime;
                    _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime);
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            _angleHorz += _angleVelHorz;
            _angleVert += _angleVelVert;

            // Create the camera matrix and set it as the current ModelView transformation
            var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam = float4x4.LookAt(0, 20, -600, 0, 150, 0, 0, 1, 0);

            // Check
            if (_pick)
            {
                Diagnostics.Log(_pickPos);
                float2 pickPosClip = _pickPos * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                _scenePicker.View = mtxCam * mtxRot;

                PickResult newPick = _scenePicker.Pick(pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

#if WEBBUILD
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect;
                        ef.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <ShaderEffectComponent>().Effect;
                        _oldColor = (float4)ef.GetEffectParam("DiffuseColor"); // cast needed
                        ef.SetEffectParam("DiffuseColor", ColorUint.Tofloat4(ColorUint.LawnGreen));
                    }
                    _currentPick = newPick;
                }
#else
                if (newPick?.Node != _currentPick?.Node)
                {
                    dynamic shaderEffectComponent; // this needs to be dynamic! & reference Microsoft.CSharp.dll

                    if (_currentPick != null)
                    {
                        shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect;
                        shaderEffectComponent.DiffuseColor = _oldColor;
                    }
                    if (newPick != null)
                    {
                        shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>().Effect;
                        _oldColor             = (float4)shaderEffectComponent.DiffuseColor;
                        shaderEffectComponent.DiffuseColor = ColorUint.Tofloat4(ColorUint.LawnGreen);
                    }
                    _currentPick = newPick;
                }
#endif
                _pick = false;
            }

            RC.View = mtxCam * mtxRot;
            // Render the scene loaded in Init()
            _sceneRenderer.Render(RC);
#if GUI_SIMPLE
            //Set the view matrix for the interaction handler.
            _sih.View = RC.View;

            // Constantly check for interactive objects.
            if (!Input.Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(Input.Mouse.Position, Width, Height);
            }

            if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height);
            }
            _guiRenderer.Render(RC);
#endif
            // Swap buffers: Show the contents of the backbuffer (containing the currently rerndered farame) on the front buffer.
            Present();
        }
示例#15
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);
            _oberesGewTransform = _scene.Children.FindNodes(node => node.Name == "pfeiler_gewinde_arm_nicht_drehbar")?.FirstOrDefault()?.GetTransform();
            _RadR01Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_R_01")?.FirstOrDefault()?.GetTransform();
            _RadR02Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_L_01")?.FirstOrDefault()?.GetTransform();
            _RadR03Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_02_R")?.FirstOrDefault()?.GetTransform();
            _RadR04Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_02_L")?.FirstOrDefault()?.GetTransform();
            _RadR05Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_03_L")?.FirstOrDefault()?.GetTransform();
            _RadR06Transform    = _scene.Children.FindNodes(node => node.Name == "Rad_03_R")?.FirstOrDefault()?.GetTransform();
            _unterarmTransform  = _scene.Children.FindNodes(node => node.Name == "unterer_arm")?.FirstOrDefault()?.GetTransform(); //Oberer_arm
            //_oberarmTransform = _scene.Children.FindNodes(node => node.Name == "Oberer_arm")?.FirstOrDefault()?.GetTransform();
            _verbagTransform = _scene.Children.FindNodes(node => node.Name == "verbindung_arm_greifer")?.FirstOrDefault()?.GetTransform();


            //Vorlesung

            //Gegeben(_d)
            float 3 pAlt = _carTransform.Translation;
            float 3 pBlt = _trailerTransform.Translation;
            float 3 pAneu;

            //Auto
            float posVel = Input.Keyboard.UpDownAxis * Time.DeltaTime + 10;
            float rotVel = Input.Keyboard.LeftRightAxis * Time.DeltaTime;

            float newRot = _carTransform.Rotation.y + rotVel;

            _carTransform.Rotation = new float3(0, newRot, 0);

            float3 newPos = _carTransform.Translation + new float3(posVel * M.Sin(newRot), 0, posVel * M.Cos(newRot));

            _carTransform.Translation = newPos;


            //Position
            float3 pAneu = _carTransform.Translation + new float3(posVel * M.Sin(newRot), 0, posVel * M.Cos(newRot));

            _carTransform.Translation = newpAneu;

            //neue Trailer Position berechnen
            flaot3 v = float3.Normalize(pBalt - pAneu);

            _trailerTransform.Translation = pAneu + v * _d;

            _trailerTransform.Rotation = new float3(0, (float)System.Math.Atan2(v.x, v.z), 0);


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);


            if (Mouse.RightButton == true)
            {
                _camAngle += Mouse.Velocity.x * 0.00001f * DeltaTime / 20 * 10000;
            }
            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, -2, 10) * float4x4.CreateRotationY(_camAngle);


            //ToDO If Bedingung eingefügt

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                if (pickResults.Count > 0)
                {
                    Diagnostics.Log(pickResults[0].Node.Name);

                    PickResult newPick = null;
                    if (pickResults.Count > 0)
                    {
                        pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                        newPick = pickResults[0];
                    }
                    if (newPick?.Node != _currentPick?.Node)
                    {
                        if (_currentPick != null)
                        {
                            _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                        }
                        if (newPick != null)
                        {
                            var mat = newPick.Node.GetMaterial();
                            _oldColor         = mat.Diffuse.Color;
                            mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);
                        }
                        _currentPick = newPick;
                    }
                }
            }


            if (_currentPick != null)
            {
                switch (_currentPick.Node.Name)
                {
                case "Rad_R_01":
                    float RadR01 = _RadR01Transform.Rotation.x;
                    RadR01 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR01Transform.Rotation = new float3(RadR01, 0, 0);
                    break;

                case "Rad_L_01":
                    float RadR02 = _RadR02Transform.Rotation.x;
                    RadR02 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR02Transform.Rotation = new float3(RadR02, 0, 0);
                    break;

                case "Rad_02_R":
                    float RadR03 = _RadR03Transform.Rotation.x;
                    RadR03 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR03Transform.Rotation = new float3(RadR03, 0, 0);
                    break;

                case "Rad_02_L":
                    float RadR04 = _RadR04Transform.Rotation.x;
                    RadR04 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR04Transform.Rotation = new float3(RadR04, 0, 0);
                    break;

                case "Rad_03_L":
                    float RadR05 = _RadR05Transform.Rotation.x;
                    RadR05 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR05Transform.Rotation = new float3(RadR05, 0, 0);
                    break;

                case "Rad_03_R":
                    float RadR06 = _RadR06Transform.Rotation.x;
                    RadR06 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR06Transform.Rotation = new float3(RadR06, 0, 0);
                    break;



                case "pfeiler_gewinde_arm_nicht_drehbar":
                    float ogd = _oberesGewTransform.Rotation.y;
                    ogd += Keyboard.LeftRightAxis * 0.005f;
                    _oberesGewTransform.Rotation = new float3(0, ogd, 0);
                    break;

                case "unterer_arm":
                    float unter = _unterarmTransform.Rotation.x;
                    if (Keyboard.GetKey(KeyCodes.Up) == true)
                    {
                        if (unter <= 0.35f)
                        {
                            unter += DeltaTime * 0.1f;
                            _unterarmTransform.Rotation = new float3(unter, 0, 0);
                        }
                    }
                    if (Keyboard.GetKey(KeyCodes.Down) == true)
                    {
                        if (unter >= 0.0f)
                        {
                            unter -= DeltaTime * 0.1f;
                            _unterarmTransform.Rotation = new float3(unter, 0, 0);
                        }
                    }
                    break;

                /*case "Oberer_arm":
                 *  float obArmx = _oberarmTransform.Translation.z;
                 *  obArmx += Keyboard.UpDownAxis * 0.1f;
                 *  /*float obArmy = _oberarmTransform.Translation.z;
                 *  obArmy += Keyboard.UpDownAxis * 0.1f;*/
                /*_oberarmTransform.Translation = new float3(0, 0, obArmx);
                 * break;*/
                case "verbindung_arm_greifer":
                    float ver = _verbagTransform.Translation.y;
                    if (Keyboard.GetKey(KeyCodes.Up) == true)
                    {
                        if (ver <= -0.5f)
                        {
                            ver += DeltaTime * 2f;
                            _verbagTransform.Translation = new float3(0, ver, 0);
                        }
                    }
                    if (Keyboard.GetKey(KeyCodes.Down) == true)
                    {
                        if (ver >= -10.0f)
                        {
                            ver -= DeltaTime * 2f;
                            _verbagTransform.Translation = new float3(0, ver, 0);
                        }
                    }
                    break;
                }
            }
            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#16
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                if (pickResults.Count > 0)
                {
                    PickResult newPick = null;
                    if (pickResults.Count > 0)
                    {
                        pickResults.Sort((a, b) => Math.Sign(a.ClipPos.z - b.ClipPos.z));
                        newPick = pickResults[0];
                    }
                    if (newPick?.Node != _currentPick?.Node)
                    {
                        if (_currentPick != null)
                        {
                            _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", _oldColor);
                        }
                        if (newPick != null)
                        {
                            var mat = newPick.Node.GetComponent <ShaderEffectComponent>().Effect;
                            _oldColor = (float4)mat.GetEffectParam("DiffuseColor");
                            mat.SetEffectParam("DiffuseColor", new float4(1, 0.4f, 0.4f, 1));
                        }
                        _currentPick = newPick;
                    }
                }
            }

            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }
            else
            {
                var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);
                _angleVelHorz *= curDamp;
                _angleVelVert *= curDamp;
            }


            if (_currentPick != null)
            {
                _currentPick.Node.GetComponent <TransformComponent>().Rotation.x += 3 * Keyboard.LeftRightAxis * DeltaTime;
                _currentPick.Node.GetComponent <TransformComponent>().Rotation.z += 3 * Keyboard.UpDownAxis * DeltaTime;
            }


            _angleHorz += _angleVelHorz;
            _angleVert += _angleVelVert;

            // Create the camera matrix and set it as the current View transformation
            var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam = float4x4.LookAt(0, 0, -14, 0, 1.5f, 0, 0, 1, 0);

            RC.View = mtxCam * mtxRot;

            // Tick any animations and Render the scene loaded in Init()
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#17
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (_camAngleVelocity > 0)
            {
                _camAngleVelocity -= 0.03f;
                if (_camAngleVelocity < 0)
                {
                    _camAngleVelocity = 0;
                }
            }
            ;
            if (_camAngleVelocity < 0)
            {
                _camAngleVelocity += 0.03f;
                if (_camAngleVelocity > 0)
                {
                    _camAngleVelocity = 0;
                }
            }
            ;

            if (Mouse.RightButton)
            {
                _camAngleVelocity = Mouse.Velocity.x / 10000;
            }
            ;

            _camAngle -= _camAngleVelocity;


            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 17) * float4x4.CreateRotationY(_camAngle);


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                if (pickResults.Count > 0)
                {
                    Diagnostics.Log(pickResults[0].Node.Name);

                    PickResult newPick = null;
                    if (pickResults.Count > 0)
                    {
                        pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                        newPick = pickResults[0];
                    }
                    if (newPick?.Node != _currentPick?.Node)
                    {
                        if (_currentPick != null)
                        {
                            _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                        }
                        if (newPick != null)
                        {
                            var mat = newPick.Node.GetMaterial();
                            _oldColor         = mat.Diffuse.Color;
                            mat.Diffuse.Color = new float3(1, 0, 0);
                        }
                        _currentPick = newPick;
                    }
                }
            }

            if (_currentPick != null)
            {
                switch (_currentPick.Node.Name)
                {
                case "RadVL":
                    float xRadVL = _RadVLTransform.Rotation.x;
                    xRadVL += Keyboard.UpDownAxis * 0.2f * (DeltaTime / 16 * 1000);
                    _RadVLTransform.Rotation = new float3(xRadVL, 0, 0);
                    break;

                case "RadVR":
                    float xRadVR = _RadVRTransform.Rotation.x;
                    xRadVR += Keyboard.UpDownAxis * 0.2f * (DeltaTime / 16 * 1000);
                    _RadVRTransform.Rotation = new float3(xRadVR, 0, 0);
                    break;

                case "RadHL":
                    float xRadHL = _RadHLTransform.Rotation.x;
                    float yRadHL = _RadHLTransform.Rotation.y;
                    xRadHL += Keyboard.UpDownAxis * 0.2f * (DeltaTime / 16 * 1000);
                    yRadHL += Keyboard.LeftRightAxis * -0.02f * (DeltaTime / 16 * 1000);
                    if (yRadHL < -0.25f)
                    {
                        yRadHL = -0.25f;
                    }
                    if (yRadHL > 0.25f)
                    {
                        yRadHL = 0.25f;
                    }
                    _RadHLTransform.Rotation = new float3(xRadHL, yRadHL, 0);
                    break;

                case "RadHR":
                    float xRadHR = _RadHRTransform.Rotation.x;
                    float yRadHR = _RadHRTransform.Rotation.y;
                    xRadHR += Keyboard.UpDownAxis * 0.2f * (DeltaTime / 16 * 1000);
                    yRadHR += Keyboard.LeftRightAxis * -0.02f * (DeltaTime / 16 * 1000);
                    if (yRadHR < -0.25f)
                    {
                        yRadHR = -0.25f;
                    }
                    if (yRadHR > 0.25f)
                    {
                        yRadHR = 0.25f;
                    }
                    _RadHRTransform.Rotation = new float3(xRadHR, yRadHR, 0);
                    break;

                case "Lift":
                    float xLift = _LiftTransform.Rotation.x;
                    xLift += Keyboard.LeftRightAxis * -0.005f * (DeltaTime / 16 * 1000);
                    if (xLift < -0.22f)
                    {
                        xLift = -0.22f;
                    }
                    if (xLift > 0)
                    {
                        xLift = 0;
                    }
                    _LiftTransform.Rotation = new float3(xLift, 0, 0);
                    break;

                case "Gabel":
                    float yGabel = _GabelTransform.Translation.y;
                    yGabel += Keyboard.UpDownAxis * 0.05f * (DeltaTime / 16 * 1000);
                    if (yGabel < 0.03f)
                    {
                        yGabel = 0.03f;
                    }
                    if (yGabel > 4)
                    {
                        yGabel = 4;
                    }
                    _GabelTransform.Translation = new float3(_GabelTransform.Translation.x, yGabel, _GabelTransform.Translation.z);
                    break;
                }
            }


            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            //tower kontrolle


            // _towerTransform.Rotation = new float3(0,M.MinAngle(TimeSinceStart),0);


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);



            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 20) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }

                // Turm nur drehen wenn angeklickt
                if (pickResults.Count > 0 && pickResults[0].Node.Name == "Turm" && _currentPick != null)
                {
                    canTurn = true;
                }
                else
                {
                    canTurn = false;
                }

                //Räder drehen
                if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rad-hinten-rechts")
                {
                    gasGebenHR = true;
                }
                else
                {
                    gasGebenHR = false;
                }

                if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rad-hinten-links")
                {
                    gasGebenHL = true;
                }
                else
                {
                    gasGebenHL = false;
                }

                if (pickResults.Count > 0 && _currentPick != null && pickResults[0].Node.Name == "Rumpf")
                {
                    allrad = true;
                }
                else
                {
                    allrad = false;
                }


                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(0.5f, 0.1f, 0.4f));
                    }
                    _currentPick = newPick;
                }
            }

            if (canTurn == true)
            {
                float towerRed = _towerTransform.Rotation.y;
                towerRed += 0.05f * Keyboard.ADAxis * (-1);
                _towerTransform.Rotation = new float3(0, towerRed, 0);
            }

            if (gasGebenHR == true)
            {
                float hintenRechts = _HRTransform.Rotation.x;
                hintenRechts         += 0.1f * Keyboard.WSAxis * (-1);
                _HRTransform.Rotation = new float3(hintenRechts, 0, 0);
            }

            if (gasGebenHL == true)
            {
                float hintenLinks = _HLTransform.Rotation.x;
                hintenLinks          += 0.1f * Keyboard.WSAxis * (-1);
                _HLTransform.Rotation = new float3(hintenLinks, 0, 0);
            }
            // bei Klick auf Rumpf
            if (allrad == true)
            {
                //Hinten rechts
                float hintenRechts = _HRTransform.Rotation.x;
                hintenRechts         += 0.1f * Keyboard.WSAxis * (-1);
                _HRTransform.Rotation = new float3(hintenRechts, 0, 0);


                // Hinten links
                float hintenLinks = _HLTransform.Rotation.x;
                hintenLinks          += 0.1f * Keyboard.WSAxis * (-1);
                _HLTransform.Rotation = new float3(hintenLinks, 0, 0);

                // Vorne rechts
                float vorneRechts = _VRTransform.Rotation.x;
                vorneRechts          += 0.1f * Keyboard.WSAxis * (-1);
                _VRTransform.Rotation = new float3(vorneRechts, 0, 0);

                //vorne links
                float vorneLinks = _VLTransform.Rotation.x;
                vorneLinks           += 0.1f * Keyboard.WSAxis * (-1);
                _VLTransform.Rotation = new float3(vorneLinks, 0, 0);
            }



            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#19
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_rightRearTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            float  speed              = Keyboard.UpDownAxis * 0.3f;
            float  rotspeed           = Keyboard.LeftRightAxis * 2;
            float  yrot               = _bodyTransform.Rotation.y + rotspeed * DeltaTime;
            float  wheelrotspeed      = speed * 20 * Time.DeltaTime;
            float  wheelrotspeeddelta = rotspeed * 2 * Time.DeltaTime;
            float3 speed3D            = new float3(speed * M.Sin(yrot), 0, speed * M.Cos(yrot));

            if (Keyboard.UpDownAxis != 0.0f)
            {
                _rightRearTransform.Rotation  = new float3(0, _rightRearTransform.Rotation.x + wheelrotspeed - wheelrotspeeddelta, 0);
                _leftRearTransform.Rotation   = new float3(0, _leftRearTransform.Rotation.x + wheelrotspeed + wheelrotspeeddelta, 0);
                _rightFrontTransform.Rotation = new float3(0, _rightFrontTransform.Rotation.x + wheelrotspeed - wheelrotspeeddelta, 0);
                _leftFrontTransform.Rotation  = new float3(0, _leftFrontTransform.Rotation.x + wheelrotspeed + wheelrotspeeddelta, 0);
                _bodyTransform.Translation    = _bodyTransform.Translation + speed3D;
                _bodyTransform.Rotation       = new float3(_bodyTransform.Rotation.x, yrot, _bodyTransform.Rotation.z);
            }


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            //RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float) Atan(15.0 / 40.0));
            _camAngle = _camAngle + 0.1f;
            RC.View   = float4x4.CreateTranslation(0, 0, 30) * float4x4.CreateRotationY(5);


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f));
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Math.Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.OrangeRed;
                    }
                    _currentPick = newPick;
                }
            }

            if (_currentPick != null)
            {
                if (_currentPick.Node.Name == "Gabel_Platte")
                {
                    if (Keyboard.GetKey(KeyCodes.Up))
                    {
                        plattformUp();
                    }
                    else if (Keyboard.GetKey(KeyCodes.Down))
                    {
                        plattformDown();
                    }
                }
                if (_currentPick.Node.Name == "Gabel")
                {
                    if (Keyboard.GetKey(KeyCodes.Up))
                    {
                        rotHalterungUp();
                    }
                    else if (Keyboard.GetKey(KeyCodes.Down))
                    {
                        rotHalterungDown();
                    }
                }
                Diagnostics.Debug(_currentPick.Node.Name);
                if (_currentPick.Node.Name == "Rad_RH" || _currentPick.Node.Name == "Rad_LH" || _currentPick.Node.Name == "Rad_RV" || _currentPick.Node.Name == "Rad_LV")
                {
                    if (Keyboard.GetKey(KeyCodes.Left))
                    {
                        driveBackward();
                    }
                    else if (Keyboard.GetKey(KeyCodes.Right))
                    {
                        driveForward();
                    }
                }
                if (_currentPick.Node.Name == "Fahrzeug")
                {
                    if (Keyboard.GetKey(KeyCodes.Up))
                    {
                        _carTransform.Rotation = new float3(0, _carTransform.Rotation.y + 1.5f * Time.DeltaTime, 0);
                    }
                    else if (Keyboard.GetKey(KeyCodes.Down))
                    {
                        _carTransform.Rotation = new float3(0, _carTransform.Rotation.y - 1.5f * Time.DeltaTime, 0);
                    }

                    if (Keyboard.GetKey(KeyCodes.Left))
                    {
                        driveBackward();
                    }
                    else if (Keyboard.GetKey(KeyCodes.Right))
                    {
                        driveForward();
                    }
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
示例#21
0
        private void HandleCameraAndPicking()
        {
            var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);

            //Camera Rotation
            if (Mouse.MiddleButton && !Keyboard.GetKey(KeyCodes.LShift))
            {
                _angleVelHorz = -RotationSpeed * Mouse.XVel * 0.00002f;
                _angleVelVert = RotationSpeed * Mouse.YVel * 0.00002f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint)
            {
                float2 touchVel;
                touchVel      = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * 0.00002f;
                _angleVelVert = RotationSpeed * touchVel.y * 0.00002f;
            }

            // Zoom & Roll
            if (Touch.TwoPoint)
            {
                if (!_twoTouchRepeated)
                {
                    _twoTouchRepeated = true;
                    _angleRollInit    = Touch.TwoPointAngle - _angleRoll;
                    _offsetInit       = Touch.TwoPointMidPoint - _offset;
                }
                _zoomVel   = Touch.TwoPointDistanceVel * -0.001f;
                _angleRoll = Touch.TwoPointAngle - _angleRollInit;
                _offset    = Touch.TwoPointMidPoint - _offsetInit;
            }
            else if (!_isTranslating)
            {
                _twoTouchRepeated = false;
                _zoomVel          = Mouse.WheelVel * -0.005f;
                _angleRoll       *= curDamp * 0.8f;
                _offset          *= curDamp * 0.8f;
            }
            _zoom += _zoomVel;
            // Limit zoom
            if (_zoom < 2)
            {
                _zoom = 2;
            }

            _angleHorz += _angleVelHorz;
            // Wrap-around to keep _angleHorz between -PI and + PI
            _angleHorz = M.MinAngle(_angleHorz);

            _angleVert += _angleVelVert;
            // Limit pitch to the range between [-PI/2, + PI/2]
            _angleVert = M.Clamp(_angleVert, -M.PiOver2, M.PiOver2);

            // Wrap-around to keep _angleRoll between -PI and + PI
            _angleRoll = M.MinAngle(_angleRoll);

            //Camera Translation
            if (Keyboard.GetKey(KeyCodes.LShift) && Mouse.MiddleButton)
            {
                _xPos += -RotationSpeed * Mouse.XVel * 0.00002f;
                _yPos += RotationSpeed * Mouse.YVel * 0.00002f;
            }

            // Create the camera matrix and set it as the current ModelView transformation
            var mtxRot = float4x4.CreateRotationZ(_angleRoll) * float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam = float4x4.LookAt(_xPos, _yPos, -_zoom, _xPos, _yPos, 0, 0, 1, 0);

            var viewMatrix = mtxCam * mtxRot * _sceneScale;

            //Picking
            if (Mouse.RightButton)
            {
                _pickPos = Mouse.Position;
                Diagnostics.Log(_pickPos);
                var pickPosClip = _pickPos * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                _scenePicker.View       = viewMatrix;
                _scenePicker.Projection = _projection;
                var newPick = _scenePicker.Pick(pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (newPick != null)
                    {
                        SelectGeometry(newPick.Node);
                    }
                    _currentPick = newPick;
                }
            }

            RC.View = viewMatrix;
            //var mtxOffset = float4x4.CreateTranslation(2 * _offset.x / Width, -2 * _offset.y / Height, 0);
            RC.Projection = /*mtxOffset **/ _projection;
        }
        // RenderAFrame is called once a frame
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();
            RC.View = float4x4.CreateTranslation(0, 0, 4) * float4x4.CreateRotationX(-(float)Math.Atan(30.0 / 40.0));
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            _backRightTransform.Rotation  = _backLeftTransform.Rotation;
            _frontLeftTransform.Rotation  = _backLeftTransform.Rotation;
            _frontRightTransform.Rotation = _backLeftTransform.Rotation;
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.LimeGreen;
                    }
                    _currentPick = newPick;
                }
            }

            if (_currentPick != null)
            {
                Transform currentTransform = _currentPick.Node.GetTransform();
                switch (_currentPick.Node.Name)
                {
                case "kuppel":
                    currentTransform.Rotation = currentTransform.Rotation + new float3(0, Keyboard.ADAxis * DeltaTime * 5, 0);
                    break;

                case "canon":
                    _winkelX += Keyboard.WSAxis * DeltaTime;
                    Diagnostics.Debug(_winkelX);
                    if (_winkelX > 1f && _winkelX < 1.7f)
                    {
                        currentTransform.Rotation = new float3(_winkelX, 0, 0);
                    }
                    else if (_winkelX <= 1f)
                    {
                        _winkelX = 1f;
                    }
                    else if (_winkelX >= 1.7f)
                    {
                        _winkelX = 1.7f;
                    }

                    break;

                case "chassis":
                    break;

                default:
                    _backLeftTransform.Rotation = currentTransform.Rotation + new float3(Keyboard.WSAxis * DeltaTime * 3f, 0, 0);
                    break;
                }
            }



            // Setup the camera


            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#23
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Mouse and keyboard movement
            if (Mouse.LeftButton)
            {
                _pick    = true;
                _pickPos = Mouse.Position;
            }
            else
            {
                _pick  = false;
                toggle = false;
            }

            _DistanceFactor = _DistanceFactor + Mouse.WheelVel * 0.001f;

            _LookAtPosition   = float3.Lerp(_LookAtPositionLerpTo, _LookAtPositionLerpFrom, _LerpTimer);
            _LookFromPosition = float3.Lerp(_LookFromPositionLerpTo, _LookFromPositionLerpFrom, _LerpTimer);

            var mtxCam = float4x4.LookAt(_LookFromPosition * _DistanceFactor, _LookAtPosition, _LookUpDefault);

            if (_pick && !toggle)
            {
                float2 pickPosClip = _pickPos * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                _scenePicker.View = mtxCam;

                PickResult newPick = _scenePicker.Pick(pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();


                if (newPick != null)
                {
                    Diagnostics.Log("PositionCenter: " + GetTriagleCenter(newPick));
                    Diagnostics.Log("PositionBary: " + GetTriagleBarycentric(newPick));
                    Diagnostics.Log("NormalsCenter: " + GetNormalsCenter(newPick));
                    Diagnostics.Log("NormalBary: " + GetNormalsBarycentric(newPick));
                    _LookAtPositionLerpFrom = _LookAtPosition;
                    _LookAtPositionLerpTo   = GetTriagleBarycentric(newPick);

                    _LookFromPositionLerpFrom = _LookFromPosition;
                    _LookFromPositionLerpTo   = GetTriagleBarycentric(newPick) + GetNormalsBarycentric(newPick);

                    _LerpTimer = 1;

                    toggle = true;
                }
            }

            // Render the scene loaded in Init()
            RC.ModelView = mtxCam;
            _sceneRenderer.Render(RC);
            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();

            if (_LerpTimer > 0)
            {
                _LerpTimer -= (Time.DeltaTime / _LerpSpeed);
            }

            if (_LerpTimer < 0)
            {
                _LerpTimer = 0;
            }
        }
示例#24
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_rechtsVorneTransform.Rotation = new float3(M.MinAngle(TimeSinceStart), 0, 0);

            float rechts_vorne_rotation_z = _rechtsVorneTransform.Rotation.z;

            rechts_vorne_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime;

            float rechts_vorne_rotation_y = _rechtsVorneTransform.Rotation.y;

            rechts_vorne_rotation_y += Keyboard.LeftRightAxis * DeltaTime;

            if (rechts_vorne_rotation_y < 0.25 && rechts_vorne_rotation_y > -0.25)
            {
                _rechtsVorneTransform.Rotation = new float3(0, rechts_vorne_rotation_y, rechts_vorne_rotation_z);
            }
            else
            {
                _rechtsVorneTransform.Rotation = new float3(0, _rechtsVorneTransform.Rotation.y, rechts_vorne_rotation_z);
            }

            //Diagnostics.Log(rechts_vorne_rotation_y);

            float links_vorne_rotation_z = _linksVorneTransform.Rotation.z;

            links_vorne_rotation_z += 2 * -Keyboard.UpDownAxis * DeltaTime;

            float links_vorne_rotation_y = _linksVorneTransform.Rotation.y;

            links_vorne_rotation_y += Keyboard.LeftRightAxis * DeltaTime;

            if (links_vorne_rotation_y < 0.25 && links_vorne_rotation_y > -0.25)
            {
                _linksVorneTransform.Rotation = new float3(0, links_vorne_rotation_y, links_vorne_rotation_z);
            }
            else
            {
                _linksVorneTransform.Rotation = new float3(0, _linksVorneTransform.Rotation.y, links_vorne_rotation_z);
            }


            float links_hinten_rotation_z = _linksHintenTransform.Rotation.z;

            links_hinten_rotation_z       += 2 * -Keyboard.UpDownAxis * DeltaTime;
            _linksHintenTransform.Rotation = new float3(0, 0, links_hinten_rotation_z);

            float rechts_hinten_rotation_z = _rechtsHintenTransform.Rotation.z;

            rechts_hinten_rotation_z       += 2 * -Keyboard.UpDownAxis * DeltaTime;
            _rechtsHintenTransform.Rotation = new float3(0, 0, rechts_hinten_rotation_z);



            if (_Arm1)
            {
                float arm1_rotation_y = _Arm1Transform.Rotation.y;
                arm1_rotation_y        += 2 * Keyboard.ADAxis * DeltaTime;
                _Arm1Transform.Rotation = new float3(0, arm1_rotation_y, 0);
            }

            if (_Arm2)
            {
                float arm2_rotation_z = _Arm2Transform.Rotation.z;
                arm2_rotation_z += 2 * Keyboard.WSAxis * DeltaTime;
                if (arm2_rotation_z <= 1.5 && arm2_rotation_z >= -1.5)
                {
                    _Arm2Transform.Rotation = new float3(0, 0, arm2_rotation_z);
                }
            }

            if (_Arm3)
            {
                float arm3_rotation_z = _Arm3Transform.Rotation.z;
                arm3_rotation_z += 2 * Keyboard.WSAxis * DeltaTime;
                if (arm3_rotation_z <= 1 && arm3_rotation_z >= -1)
                {
                    _Arm3Transform.Rotation = new float3(0, 0, arm3_rotation_z);
                }
                //Diagnostics.Log(arm3_rotation_z);
            }


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            _camAngle += 12.0f * M.Pi / 180.0f * DeltaTime;
            RC.View    = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationY(_camAngle);

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f));

                        if (newPick.Node.Name == "Arm1")
                        {
                            _Arm1 = true;
                            _Arm2 = false;
                            _Arm3 = false;
                        }
                        else if (newPick.Node.Name == "Arm2")
                        {
                            _Arm1 = false;
                            _Arm2 = true;
                            _Arm3 = false;
                        }
                        else if (newPick.Node.Name == "Arm3")
                        {
                            _Arm1 = false;
                            _Arm2 = false;
                            _Arm3 = true;
                        }
                        else
                        {
                            _Arm1 = false;
                            _Arm2 = false;
                            _Arm3 = false;
                        }
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            /*_rightWheelFrontTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _leftWheelFrontTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _rightWheelBackTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);
             * _leftWheelBackTransform.Rotation = new float3(0, -M.MinAngle(TimeSinceStart), 0);*/

            _rightWheelFrontTransform.Rotation.y += Keyboard.WSAxis * DeltaTime;
            _leftWheelFrontTransform.Rotation.y  += Keyboard.WSAxis * DeltaTime;
            _rightWheelBackTransform.Rotation.y  += Keyboard.WSAxis * DeltaTime;
            _leftWheelBackTransform.Rotation.y   += Keyboard.WSAxis * DeltaTime;



            //_bodyTransform.Translation.xz += Keyboard.ADAxis * DeltaTime;
            _bodyTransform.Translation.z += Keyboard.LeftRightAxis / 10;
            _bodyTransform.Translation.x += Keyboard.WSAxis / 10;
            _bodyTransform.Rotation.y    += Keyboard.ADAxis * DeltaTime;


            //_scenePick.Pick(RC, pickPosClip)


            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Math.Atan(15.0 / 40.0));

            //Red Base movement
            _firstExcavatorArmTransform.Rotation.y += Keyboard.UpDownAxis * DeltaTime;

            //Green UpperArm movement
            //_secondExcavatorArmTransform.Rotation.x += Keyboard.UpDownAxis * DeltaTime;

            //Blue UpperArm movement
            //_thirdExcavatorArmTransform.Rotation.x += Keyboard.WSAxis * DeltaTime;


            //binding piece movement
            //_bindingHandTransform.Rotation.y += Keyboard.ADAxis * DeltaTime;

            //Create Moving possibility with mouse to look around
            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angelVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angelVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _keys = false;
                var touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angelVelHorz = -RotationSpeed * touchVel.x * DeltaTime * 0.0005f;
                _angelVelVert = -RotationSpeed * touchVel.y * DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angelVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime;
                    _angelVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);
                    _angelVelHorz *= curDamp;
                    _angelVelVert *= curDamp;
                }
            }

            _angelHorz += _angelVelHorz;
            _angelVert += _angelVelVert;

            var mtxRot = float4x4.CreateRotationX(_angelVert) * float4x4.CreateRotationY(_angelHorz);
            var mtxCam = float4x4.LookAt(0, 10, -30, 0, 0, 0, 0, 1, 0);

            RC.View = mtxCam * mtxRot;

            //_firstHandTransform.Rotation.x = -_angel;
            //_secondHandTransform.Rotation.x = _angel;

            if (opening)
            {
                if (_angel < 0.5f)
                {
                    _angel += 0.5f * DeltaTime;
                }
            }
            else
            {
                if (_angel > -0.5f)
                {
                    _angel -= 0.5f * DeltaTime;
                }
            }

            if (Keyboard.GetKey(KeyCodes.Space))
            {
                if (!spacePressed)
                {
                    opening = !opening;
                }
                spacePressed = true;
            }
            else
            {
                spacePressed = false;
            }

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).OrderBy(pr => pr.ClipPos.z).FirstOrDefault();
                _keys = false;


                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }
                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <SurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.OrangeRed;
                        Diagnostics.Debug("The picked object is " + newPick.Node.Name);
                        var eftransform = newPick.Node.GetComponent <Transform>();
                        eftransform.Rotation.y += Keyboard.UpDownAxis * DeltaTime;
                    }
                    _currentPick = newPick;
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#26
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            RC.Viewport(0, 0, Width, Height);

            // Mouse and keyboard movement
            if (Input.Keyboard.LeftRightAxis != 0 || Input.Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

            if (Input.Mouse.LeftButton)
            {
                _pick         = true;
                _pickPos      = Input.Mouse.Position;
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Input.Mouse.XVel * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Input.Mouse.YVel * Time.DeltaTime * 0.0005f;
            }
            else if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _pick    = true;
                _pickPos = Input.Touch.GetPosition(TouchPoints.Touchpoint_0);
                var touchVel = Input.Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * Time.DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * Time.DeltaTime * 0.0005f;
            }
            else
            {
                _pick = false;
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Input.Keyboard.LeftRightAxis * Time.DeltaTime;
                    _angleVelVert = -RotationSpeed * Input.Keyboard.UpDownAxis * Time.DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * Time.DeltaTime);
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            _angleHorz += _angleVelHorz;
            _angleVert += _angleVelVert;

            // Create the camera matrix and set it as the current ModelView transformation
            var mtxRot = float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam = float4x4.LookAt(0, 20, -600, 0, 150, 0, 0, 1, 0);

            var perspective  = float4x4.CreatePerspectiveFieldOfView(_fovy, (float)Width / Height, ZNear, ZFar);
            var orthographic = float4x4.CreateOrthographic(Width, Height, ZNear, ZFar);

            // Check
            if (_pick)
            {
                float2 pickPosClip = (_pickPos * new float2(2.0f / Width, -2.0f / Height)) + new float2(-1, 1);

                RC.View = mtxCam * mtxRot;

                PickResult newPick = _scenePicker.Pick(RC, pickPosClip).ToList().OrderBy(pr => pr.ClipPos.z).FirstOrDefault();
                Diagnostics.Debug(newPick);

                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        var ef = _currentPick.Node.GetComponent <DefaultSurfaceEffect>();
                        ef.SurfaceInput.Albedo = _oldColor;
                    }

                    if (newPick != null)
                    {
                        var ef = newPick.Node.GetComponent <DefaultSurfaceEffect>();
                        _oldColor = ef.SurfaceInput.Albedo;
                        ef.SurfaceInput.Albedo = (float4)ColorUint.LawnGreen;
                    }
                    _currentPick = newPick;
                }

                _pick = false;
            }

            RC.View       = mtxCam * mtxRot;
            RC.Projection = perspective;
            // Render the scene loaded in Init()
            _sceneRenderer.Render(RC);

            RC.Projection = orthographic;
            // Constantly check for interactive objects.
            if (!Input.Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(RC, Input.Mouse.Position, Width, Height);
            }

            if (Input.Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Input.Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(RC, Input.Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height);
            }
            _guiRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#27
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // _baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            _rad1Transform = _scene.Children.FindNodes(node => node.Name == "Rad1")?.FirstOrDefault()?.GetTransform();
            float rad1Rotation = _rad1Transform.Rotation.y;

            rad1Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad1Transform.Rotation = new float3(0, rad1Rotation, 0);

            _rad2Transform = _scene.Children.FindNodes(node => node.Name == "Rad2")?.FirstOrDefault()?.GetTransform();
            float rad2Rotation = _rad2Transform.Rotation.y;

            rad2Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad2Transform.Rotation = new float3(0, rad2Rotation, 0);

            _rad3Transform = _scene.Children.FindNodes(node => node.Name == "Rad3")?.FirstOrDefault()?.GetTransform();
            float rad3Rotation = _rad3Transform.Rotation.y;

            rad3Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad3Transform.Rotation = new float3(0, rad3Rotation, 0);

            _rad4Transform = _scene.Children.FindNodes(node => node.Name == "Rad4")?.FirstOrDefault()?.GetTransform();
            float rad4Rotation = _rad4Transform.Rotation.y;

            rad4Rotation           += 2 * Keyboard.UpDownAxis * DeltaTime;
            _rad4Transform.Rotation = new float3(0, rad4Rotation, 0);

            _griffTransform = _scene.Children.FindNodes(node => node.Name == "Griff")?.FirstOrDefault()?.GetTransform();
            float griffRotation = _griffTransform.Rotation.y;

            griffRotation += 0.1f * Keyboard.UpDownAxis;

            if (griffRotation > 1.5f)
            {
                griffRotation = 1.5f;
            }
            if (griffRotation < 0)
            {
                griffRotation = 0;
            }

            _griffTransform.Rotation = new float3(0, griffRotation, 0);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, -1, 10) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_camAngle);

            if (Mouse.RightButton)
            {
                _camSpeed = Mouse.Velocity.x;
            }
            else
            {
                _camSpeed = _camSpeed * 0.9f;
            }

            _camAngle = _camAngle + 0.005f * _camSpeed * Time.DeltaTime;


            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();

                PickResult newPick = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        _currentPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        _oldColor = (float3)newPick.Node.GetComponent <ShaderEffectComponent>().Effect.GetEffectParam("DiffuseColor");
                        newPick.Node.GetComponent <ShaderEffectComponent>().Effect.SetEffectParam("DiffuseColor", new float3(_oldColor.r * 0.5f, _oldColor.g * 0.5f, _oldColor.b * 0.5f));
                    }
                    _currentPick = newPick;
                }
            }

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            //RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float) Atan(15.0 / 40.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();

                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    Diagnostics.Log(pickResults[0].Node.Name);
                }
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (Keyboard.ADAxis != 0)
            {
                _camRotation += 0.05f * Keyboard.ADAxis;
            }

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationX(-(float)Atan(15.0 / 40.0)) * float4x4.CreateRotationY(_camRotation);

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;

                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();

                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    _newPick = pickResults[0];
                }

                if (_newPick != _currentPick)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (_newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", new float3(1, 0.4f, 0.4f));
                    }
                    _currentPick = _newPick;
                }
            }

            if (_newPick?.Node.Name == "Haus")
            {
                float Haus = _haus.Rotation.y;
                Haus          += velocity * Keyboard.LeftRightAxis * DeltaTime;
                _haus.Rotation = new float3(0, Haus, 0);
            }

            if (_newPick?.Node.Name == "Unterarm")
            {
                float unterarm = _unterarm.Rotation.z;
                unterarm += velocity * Keyboard.LeftRightAxis * DeltaTime;
                if (unterarm > -0.4f)
                {
                    unterarm = -0.4f;
                }
                else if (unterarm < -1.5f)
                {
                    unterarm = -1.5f;
                }
                _unterarm.Rotation = new float3(0, 0, unterarm);
            }

            if (_currentPick?.Node.Name == "Schaufel")
            {
                float schaufel = _schaufel.Rotation.z;
                schaufel += velocity * Keyboard.UpDownAxis * DeltaTime;
                if (schaufel > -0.4f)
                {
                    schaufel = -0.4f;
                }
                else if (schaufel < -1.5f)
                {
                    schaufel = -1.5f;
                }
                _schaufel.Rotation = new float3(0, 0, schaufel);
            }

            if (_currentPick?.Node.Name == "ReifenLV")
            {
                float reifenLV = _reifenLV.Rotation.z;
                reifenLV          += velocity * Keyboard.WSAxis * DeltaTime;
                _reifenLV.Rotation = new float3(0, 0, reifenLV);
            }

            if (_currentPick?.Node.Name == "ReifenRV")
            {
                float reifenRV = _reifenRV.Rotation.z;
                reifenRV          += velocity * Keyboard.WSAxis * DeltaTime;
                _reifenRV.Rotation = new float3(0, 0, reifenRV);
            }

            if (_currentPick?.Node.Name == "ReifenLH")
            {
                float reifenLH = _reifenLH.Rotation.z;
                reifenLH          += velocity * Keyboard.WSAxis * DeltaTime;
                _reifenLH.Rotation = new float3(0, 0, reifenLH);
            }

            if (_currentPick?.Node.Name == "ReifenRH")
            {
                float reifenRH = _reifenRH.Rotation.z;
                reifenRH          += velocity * Keyboard.WSAxis * DeltaTime;
                _reifenRH.Rotation = new float3(0, 0, reifenRH);
            }



            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#29
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_baseTransform.Rotation = new float3(0, M.MinAngle(TimeSinceStart), 0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 10) * float4x4.CreateRotationX(-(float)Atan(5.0 / 10.0));

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                PickResult        newPick     = null;
                if (pickResults.Count > 0)
                {
                    pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                    newPick = pickResults[0];
                }
                if (newPick?.Node != _currentPick?.Node)
                {
                    if (_currentPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = _currentPick.Node.GetComponent <ShaderEffectComponent>();
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor);
                    }
                    if (newPick != null)
                    {
                        ShaderEffectComponent shaderEffectComponent = newPick.Node.GetComponent <ShaderEffectComponent>();
                        _oldColor = (float3)shaderEffectComponent.Effect.GetEffectParam("DiffuseColor");
                        shaderEffectComponent.Effect.SetEffectParam("DiffuseColor", _oldColor + (new float3(0.25f, 0.25f, 0.25f)));
                    }
                    _currentPick = newPick;
                    Diagnostics.Log(_currentPick?.Node.Name);
                }
            }

            switch (_currentPick?.Node.Name)
            {
            case "Body":
                TransformComponent transBody = _currentPick.Node.GetComponent <TransformComponent>();
                IEnumerable <TransformComponent> transWheels = _scene.Children.FindNodes(node => node.Name.Contains("Wheels")).Select(node => tc(node));
                transBody.Rotation.y += DeltaTime * Keyboard.ADAxis;
                foreach (TransformComponent wheel in transWheels)
                {
                    wheel.Rotation.x += DeltaTime * Keyboard.WSAxis * 8.0f;
                }
                break;

            case "Muzzle":
            case "Tower":
                TransformComponent transMuzzle = _scene.Children.FindNodes(node => node.Name == ("MuzzleTower")).FirstOrDefault().GetComponent <TransformComponent>();
                TransformComponent transTower  = _scene.Children.FindNodes(node => node.Name == ("Tower")).FirstOrDefault().GetComponent <TransformComponent>();
                transMuzzle.Rotation.x = limit(transMuzzle.Rotation.x + DeltaTime * -Keyboard.WSAxis, -0.32f * M.Pi, 0.08f * M.Pi);
                transTower.Rotation.y += DeltaTime * Keyboard.ADAxis;
                break;

            case "Wheels1":
            case "Wheels2":
            case "Wheels3":
            case "Wheels4":
            case "Wheels5":
                TransformComponent transWheel = _currentPick.Node.GetComponent <TransformComponent>();
                transWheel.Rotation.x += DeltaTime * Keyboard.WSAxis * 8.0f;
                break;
            }

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
示例#30
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //_trailerTransform.Rotation = new float3(0,0,0);

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            if (Mouse.RightButton == true)
            {
                _camAngle += Mouse.Velocity.x * 0.00001f * DeltaTime / 20 * 10000;
            }



            // Setup the camera
            //RC.View = float4x4.CreateTranslation(0,-5,40) * float4x4.CreateRotationY(pBalt.y);

            //RC.View = float4x4.CreateTranslation(pBneu) * float4x4.CreateRotationY(_camAngle);
            RC.View = float4x4.CreateRotationX(-M.Pi / 7.3f) * float4x4.CreateRotationY(M.Pi - _trailerTransform.Rotation.y) * float4x4.CreateTranslation(-_trailerTransform.Translation.x, -6, -_trailerTransform.Translation.z);
            //ToDO If Bedingung eingefügt

            if (Mouse.LeftButton)
            {
                float2 pickPosClip = Mouse.Position * new float2(2.0f / Width, -2.0f / Height) + new float2(-1, 1);
                _scenePicker.View       = RC.View;
                _scenePicker.Projection = RC.Projection;
                List <PickResult> pickResults = _scenePicker.Pick(pickPosClip).ToList();
                if (pickResults.Count > 0)
                {
                    Diagnostics.Log(pickResults[0].Node.Name);

                    PickResult newPick = null;
                    if (pickResults.Count > 0)
                    {
                        pickResults.Sort((a, b) => Sign(a.ClipPos.z - b.ClipPos.z));
                        newPick = pickResults[0];
                    }
                    if (newPick?.Node != _currentPick?.Node)
                    {
                        if (_currentPick != null)
                        {
                            _currentPick.Node.GetMaterial().Diffuse.Color = _oldColor;
                        }
                        if (newPick != null)
                        {
                            var mat = newPick.Node.GetMaterial();
                            _oldColor         = mat.Diffuse.Color;
                            mat.Diffuse.Color = new float3(1, 0.4f, 0.4f);

                            _Pallete = newPick.Node.GetTransform().Translation.y - 2.5f;
                        }
                        _currentPick = newPick;
                    }
                }
            }


            if (_currentPick != null)
            {
                if (_currentPick.Node.Name == "Rad_R_01")
                {
                    float RadR01 = _RadR01Transform.Rotation.x;
                    RadR01 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR01Transform.Rotation = new float3(RadR01, 0, 0);
                }
                else if (_currentPick.Node.Name == "Rad_L_01")
                {
                    float RadR02 = _RadR02Transform.Rotation.x;
                    RadR02 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR02Transform.Rotation = new float3(RadR02, 0, 0);
                }
                else if (_currentPick.Node.Name == "Rad_02_R")
                {
                    float RadR03 = _RadR03Transform.Rotation.x;
                    RadR03 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR03Transform.Rotation = new float3(RadR03, 0, 0);
                }
                else if (_currentPick.Node.Name == "Rad_02_L")
                {
                    float RadR04 = _RadR04Transform.Rotation.x;
                    RadR04 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR04Transform.Rotation = new float3(RadR04, 0, 0);
                }
                else if (_currentPick.Node.Name == "Rad_03_L")
                {
                    float RadR05 = _RadR05Transform.Rotation.x;
                    RadR05 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR05Transform.Rotation = new float3(RadR05, 0, 0);
                }
                else if (_currentPick.Node.Name == "Rad_03_R")
                {
                    float RadR06 = _RadR06Transform.Rotation.x;
                    RadR06 += Keyboard.ADAxis * 2.0f * (DeltaTime);
                    _RadR06Transform.Rotation = new float3(RadR06, 0, 0);
                }
                else if (_currentPick.Node.Name == "Pallete")
                {
                }



                if (_currentPick.Node.Name == "pfeiler_gewinde_arm_nicht_drehbar")
                {
                    float ogd = _oberesGewTransform.Rotation.y;
                    ogd += Keyboard.LeftRightAxis * 0.005f;
                    _oberesGewTransform.Rotation = new float3(0, ogd, 0);
                }
                else if (_currentPick.Node.Name == "unterer_arm")
                {
                    float unter = _unterarmTransform.Rotation.x;
                    if (Keyboard.GetKey(KeyCodes.Up) == true)
                    {
                        if (unter <= 0.35f)
                        {
                            unter += DeltaTime * 0.1f;
                            _unterarmTransform.Rotation = new float3(unter, 0, 0);
                        }
                    }
                    if (Keyboard.GetKey(KeyCodes.Down) == true)
                    {
                        if (unter >= 0.0f)
                        {
                            unter -= DeltaTime * 0.1f;
                            _unterarmTransform.Rotation = new float3(unter, 0, 0);
                        }
                    }
                }

                /*case "Oberer_arm":
                 *  float obArmx = _oberarmTransform.Translation.z;
                 *  obArmx += Keyboard.UpDownAxis * 0.1f;
                 *  /*float obArmy = _oberarmTransform.Translation.z;
                 *  obArmy += Keyboard.UpDownAxis * 0.1f;*/
                /*_oberarmTransform.Translation = new float3(0, 0, obArmx);
                 * break;*/
                else if (_currentPick.Node.Name == "verbindung_arm_greifer")
                {
                    float ver = _verbagTransform.Translation.y;
                    if (Keyboard.GetKey(KeyCodes.Up) == true)
                    {
                        if (ver <= -0.5f)
                        {
                            ver += DeltaTime * 2f;
                            _verbagTransform.Translation = new float3(0, ver, 0);
                        }
                    }
                    if (Keyboard.GetKey(KeyCodes.Down) == true)
                    {
                        if (ver >= -10.0f)
                        {
                            ver -= DeltaTime * 2f;
                            _verbagTransform.Translation = new float3(0, ver, 0);
                        }
                    }
                }
            }
            float Rad_03 = _RadR03Transform.Rotation.x;

            Rad_03 += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadR03Transform.Rotation = new float3(Rad_03, 0, 0);

            float Rad_04 = _RadR04Transform.Rotation.x;

            Rad_04 += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadR04Transform.Rotation = new float3(Rad_04, 0, 0);

            float Rad_05 = _RadR05Transform.Rotation.x;

            Rad_05 += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadR05Transform.Rotation = new float3(Rad_05, 0, 0);

            float Rad_06 = _RadR06Transform.Rotation.x;

            Rad_06 += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            _RadR06Transform.Rotation = new float3(Rad_06, 0, 0);

            float Rad_01x = _RadR01Transform.Rotation.x;
            float Rad_01y = _RadR01Transform.Rotation.y;

            Rad_01x += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            Rad_01y  = -Keyboard.ADAxis * -0.35f;
            _RadR01Transform.Rotation = new float3(Rad_01x, Rad_01y, 0);

            float Rad_02x = _RadR02Transform.Rotation.x;
            float Rad_02y = _RadR02Transform.Rotation.y;

            Rad_02x += Keyboard.WSAxis * 0.15f * (DeltaTime / 16 * 1000);
            Rad_02y  = -Keyboard.ADAxis * -.35f;
            _RadR02Transform.Rotation = new float3(Rad_02x, Rad_02y, 0);

            float xArm    = _unterarmTransform.Rotation.x;
            float yVerbag = _verbagTransform.Translation.y;

            if (_Pallete < yVerbag)
            {
                yVerbag -= DeltaTime;
                if (_Pallete > yVerbag)
                {
                    yVerbag = _Pallete;
                }
            }

            if (_Pallete > yVerbag)
            {
                //xArm -= DeltaTime;
                yVerbag += DeltaTime;
                if (_Pallete < yVerbag)
                {
                    //xArm = _Pallete;
                    yVerbag = _Pallete;
                }
            }



            _verbagTransform.Translation = new float3(_verbagTransform.Translation.x, yVerbag, _verbagTransform.Translation.z);


            float3 pAalt = _carTransform.Translation;
            float3 pBalt = _trailerTransform.Translation;

            float posVel = -Keyboard.WSAxis * Time.DeltaTime;
            float rotVel = Keyboard.ADAxis * Time.DeltaTime;

            float newRot = _carTransform.Rotation.y + (rotVel * Keyboard.WSAxis * Time.DeltaTime * 30);

            _carTransform.Rotation = new float3(0, newRot, 0);

            float3 pAneu = _carTransform.Translation + new float3(posVel * M.Sin(newRot) * 10, 0, posVel * M.Cos(newRot) * 10);

            _carTransform.Translation = pAneu;

            float3 pBneu = pAneu + (float3.Normalize(pBalt - pAneu) * _d);

            _trailerTransform.Translation = pBneu;

            _trailerTransform.Rotation = new float3(0, (float)System.Math.Atan2(float3.Normalize(pBalt - pAneu).x, float3.Normalize(pBalt - pAneu).z), 0);

            // Render the scene on the current render context
            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered farame) on the front buffer.
            Present();
        }