Skip to main content
gamedev.net
🔒 Locked

improving ms3d tutorial

Started by rogerdv Jan 20, 2006 at 6:54 AM 6 replies 1.5k views
Original Post
rogerdv
rogerdv
I haven been trying to adapt the ms3d animation loading tutorial to integrate it in my project. But when I try to change the draw() function to render the model in a given coordinate I got a deformed model because of textures being mappeg wrong. Can somebody give me an idea about how to solve this problem?
eSCHEn
eSCHEn
Hmm, not really a lot of information to go on there rogerdv. Could you post your draw() function in [#source]CODE IN HERE[#/source] tags (removing the hashes of course) and a screenshot of what is happening?
--
Cheers,
Darren Clark
rogerdv
rogerdv
Sorry for the lack of screenshots, I took 4, but for some reason the application windows is too dark and you cant notice the problem. Here is the draw() function:

void Model::draw(float x, float y, float z) {    float tmpvec[3];        //Temporary vector                    // { NEW }    advanceAnimation();                    // { end NEW }    GLboolean texEnabled = glIsEnabled( GL_TEXTURE_2D );    // Draw by group    for ( int i = 0; i < m_numMeshes; i++ )    {        int materialIndex = m_pMeshes.m_materialIndex;        if ( materialIndex >= 0 )        {            glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient );            glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse );            glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular );            glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive );            glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );            if ( m_pMaterials[materialIndex].m_texture > 0 )            {                glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture );                glEnable( GL_TEXTURE_2D );            }            else                glDisable( GL_TEXTURE_2D );        }        else        {            // Material properties?            glDisable( GL_TEXTURE_2D );        }        glBegin( GL_TRIANGLES );        {            for ( int j = 0; j < m_pMeshes.m_numTriangles; j++ )            {                int triangleIndex = m_pMeshes.m_pTriangleIndices[j];                const Triangle* pTri = &m_pTriangles[triangleIndex];                for ( int k = 0; k < 3; k++ )                {                    int index = pTri->m_vertexIndices[k];                    // { NEW }                    if ( m_pVertices[index].m_boneID == -1 )                    {                        // same as before                        glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );                        glNormal3fv( pTri->m_vertexNormals[k] );                        /**Added by me: adjust to coordinates*/                        tmpvec[0]=m_pVertices[index].m_location[0]+x;                        tmpvec[1]=m_pVertices[index].m_location[1]+y;                        tmpvec[2]=m_pVertices[index].m_location[2]+z;                        glVertex3fv( tmpvec );                        // end of added by me                         //////Original drawing line                        //glVertex3fv( m_pVertices[index].m_location );                    }                    else                    {                        // rotate according to transformation matrix                        const Matrix& final = m_pJoints[m_pVertices[index].m_boneID].m_final;                        glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );                        Vector newNormal( pTri->m_vertexNormals[k] );                        newNormal.transform3( final );                        newNormal.normalize();                        glNormal3fv( newNormal.getVector());                                                /**Added by me: adjust to coordinates*/                        tmpvec[0]=m_pVertices[index].m_location[0]+x;                        tmpvec[1]=m_pVertices[index].m_location[1]+y;                        tmpvec[2]=m_pVertices[index].m_location[2]+z;                        Vector newVertex( tmpvec );                          ///End of added by me                           ////////////Original line                                              //Vector newVertex( m_pVertices[index].m_location );                        newVertex.transform( final );                        glVertex3fv( newVertex.getVector());                    }                    // { end NEW }                }            }        }        glEnd();    }    if ( texEnabled )        glEnable( GL_TEXTURE_2D );    else        glDisable( GL_TEXTURE_2D );}


I confirmed that the drawing method works, by testing an untextured mesh.
eSCHEn
eSCHEn
Hmm, looks fine to me. Not went through it with a fine tooth comb but nothing seems to be glaringly obvious. These kinds of errors can be tricky to pin down without a screenshot, is there no way you can boost the gamma using your video driver control panel and get a better shot?
--
Cheers,
Darren Clark
rogerdv
rogerdv
Well, I fixed the problem with gimp.
Here is the good model:


And here is the bad one.


When I try the model without skin, it is drawn correctly, so, my relocation code is working, but the texture mapping is still applied using model coordinates, not the final ones.
silvermace
silvermace
to be quite honest, that looks like geometry deformation. Disabling the texturing code doesn't neccessarily mean that thats where the problem lies.

from that screenshot, I'd make a guess at out-of-bounds access into the vertex array, or the API reading from a point inside the VA and crossing boundaries into one of the other arrays (Colour, Texture etc) - are all your data arrays in contiguous space?

EDIT: It's hard to see whats going on, maybe supplying a small demo to download so that we can take a hands on look? I can provide some temporary hosting if need be.
relpats_eht
relpats_eht
Or, you could try undoing your changes, and just adding glTranslatef(x, y, z) at the top of the draw function and glTranslatef(-x, -y, -z) at the bottom of the draw function.
relpats_eht

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.