public RaycastCamera() { Position = new Vector2(1.5f, 1.5f); Direction = new Vector2(1, 0); Vector2Ext.Normalize(ref Direction); CameraPlane = new Vector2(0, -1) * VectorPlaneLength; Move(Position, Direction); }
private void Rotate(Double target, Int32 direction) { var length = Math.PI / 2; Movement = (gameTime) => { float rotation = 0.004f * direction * 40.0f; rotation = (float)Math.Min(length, rotation); length -= Math.Abs(rotation); // Convert rotation to direction Matrix2D rotMatrix = Matrix2D.CreateRotationZ(rotation); Vector2 newDirection = Vector2.Transform(Direction, Matrix2D.Convert(rotMatrix)); Direction = newDirection; Vector2 newVectorPlane = Vector2.Transform(CameraPlane, Matrix2D.Convert(rotMatrix)); CameraPlane = newVectorPlane; if (length <= 0) { // set the direction vector and update Direction.X = (float)Math.Cos(target); Direction.Y = (float)Math.Sin(target); // Set the vector plane as the normal to the direction vector CameraPlane.X = Direction.Y; CameraPlane.Y = -1 * Direction.X; Vector2Ext.Normalize(ref CameraPlane); CameraPlane *= VectorPlaneLength; Movement = null; } }; }