// // The camera is placed in such a way // it can display the content of the BBox // In all regards, it is also placed along the negative Z axis // Looking towards the positive Z axis // with a (0,1,0) Up vector // public override void LookAt(BoundingBox BBox, LookAtDirection dir = LookAtDirection.POSITIVE_Z) { Reset(); _bbox = BBox; _center = (BBox.Maximum + BBox.Minimum) / 2; Vector3 LMax = BBox.Maximum - BBox.Minimum; float lmax = Math.Max(LMax.Z, Math.Max(LMax.X, LMax.Y)); Vector3 translation = _center; translation.Z = -(lmax / (float)Math.Tan(_camera.Fov) + lmax / 2 + _center.Z); _cameraWorldTransform = Matrix.Translation(translation); _camera.WorldTransform = _cameraWorldTransform; Matrix r = Matrix.Identity; if (dir == LookAtDirection.POSITIVE_Z) { r = Matrix.Identity; } else if (dir == LookAtDirection.NEGATIVE_Z) { r = Matrix.RotationY((float)Math.PI); } else if (dir == LookAtDirection.POSITIVE_X) { r = Matrix.RotationY((float)Math.PI / 2f); } else if (dir == LookAtDirection.NEGATIVE_X) { r = Matrix.RotationY(-(float)Math.PI / 2f); } else if (dir == LookAtDirection.POSITIVE_Y) { r = Matrix.Translation(-_center) * Matrix.RotationX(-(float)Math.PI / 2f) * Matrix.Translation(_center); } else if (dir == LookAtDirection.NEGATIVE_Y) { r = Matrix.Translation(-_center) * Matrix.RotationX((float)Math.PI / 2f) * Matrix.Translation(_center); } _cameraWorldTransform = Matrix.Translation(translation) * r; _camera.WorldTransform = _cameraWorldTransform; }
public abstract void LookAt(BoundingBox BBox, LookAtDirection dir = LookAtDirection.POSITIVE_Z);