Dear Fltk friends,
I'm trying to write a very little 3D engine, to use it for
a very very simple CAD (points, lines, planes, axis and
opengl triangles or quads) and Kinematic simulator(with 2
kind of links, prismatic and revolution, You can simulate
99% of numerical control machines).

I am not sure wath may be the best way to manage scaling,
including the ratio between w() and h() of the Fl_Gl_Window.

My first try is to do most in the MODELVIEW matrix, as You
can read in "The camera analogy" (a paper from SGI).

My need is to have the maximum precision (specially in the
rotation part of the matrix), for objects that may go from
mm 100 to mm 10000.

Any comment is welcome!
Giovanni Rosso, Rome, Italy.

Here is my actual try (from draw function of the Fl_Gl_Window):

  if(!valid())
  {
  valid(1);

  // ****************
  // *** Reshape: ***
  // ****************

  glViewport(0, 0, (GLsizei)w(), (GLsizei)h());
  ratio = (double)w() / (double)h();

  // *** xyz_fact will be used to scale MODELVIEW matrix:
  xyz_fact[0]=2.0/((double)w()*0.005);
  xyz_fact[1]=2.0/((double)h()*0.005);
  xyz_fact[2]=xyz_fact[1];
  flg_scl=1;

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, 5000, -5000);

  // *******************
  // *** End Reshape ***
  // *******************
  }
..
..
..
// ***********************************************
// *** begin GL_MODELVIEW transformations: *******
// ***********************************************
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // *** Transl in Identity coords:
  glTranslated(pt_traslMDV_id[0] ,pt_traslMDV_id[1], pt_traslMDV_id[2]);

  if(flg_scl) // *** if scale factor changed ...
    {
    scl_xyz[0]=xyz_fact[0]*scl_fact;
    scl_xyz[1]=xyz_fact[1]*scl_fact;
    scl_xyz[2]=xyz_fact[2]*scl_fact;
    }

  glScaled(scl_xyz[0], scl_xyz[1], scl_xyz[2]);

  // *** applying rotation matrix
  // *** (mtrx_MDV_rot is only rotation, no transl, no scale):
  glMultMatrixd(mtrx_MDV_rot);

  if(flg_rot) // *** if rotation changed ...
    {
    // *** Transl to the new rotation point, that may be different
    // *** from MODELVIEW matrix origin. This transl after transl
    // *** in identity coords, scaling and rotating:
    glTranslated(pt_traslrot[0], pt_traslrot[1], pt_traslrot[2]);

    glGetDoublev(GL_MODELVIEW_MATRIX, mtrx_MDV);

    // *** The new rotation point, transformed
    // *** in MODELVIEW matrix identity:
    Vec3XMatr33(pt_zero, mtrx_MDV, pt_tmp);
    pt_traslrotMDV_id[0] = pt_tmp[0] + mtrx_MDV[12];
    pt_traslrotMDV_id[1] = pt_tmp[1] + mtrx_MDV[13];
    pt_traslrotMDV_id[2] = pt_tmp[2] + mtrx_MDV[14];

    // *** Appling new rotation to mtrx_MDV_rot:
    glLoadMatrixd(mtrx_MDV_rot);
    glRotated(angvers, vers_cross[0], vers_cross[1], vers_cross[2]);
    glGetDoublev(GL_MODELVIEW_MATRIX, mtrx_MDV_rot);

    // *** Re-doing transl(on new rotation point,
    // *** in MODELVIEW matrix identity),
    // *** scaling and appling new rotation:
    glLoadIdentity();
    glTranslated(pt_traslrotMDV_id[0], pt_traslrotMDV_id[1], 
pt_traslrotMDV_id[2]);
    glScaled(scl_xyz[0], scl_xyz[1], scl_xyz[2]);
    glMultMatrixd(mtrx_MDV_rot);

    // *** Inverse transl from rotation point, to render objects
    // *** in coords from MODELVIEW matrix origins:
    glTranslated(-pt_traslrot[0], -pt_traslrot[1], -pt_traslrot[2]);
    }

  // *** Preparation of the next point for transl origins
  // *** of MODELVIEW_MATRIX, in Identity coords:
  glGetDoublev(GL_MODELVIEW_MATRIX, mtrx_MDV_act);
  Vec3XMatr33(pt_zero, mtrx_MDV_act, pt_tmp);
  pt_traslMDV_id[0]= pt_tmp[0]+mtrx_MDV_act[12];
  pt_traslMDV_id[1]= pt_tmp[1]+mtrx_MDV_act[13];
  pt_traslMDV_id[2]= pt_tmp[2]+mtrx_MDV_act[14];

// ***********************************************
// *** End of GL_MODELVIEW transformations: ******
// ***********************************************

_______________________________________________
fltk-opengl mailing list
fltk-opengl@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-opengl

Reply via email to