Пример #1
0
void t_screen::gl_init(int w, int h)
{
    glViewport(0,0, w,h);
    
    glEnable(GL_TEXTURE_2D);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    width= w; height= h;
    
    rebuildtextures();
    if(ortho) setortho();
    else setperspective();
    
    flux_screenresize(w, h);
}
Пример #2
0
Файл: main.c Проект: damora/ivr
void initcamera()
{

    // initialize view (u,v,n) in world coordinates
    vrp.x = vrp.y = vrp.z = 0.0f;
    dir.x = 0.0f;
    dir.y = 0.0f;
    dir.z = -1.0f;
    up.x = 0.0f;
    up.y = 1.0f;
    up.z = 0.0f;

    // initialize viewvolume in image plane (assumes that imageplane reference point is 0,0,0)
    // adjust so we have same aspect ratio as window
    float fwidth = FRUSTUMWIDTH;
    float fheight = FRUSTUMHEIGHT;
    float aspect;
    if (viewport.w > viewport.h) {
        aspect = (float) viewport.w/viewport.h;
        fwidth = fwidth * aspect;
    }
    else {
        aspect = (float) viewport.h/viewport.w;
        fheight = fheight * aspect;
    }
    frustum.bottom = -fheight/2.0f;
    frustum.top = -frustum.bottom;
    frustum.left = -fwidth/2.0f;
    frustum.right = -frustum.left;

    // initialize eyepos origin
#ifdef ORTHO
    e.u = 0.0f;
    e.v = 0.0f;
    e.n = -10000.0f; 	//ORTHO
    frustum.near = -2.0f;
    frustum.far = 2.0f;
#else
    e.u = 0.0f;
    e.v = 0.0f;
    e.n = -5.0f;		// PERSPECTIVE
    frustum.near = 0.1f;
    frustum.far = 100.0f;
#endif

    // initialize viewvolume in image plane (assumes that imageplane reference point is 0,0,0)
    viewvolume.bottom = frustum.bottom;
    viewvolume.left = frustum.left;
    viewvolume.top = frustum.top;
    viewvolume.right = frustum.right;
    viewvolume.far = frustum.far;
    viewvolume.near = frustum.near;


    // set projection matrix
#ifdef ORTHO
    setortho(scale, viewvolume);
#else
    float fovy = 2.0f * atan(frustum.top/-e.n);
    fovy = fovy * DEGREES;

    setperspective(fovy, 1.0f, 0.1f, 100.0f);
#endif

    // initialize view (u,v,n) in world coordinates
    camera.r.x = vrp.x;
    camera.r.y = vrp.y;
    camera.r.z = vrp.z;
    camera.n.x = dir.x;
    camera.n.y = dir.y;
    camera.n.z = dir.z;
    camera.v.x = up.x;
    camera.v.y = up.y;
    camera.v.z = up.z;
    camera.v = normalize3f(camera.v);
    camera.u = cross3f(camera.n, camera.v);
    camera.e.u = e.u;
    camera.e.v = e.v;
    camera.e.n = e.n;

    // set view to world transform matrix
    setvwm(vwm, camera);

    // set world to view transform matrix
    setwvm(wvm, camera);

    // initialize eyepos origin
    eyepos.u = e.u;
    eyepos.v = e.v;
    eyepos.n = e.n;


    return;
}