Plugin Cafe's original forum is still archived and available for searches. The ability to post here has been disabled.
 
Developer's Forum [PREV] [NEXT]
Subject: RE: GL projections
From: Mikael Sterner
Date: 2/28/2002 2:45 PM GMT
    >On an OpenGL related note ... I've posted this
    >before and got no answer - but does anyone know
    >what camera matrix C4d uses for their OpenGL
    >context (ie I don't think it's the stock standard
    >gluPerspective() .. prob some strange transform
    >matrix using glFrustrum() ) .. I need it to match
    >glFur's camera to cinemas....

    C4D handles the projections itself, so there's no 1:1 correspondence with a GL mode. Here's the reference code for the projections:

    #define CAMDIST 0.05
    
    Vector WorldToCamera(const Vector &p)
    {
      return p*inverse_camera_matrix;
    }
    
    Vector CameraToWorld(const Vector &p)
    {
      return p*camera_matrix;
    }
    
    Vector CameraToScreen(const Vector &pp)
    {
      Vector p = pp;
    
      if (projection==Pperspective)
      {
        Real nz = p.z<=0.0 ? 1.0/CAMDIST : 1.0/(p.z + CAMDIST);
        p.x = p.x*scale.x*nz+off.x;
        p.y = p.y*scale.y*nz+off.y;
        return p;
      }
    
      p.x = (p.x*scale.x)+off.x;
      p.y = (p.y*scale.y)+off.y;
    
      switch (projection)
      {
        case Pmilitary:  case Pfrog: case Pbird: case Pgentleman:
          p.x += p.z*scale.x*scalez.x;
          p.y -= p.z*scale.y*scalez.y;
          break;
      }
    
      return p;
    }
    
    Vector ScreenToCamera(const Vector &pp)
    {
      Vector p = pp;
    
      switch (projection)
      {
        case Pmilitary:  case Pfrog:  case Pbird: case Pgentleman:
          p.x -= p.z*scale.x*scalez.x;
          p.y += p.z*scale.y*scalez.y;
          break;
      }
    
      p.x = (p.x-off.x)/scale.x;
      p.y = (p.y-off.y)/scale.y;
    
      if (projection==Pperspective)
      {
        Real nz = p.z + CAMDIST;
        p.x *= nz;
        p.y *= nz;
      }
      return p;
    }
    


    For non-axometric projection here's the code how to calculate off/scale:

    void InitView(BaseObject *camera, Real xres, Real yres, Real pix_x, Real pix_y)
    {
      // xres/yres are the resolution
      // pix_x/pix_y are the pixel aspect ratio (normally 1:1)
    
      Matrix opm = camera->GetMg();
      Real ap;
      BaseContainer data = camera->GetDataInstance();
    
      projection=data.GetLong(CAMERA_PROJECTION,Pperspective);
      if (projection!=Pperspective && projection!=Pparallel)
      {
        opm.v1 = Vector(1.0,0.0,0.0);
        opm.v2 = Vector(0.0,1.0,0.0);
        opm.v3 = Vector(0.0,0.0,1.0);
      }
    
      off.x = xres*0.5;
      off.y = yres*0.5;
    
      if (b_ab==Pperspective)
      {
        ap=data.GetReal(CAMERAOBJECT_APERTURE,36.0);
        scale.x = data.GetReal(CAMERA_FOCUS,36.0) / ap * xres;
      }
      else
        scale.x = xres/1024.0*data.GetReal(CAMERA_ZOOM,1.0);
    
      scale.y = -scale.x*pix_x/pix_y;
    }
    


    Mikael Sterner
    Developer Support
Current Message String
new export to opengl friendly format - lime - 2/27/2002 10:09 AM GMT
 new RE: export to opengl friendly format - darkness - 2/27/2002 10:23 AM GMT
 new RE: export to opengl friendly format - paul Everett - 2/27/2002 10:52 AM GMT
 new RE: export to opengl friendly format - darkness - 2/28/2002 3:26 AM GMT
 new RE: GL projections - Mikael Sterner - 2/28/2002 2:45 PM GMT
 new RE: GL projections - darkness - 3/1/2002 2:17 AM GMT
[PREV] [NEXT]