Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////////////
// draw bottom window (3rd person view)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::drawSub2()
{
    // set bottom viewport
    setViewportSub(0, 0, windowWidth, windowHeight/2, 1, 100);

    // clear buffer
    glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]);   // background color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glPushMatrix();

    // First, transform the camera (viewing matrix) from world space to eye space
    glTranslatef(0, 0, -cameraDistance);
    glRotatef(cameraAngleX, 1, 0, 0); // pitch
    glRotatef(cameraAngleY, 0, 1, 0); // heading

    // draw grid
    drawGrid(10, 1);

    // draw balls
    drawSpheres();

    // draw the camera
    glPushMatrix();
    glTranslatef(0, 0, 7);
    drawCamera();
    drawFrustum(projectionLeft, projectionRight, projectionBottom, projectionTop, projectionNear, projectionFar);
    glPopMatrix();

    glPopMatrix();
}
Exemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////
// draw upper window (view from the camera)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::drawSub1()
{
    // set upper viewport
    setViewportSub(0, windowHeight/2, windowWidth, windowHeight/2, 1, 10);

    // clear buffer
    glClearColor(0.1f, 0.1f, 0.1f, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glPushMatrix();

    // set view matrix ========================================================
    // copy the matrix to OpenGL GL_MODELVIEW matrix
    // Note that OpenGL uses column-major matrix, so transpose the matrix first
    // See updateViewMatrix() how matrixView is constructed. The equivalent
    // OpenGL calls are;
    //    glLoadIdentity();
    //    glRotatef(-cameraAngle[2], 0, 0, 1); // roll
    //    glRotatef(-cameraAngle[1], 0, 1, 0); // heading
    //    glRotatef(-cameraAngle[0], 1, 0, 0); // pitch
    //    glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);
    glLoadMatrixf(matrixView.getTranspose());

    // always draw the grid at the origin (before any modeling transform)
    drawGrid(10, 1);

    // transform objects ======================================================
    // From now, all transform will be for modeling matrix only.
    // (from object space to world space)
    // See updateModelMatrix() how matrixModel is constructed. The equivalent
    // OpenGL calls are;
    //    glLoadIdentity();
    //    glTranslatef(modelPosition[0], modelPosition[1], modelPosition[2]);
    //    glRotatef(modelAngle[0], 1, 0, 0);
    //    glRotatef(modelAngle[1], 0, 1, 0);
    //    glRotatef(modelAngle[2], 0, 0, 1);

    // compute GL_MODELVIEW matrix by multiplying matrixView and matrixModel
    // before drawing the object:
    // ModelView_M = View_M * Model_M
    // This modelview matrix transforms the objects from object space to eye space.
    // copy modelview matrix to OpenGL after transpose
    glLoadMatrixf(matrixModelView.getTranspose());

    // draw a teapot after ModelView transform
    // v' = Mmv * v
    drawAxis(4);
    drawTeapot();

    glPopMatrix();
}
Exemplo n.º 3
0
///////////////////////////////////////////////////////////////////////////////
// draw bottom window (3rd person view)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::drawSub2()
{
    // set bottom viewport
    setViewportSub(0, 0, windowWidth, windowHeight/2, NEAR_PLANE, FAR_PLANE);

    // clear buffer
    glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]);   // background color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glPushMatrix();

    // First, transform the camera (viewing matrix) from world space to eye space
    glTranslatef(0, 0, -cameraDistance);
    glRotatef(cameraAngleX, 1, 0, 0); // pitch
    glRotatef(cameraAngleY, 0, 1, 0); // heading

    // draw grid
    drawGrid(10, 1);

    // draw a teapot
    glPushMatrix();
    glTranslatef(modelPosition[0], modelPosition[1], modelPosition[2]);
    glRotatef(modelAngle[0], 1, 0, 0);
    glRotatef(modelAngle[1], 0, 1, 0);
    glRotatef(modelAngle[2], 0, 0, 1);
    drawAxis(4);
    drawTeapot();
    glPopMatrix();

    // draw the camera
    glPushMatrix();
    glTranslatef(cameraPosition[0], cameraPosition[1], cameraPosition[2]);
    glRotatef(cameraAngle[0], 1, 0, 0);
    glRotatef(cameraAngle[1], 0, 1, 0);
    glRotatef(cameraAngle[2], 0, 0, 1);
    drawCamera();
    drawFrustum(FOV_Y, 1, 1, 10);
    glPopMatrix();

    glPopMatrix();
}
Exemplo n.º 4
0
///////////////////////////////////////////////////////////////////////////////
// draw upper window (view from the camera)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::drawSub1()
{
    // set upper viewport
    setViewportSub(0, windowHeight/2, windowWidth, windowHeight/2, projectionLeft, projectionRight, projectionBottom, projectionTop, projectionNear, projectionFar);

    // get matrix
    glGetFloatv(GL_PROJECTION_MATRIX, matrixProjection);

    // clear buffer
    glClearColor(0.1f, 0.1f, 0.1f, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // initialze ModelView matrix
    glPushMatrix();
    glLoadIdentity();

    // view transform
    glTranslatef(0, 0, -7);

    drawSpheres();

    glPopMatrix();
}
Exemplo n.º 5
0
///////////////////////////////////////////////////////////////////////////////
// draw upper window (view from the camera)
///////////////////////////////////////////////////////////////////////////////
void ModelGL::drawSub1()
{
    // set upper viewport
    setViewportSub(0, windowHeight/2, windowWidth, windowHeight/2, 1, 10);

    // clear buffer
    glClearColor(0.1f, 0.1f, 0.1f, 1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // initialze ModelView matrix
    glPushMatrix();
    glLoadIdentity();

    // ModelView matrix is product of viewing matrix and modeling matrix
    // ModelView_M = View_M * Model_M
    // First, transform the camera (viewing matrix) from world space to eye space
    // Notice all values are negated, because we move the whole scene with the
    // inverse of camera transform
    glRotatef(-cameraAngle[2], 0, 0, 1); // roll
    glRotatef(-cameraAngle[1], 0, 1, 0); // heading
    glRotatef(-cameraAngle[0], 1, 0, 0); // pitch
    glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);

    // we have set viewing matrix upto this point. (Matrix from world space to eye space)
    // save the view matrix only
    glGetFloatv(GL_MODELVIEW_MATRIX, matrixView); // save viewing matrix
    //=========================================================================


    // always draw the grid at the origin (before any modeling transform)
    drawGrid(10, 1);

    // In order to get the modeling matrix only, reset GL_MODELVIEW matrix
    glLoadIdentity();

    // transform the object
    // From now, all transform will be for modeling matrix only. (transform from object space to world space)
    glTranslatef(modelPosition[0], modelPosition[1], modelPosition[2]);
    glRotatef(modelAngle[0], 1, 0, 0);
    glRotatef(modelAngle[1], 0, 1, 0);
    glRotatef(modelAngle[2], 0, 0, 1);

    // save modeling matrix
    glGetFloatv(GL_MODELVIEW_MATRIX, matrixModel);
    //=========================================================================


    // re-strore GL_MODELVIEW matrix by multiplying matrixView and matrixModel before drawing the object
    // ModelView_M = View_M * Model_M
    glLoadMatrixf(matrixView);              // Mmv = Mv
    glMultMatrixf(matrixModel);             // Mmv *= Mm

    // save ModelView matrix
    glGetFloatv(GL_MODELVIEW_MATRIX, matrixModelView);
    //=========================================================================


    // draw a teapot after ModelView transform
    // v' = Mmv * v
    drawAxis(4);
    drawTeapot();

    glPopMatrix();
}