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 10 of 12

Thread: rotating large models

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Nov 2013
    Posts
    30

    rotating large models

    I am writing what I intend to be an Open Source implementation of NASTRAN. My sample model has 5,000 lines, 5,000 triangles, 10,000 quadrilaterals and 10,000 points. I am trying to rotate the model by dragging the mouse. It works very nicely for small models: I can rotate the model to the desired viewing angle prior to releasing the mouse. My problem is that the program tries to write the entire model for each glutMotionFunc() call.

    Is there some way to force a swapbuffer/purge at the instant of glutMotionFunc() call? The model will still be incomplete, but the viewer can still get feedback on the current rotation angles.

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    12
    Am i being stupid or are you unable to just use glRotate(); to rotate the model to the desired angle?

  3. #3
    Intern Newbie
    Join Date
    Nov 2013
    Posts
    30
    void move(int x, int y){ // creates dynamic display from mouse drag
    int dx, dy, dz;
    dx = downx -x; dy = downy - y;
    glutSwapBuffers();
    glMatrixMode(GL_MODELVIEW);
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glColor3f(1.0, 0.3, 0.3);
    glOrtho( ...
    glPushMatrix();
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(ctrx, ctry, ctrz);

    glRotatef((theta -90*dy/WindowHeight), 0.0, 1.0, 0.0);
    glRotatef((phi -90*dx/WindowWidth), 1.0, 0.0, 0.0)

    glTranslatef(-ctrx, -ctry, -ctrz);
    model(); //generates model
    glPopMatrix();
    glutSwapBuffers();
    }
    int main(...
    glutMotionFunc(move);

    As I said, the problem is the size of the model. On my machine, it takes about two seconds to generate the model. With a smaller model (e.g. the teapot), it rotates in real time as I drag the mouse.

    Quote Originally Posted by joehot200 View Post
    Am i being stupid or are you unable to just use glRotate(); to rotate the model to the desired angle?

  4. #4
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    345
    It looks from your code like you're rebuilding the model every time you move it. You don't need to do this unless the model itself is deforming, and this is the source of your performance loss. Generate the model once and store it in vertex buffer objects (VBOs; modern way), or a display list (older GL way). Then just do your matrix transformations, draw using the buffers or list, and it should transform much faster.

  5. #5
    Intern Newbie
    Join Date
    Nov 2013
    Posts
    30
    I have not learned to use VBOs, Example 2-28 in OpenGL Programming Guide 7th ed. mentions VBOs, but what I see is VAOs loaded into the kernel via glDrawElements(PrimType[i], NumElements[i], GL_UNSIGNED_BYTE, BUFFER_OFFSET(0); Am I on the right track?

    Quote Originally Posted by malexander View Post
    It looks from your code like you're rebuilding the model every time you move it. You don't need to do this unless the model itself is deforming, and this is the source of your performance loss. Generate the model once and store it in vertex buffer objects (VBOs; modern way), or a display list (older GL way). Then just do your matrix transformations, draw using the buffers or list, and it should transform much faster.

  6. #6
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    40
    Let's see what's happening inside the model() function

Posting Permissions

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