public Player(Vector coord, SphericalVec directionVector) { Coord = coord; DirectionVector = directionVector; if (!DirectionVector.EvokeSinCosCalculation) { DirectionVector.EvokeSinCosCalculation = true; } }
private void FrameTick_Tick(object sender, EventArgs e) { double TimeElapsed = (DateTime.Now - TimeOfPreviousFrameTick).TotalSeconds; // Time elapsed since previous frame tick TimeOfPreviousFrameTick = DateTime.Now; frameTickDurations.Add(TimeElapsed); if (frameTickDurations.Count > frameTickDurations_NumOfSamples) { frameTickDurations.RemoveAt(0); } FPS = frameTickDurations.Count / frameTickDurations.Sum(); // Calculate average FPS if (keyControl.NotPausedOrHoldingControl) { double rotationSensitivity = 8 * 0.01; // Const X, where ChangeInAngleInDeg = X * ChangeInScreenCoord double movementSpeed = 5; // UnitPerSec aka BlocksPerSec #region Up-down rotation double Y_Offset = 500 - Cursor.Position.Y; player.DirectionVector.VertAngDeg -= Y_Offset * rotationSensitivity; #endregion #region Left-Right rotation double X_Offset = 500 - Cursor.Position.X; player.DirectionVector.HoriAngDeg -= X_Offset * rotationSensitivity; Cursor.Position = new Point(500, 500); #endregion #region Movement double distanceMoved = movementSpeed * TimeElapsed; // UnitPerSec * TimeInSeconds if (keyControl.MoveForward) { player.Coord += player.DirectionVector.ToVector() * distanceMoved; } if (keyControl.MoveBackward) { player.Coord -= player.DirectionVector.ToVector() * distanceMoved; } if (keyControl.MoveLeft) { SphericalVec temp = player.DirectionVector.ReturnOffset(0, -(Math.PI / 2), 0, rad: true, evokeSinCos: false); temp.VertAngRad = Math.PI / 2; player.Coord += temp.ToVector() * distanceMoved; } if (keyControl.MoveRight) { SphericalVec temp = player.DirectionVector.ReturnOffset(0, (Math.PI / 2), 0, rad: true, evokeSinCos: false); temp.VertAngRad = Math.PI / 2; player.Coord += temp.ToVector() * distanceMoved; } if (keyControl.FlyUp) { player.Coord.Y += 1.0 * distanceMoved; } if (keyControl.FlyDown) { player.Coord.Y -= 1.0 * distanceMoved; } #endregion } Invalidate(); #region Dynamic FrameTick Interval Adjuster if (FPS < 60 && FPS != 0 && FrameTick.Interval > 5) { FrameTick.Interval--; } else { FrameTick.Interval++; } #endregion }
public Player(Vector coord) { Coord = coord; DirectionVector = new SphericalVec(0, 0, 1, evokeSinCos: true); }