Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In my game I have model loading functions for Assimp model loading library. I can load the model and render it, but the model displays incorrectly. The models load in as if they were using a seperate projection matrix. I have looked over my code over and over again, but I probably keep on missing the obvious reason why this is happening.

Here is an image of my game: Misshaped cube

It's simply a 6 sided cube, but it's off big time!

Here are my code snippets for rendering the cube to the screen:

void C_MediaLoader::display(void)
{
    float tmp;

    glTranslatef(0,0,0);
    // rotate it around the y axis
    glRotatef(angle,0.f,0.f,1.f);
    glColor4f(1,1,1,1);

    // scale the whole asset to fit into our view frustum 
    tmp = scene_max.x-scene_min.x;
    tmp = aisgl_max(scene_max.y - scene_min.y,tmp);
    tmp = aisgl_max(scene_max.z - scene_min.z,tmp);
    tmp = (1.f / tmp);
    glScalef(tmp/5, tmp/5, tmp/5);

    // center the model
    //glTranslatef( -scene_center.x, -scene_center.y, -scene_center.z );
    // if the display list has not been made yet, create a new one and
    // fill it with scene contents
    if(scene_list == 0) {
        scene_list = glGenLists(1);
        glNewList(scene_list, GL_COMPILE);
            // now begin at the root node of the imported data and traverse
            // the scenegraph by multiplying subsequent local transforms
            // together on GL's matrix stack.
        recursive_render(scene, scene->mRootNode);
        glEndList();
    }
    glCallList(scene_list);
}



void C_MediaLoader::recursive_render (const struct aiScene *sc, const struct aiNode* nd)
{
    unsigned int i;
    unsigned int n = 0, t;
    struct aiMatrix4x4 m = nd->mTransformation;

    // update transform
    aiTransposeMatrix4(&m);
    glPushMatrix();
    glMultMatrixf((float*)&m);

    // draw all meshes assigned to this node
    for (; n < nd->mNumMeshes; ++n) {
        const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];

        apply_material(sc->mMaterials[mesh->mMaterialIndex]);

        if(mesh->mNormals == NULL) {
            glDisable(GL_LIGHTING);
        } else {
            glEnable(GL_LIGHTING);
        }

        for (t = 0; t < mesh->mNumFaces; ++t) {
            const struct aiFace* face = &mesh->mFaces[t];
            GLenum face_mode;

            switch(face->mNumIndices) {
                case 1: face_mode = GL_POINTS; break;
                case 2: face_mode = GL_LINES; break;
                case 3: face_mode = GL_TRIANGLES; break;
                default: face_mode = GL_POLYGON; break;
            }

            glBegin(face_mode);

            for(i = 0; i < face->mNumIndices; i++) {
                int index = face->mIndices[i];

                if(mesh->mColors[0] != NULL)
                    glColor4fv((GLfloat*)&mesh->mColors[0][index]);

                if(mesh->mNormals != NULL) 
                    glNormal3fv(&mesh->mNormals[index].x);

                glVertex3fv(&mesh->mVertices[index].x);
            }

            glEnd();
        }
    }
    // draw all children
    for (n = 0; n < nd->mNumChildren; ++n) {
        recursive_render(sc, nd->mChildren[n]);
    }
    glPopMatrix();
}

Sorry there is so much code to look through, but I really cannot find the problem, and I would love to have help.

share|improve this question
    
Debug it, make sure it's using the correct face_mode and check to make sure all the indices are getting added. –  Byte56 Mar 28 '12 at 4:39
    
I've already done that, in ANY mode it has the exact same effect as seen in the image. –  Brendan Webster Mar 28 '12 at 4:41
    
Really. If face_mode is set to GL_POINTS, it shows a deformed cube the the one you have in your image? –  Byte56 Mar 28 '12 at 4:43
    
not exactly, but it does the same thing, where it is smaller and get's larger the farther it is in the z axis –  Brendan Webster Mar 28 '12 at 4:44
2  
It looks like you just have some really weird perspective going on. How are you setting up your view and projection matrices? –  Jason Morales Mar 28 '12 at 8:26
show 12 more comments

1 Answer

up vote 5 down vote accepted

Turns out this was an issue with my perspective, I was able to solve my problem by setting the gluPerspective correctly:

void C_MediaLoader::display(void)
{
    glLoadIdentity();
    gluPerspective(45, 640/480,
        1.0, 1000.0);  /* Znear and Zfar */

    // remainder code is the same as before...
}

Thanks for everyone's help!

share|improve this answer
    
You should post a little more detail about how you solved the problem instead of what you have here. –  Byte56 Mar 28 '12 at 18:36
    
OK, I just added in the extra details –  Brendan Webster Mar 28 '12 at 18:43
2  
I edited your post to better reflect the answer. Remember to accept your answer when you're able. –  Byte56 Mar 28 '12 at 20:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.