【ARtooklit】Translation and rotation of coordinate system

In the six steps of ARToolKit, the fourth step is the arGetTransMat function to calculate the transfer matrix of the camera, in order to make the coordinates between the camera and the identification card correspond, in order to have a good connection between the camera and the identification card.

So how does the arGetTransMat function calculate the camera's transition matrix? Here is an article that introduces the computer's transition matrix from the algorithm of the transition matrix http://haiyangxu.github.io/posts/2014/2014-06-12-camera- matrix.html

This time we will learn how the camera is connected to the identification card.

ARToolKit provides the position of the logo in the camera's coordinate system, and uses the opengl matrix system to calculate the position of the virtual object. The virtual object is then displayed in the coordinates of the identification card corresponding to the camera coordinate system. The coordinate system (CS) used by ARToolKit, the CS coordinate system has the same orientation as the opengl coordinate system. Therefore any transformation applied to the object associated with the identity should follow OpenGL's transformation rules. The specific corresponding function is the glTranslatef function, this function belongs to the function in opengl, glTranslatef (double x, double y, double z), the value of xyz is the origin of the current screen center, changing the value of xyz can make virtual Objects move along the X, Y and Z axes, and for movement there is a rule:

1. The X coordinate axis is from left to right, the Y coordinate axis is from bottom to top, and the Z coordinate axis is from inside to outside.

2. The coordinate value of the center of the OpenGL screen is the 0.0f point on the X and Y axes.

3. The coordinate value to the left of the center is negative, and the right is positive.
   Moving to the top of the screen is a positive value, moving to the bottom of the screen is a negative value.
   Moving deep into the screen is negative, moving out of the screen is positive.

When changing the parameters in the glTranslatef function, the position of the virtual object will move, and when moving, you are not moving relative to the center of the screen, but relative to the current screen position. Related to the current screen.

OpenGL function glRotatef

The glRotatef(angle, x, y, z) function rotates the virtual object. Similar to glTranslatef(x, y, z), glRotatef(angle, x, y, z) also operates on the coordinate system. The rotation axis passes through the origin, the direction is (x, y, z), the rotation angle is angle, and the direction satisfies the right-hand rule.

Rotation function: glRotatef(float angle, float X, float Y, float Z) where angle specifies the angle at which the object is rotated, and the three parameters X, Y, and Z together determine the direction of the rotation axis. That is, the glRotatef function rotates an object along the specified axis by an angle angle.

2. Rotation implementation method:

  float rotateTri;

  float rotateQuad;

  //rotate triangle

  gl.glRotatef(rotateTri, 0.0f, 1.0f, 0.0f);

  //rotate the quad

  gl.glRotatef(rotateQuad, 1.0f, 0.0f, 0.0f);

  //In order to keep rotating, the angle of rotation needs to be changed continuously.

  rotateTri += 0.5f;

  rotateQuad -= 0.5f;

As long as the glRotatef rotation function in opengl is added , the virtual object can be rotated at different angles.

The glLoadIdentity() function moves the origin of the current user coordinate system to the center of the screen: similar to a reset operation, it should be written before the glTranslatef function, or after the glRotatef function, to stop rotation or translation



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325581370&siteId=291194637