/// <summary> /// Initializes a new instance of the <see cref="OrbitCameraAligned"/> class. /// </summary> /// <param name="view">The view from which to retrieve input and aspect ratio.</param> /// <param name="rotationSpeedBase">The base (i.e. at default zoom distance) rotation speed of the camera, in radians per per update.</param> /// <param name="fieldOfViewRadians">The camera's field of view, in radians.</param> /// <param name="nearPlaneDistance">The distance of the near plane from the camera.</param> /// <param name="farPlaneDistance">The ditance of the far plane from the camera.</param> public OrbitCameraAligned( MyOTKEWindow view, float rotationSpeedBase, float fieldOfViewRadians, float nearPlaneDistance, float farPlaneDistance) { this.view = view; RotationSpeedBase = rotationSpeedBase; FieldOfViewRadians = fieldOfViewRadians; NearPlaneDistance = nearPlaneDistance; FarPlaneDistance = farPlaneDistance; }
/// <summary> /// Initializes a new instance of the <see cref="PanningCamera"/> class. /// </summary> /// <param name="view">The view from which to retrieve input and aspect ratio.</param> /// <param name="fieldOfViewRadians">The camera's field of view, in radians.</param> /// <param name="nearPlaneDistance">The distance of the near plane from the camera.</param> /// <param name="farPlaneDistance">The ditance of the far plane from the camera.</param> /// <param name="initialTarget">The initial position at which the camera should point.</param> /// <param name="movementSpeed">The movement speed of the camera, in units per second per unit distance from target.</param> /// <param name="verticalAngle">The initial angle, in radians, between the camera's view direction and the Z-axis.</param> public PanningCamera( MyOTKEWindow view, float fieldOfViewRadians, // = (float)Math.PI / 4.0f; float nearPlaneDistance, // = 0.01f; float farPlaneDistance, // = 100f; Vector3 initialTarget, float movementSpeed, float verticalAngle) { this.view = view; FieldOfViewRadians = fieldOfViewRadians; NearPlaneDistance = nearPlaneDistance; FarPlaneDistance = farPlaneDistance; target = initialTarget; this.movementSpeed = movementSpeed / Distance; this.VerticalAngle = verticalAngle; }
/// <summary> /// Initializes a new instance of the <see cref="Ray"/> struct that originates from a given camera position, /// and points in the direction as indicated by the current mouse cursor position in a view. /// </summary> /// <param name="camera">The camera to project the ray from.</param> /// <param name="view">The view from which to retrieve the mouse position to determine the ray's direction.</param> public Ray(ICamera camera, MyOTKEWindow view) { // http://antongerdelan.net/opengl/raycasting.html float x = (2.0f * view.CenterOffset.X) / view.ClientSize.X; float y = -(2.0f * view.CenterOffset.Y) / view.ClientSize.Y; var ray_clip = new Vector4(x, y, -1.0f, 0f); Matrix4.Invert(camera.Projection, out var projInverse); var ray_eye = projInverse * ray_clip; ray_eye = new Vector4(ray_eye.X, ray_eye.Y, -1.0f, 0.0f); Matrix4.Invert(camera.View, out var viewInverse); var ray_wor = viewInverse * ray_eye; Direction = Vector3.Normalize(new Vector3(ray_wor.X, ray_wor.Y, ray_wor.Z)); Origin = camera.Position; // todo: do we really need a camera position? }
/// <summary> /// Initializes a new instance of the <see cref="FirstPersonCamera"/> class. /// </summary> /// <param name="view">The view from which to retrieve user input.</param> /// <param name="movementSpeed">The movement speed of the camera, in units per second.</param> /// <param name="rotationSpeed">The "rotation speed" of the camera - the multiplicand of the mouse cursor offset to radians.</param> /// <param name="fieldOfViewRadians">The field of view of the camera, in radians.</param> /// <param name="nearPlaneDistance">The distance of the near plane from the camera.</param> /// <param name="farPlaneDistance">The distance of the far plane from the camera.</param> /// <param name="initialPosition">The initial position of the camera.</param> /// <param name="initialHorizontalAngleRadians">The initial angle between the camera direction and the Y axis, in radians.</param> /// <param name="initialVerticalAngleRadians">The initial angle between between the camera direction and the X axis, in radians.</param> public FirstPersonCamera( MyOTKEWindow view, float movementSpeed, float rotationSpeed, float fieldOfViewRadians, float nearPlaneDistance, float farPlaneDistance, Vector3 initialPosition, float initialHorizontalAngleRadians, float initialVerticalAngleRadians) { this.view = view; this.MovementSpeed = movementSpeed; this.RotationSpeed = rotationSpeed; this.FieldOfViewRadians = fieldOfViewRadians; this.NearPlaneDistance = nearPlaneDistance; this.FarPlaneDistance = farPlaneDistance; this.Position = initialPosition; this.horizontalAngle = initialHorizontalAngleRadians; this.verticalAngle = initialVerticalAngleRadians; }