static Camera() { positionAcceleration = new DecimalVector(0m, 0m, 0m); positionAccelerationFadeOut = new DecimalVector(0m, 0m, 0m); Angle = new DecimalVector(0m, 0m, 0m); angularAcceleration = new DecimalVector(0m, 0m, 0m); angularAccelerationFadeOut = new DecimalVector(0m, 0m, 0m); Location = new DecimalVector(0m, 0m, 0m); Target = new DecimalVector(0m, 0m, 1m); ControlMode = Mode.Default; Up = new DecimalVector(0m, 1m, 0m); Sensitivity = 1; halfAngle = new DecimalVector(0m, 0m); halfSpeed = new DecimalVector(0m, 0m); CameraTimer = new Timer(); CameraTimer.Interval = 10; CameraTimer.Tick += AnimationStep; CameraTimer.Tick += TimerTick; CameraTimer.Start(); }
private void Initialize() { StartingLocation = new Vector(0f, 0f, 0f); fObject = new FlyingObject(Parent, ModelManager.modelBank[0].model, 7); fObject.ShaderProgram = GeneralGraphics.SimulatedLighting; var physGui = new Object(); physGui.Location = new Vector(0f, 0f, 0f); PhysicsObject obj = new PhysicsObject(); obj.Velocity = fObject.PhysicalBody.Velocity; obj.ParentObject = physGui; for (int i = 0; i < 8; ++i) { obj.ModulatePhysics(); obj.ApplyNaturalForces(); } var target = new DecimalVector((decimal)physGui.Location.X, (decimal)physGui.Location.Y, (decimal)physGui.Location.Z + 10); Camera.MoveTo(target, 60); timer = new Timer(); timer.Interval = 10; timer.Tick += AnimationStep; timer.Start(); fObject.Start(); }
// Converter: decimalVector v2 = decimalVector.FromVector( v1 ); public static DecimalVector FromVector(DecimalVector that) { return(new DecimalVector(that)); }
// Constructor: decimalVector v2 = new decimalVector( v1 ); public DecimalVector(DecimalVector that) : base() { this.CopyFromArray(that.ToArray()); return; }
public static void RotateAround(DecimalVector position, decimal angularVelocity = 0.5m) { rotationCenter = position; rotationRadius = (decimal)Math.Sqrt((double)(Location.X - position.X) * (double)(Location.X - position.X) + (double)(Location.Z - position.Z) * (double)(Location.Z - position.Z)); rotationAngle = (decimal)GeometryMath.DegreeToRadian(Math.Asin((float)(Location.Z - position.Z) / (float)rotationRadius)); rotate = true; Camera.angularVelocity = angularVelocity; }
/// <summary> /// Moves the camera to a given point. /// </summary> /// <param name="position">The position to move the camera to.(Z plane)</param> /// <param name="time">The time for which the movement is completed in milliseconds.</param> public static void MoveTo(DecimalVector position, decimal time) { position.Z = -position.Z; position.Y = -position.Y; position.X = -position.X; time /= 2; useTargets = true; if (positionAcceleration.Z == 0m && Math.Abs(Zoom - position.Z) > GameConstants.ZoomErrorMargin) if (ControlMode == Mode.Smooth) { int direction = -Math.Sign(Zoom - position.Z); decimal distance = Math.Abs(Zoom - position.Z) / 2; positionAcceleration.Z = direction * (2 * distance) / (time * time); positionAccelerationFadeOut.Z = (-direction) * positionAcceleration.Z; time -= 1; halfSpeed.Z = positionAcceleration.Z * time; } else { //do nothing } if (positionAcceleration.X == 0m && Math.Abs(Location.X - position.X) > GameConstants.ZoomErrorMargin) if (ControlMode == Mode.Smooth) { int direction = -Math.Sign(Location.X - position.X); decimal distance = Math.Abs(Location.X - position.X) / 2; positionAcceleration.X = direction * (2 * distance) / (time * time); positionAccelerationFadeOut.X = (-direction) * positionAcceleration.X; time -= 1; halfSpeed.X = positionAcceleration.X * time; } else { //do nothing } if (positionAcceleration.Y == 0m && Math.Abs(Location.Y - position.Y) > GameConstants.ZoomErrorMargin) if (ControlMode == Mode.Smooth) { int direction = -Math.Sign(Location.Y - position.Y); decimal distance = Math.Abs(Location.Y - position.Y) / 2; positionAcceleration.Y = direction * (2 * distance) / (time * time); positionAccelerationFadeOut.Y = (-direction) * positionAcceleration.Y; time -= 1; halfSpeed.Y = positionAcceleration.Y * time; } else { //do nothing } }
/// <summary> /// Rotates the camera to look at a given point. /// </summary> /// <param name="target">The point to look at.</param> /// <param name="time">The time for which the rotation is completed in milliseconds.</param> public static void LookAt(DecimalVector target, decimal time) { useTargets = true; //opengl axis hack target.Y = -target.Y; time /= 2; #region X axis int direction = -Math.Sign(Angle.X - target.Y); //Console.WriteLine("distance:{0}", Math.Abs(Angle.X - target.Y)); if (angularAcceleration.X == 0m && Math.Abs(Angle.X - target.Y) >= 5.0m) if (ControlMode == Mode.Smooth) { decimal distance = Math.Abs(Angle.X - target.Y) / 2; angularAcceleration.X = direction * (2 * distance) / (time * time); angularAccelerationFadeOut.X = (-direction) * angularAcceleration.X; time -= 1; halfAngle.X = angularAcceleration.X * time; } else { //do nothing } #endregion #region Y axis direction = -Math.Sign(Angle.Y - target.X); //Console.WriteLine("distance:{0}", Math.Abs(Angle.X - target.Y)); if (angularAcceleration.Y == 0m && Math.Abs(Angle.Y - target.X) >= 5.0m) if (ControlMode == Mode.Smooth) { decimal distance = Math.Abs(Angle.Y - target.X) / 2; angularAcceleration.Y = direction * (2 * distance) / (time * time); angularAccelerationFadeOut.Y = (-direction) * angularAcceleration.Y; time -= 1; halfAngle.Y = angularAcceleration.Y * time; } else { //do nothing } #endregion }