OSG Coordinate System ????????

Source: Internet
Author: User

For the following code (from OSG Navy tutorial, Section 10, use a custom matrix to place the camera, but the data is changed ):

Tankxform-> setposition (OSG: vec3 (0, 60, 8 ));

// The camera has 60 units at the rear of the tank and 7 units at the top.

T. maketranslate (0,); // pan along Z + 15

A = r * t; // set R to a matrix that rotates around the Y axis + 20 degrees

C = OSG: matrixf: makerotate (-m_pi/2.0, 1, 0, 0) // C is rotated around the X axis-90 degrees

While (! Viewer. Done ())

{// Do not use the default trackballmanipulator to customize the view matrix.

Viewer. getcamera ()-> setviewmatrix (OSG: matrixf: inverse (a) * C );

Viewer. Frame ();

}

At the underlying layer, it is all the OpenGL coordinate system (Y up ). Set the inverse of a to ~, MV =
A ~ * C, and the final display effect is mv ~ = (~ * C )~ = C ~ * A = C ~ * (R * t), that is, (turning around the X axis + 90 degrees * turning around the Y axis + 20 degrees
* Translate along Z 15), then the new viewpoint position V '= V * mv ~, The line vector is used, that is, the coordinate system of the viewpoint is transformed from the back to the back. That is, the coordinate system of the viewpoint is first moved to 15 along Z, then rotated to + 20 degrees around the Y axis, and finally rotated to + 90 degrees around the X axis. In OpenGL, gltranslatef and glrotatef are used to transform the current local coordinate system: V '= T * r * V, indicating that the local coordinate system is first translated (that is, t ), then rotate the local coordinate system (that is, R ). V '= T * r * V can also be imagined as a coordinate change of point V in the world coordinate system. Note that point V does not have a local coordinate system, there is only one fixed world coordinate system. Every change to point V is based on this fixed world coordinate system.

In, the green XYZ axis is the standard OpenGL axis. First, translate 15 along Z, then turn around the Y axis + 20 degrees, turn to the Black xryrzr coordinate system, and then turn around the X axis to 90 degrees, turns to the final red, X 'y' Z' coordinate system, and the line of sight (Blue Line) is negative to the Z' axis. The bottom layer is always the OpenGL coordinate system, but the upper layer shows the effect of moving the viewpoint to Z = 15 in the Z-up coordinate system, check the tanks z = 8 and Y = 60 at the bottom.

Special note: Camera: setviewmatrix () only changes the viewpoint coordinate system (including the viewpoint coordinate). Other coordinate systems remain unchanged and are still OpenGL coordinate systems. In addition, setviewmatrix (MV) displays the inverse matrix of the MV, so be sure to pay attention to it. You can do this:

Setviewmatrix (inverse (a) * rotates around the X axis-90 degrees). In this way, we can regard a as the Z-up Coordinate System of matrixmanipulator (that is, the Z-up and Y-backward coordinates, line of sight toward the Y axis ). It can be seen that, in the Z-up coordinate system (the line of sight is the y-axis positive, that is, the vertical xz Z plane is in the middle), the viewpoint is transformed by A. At this time, some external transformations can also be seen as the Z-up coordinate system, such as tankxform-> setposition (
OSG: vec3 (, 8); at this time, it is equivalent to moving 8 Up In The Z axis, that is, moving 8 up, and moving 60 on the Y axis, that is, move 60 to the inner.

Remember: The above is just a (imaginary) Z-up coordinate system, but it is still an OpenGL coordinate system. You can only use the OpenGL coordinate system to see it, so as to avoid errors.

 

Summary:

(1) For setviewmatrix (~), It can be analyzed as follows: both the viewpoint V and the coordinate point P of the ry are under OpenGL coordinates, and the viewpoint a (along with the local OpenGL Coordinate System of the viewpoint) is transformed, then let's look at the position of P on a's line of sight.

(2) viewer. getcamera ()-> setviewmatrix (OSG: matrixf: inverse (OSG: matrix: Rotate (OSG: PI/2.0,
1, 0, 0) * r *
T), you can place both the Point of view V and the coordinate point P of the ry under the OSG coordinate, and change the Point of view R * t.

 

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.