private static readonly UnitVector3D nY = new UnitVector3D(0, 1, 0); // in game y-axis, pointing upwards // keyboard control --> forward, backward, left and right // --> rotate left right, pitch up and down public static void MoveCamera(GameCamera gameCamera, Vector2D direction, double scale) { gameCamera.moveSpeedScale = scale; // direction is where the keyboard or the joystick or what is moving in the direction of joystick canvas // say, forward is new Vector2D(0, -1) // backward is new Vector2D(0, 1) // move camera direction /= direction.Length; // Normalize() Vector2D joystick_forward = new Vector2D(0, -1); MathNet.Spatial.Units.Angle moveAngle = direction.SignedAngleTo(joystick_forward, true); Vector3D camVector = gameCamera.HeadingUnitVector.ToVector3D(); // where the camera is pointing try { camVector = camVector.Rotate(nY, -moveAngle); // find the direction the movment should go in gameCamera.moveVector = camVector.Normalize(); } catch (Exception what_ex) { } }
public double GetPitch() { double actual_pitch = 0; try { UnitVector3D uv = new UnitVector3D(X.X, X.Y, X.Z); UnitVector3D u0 = new UnitVector3D(X.X, 0, X.Z); MathNet.Spatial.Units.Angle angle = uv.AngleTo(u0); if (X.Y < 0) { actual_pitch = -angle.Degrees; } else { actual_pitch = angle.Degrees; } } catch (Exception) { } return(Math.Floor(actual_pitch)); }
public double GetRoll() // which unit vector is used to calculate direction? { double actual_roll = 0; try { UnitVector3D uv = new UnitVector3D(Z.X, Z.Y, Z.Z); UnitVector3D u0 = new UnitVector3D(Z.X, 0, Z.Z); MathNet.Spatial.Units.Angle angle = uv.AngleTo(u0); if (Y.X < 0) { actual_roll = -angle.Degrees; } else { actual_roll = angle.Degrees; } } catch (Exception) { } return(Math.Floor(actual_roll)); }
public double GetHeading() // heading { UnitVector3D uv = new UnitVector3D(X.X, 0, X.Z); UnitVector3D u0 = new UnitVector3D(1, 0, 0); MathNet.Spatial.Units.Angle angle = uv.AngleTo(u0); double actual_angle; if (X.Z < 0) { actual_angle = 360 - angle.Degrees; } else { actual_angle = angle.Degrees; } return(Math.Floor(actual_angle)); // because LO uses floor }
/// <summary> /// Method to Rotate a 3D Point of type <see cref="devDept.Geometry.Point3D"/>. This is needed because the <see cref="devDept"/> namespace doesn't have a method to Rotate Point /// This method draws a line between the Point to be rotated and Point on the Axis of Rotataion about which the point is to be rotated and then rotates that line /// </summary> /// <param name="_pointToBeRotated">Point to be rotated</param> /// <param name="_pointToRotateAbout">Point on the Axis Line about which the concerned Point is to be rotated</param> /// <param name="_rotationLine">Axis of Rotation</param> /// <param name="_angleOfRotation">Angle of Rotation</param> /// <returns></returns> public Point3D RotatePoint(Point3D _pointToBeRotated, Point3D _pointToRotateAbout, Line _rotationLine, MathNet.Spatial.Units.Angle _angleOfRotation) { Line tempLine = new Line(_pointToRotateAbout.X, _pointToRotateAbout.Y, _pointToRotateAbout.Z, _pointToBeRotated.X, _pointToBeRotated.Y, _pointToBeRotated.Z); ///<summary>Rotating the Line should also rotate the Point of Interst</summary> tempLine.Rotate(_angleOfRotation.Radians, _rotationLine.StartPoint, _rotationLine.EndPoint); _pointToBeRotated = new Point3D(tempLine.EndPoint.X, tempLine.EndPoint.Y, tempLine.EndPoint.Z); return(_pointToBeRotated); }