User:Hg200: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 80: Line 80:
   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 the matrix "x_projection" is assembled. It is used to scale the image of the above transformation into the bounding box of the window. For this purpose, the field of view (FOV) must be calculated:


{{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 105: Line 105:
     v_angle = get_cameraviewangle ();
     v_angle = get_cameraviewangle ();


  // x_projection = diag([1, 1, 1, 1])
  Matrix x_projection = xform_matrix ();
   // 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 126: Line 128:
     pix = (bb(2) < bb(3) ? bb(2) : bb(3));
     pix = (bb(2) < bb(3) ? bb(2) : bb(3));


  // x_viewport = diag([1, 1, 1, 1])
  Matrix x_viewport = xform_matrix ();
   // 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 134: Line 138:
</syntaxhighlight>}}
</syntaxhighlight>}}


Note: The projection matrix just scales x, y so that the image fits tightly into the bounding box. The z-coordinate is not modified!
Note: The matrix just scales x, y so that the image fits tightly into the bounding box. The z-coordinate is not modified.