3D Game Development with LWJGL 3 Chapter 3: Introduction to coordinates

This chapter will discuss coordinates and coordinate systems, trying to introduce in a simple way some basic mathematical concepts that will support the techniques and topics discussed in subsequent chapters. To improve readability, this section will assume some simplified scenarios, possibly at the expense of accuracy.

We locate objects in space by specifying their coordinates. For example, with a map, you would specify a location on the map by its longitude and latitude. A point can be accurately identified with just a pair of numbers, which are the coordinates of that point (a bit more complicated in reality, because the Earth is a non-perfect ellipse and the map is its projection, so more data is needed, But it's a good analogy).

A coordinate system is a system that uses one or more numbers, that is, one or more components to uniquely specify the location of a point. Different coordinate systems (Cartesian, polar, etc.) can be converted to each other. This chapter will use the Cartesian coordinate system to describe the subsequent content.

In the Cartesian coordinate system, for two dimensions, coordinates are defined by two numbers measuring the vertical signed distance from the X and Y axes.
Cartesian coordinate system

Continuing with the map analogy, a coordinate system defines an origin. For geographic coordinates, the origin is set to the intersection of the equator and the zero meridian cross (also known as the prime meridian). Depending on where we set the origin, the coordinates of a specific point will be different. The coordinate system also defines the direction of the axes. In the above image, when the point moves to the right, the X coordinate increases, and when the point moves upward, the Y coordinate increases. However, we can also define an alternative Cartesian coordinate system with different axis orientations, in which different coordinates will be obtained.
Alternative Cartesian coordinate system
As you can see, we need to define some arbitrary parameters, such as the origin and the direction of the axes, in order to give the proper meaning to the pairs of numbers that make up the coordinates. We call a coordinate system with this set of arbitrary parameters a coordinate space. We must use the same coordinate space to handle coordinate groups. The nice thing is that you can transform coordinates from one space to another simply by translating and rotating.

If you are dealing with 3D coordinates, you need to add a Z axis. The 3D coordinates will be a set of three numbers (x,y,z).
3D Cartesian coordinate system
As with the 2D Cartesian coordinate system, we can change the orientation of the axes in 3D coordinate space as long as the axes are perpendicular to each other. The figure below represents another 3D coordinate space.
Alternative 3D Cartesian coordinate system
3D coordinates can be divided into two types: left-handed coordinate system (left handed) and right-handed coordinate system (right handed). How to determine what type of coordinate system it is? Open your hand and form an "L" between your thumb and index finger. The middle finger is perpendicular to the thumb and index finger. At this time, the thumb points in the positive direction of the X-axis, the index finger points in the positive direction of the Y-axis, and the middle finger points in the positive direction of the Z-axis. Your left and right hands correspond to the left-hand coordinate system and the right-hand coordinate system respectively.
Left-hand coordinate system and right-hand coordinate system
For 2D coordinate spaces, using rotation can transform one coordinate space into another, so 2D coordinate spaces are equivalent. In contrast, 3D spaces are not all equivalent. Rotation can be used to transform one coordinate space into another coordinate space only in the same hand system (either left-handed or right-handed).

Now that we have explained some basic principles, let's talk about terminology commonly used in working with 3D graphics. When we explain how to render 3D models in subsequent chapters, we will see different 3D coordinate spaces, because these coordinate spaces have their own context and purpose. No set of coordinates is meaningless. When you're checking a coordinate (eg: 40.438031, -3.676626), it may or may not tell you the relevant information. If I say it is a geometric coordinate (latitude and longitude), then you will know that it is the coordinate of Madrid.

When loading a 3D object, we get a set of 3D coordinates. These coordinates are represented in a coordinate space called object coordinate space. When graphic designers create these 3D models, they don't know everything about the 3D scene in which the model will appear. Therefore, they can only define coordinates using the coordinate space relevant to the model.

When a 3D scene is drawn, all 3D objects will correspond to a coordinate space called world space. We need to convert 3D object space coordinates to world space coordinates. Some objects need to be rotated, stretched or enlarged, and transformed before they can be displayed correctly in a 3D scene.

Just like moving the camera in 3D space, we also need to limit the extent of the 3D space being displayed. Then, world space coordinates need to be converted to camera or view space coordinates. Finally these coordinates need to be converted to screen coordinates, i.e. 2D, so we need to project the 3D view coordinates into the 2D screen coordinate space.

The picture below shows the OpenGL coordinates (the Z axis is perpendicular to the screen), and the coordinates are between -1 and +1.
OpenGL coordinates
Don't worry if you still don't understand these concepts clearly; subsequent chapters will revisit these issues and provide practical examples.

Guess you like

Origin blog.csdn.net/m0_37942304/article/details/108004807