Understanding of the various coordinate systems in OpenGL [go]

Source: Internet
Author: User

OpenGL coordinate system can be divided into: World coordinate system and current drawing coordinate system.

World coordinate system : In OpenGL, the world coordinate system is at the center of the screen as the origin (0, 0, 0), and is always the same. You face

screen, your right side is the x positive axis, which is the y positive axis, and the screen points to your z-axis. The unit of length is determined as follows:

The window range is exactly ( -1,-1) to (a), that is, the lower-left corner of the screen coordinates ( -1,-1), the upper-right corner

Coordinates are (in).

current drawing coordinate system : is the coordinate system at which the object is drawn. When the program is just initialized, the world coordinate system and the current drawing coordinate system are coincident

Of When using Gltranslatef (), Glscalef (), Glrotatef (), etc. to translate the current drawing coordinate system,

After scaling and rotating transformations, the world coordinate system and the current drawing coordinate system no longer overlap. Note that the translational rotation here

The rotation is to translate the current drawing coordinate system as a whole in a world coordinate system. Then, change to

, drawing functions such as glvertex3f () are plotted in the current drawing coordinate system, all

Function parameters are also relative to the current drawing coordinate system.

Today we look at 3D Model animation code, found that using four-tuple interpolation and rotation, understand the use of Euler angle rotation will have a universal lock problem exists. But this is based on the rotation of the model coordinate system, and then the OGL in the matrix changes in the part of the study again. Found a good article, forward learning, stay for review.

OpenGL uses right-hand coordinates

From left to right, x increments
From bottom to top, y increments
From far to near, Z increments


--------------------------------------------------------------------------------

OpenGL coordinate system can be divided into: World coordinate system and current drawing coordinate system.

The world coordinate system takes the center of the screen as the origin (0, 0, 0). You face the screen, your right side is the x positive axis, the top is the y positive axis, the screen points to your z-axis. The unit of length is determined as follows: The window range is exactly ( -1,-1) to (in) the unit.

The current drawing coordinate system is the coordinate system at which the object is drawn . When the program is just initialized, the world coordinate system and the current drawing coordinate system are coincident . When using Gltranslatef (), Glscalef (), Glrotatef () to translate, scale, and rotate the current drawing coordinate system, the world coordinate system and the current drawing coordinate system are no longer coincident. After the change, and then using glvertex3f () and other drawing functions to draw, are in the current drawing coordinate system to draw, all the function parameters are relative to the current drawing coordinate system in terms of .

6 Types of coordinate systems in OpenGL

There are 6 types of coordinate systems in OpenGL,

1. Object or model coordinates

2. World coordinates

3. Eye (or Camera) coordinates

4. Clip coordinates

5. Normalized device coordinates

6. Window (or screen) coordinates

The transformation from object coordainates to world coordinates to camera coordinate, in OpenGL, is called Model-view conversion, when initialized, object coordinates and world coordinates also have camera coordinates coordinates coincident at the origin, and the transformation matrix is identity. Model-view Matix convert POINTS,VECTORSD to camera coordinate system.

In OpenGL programming, there is a puzzling problem, that the coordinate system is not moving, I think you want to refer to the coordinate system is not moving. For example, I want to set up an object, put it in the camera coordinate system, at this point, I take the camera's origin as a reference point. Of course, when I want to see this object, I will use the origin of the object as the reference point, moving the camera coordinate system origin, you can see the object. Seems to have written a bunch of crap, hehe.

Four of these coordinates are often used in programs: world coordinates, object coordinates, device coordinates, and eye coordinates .

World coordinates are used in OpenGL to describe the coordinates of the scene, z+ axis vertical screen outward, x+ from left to right, y+ axis from bottom to top, is the right-hand Cartesian coordinate system. We use this coordinate system to describe the position of the object and the light source.

Placing an object in a scene is the translation of an object to a specific position and a certain angle of rotation, which is the coordinate transformation. OpenGL provides the gltranslate*/glrotate*/glscale* three coordinate transformation command, using OpenGL's Matrix Operations Command, you can implement arbitrary complex coordinate transformation.

very important :OpenGL has a coordinate transformation matrix stack (Modelview), the top of the stack is the current coordinate transformation matrix , into the OpenGL pipeline each coordinate (homogeneous coordinates) will first multiply the matrix, The result is the world coordinates of the corresponding point in the scene. The coordinate transformations in OpenGL are all done by matrix operations, and are exactly the same as those described in the graphics textbook. It is important to note that the matrix multiplication in the transformation is the left multiplication, and the matrix multiplication is different from the arithmetic multiplication, which does not conform to the commutative law (if you do not understand to see the matrix Algebra book well).

gltranslate* (x, Y, z): Panning, the parameter is the amount of movement of each axis.
Glrotate (d,x,y,z): Rotation, the first parameter is the degree of rotation, and the following three parameters indicate whether to rotate around the axis. Usually only one in X, Y, Z is 1, the remainder is 0, and the complex rotation is accomplished with several consecutive rotation commands. Because of the characteristics of the left multiplication of matrix operations, the order of rotation commands is the opposite of the rotation action .

object coordinates are "world coordinates" that are created at a point of the object, which is applied only to the object , and is used to simplify the description of the coordinates of each part of the object. When the object is placed in the scene, the coordinates of each part undergo the same transformation, the relative position is unchanged, so it can be regarded as a whole, consistent with the human thinking habit.

The eye coordinate is the direction of the coordinate system with the point of view as the origin and the direction of the line of sight in the positive direction of the z+ axis. The OpenGL pipeline transforms the world coordinates first to the eye coordinates and then to the crop, and only the scene within the sight range (see body) enters the next stage of the calculation.

Similarly, there is a projection transformation matrix stack (Projection), the stack top matrix is the current projection transformation matrix, which is responsible for transforming the scene coordinates to the eye coordinates, the resulting result is the cropped scene part, called the clipping coordinates. The previously mentioned view body setting is actually building the matrix.

Device coordinates : one of the important functions of OpenGL is to calculate the three-dimensional world coordinate through transformation, projection, etc., and finally figure out its corresponding position on the display device, which is called device coordinates. Coordinates on devices such as screens, printers, and so on are two-dimensional coordinates. It is worth mentioning that OpenGL can be drawn using only a portion of the device, which is called the viewport or viewport (viewport). The projection results from the coordinates in the viewport (projected coordinates), and the computational process from projected coordinates to device coordinates is the device transformation.

Matrix stack switch:glmatrixmode (gl_modelviewing or gl_projection); After this command executes, the matrix stack of the arguments is the current matrix stack, and subsequent matrix stack manipulation commands will act upon it .

Matrix Stack Manipulation Commands:
Glpushmatrix (); The current matrix is in the stack, at which point the stack top value is pressed into the stack.
Glpopmatrix (); Stack ejection stack, usually in conjunction with the previous command.
Glloadidentity (); Set the top of the stack to the invariant matrix (that is, the diagonal is all 1 other 0).
Glmultmatrix (m); set stack top t to M · T.

Transferred from: http://blog.chinaunix.net/u1/49717/showart_2263380.html

Understanding of the various coordinate systems in OpenGL [go]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.