Polar and Spherical coordinate systems - Gr8-Tools/game-developer-roadmap-doc GitHub Wiki

Total time: 3.5 hours

Polar and spherical coordinate systems are alternative ways of representing points in a two-dimensional and three-dimensional space, respectively. These coordinate systems are widely used in various fields, including game development, physics, and engineering.

Subtopics and Definitions

  1. Polar Coordinate System - In a polar coordinate system, a point in the plane is described using two values: the radial distance (r) from the origin to the point and the angle (θ) formed by a reference line (usually the positive x-axis) and the line segment connecting the origin to the point.
  2. Cartesian Coordinate System - The Cartesian coordinate system is the traditional coordinate system used in mathematics and game development. It represents a point in a two-dimensional space using two values: the x-coordinate (horizontal distance) and the y-coordinate (vertical distance) relative to an origin.
  3. Conversion between Polar and Cartesian Coordinates - To convert a point from polar coordinates (r, θ) to Cartesian coordinates (x, y), you can use the following formulas: x = r * cos(θ) and y = r * sin(θ). Similarly, to convert a point from Cartesian coordinates (x, y) to polar coordinates (r, θ), you can use the formulas: r = sqrt(x^2 + y^2) and θ = atan2(y, x).
  4. Spherical Coordinate System - In a spherical coordinate system, a point in the three-dimensional space is described using three values: the radial distance (ρ) from the origin to the point, the polar angle (θ) formed by the positive z-axis and the line segment connecting the origin to the point, and the azimuthal angle (φ) formed in the xy-plane between the positive x-axis and the line segment connecting the origin to the projection of the point on the xy-plane.
  5. Conversion between Spherical and Cartesian Coordinates - To convert a point from spherical coordinates (ρ, θ, φ) to Cartesian coordinates (x, y, z), you can use the following formulas: x = ρ * sin(θ) * cos(φ), y = ρ * sin(θ) * sin(φ), and z = ρ * cos(θ). Conversely, to convert a point from Cartesian coordinates (x, y, z) to spherical coordinates (ρ, θ, φ), you can use the formulas: ρ = sqrt(x^2 + y^2 + z^2), θ = acos(z / ρ), and φ = atan2(y, x).

Understanding and being able to work with both polar and spherical coordinate systems is essential for various game development tasks, such as positioning objects in a 2D or 3D space, implementing camera controls, or creating realistic particle systems. By familiarizing yourself with these coordinate systems and their conversions, you can enhance your ability to manipulate positions and angles in game development applications.

Additional Materials

Videos

  1. Spherical Coordinates 3D Animation

10 minutes

Tasks

Cube-game

The following tasks extend current game experience in our "Cube"-competitor game (where we trying achieve as more goals as we can)

  1. Add new Camera source: now there will be two Cameras. First camera will provide first-person view, and the second - third-person one. Provide mechanics to switch views from one camera to another (here you can find one of solution).

30 minutes

  1. Provide mouse control mechanics for both of Cameras.
    • Let First camera rotate around fixed point in 15 degrees vertical and 30 degrees horizontal. Camera should follow the mouse in not pressed state. Switching to this Camera view is accompanied by its installation to the default position (forward looking one).

    Here you peek the base for the implementation. It's only the source, don't copy the whole code. As you rotate with help of 'A' and 'D' keys here you only need to have an opportunity to look "at your feet" or to the sides at a small angle.

    • The second camera should rotate in a sphere around the game character. Switching to this Camera view is accompanied by its installation to certain default position (i.e., behind and up the game character). Camera should respond to the mouse movements in a pressed state (pressed left button), and shouldn't respond in other case.

2.5 hours