// RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

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

            foreach (var item in _scene.Children.Select((value, i) => new { i, value }))
            {
                var transformComponent = item.value.GetComponent <TransformComponent>();
                transformComponent.Translation = new float3(
                    transformComponent.Translation.x,
                    5 * M.Sin(4 * TimeSinceStart + item.i * 1),
                    transformComponent.Translation.z
                    );

                float scaleValue = 0.3f * M.Sin(2 * TimeSinceStart + item.i * 1) + 1;

                transformComponent.Scale = new float3(scaleValue, scaleValue, scaleValue);
            }

            // Setup the camera
            _camAngle += 90.0f * M.Pi / 180.0f * DeltaTime;

            RC.View = float4x4.CreateTranslation(0, 0, 60) * float4x4.CreateRotationY(_camAngle);

            // 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();
        }
Пример #2
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            // Clear the back buffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

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

            var speed = Mouse.Velocity + Touch.GetVelocity(TouchPoints.Touchpoint_0);

            if (Mouse.LeftButton || Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _alpha -= speed.x * 0.0001f;
                _beta  -= speed.y * 0.0001f;
            }

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

            RC.View = mtxCam * mtxRot;

            _renderer.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()
        {
            SetProjectionAndViewport();

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

            _cubeTransform.Rotation = _cubeTransform.Rotation + new float3(0, 0.0001f * Time.DeltaTime, 0);
            //Zeitschwankung durch Frameratenabhängikeit (einsehen?)
            //Diagnostics.Debug("DeltaTime: " + Time.DeltaTime);

            Diagnostics.Debug("Keyboard <-> axis:" + Keyboard.LeftRightAxis);

            _cubeTransform.Rotation = new float3(0, 90 * (3.141592f / 360.0f) * Time.TimeSinceStart, 0);

            Diagnostics.Debug("Keyboard <-> axis: " + Keyboard.LeftRightAxis);
            //Ausschlag des Würfels nach links und rechts
            _cubeTransform.Translation.x = 5 * M.Sin(2 * Time.TimeSinceStart);
            // Zeitausgabe auf der Console seit dem Start


            _cubeShader.SurfaceInput.Albedo = new float4(0.5f + 0.5f * M.Sin(2 * Time.TimeSinceStart), 0, 0, 1);


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

            // Swap buffers: Show the content
            // Back clipping happens at 2000 (Anything further away from the camera than 2000 world units gets clipped, polygons will be cut)

            //var projection = float4x4.CreatePerspectiveFieldOfView(M.PiOver4, aspectRatio, 1, 20000);
            //RC.Projection = projection;

            Present();
        }
Пример #4
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

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

            // Animate the camera angle
            _camAngle = _camAngle + 90.0f * M.Pi / 180.0f * DeltaTime;

            // Animate the cube
            cTransform[0].Translation = new float3(0, 5 * M.Sin(3 * TimeSinceStart), 0);

            for (int i = 1; i < maxIndex; i++)
            {
                var scale = cTransform[i].Scale;
                if (scale.y > 0.2)
                {
                    scale = new float3(scale.x, scale.y - 0.3f * DeltaTime, scale.z);
                }
                else
                {
                    scale.y = 1;
                }
                cTransform[i].Scale = scale;
            }

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

            _sceneRenderer.Render(RC);

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

            RC.ClearColor = new float4(250 / 255 * M.Sin(3 * TimeSinceStart) + 1, 1 * M.Sin(3 * TimeSinceStart) + 1, 10 / 255 * M.Sin(3 * TimeSinceStart) + 1, 0);

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

            _camAngle = _camAngle + 90.0f * M.Pi / 180.0f * DeltaTime;
            _cubeTransform.Translation  = new float3(0, 5 * M.Sin(3 * TimeSinceStart), 0);
            _cubeTransform2.Rotation    = new float3(5 * TimeSinceStart, 0, 0);
            _cubeTransform3.Rotation    = new float3(0, 5 * M.Sin(3 * TimeSinceStart), 0);
            _cubeTransform4.Translation = new float3(50 * M.Sin(3 * TimeSinceStart) - 70, 0, 0);
            _cubeTransform5.Rotation    = new float3(0, TimeSinceStart, 0);
            _cubeTransform5.Scale       = new float3(5 * M.Sin(3 * TimeSinceStart) + 1, 1 * M.Sin(3 * TimeSinceStart) + 1, 5 * M.Sin(3 * TimeSinceStart) + 1);


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

            //cubeShader = new float4(1, 0, 0, 1);

            // 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();
        }
Пример #6
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            /* foreach (var _time in _cubeAnimation)
             * {
             *   _time.Rotation.x = 1 * M.Sin(1 * TimeSinceStart);
             *   _time.Rotation.z = 3 * M.Sin(1 * TimeSinceStart);
             *   _time.Rotation.y = 2 * M.Sin(1 * TimeSinceStart);
             * }
             *
             * foreach (var _time in _cubeAnimation)
             * {
             *   // _time.Translation.x -= 1.5f * M.Sin(10 * TimeSinceStart);
             *  // _time.Translation.z += 1.0f * M.Sin(6 * TimeSinceStart);
             *
             * } */
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            // Animate the camera angle
            _camAngle = _camAngle + 90.0f * M.Pi / 375.0f * DeltaTime;

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

            _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()
        {
            SetProjectionAndViewport();

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

            // Animate the camera angle
            _camAngle = _camAngle + 90.0f * M.Pi / 180.0f * DeltaTime;

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

            // Animate the cube
            //ort
            _cubeTransform.Translation  = new float3(0, 1 * M.Sin(2 * TimeSinceStart), 0);
            _cubeTransform2.Translation = new float3(0, 5 * M.Cos(2 * TimeSinceStart), 10);
            _cubeTransform3.Translation = new float3(0, 5 * M.Sin(2 * TimeSinceStart), 20);

            //skale
            _cubeTransform.Scale = new float3(1, M.Cos(2 * TimeSinceStart), 1);

            //Rotation
            _cubeTransform.Rotation = new float3(M.Cos(2 * TimeSinceStart), 1, 1);

            // 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();
        }
Пример #8
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            float gegenstandx = _baseTransform.Rotation.x;

            gegenstandx += 1.5f * DeltaTime * Keyboard.UpDownAxis;

            float gegenstandy = _baseTransform.Rotation.y;

            gegenstandy            += 1.5f * DeltaTime * Keyboard.LeftRightAxis;
            _baseTransform.Rotation = new float3(gegenstandx, gegenstandy, 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));

            // 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);

            var speed = Mouse.Velocity + Touch.GetVelocity(TouchPoints.Touchpoint_0);

            if (Mouse.LeftButton || Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _alpha -= speed.x * 0.0001f;
                _beta  -= speed.y * 0.0001f;
            }

            // Create the camera matrix and set it as the current View transformation.
            var mtxRot = float4x4.CreateRotationX(_beta) * float4x4.CreateRotationY(_alpha);
            var mtxCam = float4x4.LookAt(0, 0, -80, 0, 0, 0, 0, 1, 0);

            RC.View = mtxCam * mtxRot * ModelXForm(new float3(-55, -8, 0), float3.Zero);

            _renderer.Render(RC);

            Present();
        }
Пример #10
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

            _sceneRenderer.Render(RC);

            Present();
        }
Пример #11
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 (Keyboard.LeftRightAxis != 0 || Keyboard.UpDownAxis != 0)
            {
                _keys = true;
            }

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

            _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, 2, -8, 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();
        }
Пример #12
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            if (Mouse.RightButton)
            {
                _valHorzSnd = Mouse.XVel * 0.003f * DeltaTime;
                _valVertSnd = Mouse.YVel * 0.003f * DeltaTime;

                _anlgeHorznd  += _valHorzSnd;
                _angleVertSnd += _valVertSnd;

                _valHorzSnd = _valVertSnd = 0;

                _sndCamTransform.FpsView(_anlgeHorznd, _angleVertSnd, Keyboard.WSAxis, Keyboard.ADAxis, DeltaTime * 10);
            }
            else if (Mouse.LeftButton)
            {
                _valHorzMain = Mouse.XVel * 0.003f * DeltaTime;
                _valVertMain = Mouse.YVel * 0.003f * DeltaTime;

                _anlgeHorzMain += _valHorzMain;
                _angleVertMain += _valVertMain;

                _valHorzMain = _valVertMain = 0;

                _mainCamTransform.FpsView(_anlgeHorzMain, _angleVertMain, Keyboard.WSAxis, Keyboard.ADAxis, DeltaTime * 10);
            }

            float4x4 viewProjection = _mainCam.GetProjectionMat(Width, Height, out float4 viewport) * float4x4.Invert(_mainCamTransform.Matrix());

            _frustum.Vertices = Frustum.CalculateFrustumCorners(viewProjection).ToArray();

            Frustum frustum = new Frustum();

            frustum.CalculateFrustumPlanes(viewProjection);

            // Sets a mesh inactive if it does not pass the culling test and active if it does.
            // The reason for this is to achieve that the cubes don't get rendered in the viewport in the upper right.
            // Because SceneRenderer.RenderMesh has an early-out if a Mesh is inactive we do not perform the culling test twice.
            UserSideFrustumCulling(_rocketScene.Children, frustum);

            _sceneRenderer.Render(RC);
            _guiRenderer.Render(RC);

            if (!Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(RC, Mouse.Position, Width, Height);
            }

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

            // 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()
        {
            // Steuerung
            float bodyRot = _bodyTransform.Rotation.y;

            bodyRot += 2 * Keyboard.LeftRightAxis * DeltaTime;
            _bodyTransform.Rotation = new float3(0, bodyRot, 0);

            float upperArm = _upperArmTransform.Rotation.x;

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

            float underArm = _foreArmTransform.Rotation.x;

            underArm += 2 * Keyboard.WSAxis * DeltaTime;
            _foreArmTransform.Rotation = new float3(underArm, 0, 0);

            // Kamera
            if (Mouse.LeftButton)
            {
                _camAngle += 0.01f * Mouse.Velocity.x * DeltaTime;
            }

            // Kralle unten
            float kralleunten = _kralleunten.Rotation.z;

            kralleunten += 2 * Keyboard.ADAxis * DeltaTime;

            // Kralle oben
            float kralleoben = _kralleoben.Rotation.z;

            kralleoben += -2 * Keyboard.ADAxis * DeltaTime;

            //Krallen beschränken
            if (kralleoben <0.206& kralleoben> -1.509)
            {
                _kralleunten.Rotation = new float3(0, 0, kralleunten);
                _kralleoben.Rotation  = new float3(0, 0, kralleoben);
            }

            SetProjectionAndViewport();

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

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

            // 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();
        }
Пример #14
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);

            HandleCameraAndPicking();
            InteractionHandler();
            _renderer.Render(RC);
            RC.ClearColor = new float4(.7f, .7f, .7f, 1);

            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();
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth); // depth buffer, tiefe


            _cubeTransform1.Rotation      = _cubeTransform1.Rotation + new float3(0, 90 * (M.Pi / 180.0f) * Time.DeltaTime, 0); // umrechnung von pro fram in pro sekunde
            _cubeTransform1.Translation.x = 20 * M.Sin(2 * Time.TimeSinceStart);
            _cubeTransform1.Translation.y = 20 * M.Cos(2 * Time.TimeSinceStart);
            _cubeTransform2.Rotation      = _cubeTransform2.Rotation - new float3(0, 90 * (M.Pi / 180.0f) * Time.DeltaTime, 0);
            Diagnostics.Debug("Keyboard <-> Axis: " + Keyboard.LeftRightAxis);


            _cubeTransform2.Translation.x = 20 * M.Sin(2 * Time.TimeSinceStart);
            _cubeTransform2.Translation.z = 20 * M.Cos(2 * Time.TimeSinceStart) + 70;


            _cubeTransform3.Rotation = _cubeTransform2.Rotation;
            _cubeTransform4.Rotation = _cubeTransform2.Rotation;


            _cubeTransform3.Translation.y = 20 * M.Sin(2 * Time.TimeSinceStart);
            _cubeTransform3.Translation.z = 20 * M.Cos(-2 * Time.TimeSinceStart) + 70;

            _cubeTransform4.Scale.x = (0.3f * M.Sin(2 * Time.TimeSinceStart)) + 1;
            _cubeTransform4.Scale.y = (0.3f * M.Sin(2 * Time.TimeSinceStart)) + 1;
            _cubeTransform4.Scale.z = (0.3f * M.Sin(2 * Time.TimeSinceStart)) + 1 + (0.5f * Keyboard.LeftRightAxis);


            if (Mouse.LeftButton)
            {
                _cubeshader2.SurfaceInput.Albedo = new float4(0.5f + 0.5f * M.Sin(2 * Time.TimeSinceStart), 0, 0.5f, 1);
            }
            else
            {
                _cubeshader.SurfaceInput.Albedo = new float4(0.5f + 0.5f * M.Cos(2 * Time.TimeSinceStart), 0.5f + 0.5f * M.Sin(4 * Time.TimeSinceStart), 0.5f + 0.5f * M.Cos(2 * Time.TimeSinceStart), 1);
            }



            _sceneRenderer.Render(RC);

            //hier spielt die musik

            // 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()
        {
            SetProjectionAndViewport();

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

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

            // 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();
        }
Пример #18
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            RC.ClearColor = new float4(0.75f, 0.75f, 0.75f, 1);

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

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

            var speed = Mouse.Velocity + Touch.GetVelocity(TouchPoints.Touchpoint_0);

            if (Mouse.LeftButton || Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _alpha -= speed.x * 0.00001f;
                _beta  -= speed.y * 0.00001f;
            }

            // damping
            var curDamp = (float)System.Math.Exp(-0.8 * Time.DeltaTime);

            _alpha *= curDamp;
            _beta  *= curDamp;

            _zoom += Mouse.WheelVel * 0.05f;

            _scene.Children[0].GetComponentsInChildren <Transform>().ToList().ForEach(t => { if (t.Name != "TextTransform")
                                                                                             {
                                                                                                 t.Rotate(new float3(_beta, _alpha, 0));
                                                                                             }
                                                                                      });

            // Create the camera matrix and set it as the current ModelView transformation
            _offsetX += Keyboard.ADAxis * -0.4f;
            _offsetY += Keyboard.WSAxis * -0.3f;
            var mtxCam = float4x4.LookAt(0, 0, _zoom, 0, 0, 0, 0, 1, 0);
            var offset = float4x4.CreateTranslation(new float3(_offsetX, _offsetY, 0));

            RC.View = mtxCam * offset;

            _renderer.Render(RC);

            _guiDescRenderer.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()
        {
            SetProjectionAndViewport();

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

            RC.View = float4x4.CreateTranslation(0, 0, 50) * float4x4.CreateRotationY(_camAngle);

            _camAngle = _camAngle + 0.05f;
            _cubeTransform.Translation = _cubeTransform.Translation + new float3(0, 0.1f, 0);

            _sceneRenderer.Render(RC);

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present();
        }
Пример #20
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

            _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)Math.Atan(15.0 / 40.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();
        }
Пример #21
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();
        }
Пример #22
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();

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

            // Diagnostics.Debug(Input.Keyboard.LeftRightAxis);
            // Diagnostics.Debug(Input.Mouse.Velocity);

            _camAngle = _camAngle + 6.28f * Time.DeltaTime * Input.Keyboard.LeftRightAxis;
            _cubeEffect.SurfaceInput.Albedo = new float4(0, 0.5f + 0.5f * M.Sin(Time.TimeSinceStart), 0, 1);

            RC.View = float4x4.CreateTranslation(0, 0, 50) * float4x4.CreateRotationY(_camAngle);
            _cubeTransform.Translation = new float3(0, 10 * M.Sin(Time.TimeSinceStart), 0);


            _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()
        {
            SetProjectionAndViewport();

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

            // Animate the camera angle
            _camAngle = _camAngle + 90.0f * M.Pi / 180.0f * DeltaTime;
            //Diagnostics.Log(_camAngle.ToString());

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

            // Animate the cube
            _cubeTransform.Translation = new float3(0, 5 * M.Sin(3 * TimeSinceStart), 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();
        }
Пример #24
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame() //Farbe wird hier gelöscht; wird immer aufgerufen wenn ein Bild gerendert wird
        {
            SetProjectionAndViewport();

            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);     //Nachdem BB gecleart wird, kann man es mit Farben, Pixel oder weiteren Infos füllen

            Diagnostics.Debug("DeltaTime: " + Time.DeltaTime); // DeltaTime = Zeitabstand pro Frame?

            // _cubeTransform.Rotation = _cubeTransform.Rotation + new float3(0, 0.005f, 0); // addiert einen kleinen Wert zur y-Rotation
            _cubeTransform.Rotation = _cubeTransform.Rotation + new float3(0, 90 * (3.141592f / 180.0f) * Time.DeltaTime, 0);
            // _cubeTransform.Translation = _cubeTransform.Translation + new float3 (0.1f, 0, 0);
            _cubeTransform.Translation.x = 5 * M.Sin(2 * Time.TimeSinceStart); // Sinus Funktion zwischen -5 und 5 -> wird schneller ; erzeugt schwingungsartiges Verhalten
            // Diagnostics.Debug("TimeSinceStart: " + Time.TimeSinceStart); //damit kann man zusatzinfos aus der Konsole ausgeben

            _cubeShader.SurfaceInput.Albedo = new float4(0.5f + 0.5f * M.Sin(2 * Time.TimeSinceStart), 0, 0, 1); // Wert schwankt zwischen 0 & 1
            //Albedo = Grundfargbe ohne Beleuchtung wird verändert; 3 RGB Komponente; 4. Komponente = Tranparenz-Komponente

            _sceneRenderer.Render(RC); //hier wird gerendert

            // Swap buffers: Show the contents of the backbuffer (containing the currently rendered frame) on the front buffer.
            Present(); // Die Infos im BB wird in FB kopiert und ausgegeben
        }
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            SetProjectionAndViewport();


            //Rotate camera with mouse
            if (Mouse.LeftButton)
            {
                _camAngleX += -.01f * DeltaTime * Mouse.Velocity.y;
                _camAngleY += -.01f * DeltaTime * Mouse.Velocity.x;
            }

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

            // Setup the camera
            RC.View = float4x4.CreateTranslation(0, 0, 40) * float4x4.CreateRotationYX(new float2(_camAngleX, _camAngleY));

            // 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);

            #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();
        }
        // 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();
        }
Пример #28
0
        // RenderAFrame is called once a frame
        public override void RenderAFrame()
        {
            //if (_gamePad != null)
            //    Diagnostics.Log(_gamePad.LSX);

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

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

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

            var curDamp = (float)System.Math.Exp(-Damping * DeltaTime);

            // Zoom & Roll
            if (Touch.TwoPoint)
            {
                if (!_twoTouchRepeated)
                {
                    _twoTouchRepeated = true;
                    _angleRollInit    = Touch.TwoPointAngle - _angleRoll;
                    _offsetInit       = Touch.TwoPointMidPoint - _offset;
                    _maxPinchSpeed    = 0;
                }
                _zoomVel   = Touch.TwoPointDistanceVel * -0.01f;
                _angleRoll = Touch.TwoPointAngle - _angleRollInit;
                _offset    = Touch.TwoPointMidPoint - _offsetInit;
                float pinchSpeed = Touch.TwoPointDistanceVel;
                if (pinchSpeed > _maxPinchSpeed)
                {
                    _maxPinchSpeed = pinchSpeed;                              // _maxPinchSpeed is used for debugging only.
                }
            }
            else
            {
                _twoTouchRepeated = false;
                _zoomVel          = Mouse.WheelVel * -0.5f;
                _angleRoll       *= curDamp * 0.8f;
                _offset          *= curDamp * 0.8f;
            }


            // UpDown / LeftRight rotation
            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }

            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint)
            {
                _keys = false;
                float2 touchVel;
                touchVel      = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime;
                    _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime;
                }
                else
                {
                    _angleVelHorz *= curDamp;
                    _angleVelVert *= curDamp;
                }
            }

            _zoom += _zoomVel;
            // Limit zoom
            if (_zoom < 80)
            {
                _zoom = 80;
            }
            if (_zoom > 2000)
            {
                _zoom = 2000;
            }

            _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);

            // Create the camera matrix and set it as the current View transformation
            var mtxRot    = /*float4x4.CreateRotationZ(_angleRoll) **/ float4x4.CreateRotationX(_angleVert) * float4x4.CreateRotationY(_angleHorz);
            var mtxCam    = float4x4.LookAt(0, 20, -_zoom, 0, 0, 0, 0, 1, 0);
            var mtxOffset = float4x4.CreateTranslation(2f * _offset.x / Width, -2f * _offset.y / Height, 0);

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

            RC.View       = view;
            RC.Projection = orthographic;
            // Constantly check for interactive objects.
            _sih.CheckForInteractiveObjects(RC, Mouse.Position, Width, Height);

            if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(RC, Touch.GetPosition(TouchPoints.Touchpoint_0), Width, Height);
            }
            // Tick any animations and Render the scene loaded in Init()
            RC.View       = view;
            RC.Projection = perspective;
            _sceneRenderer.Animate();
            _sceneRenderer.Render(RC);

            RC.View       = view;
            RC.Projection = orthographic;
            _guiRenderer.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()
        {
            SetProjectionAndViewport();

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

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


            //------------------------ INFO: -----------------------------
            // hoch - runter : pfeiltasten updown
            // links - rechts : pfeiltasten leftright
            // öffnen schliesen : w - s tasten
            //kamera drehen : mausklick + drag



            // base movement

            if (Mouse.LeftButton)
            {
                _camAngle += Mouse.Velocity.x * Time.DeltaTime * 0.003f;
            }



            _bodyTransform.Rotation.y += Keyboard.LeftRightAxis * Time.DeltaTime;

            _upperarmTransform.Rotation.x += Keyboard.UpDownAxis * Time.DeltaTime;

            _forearmTransform.Rotation.x += Keyboard.UpDownAxis * Time.DeltaTime;



            winkel += (Keyboard.WSAxis * Time.DeltaTime);
            if (winkel >= -0.5f && winkel <= 0.7f)
            {
                _fingerUpTransform.Rotation.x     = winkel;
                _fingerLeftTransform.Rotation.z   = -winkel;
                _fingerRightTransform.Rotation.z  = winkel;
                _fingerBottomTransform.Rotation.x = -winkel;
            }
            else if (winkel < -0.5f)
            {
                winkel = -0.5f;
            }
            else if (winkel > 0.7f)
            {
                winkel = 0.7f;
            }



            // 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()
        {
            // Clear the backbuffer
            RC.Clear(ClearFlags.Color | ClearFlags.Depth);

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

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

            if (Mouse.LeftButton)
            {
                _keys         = false;
                _angleVelHorz = -RotationSpeed * Mouse.XVel * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * Mouse.YVel * DeltaTime * 0.0005f;
            }
            else if (Touch.GetTouchActive(TouchPoints.Touchpoint_0))
            {
                _keys = false;
                var touchVel = Touch.GetVelocity(TouchPoints.Touchpoint_0);
                _angleVelHorz = -RotationSpeed * touchVel.x * DeltaTime * 0.0005f;
                _angleVelVert = -RotationSpeed * touchVel.y * DeltaTime * 0.0005f;
            }
            else
            {
                if (_keys)
                {
                    _angleVelHorz = -RotationSpeed * Keyboard.LeftRightAxis * DeltaTime;
                    _angleVelVert = -RotationSpeed * Keyboard.UpDownAxis * DeltaTime;
                }
                else
                {
                    var curDamp = (float)System.Math.Exp(-Damping * 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, +2, -10, 0, +2, 0, 0, 1, 0);

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

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

            //Constantly check for interactive objects.

            RC.Projection = orthographic;
            if (!Mouse.Desc.Contains("Android"))
            {
                _sih.CheckForInteractiveObjects(RC, Mouse.Position, Width, Height);
            }
            if (Touch.GetTouchActive(TouchPoints.Touchpoint_0) && !Touch.TwoPoint)
            {
                _sih.CheckForInteractiveObjects(RC, 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();
        }