|
From: Mike D. <o3d...@us...> - 2004-07-25 10:36:09
|
Update of /cvsroot/grappelmann/spaceplane In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17203 Modified Files: gravity.cpp makefile mesh.cpp model_loader.cpp model_loader.h scene_object.cpp scene_object.h Log Message: - added material and transform nodes - fixed a few small bugs Index: gravity.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/gravity.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** gravity.cpp 23 Jul 2004 05:43:48 -0000 1.4 --- gravity.cpp 25 Jul 2004 10:35:59 -0000 1.5 *************** *** 146,153 **** */ if(SystemStateSingleton::instance().middleButtonPressed) { ! clposZ++; //xAngle += 5; } else { ! cposZ++; //yAngle += 5; } --- 146,153 ---- */ if(SystemStateSingleton::instance().middleButtonPressed) { ! cposZ++; //xAngle += 5; } else { ! clposZ++; //yAngle += 5; } *************** *** 306,310 **** ModelLoader* modelLoader = new X3DLoader(); SceneObject* slugMobile = modelLoader->loadModel(vrmlFilename); - slugMobile->makeDisplayList(); //Model monkey(vrmlFilename); --- 306,309 ---- *************** *** 337,340 **** --- 336,340 ---- Coord3D lightPos; + slugMobile->makeDisplayList(); //ModelDrawer monkeyDrawer(&monkey); *************** *** 411,422 **** GLfloat light_position[] = { lightPos.m_x, lightPos.m_y, lightPos.m_z, 1.0 }; ! GLfloat mat_specular[] = { 0.5, 0.5, 0.5, 1.0 }; ! GLfloat mat_shininess[] = { 20.0 }; ! GLfloat mat_ambient[] = { 0.8, 0.8, 0.8, 1.0 }; ! GLfloat white_light[] = { 0.8, 0.8, 0.8, 1.0 }; ! GLfloat ambient_light[] = { 0.5, 0.5, 0.5, 1.0 }; ! glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); ! glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); ! glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); --- 411,416 ---- GLfloat light_position[] = { lightPos.m_x, lightPos.m_y, lightPos.m_z, 1.0 }; ! GLfloat white_light[] = { 1, 1, 1, 1.0 }; ! GLfloat ambient_light[] = { 1, 1, 1, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); *************** *** 442,446 **** glRotatef(-rotation.m_z, 0.0, 0.0, 1.0); glTranslatef(position.m_x, position.m_y, position.m_z); ! position.m_z -= 0.1; glColor3f(1, 1, 1); --- 436,440 ---- glRotatef(-rotation.m_z, 0.0, 0.0, 1.0); glTranslatef(position.m_x, position.m_y, position.m_z); ! //position.m_z -= 0.1; glColor3f(1, 1, 1); *************** *** 492,495 **** --- 486,493 ---- /* $Log$ + Revision 1.5 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.4 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays Index: scene_object.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/scene_object.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** scene_object.cpp 23 Jul 2004 05:43:48 -0000 1.3 --- scene_object.cpp 25 Jul 2004 10:35:59 -0000 1.4 *************** *** 28,31 **** --- 28,32 ---- m_displayListCreated = true; } else { + cout << "drawing" <<endl; draw(); } *************** *** 42,45 **** --- 43,47 ---- // draw if there is no display list if(!m_displayListCreated) { + //cout << "trying to draw" << endl; _draw(); // otherwise call the display list *************** *** 52,60 **** } ! bool SceneObject::_draw() { ! // then the children for(vector<SceneObject*>::iterator i = m_children.begin(); i != m_children.end(); i++) { (*i)->draw(); } return true; --- 54,70 ---- } ! bool SceneObject::drawChildren() { ! glPushMatrix(); for(vector<SceneObject*>::iterator i = m_children.begin(); i != m_children.end(); i++) { (*i)->draw(); } + glPopMatrix(); + + return true; + } + + bool SceneObject::_draw() { + // then the children + drawChildren(); return true; *************** *** 91,94 **** --- 101,108 ---- /* $Log$ + Revision 1.4 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.3 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays Index: mesh.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/mesh.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mesh.cpp 23 Jul 2004 05:43:48 -0000 1.3 --- mesh.cpp 25 Jul 2004 10:35:59 -0000 1.4 *************** *** 37,40 **** --- 37,41 ---- bool Mesh::_draw() { // first draw myself + cout << "<Mesh::_draw>\tI'm a star!" << endl; // then draw the children *************** *** 42,45 **** --- 43,49 ---- (*i).draw(); } + + // draw any sub nodes + drawChildren(); return true; *************** *** 48,51 **** --- 52,59 ---- /* $Log$ + Revision 1.4 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.3 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays Index: model_loader.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/model_loader.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** model_loader.h 23 Jul 2004 05:43:48 -0000 1.2 --- model_loader.h 25 Jul 2004 10:35:59 -0000 1.3 *************** *** 14,17 **** --- 14,19 ---- #include "scene_object.h" #include "mesh.h" + #include "transform.h" + #include "material.h" #include <assert.h> #include <vector> *************** *** 39,42 **** --- 41,47 ---- SceneObject* _convertDOMNode(DOMNode* domNode, SceneObject* parent = NULL, long curLevel = 0); SceneObject* _createSceneObjectFromDOMNode(DOMNode* domNode, bool& parentMustHandleChildren); + SceneObject* _createTransform(DOMNode* domNode); + SceneObject* _createMaterial(DOMNode* domNode); + SceneObject* _createMesh(DOMNode* domNode); bool _convertCharToVector(vector<int>& intVector, string intString); bool _convertCharToVector(vector<double>& intVector, string intString); *************** *** 45,48 **** --- 50,57 ---- /* $Log$ + Revision 1.3 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.2 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays Index: makefile =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** makefile 21 Jul 2004 19:32:44 -0000 1.3 --- makefile 25 Jul 2004 10:35:59 -0000 1.4 *************** *** 10,14 **** GRAVITY_DEPS= ! GRAVITY_OBJS=gravity.o opengl_utils.o object3d.o vrml_v1.o system_state.o statgraph.o statgraphrenderer.o model.o model_loader.o mesh.o polygon.o scene_object.o all: gravity --- 10,14 ---- GRAVITY_DEPS= ! GRAVITY_OBJS=gravity.o opengl_utils.o object3d.o vrml_v1.o system_state.o statgraph.o statgraphrenderer.o model.o model_loader.o mesh.o polygon.o scene_object.o transform.o material.o all: gravity Index: scene_object.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/scene_object.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** scene_object.h 23 Jul 2004 05:43:48 -0000 1.3 --- scene_object.h 25 Jul 2004 10:35:59 -0000 1.4 *************** *** 23,26 **** --- 23,27 ---- bool makeDisplayList(); virtual bool draw(); + bool drawChildren(); virtual SceneObject& operator=(const SceneObject& rhs); *************** *** 38,41 **** --- 39,46 ---- /* $Log$ + Revision 1.4 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.3 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays Index: model_loader.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/model_loader.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** model_loader.cpp 23 Jul 2004 05:43:48 -0000 1.3 --- model_loader.cpp 25 Jul 2004 10:35:59 -0000 1.4 *************** *** 170,298 **** parentMustHandleChildren = false; ! // this is a mesh ! Mesh* mesh = new Mesh(); ! vector<int> coordIndexes; ! vector<int> normalIndexes; ! vector<double> coords; ! vector<double> normals; ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* attributes = domNode->getAttributes(); ! if(attributes != NULL) { ! // get the coord indices ! DOMNode* coordIndexesNode = attributes->getNamedItem(XMLString::transcode("coordIndex")); ! if(coordIndexesNode->getNodeValue() != NULL) { ! //cout << "coordIndexes [" << XMLString::transcode(coordIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(coordIndexes, XMLString::transcode(coordIndexesNode->getNodeValue())); ! } ! ! // get the normal indices ! DOMNode* normalIndexesNode = attributes->getNamedItem(XMLString::transcode("normalIndex")); ! if(normalIndexesNode->getNodeValue() != NULL) { ! //cout << "normalIndexes [" << XMLString::transcode(normalIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(normalIndexes, XMLString::transcode(normalIndexesNode->getNodeValue())); ! } } ! // now we need to get the coord/normal objects nodes ! DOMNode* curChild = domNode->getFirstChild(); ! while(curChild != NULL) { ! if(curChild->getNodeType() == DOMNode::ELEMENT_NODE) { ! cout << "IndexedFaceSet node type [" << domNode->getNodeType() << "] node name [" << XMLString::transcode(domNode->getNodeName()) << "]" << endl; ! char* childNodeName = XMLString::transcode(curChild->getNodeName()); ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* curChildAttributes = curChild->getAttributes(); ! if(curChildAttributes != NULL) { ! if(strcmp(childNodeName, "Coordinate") == 0) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot coordinate child" << endl; ! // get the coord indices ! DOMNode* coordsNode = curChildAttributes->getNamedItem(XMLString::transcode("point")); ! if((coordsNode != NULL) && (coordsNode->getNodeValue() != NULL)) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot point attribute" << endl; ! _convertCharToVector(coords, XMLString::transcode(coordsNode->getNodeValue())); ! } ! } else if(strcmp(childNodeName, "Normal") == 0) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot normal child" << endl; ! // get the coord indices ! DOMNode* normalsNode = curChildAttributes->getNamedItem(XMLString::transcode("vector")); ! if((normalsNode != NULL) && (normalsNode->getNodeValue() != NULL)) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot vector attribute" << endl; ! _convertCharToVector(normals, XMLString::transcode(normalsNode->getNodeValue())); ! } } } } - - // now get the child's sibling - DOMNode* nextChild = curChild->getNextSibling(); - curChild = nextChild; } ! // now run through the coords and add them to the mesh ! // *** NOTE *** we make the assumption that there are the same number of normals as vertices ! // *** NOTE *** we need to presize the mesh vector, because it keeps on copying the polygons ! vector<int>::size_type normalCount = normalIndexes.size(); ! vector<double>::size_type coordsSize = coords.size(); ! vector<double>::size_type normalsSize = normals.size(); ! int coordIndex = 0; ! int normalIndex = 0; ! Coord3D coord; ! Coord3D normal; ! Polygon* curPolygon = new Polygon(); ! for(vector<int>::size_type i = 0; i < normalCount; i++) { ! ! //cout << "\tcoordIndex [" << coordIndexes[i] << "] coord x [" << coord.m_x << "] y [" << coord.m_y << "] z [" << coord.m_z << "]" << endl; ! //cout << "\tnormalIndex [" << normalIndexes[i] << "] normal x [" << normal.m_x << "] y [" << normal.m_y << "] z [" << normal.m_z << "]" << endl; ! // add to mesh and restart for next polygon ! // *** NOTE *** we could be reusing the polygon, but I just want to get this going ! if(coordIndexes[i] == -1) { ! mesh->addPolygon(*curPolygon); ! ! delete(curPolygon); ! curPolygon = new Polygon(); ! } else { ! coordIndex = coordIndexes[i] * 3; ! normalIndex = normalIndexes[i] * 3; ! ! //assert((coordIndex + 2) < coordsSize); ! //assert((normalIndex + 2) < normalsSize); ! if(coordIndex + 2 >= coordsSize) { ! cout << "coordsSize [" << coordsSize << "] coordIndex [" << coordIndex << "]" << endl; ! break; ! } ! if(normalIndex + 2 >= normalsSize) { ! cout << "normalsSize [" << normalsSize << "] normalIndex [" << normalIndex << "]" << endl; ! break; ! } ! coord.m_x = coords[coordIndex]; ! coord.m_y = coords[coordIndex + 1]; ! coord.m_z = coords[coordIndex + 2]; ! normal.m_x = normals[normalIndex]; ! normal.m_y = normals[normalIndex + 1]; ! normal.m_z = normals[normalIndex + 2]; ! curPolygon->addCoord(coord); ! curPolygon->addNormal(normal); ! } } ! // done, return ! return mesh; ! } ! ! /* ! else { ! SceneObject* dummy = new SceneObject(); ! return dummy; } - */ ! return NULL; } --- 170,425 ---- parentMustHandleChildren = false; ! return _createMesh(domNode); ! } else if(strcmp(nodeName, "Transform") == 0) { ! // parent must ignore children, we can handle them! ! //parentMustHandleChildren = false; ! ! return _createTransform(domNode); ! } else if(strcmp(nodeName, "Material") == 0) { ! return _createMaterial(domNode); ! } ! /* ! else { ! SceneObject* dummy = new SceneObject(); ! return dummy; ! } ! */ ! ! return NULL; ! } ! ! SceneObject* X3DLoader::_createMaterial(DOMNode* domNode) { ! Material* material = new Material(); ! ! vector<double> diffuse; ! vector<double> emission; ! vector<double> specular; ! ! /* ! <Appearance> ! <Material ! +ambientIntensity="0.500" ! +diffuseColor="0.640 0.640 0.640" ! +emissiveColor="0.800 0.800 0.800" ! shininess="0.196" ! +specularColor="1.000 1.000 1.000" ! transparency="0.000"/> ! </Appearance> ! */ ! ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* attributes = domNode->getAttributes(); ! if(attributes != NULL) { ! // get the ambientIntensity ! DOMNode* ambientIntensityNode = attributes->getNamedItem(XMLString::transcode("ambientIntensity")); ! if(ambientIntensityNode->getNodeValue() != NULL) { ! cout << "ambientIntensityNode [" << XMLString::transcode(ambientIntensityNode->getNodeValue()) << "]" << endl; } ! // get the ambientIntensity ! DOMNode* shininessNode = attributes->getNamedItem(XMLString::transcode("shininess")); ! if(shininessNode->getNodeValue() != NULL) { ! cout << "shininessNode [" << XMLString::transcode(shininessNode->getNodeValue()) << "]" << endl; ! } ! ! DOMNode* emissionNode = attributes->getNamedItem(XMLString::transcode("emissiveColor")); ! if(emissionNode->getNodeValue() != NULL) { ! cout << "emissionNode [" << XMLString::transcode(emissionNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(emission, XMLString::transcode(emissionNode->getNodeValue())); ! } ! DOMNode* diffuseColorNode = attributes->getNamedItem(XMLString::transcode("diffuseColor")); ! if(diffuseColorNode->getNodeValue() != NULL) { ! cout << "diffuseColorNode [" << XMLString::transcode(diffuseColorNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(diffuse, XMLString::transcode(diffuseColorNode->getNodeValue())); ! } ! DOMNode* specularColorNode = attributes->getNamedItem(XMLString::transcode("specularColor")); ! if(specularColorNode->getNodeValue() != NULL) { ! cout << "specularColorNode [" << XMLString::transcode(specularColorNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(specular, XMLString::transcode(specularColorNode->getNodeValue())); ! } ! assert(diffuse.size() == 3); ! assert(emission.size() == 3); ! assert(specular.size() == 3); ! ! material->setAmbient(atof(XMLString::transcode(ambientIntensityNode->getNodeValue()))); ! material->setShininess(atof(XMLString::transcode(shininessNode->getNodeValue()))); ! material->setDiffuse(diffuse); ! material->setEmission(emission); ! material->setSpecular(specular); ! } ! ! return material; ! ! } ! ! SceneObject* X3DLoader::_createTransform(DOMNode* domNode) { ! Transform* transform = new Transform(); ! ! Coord3D rotation; ! double rotationSize = 0; ! Coord3D translation; ! vector<double> rotationElements; ! vector<double> translationElements; ! ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* attributes = domNode->getAttributes(); ! if(attributes != NULL) { ! // get the rotation ! DOMNode* rotationNode = attributes->getNamedItem(XMLString::transcode("rotation")); ! if(rotationNode->getNodeValue() != NULL) { ! cout << "rotation [" << XMLString::transcode(rotationNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(rotationElements, XMLString::transcode(rotationNode->getNodeValue())); ! } ! ! // get the translation ! DOMNode* translationNode = attributes->getNamedItem(XMLString::transcode("translation")); ! if(translationNode->getNodeValue() != NULL) { ! cout << "translation [" << XMLString::transcode(translationNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(translationElements, XMLString::transcode(translationNode->getNodeValue())); ! } ! ! assert(rotationElements.size() == 4); ! assert(translationElements.size() == 3); ! ! rotation.m_x = rotationElements[0]; ! rotation.m_y = rotationElements[1]; ! rotation.m_z = rotationElements[2]; ! rotationSize = rotationElements[3]; ! ! translation.m_x = translationElements[0]; ! translation.m_y = translationElements[1]; ! translation.m_z = translationElements[2]; ! } ! ! // <Transform rotation="1.000 0.000 0.000 1.571" scale="1.000 1.000 0.603" translation="1.429 -5.224 2.204"> ! ! transform->setTranslation(translation); ! transform->setRotation(rotation, rotationSize); ! ! return transform; ! ! } ! ! SceneObject* X3DLoader::_createMesh(DOMNode* domNode) { ! // this is a mesh ! Mesh* mesh = new Mesh(); ! ! vector<int> coordIndexes; ! vector<int> normalIndexes; ! vector<double> coords; ! vector<double> normals; ! ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* attributes = domNode->getAttributes(); ! if(attributes != NULL) { ! // get the coord indices ! DOMNode* coordIndexesNode = attributes->getNamedItem(XMLString::transcode("coordIndex")); ! if(coordIndexesNode->getNodeValue() != NULL) { ! //cout << "coordIndexes [" << XMLString::transcode(coordIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(coordIndexes, XMLString::transcode(coordIndexesNode->getNodeValue())); ! } ! ! // get the normal indices ! DOMNode* normalIndexesNode = attributes->getNamedItem(XMLString::transcode("normalIndex")); ! if(normalIndexesNode->getNodeValue() != NULL) { ! //cout << "normalIndexes [" << XMLString::transcode(normalIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToVector(normalIndexes, XMLString::transcode(normalIndexesNode->getNodeValue())); ! } ! } ! ! // now we need to get the coord/normal objects nodes ! DOMNode* curChild = domNode->getFirstChild(); ! while(curChild != NULL) { ! if(curChild->getNodeType() == DOMNode::ELEMENT_NODE) { ! cout << "IndexedFaceSet node type [" << domNode->getNodeType() << "] node name [" << XMLString::transcode(domNode->getNodeName()) << "]" << endl; ! char* childNodeName = XMLString::transcode(curChild->getNodeName()); ! // get the attributes (containing the coord/normal indexes) ! DOMNamedNodeMap* curChildAttributes = curChild->getAttributes(); ! ! if(curChildAttributes != NULL) { ! if(strcmp(childNodeName, "Coordinate") == 0) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot coordinate child" << endl; ! ! // get the coord indices ! DOMNode* coordsNode = curChildAttributes->getNamedItem(XMLString::transcode("point")); ! if((coordsNode != NULL) && (coordsNode->getNodeValue() != NULL)) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot point attribute" << endl; ! _convertCharToVector(coords, XMLString::transcode(coordsNode->getNodeValue())); ! } ! } else if(strcmp(childNodeName, "Normal") == 0) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot normal child" << endl; ! ! // get the coord indices ! DOMNode* normalsNode = curChildAttributes->getNamedItem(XMLString::transcode("vector")); ! if((normalsNode != NULL) && (normalsNode->getNodeValue() != NULL)) { ! cout << "<X3DLoader::_createSceneObjectFromDOMNode>\tgot vector attribute" << endl; ! _convertCharToVector(normals, XMLString::transcode(normalsNode->getNodeValue())); } } } } ! // now get the child's sibling ! DOMNode* nextChild = curChild->getNextSibling(); ! curChild = nextChild; ! } ! ! // now run through the coords and add them to the mesh ! // *** NOTE *** we make the assumption that there are the same number of normals as vertices ! // *** NOTE *** we need to presize the mesh vector, because it keeps on copying the polygons ! vector<int>::size_type normalCount = normalIndexes.size(); ! vector<double>::size_type coordsSize = coords.size(); ! vector<double>::size_type normalsSize = normals.size(); ! ! int coordIndex = 0; ! int normalIndex = 0; ! Coord3D coord; ! Coord3D normal; ! Polygon* curPolygon = new Polygon(); ! for(vector<int>::size_type i = 0; i < normalCount; i++) { ! //cout << "\tcoordIndex [" << coordIndexes[i] << "] coord x [" << coord.m_x << "] y [" << coord.m_y << "] z [" << coord.m_z << "]" << endl; ! //cout << "\tnormalIndex [" << normalIndexes[i] << "] normal x [" << normal.m_x << "] y [" << normal.m_y << "] z [" << normal.m_z << "]" << endl; ! // add to mesh and restart for next polygon ! // *** NOTE *** we could be reusing the polygon, but I just want to get this going ! if(coordIndexes[i] == -1) { ! mesh->addPolygon(*curPolygon); ! delete(curPolygon); ! curPolygon = new Polygon(); ! } else { ! coordIndex = coordIndexes[i] * 3; ! normalIndex = normalIndexes[i] * 3; ! ! //assert((coordIndex + 2) < coordsSize); ! //assert((normalIndex + 2) < normalsSize); ! if(coordIndex + 2 >= coordsSize) { ! cout << "coordsSize [" << coordsSize << "] coordIndex [" << coordIndex << "]" << endl; ! break; ! } ! if(normalIndex + 2 >= normalsSize) { ! cout << "normalsSize [" << normalsSize << "] normalIndex [" << normalIndex << "]" << endl; ! break; } + coord.m_x = coords[coordIndex]; + coord.m_y = coords[coordIndex + 1]; + coord.m_z = coords[coordIndex + 2]; + normal.m_x = normals[normalIndex]; + normal.m_y = normals[normalIndex + 1]; + normal.m_z = normals[normalIndex + 2]; ! curPolygon->addCoord(coord); ! curPolygon->addNormal(normal); ! } } ! // done, return ! return mesh; } *************** *** 326,329 **** --- 453,462 ---- endPos = startPos; } + + // now push the last element onto the vector + string::size_type pieceLength = intString.size() - 1 - startPos; + piece = intString.substr(startPos, pieceLength); + + intVector.push_back(atoi(piece.c_str())); cout << "<X3DLoader::_convertCharToVector(int)>\tvector size [" << intVector.size() << "]" << endl; *************** *** 332,336 **** } ! bool X3DLoader::_convertCharToVector(vector<double>& intVector, string intString) { string piece; --- 465,469 ---- } ! bool X3DLoader::_convertCharToVector(vector<double>& doubleVector, string intString) { string piece; *************** *** 348,352 **** piece = intString.substr(startPos, pieceLength); ! intVector.push_back(atof(piece.c_str())); //pieceCount++; --- 481,485 ---- piece = intString.substr(startPos, pieceLength); ! doubleVector.push_back(atof(piece.c_str())); //pieceCount++; *************** *** 361,365 **** } ! cout << "<X3DLoader::_convertCharToVector(double)>\tvector size [" << intVector.size() << "]" << endl; return true; --- 494,504 ---- } ! // now push the last element onto the vector ! string::size_type pieceLength = intString.size() - 1 - startPos; ! piece = intString.substr(startPos, pieceLength); ! ! doubleVector.push_back(atoi(piece.c_str())); ! ! cout << "<X3DLoader::_convertCharToVector(double)>\tvector size [" << doubleVector.size() << "]" << endl; return true; *************** *** 368,371 **** --- 507,514 ---- /* $Log$ + Revision 1.4 2004/07/25 10:35:59 o3dozone + - added material and transform nodes + - fixed a few small bugs + Revision 1.3 2004/07/23 05:43:48 o3dozone - now correctly parses x3d vertice arrays |