예제 #1
0
	/**
	 * @brief Converts an angle around the origin to a rotation.
	 * @param angle Angle in either radians or degress.
	 * @param mode The mode of the angle, defaults to radians.
	 * @return Rotation quaterion which rotates arround the origin.
	 * 
	 * This method returns a quaternion which represents a rotation within the grid.
	 * The result is a combination of the grid's own rotation and the rotation from the angle.
	 * Since we use an angle, this method is more suitable for polar coordinates than grid coordinates.
	 * Look at @c #Sector2Rotation for a similar method that uses sectors.
	 */ 
	public Quaternion Angle2Rotation (float angle, GFAngleMode mode = GFAngleMode.radians) {
		return Quaternion.AngleAxis(angle * (mode == GFAngleMode.radians ? Mathf.Rad2Deg : 1.0f), locUnits[idx[2]] * (gridPlane == GridPlane.XY ? 1.0f : -1.0f)) * _transform.rotation;
	}
예제 #2
0
	/**
	 * @brief Converts a world position to an angle around the origin.
	 * @param world Point in world space.
	 * @param mode The mode of the angle, defaults to radians.
	 * @return Angle between the point and the grid's "right" axis.
	 * 
	 * This method returns which angle around the grid a given point in world space has.
	 */
	public float World2Angle (Vector3 world, GFAngleMode mode = GFAngleMode.radians) {
		return WorldToPolar(world)[idx[1]] * (mode == GFAngleMode.radians ? 1.0f : Mathf.Rad2Deg);
	}
예제 #3
0
	/**
	 * @brief Converts an angle (radians or degree) to the corresponding sector coordinate.
	 * @param angle Angle in either radians or degress.
	 * @param mode The mode of the angle, defaults to radians.
	 * @return Sector coordinate of the angle.
	 * 
	 * This method takes in an angle and returns in which sector the angle lies.
	 * If the angle exceeds 2π or 360° it wraps around, nagetive angles are automatically subtracted from 2π or 360°.
	 * 
	 * Let's take a grid with six sectors for example, then one sector has an agle of 360° / 6 = 60°, so a 135° angle corresponds to a sector value of 130° / 60° = 2.25.
	 */
	public float Angle2Sector (float angle, GFAngleMode mode = GFAngleMode.radians) {
		angle = Float2Rad (angle * (mode == GFAngleMode.degrees ? Mathf.Deg2Rad : 1.0f));
		return angle / this.angle * (mode == GFAngleMode.degrees ? Mathf.Rad2Deg : 1.0f);
	}
예제 #4
0
	/**
	 * @brief Converts a sector to the corresponding angle coordinate (radians or degree).
	 * @param sector Sector number.
	 * @param mode The mode of the angle, defaults to radians.
	 * @return angle coordinate of the sector.
	 * 
	 * This method takes in a sector coordinate and returns the corresponding angle around the origin.
	 * If the sector exceeds the amount of sectors of the grid it wraps around, nagetive sctors are automatically subtracted from the maximum.
	 * 
	 * Let's take a grid with six sectors for example, then one sector has an agle of 360° / 6 = 60°, so a 2.25 sector corresponds to an angle of 2.25 * 60° = 135°.
	 */
	public float Sector2Angle (float sector, GFAngleMode mode = GFAngleMode.radians) {
		sector = Float2Sector (sector);
		return sector * angle * (mode == GFAngleMode.degrees ? Mathf.Rad2Deg : 1.0f);
	}
예제 #5
0
 // extract the angle around the grid from a point in world space
 public float World2Sector(Vector3 world, GFAngleMode mode = GFAngleMode.radians)
 {
     return(WorldToGrid(world)[idx[1]]);
 }
예제 #6
0
 // extract the angle around the grid from a point in world space
 public float World2Angle(Vector3 world, GFAngleMode mode = GFAngleMode.radians)
 {
     return(WorldToPolar(world)[idx[1]] * (mode == GFAngleMode.radians ? 1.0f : Mathf.Rad2Deg));
 }
예제 #7
0
 // converts an angle around the origina to a rotation
 public Quaternion Angle2Rotation(float angle, GFAngleMode mode = GFAngleMode.radians)
 {
     return(Quaternion.AngleAxis(angle * (mode == GFAngleMode.radians ? Mathf.Rad2Deg : 1.0f), locUnits[idx[2]] * (gridPlane == GridPlane.XY ? 1.0f : -1.0f)));
 }
예제 #8
0
 // converts a sector to the corresponding angle (radians or degree) coordinate
 public float Sector2Angle(float sector, GFAngleMode mode = GFAngleMode.radians)
 {
     sector = Float2Sector(sector);
     return(sector * angle * (mode == GFAngleMode.degrees ? Mathf.Rad2Deg : 1.0f));
 }
예제 #9
0
 // converts an angle (radians or degree) to the corresponding sector coordinate
 public float Angle2Sector(float angle, GFAngleMode mode = GFAngleMode.radians)
 {
     angle = Float2Rad(angle * (mode == GFAngleMode.degrees ? Mathf.Deg2Rad : 1.0f));
     return(angle / this.angle * (mode == GFAngleMode.degrees ? Mathf.Rad2Deg : 1.0f));
 }