Winding / still some model issues

Started by
0 comments, last by deadstar 15 years, 10 months ago
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] - spin &#111;n the X-axis [q][e] - spin &#111;n the Z-axis [up arrow key][down arrow key] - zoom in and out &#111;n 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: <!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre> <span class="cpp-directive">#include</span> &lt;iostream&gt; <span class="cpp-directive">#include</span> <span class="cpp-literal">"Model.h"</span> <span class="cpp-keyword">using</span> std::cout; <span class="cpp-keyword">using</span> std::endl; CModel::CModel() { m_nDisplayList = <span class="cpp-number">0</span>; m_vScale.fx = <span class="cpp-number">1</span>.0f; m_vScale.fy = <span class="cpp-number">1</span>.0f; m_vScale.fz = <span class="cpp-number">1</span>.0f; } CModel::~CModel() { <span class="cpp-keyword">if</span>( glIsList( m_nDisplayList ) ) { glDeleteLists( m_nDisplayList, <span class="cpp-number">1</span> ); } m_nDisplayList = NULL; } <span class="cpp-keyword">int</span> CModel::getDisplayList() { <span class="cpp-keyword">return</span> m_nDisplayList; } <span class="cpp-keyword">void</span> CModel::setModelScale( <span class="cpp-keyword">const</span> <span class="cpp-keyword">float</span>&amp; fx, <span class="cpp-keyword">const</span> <span class="cpp-keyword">float</span>&amp; fy, <span class="cpp-keyword">const</span> <span class="cpp-keyword">float</span>&amp; fz ) { m_vScale.fx = fx; m_vScale.fy = fy; m_vScale.fz = fz; } <span class="cpp-keyword">void</span> CModel::loadModel( string fileName ) { <span class="cpp-comment">/*if( !fileName ) { cout &lt;&lt; "File not found: " &lt;&lt; fileName; break; }*/</span> <span class="cpp-comment">//Have a look at a .ace file to see how it is fomated</span> ifstream fileReader( fileName.c_str() ); string keyWord; <span class="cpp-keyword">while</span>( !fileReader.eof() )<span class="cpp-comment">// loops until we hit the end of the file</span> { <span class="cpp-comment">//stores in words each space seperates word</span> fileReader &gt;&gt; keyWord; <span class="cpp-comment">//if it finds this word begins to save the data we want</span> <span class="cpp-keyword">if</span>( keyWord == <span class="cpp-literal">"*MESH_VERTEX"</span> ) { <span class="cpp-comment">//creats a new vector</span> m_vVertex = <span class="cpp-keyword">new</span> CVector(); <span class="cpp-comment">//index just stores the fist number</span> <span class="cpp-keyword">int</span> nIndex = <span class="cpp-number">0</span>; <span class="cpp-comment">//CVector vertex;</span> fileReader &gt;&gt; m_vVertex-&gt;nIndex; <span class="cpp-comment">//stores the coordinates in a x,y,z format</span> fileReader &gt;&gt; m_vVertex-&gt;fx; fileReader &gt;&gt; m_vVertex-&gt;fy; fileReader &gt;&gt; m_vVertex-&gt;fz; <span class="cpp-comment">//std::cout &lt;&lt; index &lt;&lt; " " &lt;&lt; m_vVertex.fx &lt;&lt; " " &lt;&lt; m_vVertex.fy &lt;&lt; " " &lt;&lt; m_vVertex.fz &lt;&lt; " " &lt;&lt; std::endl;</span> <span class="cpp-comment">//and pushes it into the list and repeats until done</span> m_lstVertices.push_back( m_vVertex ); } <span class="cpp-keyword">if</span>( keyWord == <span class="cpp-literal">"*MESH_FACE"</span> ) { <span class="cpp-comment">//m_nindicies = new int();</span> <span class="cpp-keyword">int</span> nIndex = <span class="cpp-number">0</span>; string sPoint; fileReader &gt;&gt; nIndex; fileReader &gt;&gt; sPoint; <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++i ) { fileReader &gt;&gt; sPoint; fileReader &gt;&gt; m_nIndicie; m_lstIndicies.push_back( m_nIndicie ); } <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++i ) { fileReader &gt;&gt; sPoint; fileReader &gt;&gt; m_bDrawLine; m_lstDrawLine.push_back( m_bDrawLine ); } } <span class="cpp-keyword">if</span>( keyWord == <span class="cpp-literal">"*MESH_TVERT"</span> ) { m_vTextureCoordinates = <span class="cpp-keyword">new</span> CVector(); fileReader &gt;&gt; m_vTextureCoordinates-&gt;nIndex; fileReader &gt;&gt; m_vTextureCoordinates-&gt;fx; fileReader &gt;&gt; m_vTextureCoordinates-&gt;fy; fileReader &gt;&gt; m_vTextureCoordinates-&gt;fz; m_lstTextureCoordinates.push_back( m_vTextureCoordinates ); } <span class="cpp-keyword">if</span>( keyWord == <span class="cpp-literal">"*MESH_TFACE"</span> ) { <span class="cpp-keyword">int</span> nIndex = <span class="cpp-number">0</span>; fileReader &gt;&gt; nIndex; <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++i ) { fileReader &gt;&gt; m_nTextureIndex; m_lstTextureIndex.push_back( m_nTextureIndex ); } } } } <span class="cpp-keyword">void</span> CModel::getModelInfo() { vector&lt; CVector* &gt;::iterator itVertices = m_lstVertices.begin(); vector&lt; CVector* &gt;::iterator itTextureCoordinates = m_lstTextureCoordinates.begin(); vector&lt; <span class="cpp-keyword">int</span> &gt;::iterator itTextureIndex = m_lstTextureIndex.begin(); vector&lt; <span class="cpp-keyword">int</span> &gt;::iterator itIndicies = m_lstIndicies.begin(); vector&lt; <span class="cpp-keyword">bool</span> &gt;::iterator itDrawLine = m_lstDrawLine.begin(); cout &lt;&lt; <span class="cpp-literal">"Vertex: "</span> &lt;&lt; endl; <span class="cpp-keyword">while</span>( itVertices != m_lstVertices.end() ) { cout &lt;&lt; <span class="cpp-literal">"Index: "</span> &lt;&lt; (*itVertices)-&gt;nIndex &lt;&lt; <span class="cpp-literal">" fx: "</span> &lt;&lt; (*itVertices)-&gt;fx &lt;&lt; <span class="cpp-literal">" fy: "</span> &lt;&lt; (*itVertices)-&gt;fy &lt;&lt; <span class="cpp-literal">" fz: "</span> &lt;&lt; (*itVertices)-&gt;fz &lt;&lt; endl; ++itVertices; } cout &lt;&lt; endl &lt;&lt; endl; cout &lt;&lt; <span class="cpp-literal">"Index: "</span> &lt;&lt; endl; <span class="cpp-keyword">while</span>( itIndicies != m_lstIndicies.end() ) { <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++i ) { cout &lt;&lt; (*itIndicies) &lt;&lt; <span class="cpp-literal">" "</span>; ++itIndicies; } cout &lt;&lt; endl; } cout &lt;&lt; endl &lt;&lt; endl; cout &lt;&lt; <span class="cpp-literal">"Connections: "</span> &lt;&lt; endl; <span class="cpp-keyword">while</span>( itDrawLine != m_lstDrawLine.end() ) { <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++i ) { cout &lt;&lt; (*itDrawLine) &lt;&lt; <span class="cpp-literal">" "</span>; ++itDrawLine; } cout &lt;&lt; endl; } cout &lt;&lt; endl &lt;&lt; endl; cout &lt;&lt; <span class="cpp-literal">"Texture Coordinates: "</span> &lt;&lt; endl; <span class="cpp-keyword">while</span>( itTextureCoordinates != m_lstTextureCoordinates.end() ) { cout &lt;&lt; <span class="cpp-literal">"Index: "</span> &lt;&lt; (*itTextureCoordinates)-&gt;nIndex &lt;&lt; <span class="cpp-literal">" fx: "</span> &lt;&lt; (*itTextureCoordinates)-&gt;fx &lt;&lt; <span class="cpp-literal">" fy: "</span> &lt;&lt; (*itTextureCoordinates)-&gt;fy &lt;&lt; <span class="cpp-literal">" fz: "</span> &lt;&lt; (*itTextureCoordinates)-&gt;fz &lt;&lt; endl; ++itTextureCoordinates; } cout &lt;&lt; endl &lt;&lt; endl; cout &lt;&lt; <span class="cpp-literal">"Texture Index: "</span> &lt;&lt; endl; <span class="cpp-keyword">while</span>( itTextureIndex != m_lstTextureIndex.end() ) { <span class="cpp-keyword">for</span>( <span class="cpp-keyword">int</span> i = <span class="cpp-number">0</span>; i &lt; <span class="cpp-number">3</span>; ++ i ) { cout &lt;&lt; (*itTextureIndex) &lt;&lt; <span class="cpp-literal">" "</span>; ++itTextureIndex; } cout &lt;&lt; endl; } <span class="cpp-comment">// delete (*itVertices);</span> } <span class="cpp-keyword">void</span> CModel::buildModel() { vector&lt; <span class="cpp-keyword">int</span> &gt;::iterator itTextureIndex = m_lstTextureIndex.begin(); vector&lt; <span class="cpp-keyword">int</span> &gt;::iterator itIndicies = m_lstIndicies.begin(); vector&lt; <span class="cpp-keyword">bool</span> &gt;::iterator itDrawLine = m_lstDrawLine.begin(); m_nDisplayList = glGenLists( <span class="cpp-number">1</span> ); glNewList( m_nDisplayList, GL_COMPILE ); { <span class="cpp-keyword">while</span>( 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 ); <span class="cpp-keyword">if</span>( (*itDrawLine) == <span class="cpp-number">0</span> ) { glEnd(); } ++itDrawLine; ++itTextureIndex; ++itIndicies; } drawAxis(); } glEndList(); } CVector CModel::getVertex( <span class="cpp-keyword">const</span> <span class="cpp-keyword">int</span>&amp; nIndex, vector&lt; CVector* &gt; lstName ) { vector&lt; CVector* &gt;::iterator itList = lstName.begin();<span class="cpp-comment">//+= nIndex;</span> <span class="cpp-keyword">while</span>( itList != lstName.end() ) { <span class="cpp-keyword">if</span>( (*itList)-&gt;nIndex == nIndex ) { CVector vVec( (*itList)-&gt;fx, (*itList)-&gt;fy, (*itList)-&gt;fz ); <span class="cpp-keyword">return</span> vVec; } <span class="cpp-keyword">else</span> { ++itList; } } <span class="cpp-keyword">delete</span> (*itList); <span class="cpp-keyword">return</span> <span class="cpp-number">0</span>; } <span class="cpp-keyword">void</span> CModel::drawAxis() { m_vAxis.fx = <span class="cpp-number">0</span>.0f; m_vAxis.fy = <span class="cpp-number">0</span>.0f; m_vAxis.fz = <span class="cpp-number">0</span>.0f; glColor3f( <span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f ); glPushMatrix(); glBegin( GL_LINES ); glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz ); glVertex3f( <span class="cpp-number">100</span>.0f, <span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f ); glEnd(); glColor3f( <span class="cpp-number">0</span>.0f, <span class="cpp-number">1</span>.0f, <span class="cpp-number">0</span>.0f ); glBegin( GL_LINES ); glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz ); glVertex3f( <span class="cpp-number">0</span>.0f, <span class="cpp-number">100</span>.0f, <span class="cpp-number">0</span>.0f ); glEnd(); glColor3f( <span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f, <span class="cpp-number">1</span>.0f ); glBegin( GL_LINES ); glVertex3f( m_vAxis.fx, m_vAxis.fy, m_vAxis.fz ); glVertex3f( <span class="cpp-number">0</span>.0f, <span class="cpp-number">0</span>.0f, <span class="cpp-number">100</span>.0f ); glEnd(); glPopMatrix(); } </pre></div><!–ENDSCRIPT–> 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.
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?

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

This topic is closed to new replies.

Advertisement