Exemplo n.º 1
0
        public bool Contains(System.Numerics.Vector3 point)
        {
            var vec      = point.ToSharpDX() / FRUSTUM_DIVISOR;
            var contains = _frustum.Contains(ref vec);

            return(contains == ContainmentType.Contains || contains == ContainmentType.Intersects);
        }
Exemplo n.º 2
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);
            }
        }