Jump to content
  • Advertisement
Sign in to follow this  
rogerdv

improving ms3d tutorial

This topic is 4623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!