public void ZoomIn(float amount) { Vector3 newPos = Vector3.Transform(Position, Matrix.CreateTranslation(Fwd * amount)); if (CheckNewPosition(newPos)) { Position = newPos; Theta = SetTheta(newPos); } }
public void PanDown(float amount) { Vector3 newPos = Vector3.Transform(Position, Matrix.CreateTranslation(-Up * amount)); if (CheckNewPosition(newPos)) { Position = newPos; Target = Vector3.Transform(Target, Matrix.CreateTranslation(-Up * amount)); Theta = SetTheta(newPos); } }
private bool CheckNewPosition(Vector3 newPos) { AngularRange3 newTheta = SetTheta(newPos); return(Math.Abs(newPos.X) <= Math.Abs(Range.Position.Max.X) && Math.Abs(newPos.X) >= Math.Abs(Range.Position.Min.X) && Math.Abs(newPos.Y) <= Math.Abs(Range.Position.Max.Y) && Math.Abs(newPos.Y) >= Math.Abs(Range.Position.Min.Y) && Math.Abs(newPos.Z) <= Math.Abs(Range.Position.Max.Z) && Math.Abs(newPos.Z) >= Math.Abs(Range.Position.Min.Z) && newTheta.Altitude.Max <= Range.Theta.Altitude.Max && newTheta.Altitude.Max >= Range.Theta.Altitude.Min && newTheta.Azimuth.Max <= Range.Theta.Azimuth.Max && newTheta.Azimuth.Max >= Range.Theta.Azimuth.Min); }
public void PanRight(float amount) { Vector3 right = Vector3.Cross(Up, Fwd) * -1; right.Normalize(); Vector3 newPos = Vector3.Transform(Position, Matrix.CreateTranslation(right * amount)); if (CheckNewPosition(newPos)) { Position = newPos; Target = Vector3.Transform(Target, Matrix.CreateTranslation(right * amount)); Theta = SetTheta(newPos); } }
public void OrbitVertically(float amount) { Vector3 left = Vector3.Cross(Up, Position); left.Normalize(); Vector3 newPos = Vector3.Transform(Position, Matrix.CreateFromAxisAngle(left, MathHelper.ToRadians(amount))); if (CheckNewPosition(newPos)) { Position = newPos; Up = Vector3.Transform(Up, Matrix.CreateFromAxisAngle(left, MathHelper.ToRadians(amount))); Fwd = Vector3.Transform(Fwd, Matrix.CreateFromAxisAngle(left, MathHelper.ToRadians(amount))); Theta = SetTheta(newPos); } }
private AngularRange3 SetTheta(Vector3 position) { Vector3 norm = position; norm.Normalize(); float azimuth = 0f; if (norm.Z > 0) { if (norm.X <= 0) { azimuth = MathHelper.Pi + (float)Math.Abs(Math.Asin(norm.X)); // quad 3 } else { azimuth = MathHelper.Pi - (float)Math.Abs(Math.Asin(norm.X)); // quad 2 } } else if (norm.X < 0 && norm.Z < 0) { azimuth = MathHelper.TwoPi - (float)Math.Abs(Math.Asin(norm.X)); // quad 4 } else { azimuth = (float)Math.Abs(Math.Asin(norm.X)); // quad 1 } var theta = new AngularRange3() { Azimuth = new AngularRange() { Min = 0f, Max = azimuth }, Altitude = new AngularRange() { Min = 0f, Max = (float)Math.Asin(Vector3.Dot(norm, Vector3.Up)) } }; return(theta); }
private AngularRange3 SetTheta(Vector3 position) { Vector3 norm = position; norm.Normalize(); float azimuth = 0f; if (norm.Z > 0) { if (norm.X <= 0) azimuth = MathHelper.Pi + (float)Math.Abs(Math.Asin(norm.X)); // quad 3 else azimuth = MathHelper.Pi - (float)Math.Abs(Math.Asin(norm.X)); // quad 2 } else if (norm.X < 0 && norm.Z < 0) azimuth = MathHelper.TwoPi - (float)Math.Abs(Math.Asin(norm.X)); // quad 4 else azimuth = (float)Math.Abs(Math.Asin(norm.X)); // quad 1 var theta = new AngularRange3() { Azimuth = new AngularRange() { Min = 0f, Max = azimuth }, Altitude = new AngularRange() { Min = 0f, Max = (float)Math.Asin(Vector3.Dot(norm, Vector3.Up)) } }; return theta; }