Editing User:Hg200
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
= OpenGL coordinate systems = | = Investigations on update_camera() = | ||
In the second part of <math display="inline">\rightarrow</math> "axes::properties::update_camera ()" the view transformation "x_gl_mat1" and projection matrix "x_gl_mat2" are put together. The following article illustrates some of the properties of "x_gl_mat1" and "x_gl_mat2". | |||
== OpenGL coordinate systems == | |||
In the Octave plotting backend, we find various OpenGL transformations. Some of the classic OpenGL transformation steps, as well as coordinate systems, are shown in the following picture: | In the Octave plotting backend, we find various OpenGL transformations. Some of the classic OpenGL transformation steps, as well as coordinate systems, are shown in the following picture: | ||
Line 5: | Line 9: | ||
[[File:Octave_coordinate_systems.png|center|350px]] | [[File:Octave_coordinate_systems.png|center|350px]] | ||
= The Octave coordinate system = | == The Octave coordinate system == | ||
In Octave a plot scene is defined by a "view point", a "camera target" and an "up vector". | In Octave a plot scene is defined by a "view point", a "camera target" and an "up vector". | ||
[[File:Octave_view_point_setup_to_scale.png|center|750px]] | [[File:Octave_view_point_setup_to_scale.png|center|750px]] | ||
== The role of "x_gl_mat1" == | == The role of "x_gl_mat1" == | ||
The following section of code composes the matrix "x_view", which is a | The following section of code composes the matrix "x_view", which is a subset of "x_gl_mat1". The matrix "x_gl_mat1" consists of multiple translations, scales and one rotation operation. | ||
{{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | {{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | ||
Line 57: | Line 56: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
To visualize the matrix properties, the "x_gl_mat1" matrix is multiplied by the object coordinates. The plot box is now aligned with the Z-axis and the view point is at the origin <math display="inline">[0,0,0]</math>. The matrix transforms world coordinates into camera coordinates. The purple planes show the near and far clipping planes. | |||
[[File:Octave_x_gl_mat1_setup.png|center|250px]] | |||
[[File:Octave_x_gl_mat1_setup.png|center| | |||
The individual translation, scaling and rotation operations of "x_gl_mat1", are shown in the following figure: | The individual translation, scaling and rotation operations of "x_gl_mat1", are shown in the following figure: | ||
Line 69: | Line 66: | ||
== The role of "x_gl_mat2" == | == The role of "x_gl_mat2" == | ||
The matrix "x_gl_mat2" is composed of the sub matrices "x_viewport" and "x_projection". The purpose of these matrices is to fit the 2D image of the above transformation result into a "bounding box". The bounding box is defined as follows: | |||
The matrix "x_gl_mat2" is composed of the sub matrices "x_viewport" and "x_projection". The purpose of these matrices is to fit the | |||
bb(0), bb(1): Position of the "viewport" | |||
bb(2), bb(3): Width and height of the "viewport" | |||
Hint: If you debug in "update_camera ()", you can print "bb": | Hint: If you debug in "update_camera ()", you can print "bb": | ||
(gdb) print *bb.rep.data@bb.rep.len | (gdb) print *bb.rep.data@bb.rep.len | ||
Compare the result with the output | Compare the result with the output in the Octave prompt: | ||
hax = axes (); | hax = axes (); | ||
get (hax, "position") | get (hax, "position"); | ||
In the following simplified code section, the field of view (FOV) is determined such that the image is fitted into the bounding box of the window: | |||
In the following simplified code section | |||
{{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | {{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | ||
Line 118: | Line 105: | ||
v_angle = get_cameraviewangle (); | v_angle = get_cameraviewangle (); | ||
// Calculate backwards from the angle to the ratio. This step | // Calculate backwards from the angle to the ratio. This step | ||
// is necessary because "v_angle" can be set manually. | // is necessary because "v_angle" can be set manually. | ||
Line 127: | Line 112: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
"x_viewport" is a 2D transformation used to place the "normalized" plot box in the center of the bounding box: | |||
"x_viewport" is a transformation used to place the | |||
{{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | {{Code|Section of axes::properties::update_camera ()"|<syntaxhighlight lang="C" style="font-size:13px"> | ||
Line 143: | Line 126: | ||
pix = (bb(2) < bb(3) ? bb(2) : bb(3)); | pix = (bb(2) < bb(3) ? bb(2) : bb(3)); | ||
// Move to the center of the bounding box inside the figure. | // Move to the center of the bounding box inside the figure. | ||
translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); | translate (x_viewport, bb(0)+bb(2)/2, bb(1)+bb(3)/2, 0); | ||
Line 153: | Line 134: | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
Note: The matrix | Note: The projection matrix just scales x, y so that the image fits tightly into the bounding box. The z-coordinate is not modified! | ||