Example #1
0
        public void Update(Camera camera, Size viewportSize)
        {
            // Pre-divide the position to make them small
            var pos    = camera.GetPosition() / FRUSTUM_DIVISOR;
            var target = camera.Target / FRUSTUM_DIVISOR;
            var dir    = System.Numerics.Vector3.Normalize(target - pos);

            //Extract the up vector from the second column of the rotation matrix
            System.Numerics.Matrix4x4 rotMatrix = camera.GetRotationMatrix();
            System.Numerics.Vector3   up        = new System.Numerics.Vector3(rotMatrix.M21, rotMatrix.M22, rotMatrix.M23);

            var frustumParams = new FrustumCameraParams()
            {
                Position    = pos.ToSharpDX(),
                LookAtDir   = dir.ToSharpDX(),
                UpDir       = up.ToSharpDX(),
                AspectRatio = viewportSize.Width / (float)viewportSize.Height,
                ZFar        = FRUSTUM_DIVISOR * 200,
                ZNear       = 1 / FRUSTUM_DIVISOR,

                // Blow up FOV a bit for cases when out-of-bounds objects are used
                FOV = camera.FieldOfView * 1.2f,
            };

            if (!_frustumParams.HasValue ||
                _frustumParams.Value.Position != frustumParams.Position ||
                _frustumParams.Value.LookAtDir != frustumParams.LookAtDir ||
                _frustumParams.Value.UpDir != frustumParams.UpDir ||
                _frustumParams.Value.FOV != frustumParams.FOV)
            {
                _frustumParams = frustumParams;
                _frustum       = BoundingFrustum.FromCamera(frustumParams);
            }
        }
        public void CreateBoundingFrustum()
        {
            Matrix invView = Matrix.Invert(ViewMatrix);

            CameraFrustum = BoundingFrustum.FromCamera(ViewLocation, -invView.Forward, invView.Up, Fov, ScreenNear, ScreenFar, ScreenWidth / ScreenHeight);
        }
Example #3
0
        void UpdateFrustum()
        {
            m_frustum = BoundingFrustum.FromCamera(m_position, m_look, m_up, m_fovY, m_nearZ, m_farZ, m_aspect);

            m_frustumDirty = false;
        }