Пример #1
0
void CRhGLShaderProgram::SetupViewport(const ON_Viewport& vp)
{
  ON_Xform  mv;
  bool      bHaveModeView = false;
  
  if ( m_Uniforms.rglModelViewProjectionMatrix >= 0 )
  {
    float    ModelViewProjection[16];
    ON_Xform mvp;
    
    vp.GetXform( ON::world_cs, ON::clip_cs, mvp );
    mvp.Transpose();
    
    Mat4Dto4F( &mvp.m_xform[0][0], ModelViewProjection );
    glUniformMatrix4fv( m_Uniforms.rglModelViewProjectionMatrix, 1, GL_FALSE, ModelViewProjection );
  }
    
  if ( m_Uniforms.rglModelViewMatrix >= 0 )
  {
    float  ModelView[16];
    
    vp.GetXform( ON::world_cs, ON::camera_cs, mv );
    mv.Transpose();
    bHaveModeView = true;
    
    Mat4Dto4F( &mv.m_xform[0][0], ModelView );
    glUniformMatrix4fv( m_Uniforms.rglModelViewMatrix, 1, GL_FALSE, ModelView );
  }

  if ( m_Uniforms.rglProjectionMatrix >= 0 )
  {
    float     Projection[16];
    ON_Xform  pr;
  
    vp.GetXform( ON::camera_cs, ON::clip_cs,  pr );
    pr.Transpose();
 
    Mat4Dto4F( &pr.m_xform[0][0], Projection );
    glUniformMatrix4fv( m_Uniforms.rglProjectionMatrix, 1, GL_FALSE, Projection );
  }
 
  if ( m_Uniforms.rglNormalMatrix >= 0 )
  {
    float    NormalMatrix[9];
    
    if ( !bHaveModeView )
    {
      vp.GetXform( ON::world_cs, ON::camera_cs, mv );
      mv.Transpose();
      bHaveModeView = true;
    }
    
    Mat4Dto3F( &mv.m_xform[0][0], NormalMatrix );
    glUniformMatrix3fv( m_Uniforms.rglNormalMatrix, 1, GL_FALSE, NormalMatrix );
  }
}
Пример #2
0
void ON_GL( ON_Viewport& viewport,
            int port_left, int port_right,
            int port_bottom, int port_top
          )
{
  // Sets viewport's port to port_* values and adjusts frustum
  // so it's aspect matches the port's.
  ON_Xform projectionMatrix; // camera to clip transformation

  const int port_width  = abs(port_right - port_left);
  const int port_height = abs(port_top - port_bottom);
  if ( port_width == 0 || port_height == 0 )
    return;
  const double port_aspect = ((double)port_width)/((double)port_height);

  viewport.SetFrustumAspect( port_aspect );

  viewport.SetScreenPort( port_left, port_right, port_bottom, port_top,
                          0, 0xff );

  ON_BOOL32 bHaveCameraToClip = viewport.GetXform( 
                                       ON::camera_cs,  
                                       ON::clip_cs,
                                       projectionMatrix 
                                       );

  if ( bHaveCameraToClip ) {
    projectionMatrix.Transpose();
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixd( &projectionMatrix.m_xform[0][0] );
  }
}
Пример #3
0
ON_BOOL32 ON_Light::GetLightXform( 
         const ON_Viewport& vp,
         ON::coordinate_system dest_cs, 
         ON_Xform& xform 
         ) const
{
  ON::coordinate_system src_cs = CoordinateSystem();
  return vp.GetXform( src_cs, dest_cs, xform );
}
Пример #4
0
void ON_GL( const ON_Viewport& viewport )
{
  // sets model view matrix (world to camera transformation)
  ON_Xform modelviewMatrix; // world to camera transformation
  ON_BOOL32 bHaveWorldToCamera = viewport.GetXform( 
                                       ON::world_cs,  
                                       ON::camera_cs,
                                       modelviewMatrix 
                                       );
  if ( bHaveWorldToCamera ) {
    modelviewMatrix.Transpose();
    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixd( &modelviewMatrix.m_xform[0][0] );
  }
}