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 Update() { ScreenViewProjectionMatrix = ViewMatrix * ProjectionMatrix * ViewportMatrix; if (Camera != null) { CameraParams = Camera.CreateCameraParams(ActualWidth / ActualHeight, NearPlane, FarPlane); } }
public static IEnumerable <Line3D> CreateWiredPyramid(BoundingFrustum frustum) { FrustumCameraParams prms = frustum.GetCameraParams(); Vector3[] corners = frustum.GetCorners(); Vector3[] vertices = new Vector3[5]; vertices[0] = prms.Position; vertices[1] = corners[4]; vertices[2] = corners[5]; vertices[3] = corners[6]; vertices[4] = corners[7]; List <int> indexes = new List <int>(16) { 0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2, 3, 3, 4, 4, 1 }; return(CreateFromVertices(vertices, indexes)); }