Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: setting up camera/viewing/perspective correctly

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2007
    Posts
    4

    setting up camera/viewing/perspective correctly

    Hello,
    First POST here and new to OpenGL so please be gentle with me.

    What I want to do is to plot three lines that are NOT rotated and at 90 degress to each other so as you may guess I can only see to of the but that is fine as I will do the rotation of the line at a later time. But what I am trying to do is to setup a viewing/camera angle so I can see all three, the snippet below is the product of much trial and error and little understanding so can someone help me please with a how to setup camera/viewing/perspective some the vector are plotted in the centre of viewport and can be seen correctly.

    Many thanks in advance IMK


    void COGLPLOT_1View::OnSize(UINT nType, int cx, int cy)
    {
    CView::OnSize(nType, cx, cy);

    if(cy > 0)
    {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, cx , cy );

    gluPerspective( 45.0f, (GLdouble)cx/cy , 1.0, 100 );
    gluLookAt( 3, 3, 5 , 1 , 1 , -2.5 , 0.0 , 1.0 , 0.0 );

    glMatrixMode(GL_MODELVIEW);
    }
    }
    void COGLPLOT_1View:rawAccelerometerOrientation( double X, double Y, double Z )
    {
    float Axis_wAngleX = (float)X;
    float Axis_wAngleY = (float)Y;
    float Axis_wAngleZ = (float)Z;

    glPushMatrix();

    glTranslatef( 0.0f, 0.0f, -m_fRadius);
    glRotatef(Axis_wAngleX, 1.0, 0.0, 0.0);
    glRotatef(Axis_wAngleY, 0.0, 1.0, 0.0);
    glRotatef(Axis_wAngleZ, 0.0, 0.0, 1.0);


    glEnable( GL_POINT_SMOOTH );

    glLineWidth( 5.0 );

    glBegin(GL_LINES);

    // Plot the Accelerometer X Axis
    glColor3f( 1.0,0.0,0.0);
    glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, 0.0f, -3.0f);

    // Plot the Accelerometer Y Axis
    glColor3f(0.9f,1.0,0.0);
    glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(-3.0f, 0.0f, 0.0f);

    // Plot the Accelerometer Z Axis
    glColor3f(0.0f, 1.0f, 0.0f); // Green
    glVertex3f(0.0f, 0.0f, 0.0f); glVertex3f(0.0f, -3.0f, 0.0f);

    glEnd();
    glPopMatrix();
    }

  2. #2
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    Re: setting up camera/viewing/perspective correctly

    First, I believe you should call
    glMatrixMode(GL_MODELVIEW);
    before calling gluLookAt(). Since all it does is call glMultMatrixf and glTranslate according to:
    http://www.opengl.org/documentation/...lu/lookat.html
    In your case you're multiplying the projection matrix, where you really want to multiply the modelview matrix.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2007
    Posts
    4

    Re: setting up camera/viewing/perspective correctly

    Budric many thanks for you input I have done as your post and it has made no difference to what is now on the screen. I have something working but I must say it is more by trial and error than any kind of understanding. Do you know of a good tutorial on the web, one that is more practical.. Basically how you do stuff rather than the theory behind it all as I have enough on trying to figure out the accelerometer data that I want to plot.

    Again many thanks IMK

    void COGLPLOT_1View::OnSize(UINT nType, int cx, int cy)
    {
    CView::OnSize(nType, cx, cy);

    if(cy > 0)
    {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glViewport(0, 0, cx , cy );

    glMatrixMode(GL_MODELVIEW);
    gluPerspective( 30.0f, (GLdouble)cx/cy , 1.0, 100 );
    gluLookAt( 10, 5, 5 , 1 , 0.75 , -5.5 , 0.0 , 1.0 , 0.0 );
    //glMatrixMode(GL_MODELVIEW);
    }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •