public override void Process(GameTime gameTime, int entityId) { var lens = _lensMapper.Get(entityId); var fly = _flyCameraMapper.Get(entityId); if (ActiveLens == null) { ActiveLens = lens; } var angleX = 0f; var angleY = 0f; var moveSpeed = (float)((InputManager.Instance.IsInputDown(Input.CameraIncreasedSpeed) ? fly.Speed * 2 : fly.Speed) * gameTime.ElapsedGameTime.TotalSeconds); var translation = new Vector3(0, 0, 0); if (InputManager.Instance.IsInputDown(Input.CameraMoveForward)) { translation += lens.Direction * moveSpeed; } if (InputManager.Instance.IsInputDown(Input.CameraMoveBackwards)) { translation -= lens.Direction * moveSpeed; } if (InputManager.Instance.IsInputDown(Input.CameraMoveLeft)) { translation += Vector3.Cross(Vector3.Up, lens.Direction) * moveSpeed; } if (InputManager.Instance.IsInputDown(Input.CameraMoveRight)) { translation -= Vector3.Cross(Vector3.Up, lens.Direction) * moveSpeed; } if (InputManager.Instance.IsInputDown(Input.CameraMoveUp)) { translation += new Vector3(0, moveSpeed, 0); } if (InputManager.Instance.IsInputDown(Input.CameraMoveDown)) { translation -= new Vector3(0, moveSpeed, 0); } if (!lens.CustomAspectRatio) { lens.AspectRatio = LensComponent.CalculateAspectRatio(Game1.ScreenResolutionX, Game1.ScreenResolutionY); } lens.Position += translation; if (InputManager.Instance.IsInputDown(Input.CameraFreeRotation)) { var mousePositionDifference = InputManager.Instance.CameraLookVector; angleX -= mousePositionDifference.X * moveSpeed * 3; angleY += mousePositionDifference.Y * moveSpeed * 3; } else { if (InputManager.Instance.IsInputDown(Input.CameraLookLeft)) { angleX -= moveSpeed * 6; } if (InputManager.Instance.IsInputDown(Input.CameraLookRight)) { angleX += moveSpeed * 6; } if (InputManager.Instance.IsInputDown(Input.CameraLookUp)) { angleY += moveSpeed * 6; } if (InputManager.Instance.IsInputDown(Input.CameraLookDown)) { angleY -= moveSpeed * 6; } } var cameraUpPerpendicular = Vector3.Cross(Vector3.Up, lens.Direction); cameraUpPerpendicular.Normalize(); var tempDirection = Vector3.Transform(lens.Direction, Matrix.CreateFromAxisAngle(cameraUpPerpendicular, (-MathHelper.PiOver4 / 150) * angleY)); tempDirection = Vector3.Transform(tempDirection, Matrix.CreateFromAxisAngle(Vector3.Up, (-MathHelper.PiOver4 / 150) * angleX)); tempDirection.Normalize(); lens.Direction = tempDirection; }
private static CollidableReference?GetCollidableAtMouse(Simulation simulation, LensComponent lens) { var lensDirection = new global::System.Numerics.Vector3(lens.Direction.X, lens.Direction.Y, lens.Direction.Z); var lensPosition = new global::System.Numerics.Vector3(lens.Position.X, lens.Position.Y, lens.Position.Z); var rayDirection = lensDirection; var hitHandler = default(RayHitHandler); hitHandler.T = float.MaxValue; simulation.RayCast(lensPosition, rayDirection, float.MaxValue, ref hitHandler); if (hitHandler.T < float.MaxValue) { return(hitHandler.HitCollidable); } return(null); }