예제 #1
0
파일: Camera.cs 프로젝트: LksWllmnn/Fusee
        // 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();
        }
예제 #2
0
        public static IEnumerable <object[]> GetFrustumPlanes()
        {
            var projection = float4x4.CreatePerspectiveFieldOfView(M.PiOver2, 1, 2, 10);
            var frustum    = new Frustum();

            frustum.CalculateFrustumPlanes(projection);

            var left = new PlaneF()
            {
                A = -0.5f, B = 0, C = -0.5f, D = 0
            };
            var right = new PlaneF()
            {
                A = 0.5f, B = 0, C = -0.5f, D = 0
            };

            var near = new PlaneF()
            {
                A = 0, B = 0, C = -1, D = -2
            };
            var far = new PlaneF()
            {
                A = 0, B = 0, C = 1, D = 10
            };

            var top = new PlaneF()
            {
                A = 0, B = 0.5f, C = -0.5f, D = 0
            };
            var bottom = new PlaneF()
            {
                A = 0, B = -0.5f, C = -0.5f, D = 0
            };

            yield return(new object[] { near.Normalize(), frustum.Near.Normalize() });

            yield return(new object[] { far.Normalize(), frustum.Far.Normalize() });

            yield return(new object[] { left.Normalize(), frustum.Left.Normalize() });

            yield return(new object[] { right.Normalize(), frustum.Right.Normalize() });

            yield return(new object[] { top.Normalize(), frustum.Top.Normalize() });

            yield return(new object[] { bottom.Normalize(), frustum.Bottom.Normalize() });
        }