Jump to content
  • Advertisement
Sign in to follow this  
kubapl

Winding / still some model issues

This topic is 3743 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

Hey so Ive been still working on this 3d loader in my spare time. The latest functionality that has been added is that multiple keys can be pressed, and once a key is pressed movement starts right away. Anyways the problem that I'd like to fix now is the drawing of a model that has smoothness applied to it from maya. check out the project here: http://kubapl.ath.cx/projects/joomla/3dloadrev2.zip controls are: [d][a] - spin on the Y-axis [w][s] - spin on the X-axis [q][e] - spin on the Z-axis [up arrow key][down arrow key] - zoom in and out on the Z - axis [f] - toggle frame rates (on/of) [x] - toggle x-ray mode (on/of) [1][2][3][4] - cycle threw the models Now if you cycle to the last model ( model number 4 ) you'll see the weirdness. Model number 3 is the exact same model as model number 4 but model 3 does not have any smoothness applied to it what-so-ever. here is the class that handles the model loading, building:
#include <iostream>

#include "Model.h"

using std::cout;
using std::endl;

CModel::CModel()
{
	m_nDisplayList	= 0;
	m_vScale.fx		= 1.0f;
	m_vScale.fy		= 1.0f;
	m_vScale.fz		= 1.0f;
}

CModel::~CModel()
{
	if( glIsList( m_nDisplayList ) )
	{
		glDeleteLists( m_nDisplayList, 1 );
	}
	m_nDisplayList = NULL;
}

int CModel::getDisplayList()
{
	return m_nDisplayList;
}

void CModel::setModelScale( const float& fx, const float& fy, const float& fz )
{
	m_vScale.fx = fx;
	m_vScale.fy = fy;
	m_vScale.fz = fz;
}

void CModel::loadModel( string fileName )
{
	/*if( !fileName )
	{
		cout << "File not found: " << fileName;
		break;
	}*/
	//Have a look at a .ace file to see how it is fomated
	ifstream fileReader( fileName.c_str() );
	string keyWord;

	while( !fileReader.eof() )// loops until we hit the end of the file
	{	//stores in words each space seperates word
		fileReader >> keyWord;
		//if it finds this word begins to save the data we want
		if( keyWord == "*MESH_VERTEX" )
		{	//creats a new vector
			m_vVertex = new CVector();
			//index just stores the fist number
			int nIndex = 0;
			//CVector vertex;
			fileReader >> m_vVertex->nIndex;
			//stores the coordinates in a x,y,z format
			fileReader >> m_vVertex->fx;
			fileReader >> m_vVertex->fy;
			fileReader >> m_vVertex->fz;
			//std::cout << index << "		" << m_vVertex.fx << "	" << m_vVertex.fy << "	" << m_vVertex.fz << "	" << std::endl;
			//and pushes it into the list and repeats until done
			m_lstVertices.push_back( m_vVertex );

			
		}
		if( keyWord == "*MESH_FACE" )
		{
			//m_nindicies = new int();
			int nIndex = 0;
			string sPoint;

			fileReader >> nIndex;
			fileReader >> sPoint;
			for( int i = 0; i < 3; ++i )
			{
				fileReader >> sPoint;
				fileReader >> m_nIndicie;
				m_lstIndicies.push_back( m_nIndicie );
			}
			for( int i = 0; i < 3; ++i )
			{
				fileReader >> sPoint;
				fileReader >> m_bDrawLine;
				m_lstDrawLine.push_back( m_bDrawLine );
			}
				
		}
		if( keyWord == "*MESH_TVERT" )
		{
			m_vTextureCoordinates = new CVector();

			fileReader >> m_vTextureCoordinates->nIndex;
			fileReader >> m_vTextureCoordinates->fx;
			fileReader >> m_vTextureCoordinates->fy;
			fileReader >> m_vTextureCoordinates->fz;

			m_lstTextureCoordinates.push_back( m_vTextureCoordinates );
		}
		if( keyWord == "*MESH_TFACE" )
		{
			int nIndex = 0;
			fileReader >> nIndex;
			for( int i = 0; i < 3; ++i )
			{
				fileReader >> m_nTextureIndex;

				m_lstTextureIndex.push_back( m_nTextureIndex );
			}
		}
			


	}
}

void CModel::getModelInfo()
{
	vector< CVector* >::iterator itVertices = m_lstVertices.begin();
	vector< CVector* >::iterator itTextureCoordinates = m_lstTextureCoordinates.begin();
	vector< int >::iterator itTextureIndex = m_lstTextureIndex.begin();
	vector< int >::iterator itIndicies = m_lstIndicies.begin();
	vector< bool >::iterator itDrawLine = m_lstDrawLine.begin();

	cout << "Vertex: " << endl;
	while( itVertices != m_lstVertices.end() )
	{
		cout << "Index: " << (*itVertices)->nIndex <<  "	fx: " << (*itVertices)->fx << "		fy: " << (*itVertices)->fy << "		fz: " << (*itVertices)->fz << endl;	
		++itVertices;
	}

	cout << endl << endl;
	cout << "Index: " << endl;
	while( itIndicies != m_lstIndicies.end() )
	{
		for( int i = 0; i < 3; ++i )
		{
			cout << (*itIndicies) << "	";
				
			++itIndicies;
		}
		cout << endl;
		
	}
	cout << endl << endl;
	cout << "Connections: " << endl;
	while( itDrawLine != m_lstDrawLine.end() )
	{
		for( int i = 0; i < 3; ++i )
		{
			cout << (*itDrawLine) << "  ";

			++itDrawLine;
		}
		cout << endl;
	}

	cout << endl << endl;
	cout << "Texture Coordinates: " << endl;
	while( itTextureCoordinates != m_lstTextureCoordinates.end() )
	{
		cout << "Index: " << (*itTextureCoordinates)->nIndex <<  "	fx: " << (*itTextureCoordinates)->fx << "		fy: " << (*itTextureCoordinates)->fy << "		fz: " << (*itTextureCoordinates)->fz << endl;	
		++itTextureCoordinates;
	}
	cout << endl << endl;
	cout << "Texture Index: " << endl;
	while( itTextureIndex != m_lstTextureIndex.end() )
	{
		for( int i = 0; i < 3; ++ i )
		{
			cout << (*itTextureIndex) << "	";
			++itTextureIndex;
		}
		cout << endl;
	}


//	delete (*itVertices);

}

void CModel::buildModel()
{
	vector< int >::iterator itTextureIndex = m_lstTextureIndex.begin();
	vector< int >::iterator itIndicies = m_lstIndicies.begin();
	vector< bool >::iterator itDrawLine = m_lstDrawLine.begin();
	


	m_nDisplayList = glGenLists( 1 );
	glNewList( m_nDisplayList, GL_COMPILE );
	{
		
		while( itIndicies != m_lstIndicies.end() )
		{
			glBegin( GL_TRIANGLES );

			glTexCoord2f( getVertex( (*itTextureIndex), m_lstTextureCoordinates ).fx, getVertex( (*itTextureIndex), m_lstTextureCoordinates ).fy );
			glVertex3f(	getVertex( (*itIndicies), m_lstVertices ).fx * m_vScale.fx,	getVertex( (*itIndicies), m_lstVertices ).fy * m_vScale.fy,	getVertex( (*itIndicies), m_lstVertices ).fz * m_vScale.fz );
			if( (*itDrawLine) == 0 )
			{
				glEnd();
						
			}
			++itDrawLine;
			++itTextureIndex;
			++itIndicies;
			
		}
		drawAxis();

	}
	glEndList();
}

CVector CModel::getVertex( const int& nIndex, vector< CVector* > lstName )
{
	vector< CVector* >::iterator itList = lstName.begin();//+= nIndex;
	
	while( itList != lstName.end() )
	{
		if( (*itList)->nIndex == nIndex )
		{
			CVector vVec( (*itList)->fx, (*itList)->fy, (*itList)->fz );
			return vVec;
		}
		else
		{
			++itList;
		}
		
	}

	delete (*itList);
	return 0;	
}

void CModel::drawAxis()
{
	m_vAxis.fx = 0.0f;
	m_vAxis.fy = 0.0f;
	m_vAxis.fz = 0.0f;
	glColor3f( 1.0f, 0.0f, 0.0f );
	glPushMatrix();
		glBegin( GL_LINES );
			glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz );
			glVertex3f( 100.0f, 0.0f, 0.0f );
		glEnd();
		glColor3f( 0.0f, 1.0f, 0.0f );
		glBegin( GL_LINES );
			glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz );
			glVertex3f( 0.0f, 100.0f, 0.0f );
		glEnd();
		glColor3f( 0.0f, 0.0f, 1.0f );
		glBegin( GL_LINES );
			glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz );
			glVertex3f( 0.0f, 0.0f, 100.0f );
		glEnd();
	glPopMatrix();

}


Now I think that the problem has to do with I'm either not using the right glBegin() at times or am not ending properly.

Share this post


Link to post
Share on other sites
Advertisement
That looks like improper face numbering. It's difficult to tell without some camera control though.

Smoothing groups in model packages join up vertices and recalculate face indices, so model 4 will be completely different from model 3, data-wise. Try it with a simple cube, read the vertices/faces by hand in the ASE file, then std::cout everything and check it.

Also, do you have depth testing enabled? Are the UV coords correct?

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!