|
From: Mike D. <o3d...@us...> - 2004-07-23 05:44:11
|
Update of /cvsroot/grappelmann/spaceplane In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9810 Modified Files: gravity.cpp mesh.cpp mesh.h model_loader.cpp model_loader.h object3d.h opengl_utils.h polygon.cpp polygon.h scene_object.cpp scene_object.h Log Message: - now correctly parses x3d vertice arrays - does *not* parse transforms etc Index: gravity.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/gravity.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** gravity.cpp 24 Jun 2004 19:46:40 -0000 1.3 --- gravity.cpp 23 Jul 2004 05:43:48 -0000 1.4 *************** *** 4,26 **** #include "gravity.h" ! ! ! /* ! DxfReader::DxfReader() { ! }; ! ! void DxfReader::addVertex(const DL_VertexData& data) { ! cout << "<DxfReader::addVertex>\tx [" << data.x << "] y [" << data.y << "] z [" << data.z << "] bulge [" << data.bulge << "]" << endl; ! }; ! */ ! bool handleEvents(Object3D& viewPoint, vector<Object3D>& objectArray, long objectCount) { ! ! /* Our angle of rotation. */ ! Coord3D& rotation = viewPoint.getRotation(); ! Coord3D& position = viewPoint.getPos(); ! Coord3D& velocity = viewPoint.getVelocity(); pos_t& xAngle = rotation.m_x; --- 4,12 ---- #include "gravity.h" ! #include "model_loader.h" ! bool handleEvents(Coord3D& rotation, Coord3D& position, Coord3D& velocity) { pos_t& xAngle = rotation.m_x; *************** *** 113,124 **** } if(SystemStateSingleton::instance().rightButtonPressed) { ! clposX += (double)event.motion.xrel / (double)5; ! clposY += (double)event.motion.yrel / (double)5; } if(SystemStateSingleton::instance().middleButtonPressed) { ! /* ! xAngle += (double)event.motion.yrel / (double)5; ! yAngle += (double)event.motion.xrel / (double)5; ! */ } //cout << "cposX [" << cposX << "] cposY [" << cposY << "] cposZ [" << cposZ << "]" << endl; --- 99,108 ---- } if(SystemStateSingleton::instance().rightButtonPressed) { ! cposX += (double)event.motion.xrel / (double)5; ! cposY += (double)event.motion.yrel / (double)5; } if(SystemStateSingleton::instance().middleButtonPressed) { ! clposX += (double)event.motion.yrel / (double)5; ! clposY += (double)event.motion.xrel / (double)5; } //cout << "cposX [" << cposX << "] cposY [" << cposY << "] cposZ [" << cposZ << "]" << endl; *************** *** 162,170 **** */ if(SystemStateSingleton::instance().middleButtonPressed) { - cposZ++; - //yAngle += 5; - } else { clposZ++; //xAngle += 5; } break; --- 146,154 ---- */ if(SystemStateSingleton::instance().middleButtonPressed) { clposZ++; //xAngle += 5; + } else { + cposZ++; + //yAngle += 5; } break; *************** *** 320,324 **** char* vrmlFilename = argv[1]; ! Model monkey(vrmlFilename); int flags = SDL_OPENGL; // | SDL_FULLSCREEN; --- 304,314 ---- char* vrmlFilename = argv[1]; ! ModelLoader* modelLoader = new X3DLoader(); ! SceneObject* slugMobile = modelLoader->loadModel(vrmlFilename); ! slugMobile->makeDisplayList(); ! ! //Model monkey(vrmlFilename); ! ! int flags = SDL_OPENGL; // | SDL_FULLSCREEN; *************** *** 339,366 **** atexit(SDL_Quit); - //float ratio = (float) width / (float) height; - opengl_init(); reshape_screen(0, 0, renderState.screenWidth(), renderState.screenHeight()); - /* bool done = false; ! GLint halfHeight = height / 2; ! GLint halfWidth = width / 2; ! */ ! ! ModelDrawer monkeyDrawer(&monkey); //GLuint monkeyDisplayListId = makeDisplayListFromModel(&monkey); //cout << "got monkeyDisplayListId [" << monkeyDisplayListId << "]" << endl; ! objectArray.push_back(Object3D(&monkeyDrawer)); ! Object3D& viewPoint = objectArray[0]; ! long objectCount = 0; for(; objectCount < MAX_OBJECTARRAY_SIZE; objectCount++) { objectArray.push_back(&monkeyDrawer); } // randomise the object's initial position if(!randomiseObjects(objectArray, objectCount)) { --- 329,356 ---- atexit(SDL_Quit); opengl_init(); reshape_screen(0, 0, renderState.screenWidth(), renderState.screenHeight()); bool done = false; + Coord3D rotation; + Coord3D position; + Coord3D lightPos; ! ! //ModelDrawer monkeyDrawer(&monkey); //GLuint monkeyDisplayListId = makeDisplayListFromModel(&monkey); //cout << "got monkeyDisplayListId [" << monkeyDisplayListId << "]" << endl; ! //objectArray.push_back(Object3D(&monkeyDrawer)); ! //Object3D& viewPoint = objectArray[0]; ! //long objectCount = 0; + /* for(; objectCount < MAX_OBJECTARRAY_SIZE; objectCount++) { objectArray.push_back(&monkeyDrawer); } + */ + /* // randomise the object's initial position if(!randomiseObjects(objectArray, objectCount)) { *************** *** 368,372 **** --- 358,364 ---- exit(-1); } + */ + /* // disable mouse display SDL_ShowCursor(SDL_DISABLE); *************** *** 380,386 **** statGraphRenderer.setShape(10, 10, 60, 30); // now loop until we are done while(!SystemStateSingleton::instance().done) { ! if(!handleEvents(viewPoint, objectArray, objectCount)) { printf("Error in event handler!\n"); exit(-1); --- 372,382 ---- statGraphRenderer.setShape(10, 10, 60, 30); + */ + + + // now loop until we are done while(!SystemStateSingleton::instance().done) { ! if(!handleEvents(rotation, position, lightPos)) { printf("Error in event handler!\n"); exit(-1); *************** *** 395,405 **** } if(!updateObjects(objectArray, objectCount, SystemStateSingleton::instance().tickDiff)) { printf("Couldn't update objects\n"); exit(-1); } reshape_screen(0, 0, renderState.screenWidth(), renderState.screenHeight()); ! /* Clear the color and depth buffers. */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //reshape_screen(halfWidth, 0, halfWidth, height); --- 391,403 ---- } + /* if(!updateObjects(objectArray, objectCount, SystemStateSingleton::instance().tickDiff)) { printf("Couldn't update objects\n"); exit(-1); } + */ reshape_screen(0, 0, renderState.screenWidth(), renderState.screenHeight()); ! // Clear the color and depth buffers. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //reshape_screen(halfWidth, 0, halfWidth, height); *************** *** 407,414 **** //cout << "<main>\tmonkeyDisplayListId [" << monkeyDisplayListId << "]" << endl; ! draw_screen(viewPoint, objectArray, objectCount); //reshape_screen(0, 0, halfWidth, height); //draw_screen(cposX + 10, cposY + 10, cposZ + 2, clposX, clposY, clposZ, xAngle, yAngle, zAngle); ! statGraphRenderer.render(); SDL_GL_SwapBuffers(); --- 405,476 ---- //cout << "<main>\tmonkeyDisplayListId [" << monkeyDisplayListId << "]" << endl; ! // draw_screen(viewPoint, objectArray, objectCount); //reshape_screen(0, 0, halfWidth, height); //draw_screen(cposX + 10, cposY + 10, cposZ + 2, clposX, clposY, clposZ, xAngle, yAngle, zAngle); ! // statGraphRenderer.render(); ! ! 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); ! glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); ! glEnable(GL_LIGHT0); ! ! glEnable(GL_LIGHTING); ! glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light); ! glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); ! glMatrixMode( GL_MODELVIEW ); ! glLoadIdentity( ); ! ! glColor3f(0.2, 0.2, 0.2); ! if(0 && SystemStateSingleton::instance().showGrid) { ! glutWireSphere(10.0, 50, 50); ! } ! ! //glTranslatef(0, 0, -10); ! // call draw here] ! ! glRotatef(-rotation.m_x, 1.0, 0.0, 0.0); ! glRotatef(-rotation.m_y, 0.0, 1.0, 0.0); ! 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); ! glBegin(GL_LINES); ! glVertex3f(10, 0, -20); ! glVertex3f(-10, 0, -20); ! glEnd(); ! glBegin(GL_LINES); ! glVertex3f(0, 10, -20); ! glVertex3f(0, -10, -20); ! glEnd(); ! glBegin(GL_LINES); ! glVertex3f(0, 0, -20); ! glVertex3f(0, 0, -10); ! glEnd(); ! ! glBegin(GL_LINES); ! glVertex3f(10, 20, -20); ! glVertex3f(-10, 20, 20); ! glEnd(); ! glBegin(GL_LINES); ! glVertex3f(0, 20, -20); ! glVertex3f(0, -20, 20); ! glEnd(); ! glBegin(GL_LINES); ! glVertex3f(0, 20, -20); ! glVertex3f(0, 20, 20); ! glEnd(); ! ! ! slugMobile->draw(); SDL_GL_SwapBuffers(); *************** *** 430,433 **** --- 492,499 ---- /* $Log$ + Revision 1.4 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.3 2004/06/24 19:46:40 o3dozone - added magic CVS tags Index: opengl_utils.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/opengl_utils.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** opengl_utils.h 24 Jun 2004 10:45:23 -0000 1.1.1.1 --- opengl_utils.h 23 Jul 2004 05:43:48 -0000 1.2 *************** *** 4,11 **** #include <stdlib.h> ! #include <SDL.h> ! #include <GL/gl.h> ! #include <GL/glu.h> ! #include <GL/glut.h> #include "object3d.h" --- 4,8 ---- #include <stdlib.h> ! #include "opengl_includes.h" #include "object3d.h" Index: scene_object.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/scene_object.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scene_object.cpp 21 Jul 2004 19:32:44 -0000 1.2 --- scene_object.cpp 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 7,11 **** SceneObject::SceneObject(SceneObject* parent) ! : m_parent(parent) { } --- 7,11 ---- SceneObject::SceneObject(SceneObject* parent) ! : m_parent(parent), m_displayListCreated(false) { } *************** *** 21,25 **** } ! bool SceneObject::draw(bool drawChildren) { } --- 21,62 ---- } ! bool SceneObject::makeDisplayList() { ! // first draw this object ! // generate a display list if we haven't already ! if(!m_displayListCreated) { ! if(_makeDisplayList()) { ! m_displayListCreated = true; ! } else { ! draw(); ! } ! // now call the display list ! } else { ! glCallList(m_displayListIndex); ! glFlush(); ! } ! ! return true; ! } ! ! bool SceneObject::draw() { ! // draw if there is no display list ! if(!m_displayListCreated) { ! _draw(); ! // otherwise call the display list ! } else { ! glCallList(m_displayListIndex); ! glFlush(); ! } ! ! return true; ! } ! ! bool SceneObject::_draw() { ! // then the children ! for(vector<SceneObject*>::iterator i = m_children.begin(); i != m_children.end(); i++) { ! (*i)->draw(); ! } ! ! return true; } *************** *** 27,36 **** --- 64,98 ---- m_parent = rhs.m_parent; m_children = rhs.m_children; + m_displayListCreated = rhs.m_displayListCreated; + m_displayListIndex = rhs.m_displayListIndex; return *this; } + bool SceneObject::_makeDisplayList() { + m_displayListIndex = glGenLists(1); + if(m_displayListIndex == 0) { + cout << "<ModelDrawer::_makeDisplayList>\terror when generating display list" << endl; + return false; + } + cout << "<ModelDrawer::_makeDisplayList>\tgot m_displayListIndex [" << m_displayListIndex << "]" << endl; + + glNewList(m_displayListIndex, GL_COMPILE); + if(!_draw()) { + cout << "<ModelDrawer::_makeDisplayList>\tcouldn't draw model" << endl; + return false; + } + glEndList(); + + return true; + }; + + /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' Index: model_loader.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/model_loader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** model_loader.h 21 Jul 2004 19:34:51 -0000 1.1 --- model_loader.h 23 Jul 2004 05:43:48 -0000 1.2 *************** *** 36,47 **** private: ! bool _parseX3DFile(const char* filename); SceneObject* _convertDOMNode(DOMNode* domNode, SceneObject* parent = NULL, long curLevel = 0); ! SceneObject* _createSceneObjectFromDOMNode(DOMNode* domNode); ! bool _convertCharToIntVector(vector<int>& intVector, string intString); }; /* $Log$ Revision 1.1 2004/07/21 19:34:51 o3dozone - model loader initial import --- 36,52 ---- private: ! SceneObject* _parseX3DFile(const char* filename); SceneObject* _convertDOMNode(DOMNode* domNode, SceneObject* parent = NULL, long curLevel = 0); ! SceneObject* _createSceneObjectFromDOMNode(DOMNode* domNode, bool& parentMustHandleChildren); ! bool _convertCharToVector(vector<int>& intVector, string intString); ! bool _convertCharToVector(vector<double>& intVector, string intString); }; /* $Log$ + Revision 1.2 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.1 2004/07/21 19:34:51 o3dozone - model loader initial import Index: model_loader.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/model_loader.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** model_loader.cpp 22 Jul 2004 05:01:37 -0000 1.2 --- model_loader.cpp 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 13,29 **** SceneObject* X3DLoader::loadModel(const string filename) { ! if(!_parseX3DFile(filename.c_str())) { cout << "error parsing x3d file" << endl; abort(); } ! cout << "stopping now" << endl; ! abort(); ! ! return NULL; } ! bool X3DLoader::_parseX3DFile(const char* filename) { try { XMLPlatformUtils::Initialize(); --- 13,27 ---- SceneObject* X3DLoader::loadModel(const string filename) { ! SceneObject* sceneRoot = NULL; ! if((sceneRoot = _parseX3DFile(filename.c_str())) == NULL) { cout << "error parsing x3d file" << endl; abort(); } ! return sceneRoot; } ! SceneObject* X3DLoader::_parseX3DFile(const char* filename) { try { XMLPlatformUtils::Initialize(); *************** *** 32,56 **** cout << "Error during initialization [" << message << "]" << endl; XMLString::release(&message); ! return false; } XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); // optional. ! parser->setDoNamespaces(true); // optional ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); try { parser->parse(filename); DOMDocument* domDocument = parser->getDocument(); - SceneObject* sceneRoot = NULL; if(domDocument->getDocumentElement() == NULL) { cout << "empty document" << endl; ! return false; } else if((sceneRoot = _convertDOMNode(domDocument->getDocumentElement())) == NULL) { cout << "couldn't dump dom document" << endl; ! return false; } } catch (const XMLException& toCatch) { --- 30,54 ---- cout << "Error during initialization [" << message << "]" << endl; XMLString::release(&message); ! return NULL; } XercesDOMParser* parser = new XercesDOMParser(); parser->setValidationScheme(XercesDOMParser::Val_Always); // optional. ! //parser->setDoNamespaces(scene); // optional ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase(); parser->setErrorHandler(errHandler); + SceneObject* sceneRoot = NULL; try { parser->parse(filename); DOMDocument* domDocument = parser->getDocument(); if(domDocument->getDocumentElement() == NULL) { cout << "empty document" << endl; ! return NULL; } else if((sceneRoot = _convertDOMNode(domDocument->getDocumentElement())) == NULL) { cout << "couldn't dump dom document" << endl; ! return NULL; } } catch (const XMLException& toCatch) { *************** *** 58,70 **** cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); ! return false; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); ! return false; } catch (...) { cout << "Unexpected Exception \n" ; ! return false; } --- 56,68 ---- cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); ! return NULL; } catch (const DOMException& toCatch) { char* message = XMLString::transcode(toCatch.msg); cout << "Exception message is [" << message << "]" << endl; XMLString::release(&message); ! return NULL; } catch (...) { cout << "Unexpected Exception \n" ; ! return NULL; } *************** *** 72,76 **** delete errHandler; ! return true; } --- 70,74 ---- delete errHandler; ! return sceneRoot; } *************** *** 100,104 **** // get a scene object from the DOM Node ! scene = _createSceneObjectFromDOMNode(domNode); if(scene == NULL) { cout << "<X3DLoader::_convertDOMNode>\tempty scene" << endl; --- 98,104 ---- // get a scene object from the DOM Node ! // *** NOTE *** slightly dodgy, but handleChildren gets set in the _createSceneObjectFromDOMNode call below ! bool handleChildren = true; ! scene = _createSceneObjectFromDOMNode(domNode, handleChildren); if(scene == NULL) { cout << "<X3DLoader::_convertDOMNode>\tempty scene" << endl; *************** *** 110,126 **** cout << "[" << curLevel << "] dumping attributes complete" << endl; ! ! // dump this element's children first ! DOMNode* curChild = domNode->getFirstChild(); ! while(curChild != NULL) { ! // dump the child ! SceneObject* child = _convertDOMNode(curChild, scene, curLevel + 1); ! if((child != NULL) && (child != scene)) { ! scene->addChild(child); } - - // now get the child's sibling - DOMNode* nextChild = curChild->getNextSibling(); - curChild = nextChild; } } /* --- 110,128 ---- cout << "[" << curLevel << "] dumping attributes complete" << endl; ! ! if(handleChildren) { ! // dump this element's children first ! DOMNode* curChild = domNode->getFirstChild(); ! while(curChild != NULL) { ! // dump the child ! SceneObject* child = _convertDOMNode(curChild, scene, curLevel + 1); ! if((child != NULL) && (child != scene)) { ! scene->addChild(child); ! } ! ! // now get the child's sibling ! DOMNode* nextChild = curChild->getNextSibling(); ! curChild = nextChild; } } } /* *************** *** 156,160 **** } ! SceneObject* X3DLoader::_createSceneObjectFromDOMNode(DOMNode* domNode) { assert(domNode != NULL); assert(domNode->getNodeType() == DOMNode::ELEMENT_NODE); --- 158,162 ---- } ! SceneObject* X3DLoader::_createSceneObjectFromDOMNode(DOMNode* domNode, bool& parentMustHandleChildren) { assert(domNode != NULL); assert(domNode->getNodeType() == DOMNode::ELEMENT_NODE); *************** *** 165,171 **** --- 167,181 ---- // This is the only node we are going to handle for the moment if(strcmp(nodeName, "IndexedFaceSet") == 0) { + // parent must ignore children, we can handle them! + 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(); *************** *** 173,193 **** // get the coord indices DOMNode* coordIndexesNode = attributes->getNamedItem(XMLString::transcode("coordIndex")); - vector<int> coordIndexes; if(coordIndexesNode->getNodeValue() != NULL) { //cout << "coordIndexes [" << XMLString::transcode(coordIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToIntVector(coordIndexes, XMLString::transcode(coordIndexesNode->getNodeValue())); } // get the normal indices DOMNode* normalIndexesNode = attributes->getNamedItem(XMLString::transcode("normalIndex")); - vector<int> normalIndexes; if(normalIndexesNode->getNodeValue() != NULL) { //cout << "normalIndexes [" << XMLString::transcode(normalIndexesNode->getNodeValue()) << "]" << endl; ! _convertCharToIntVector(normalIndexes, XMLString::transcode(normalIndexesNode->getNodeValue())); } } // now we need to get the coord/normal objects nodes // done, return --- 183,285 ---- // 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 *************** *** 205,213 **** } ! bool X3DLoader::_convertCharToIntVector(vector<int>& intVector, string intString) { string piece; string::size_type startPos = 0; string::size_type endPos = 0; while(endPos != string::npos) { endPos = intString.find(' ', startPos); --- 297,308 ---- } ! bool X3DLoader::_convertCharToVector(vector<int>& intVector, string intString) { string piece; + //cout << "###############################################" << endl; + string::size_type startPos = 0; string::size_type endPos = 0; + //int pieceCount = 0; while(endPos != string::npos) { endPos = intString.find(' ', startPos); *************** *** 221,225 **** intVector.push_back(atoi(piece.c_str())); ! //cout << "piece [" << piece.c_str() << "]" << endl; startPos += pieceLength; --- 316,321 ---- intVector.push_back(atoi(piece.c_str())); ! //pieceCount++; ! //cout << "piece [" << piece.c_str() << "] pieceCount [" << pieceCount << "]" << endl; startPos += pieceLength; *************** *** 231,235 **** } ! cout << "<X3DLoader::_convertCharToIntVector>\tvector size [" << intVector.size() << "]" << endl; return true; --- 327,365 ---- } ! cout << "<X3DLoader::_convertCharToVector(int)>\tvector size [" << intVector.size() << "]" << endl; ! ! return true; ! } ! ! bool X3DLoader::_convertCharToVector(vector<double>& intVector, string intString) { ! string piece; ! ! //cout << "###############################################" << endl; ! string::size_type startPos = 0; ! string::size_type endPos = 0; ! //int pieceCount = 0; ! while(endPos != string::npos) { ! endPos = intString.find(' ', startPos); ! if(endPos == string::npos) { ! break; ! } ! ! string::size_type pieceLength = endPos - startPos; ! piece = intString.substr(startPos, pieceLength); ! ! intVector.push_back(atof(piece.c_str())); ! ! //pieceCount++; ! //cout << "piece [" << piece.c_str() << "] pieceCount [" << pieceCount << "]" << endl; ! ! startPos += pieceLength; ! while((intString[startPos] == ' ') && (startPos != string::npos)) { ! startPos++; ! } ! ! endPos = startPos; ! } ! ! cout << "<X3DLoader::_convertCharToVector(double)>\tvector size [" << intVector.size() << "]" << endl; return true; *************** *** 238,241 **** --- 368,375 ---- /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/22 05:01:37 o3dozone - tree is now correctly built (albeit very sparse) Index: mesh.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/mesh.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mesh.h 21 Jul 2004 19:32:44 -0000 1.2 --- mesh.h 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 18,21 **** --- 18,22 ---- public: Mesh(SceneObject* parent = NULL); + Mesh(const Mesh& rhs); virtual ~Mesh(); *************** *** 23,26 **** --- 24,29 ---- virtual Mesh& operator=(const Mesh& rhs); + protected: + virtual bool _draw(); private: vector<Polygon> m_polygons; *************** *** 35,38 **** --- 38,45 ---- /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' Index: object3d.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/object3d.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** object3d.h 24 Jun 2004 10:45:22 -0000 1.1.1.1 --- object3d.h 23 Jul 2004 05:43:48 -0000 1.2 *************** *** 9,187 **** #include "model.h" ! typedef long double pos_t; ! ! struct Coord3D { ! Coord3D() ! : m_x(0), m_y(0), m_z(0) ! {}; ! ! Coord3D(pos_t x, pos_t y, pos_t z) ! : m_x(x), m_y(y), m_z(z) ! {}; ! ! Coord3D(const Coord3D& rhs) ! : m_x(rhs.m_x), m_y(rhs.m_y), m_z(rhs.m_z) ! {}; ! ! bool isZero() { ! if(m_x == 0 && m_y == 0 && m_z == 0) { ! return true; ! } else { ! return false; ! } ! }; ! ! bool operator==(const Coord3D& rhs) { ! if((m_x == rhs.m_x) && (m_y == rhs.m_y) && (m_z == rhs.m_z)) { ! return true; ! } else { ! return false; ! } ! }; ! ! bool operator==(const Coord3D& rhs) const { ! return((Coord3D)(*this) == rhs); ! }; ! ! Coord3D& operator=(const Coord3D& rhs) { ! m_x = rhs.m_x; ! m_y = rhs.m_y; ! m_z = rhs.m_z; ! ! return(*this); ! }; ! ! Coord3D operator*(long double rhs) const { ! return((Coord3D)(*this) * rhs); ! }; ! ! Coord3D operator*(long double rhs) { ! Coord3D result(0, 0, 0); ! ! result.m_x = m_x * rhs; ! result.m_y = m_y * rhs; ! result.m_z = m_z * rhs; ! ! return result; ! }; ! ! Coord3D operator+(const Coord3D& rhs) const { ! return((Coord3D)(*this) + rhs); ! }; ! ! Coord3D operator+(const Coord3D& rhs) { ! Coord3D result(0, 0, 0); ! ! result.m_x = m_x + rhs.m_x; ! result.m_y = m_y + rhs.m_y; ! result.m_z = m_z + rhs.m_z; ! ! return result; ! }; ! ! Coord3D operator-(const Coord3D& rhs) const { ! return((Coord3D)(*this) + rhs); ! }; ! ! Coord3D operator-(const Coord3D& rhs) { ! Coord3D result(0, 0, 0); ! ! result.m_x = m_x - rhs.m_x; ! result.m_y = m_y - rhs.m_y; ! result.m_z = m_z - rhs.m_z; ! ! return result; ! }; ! ! Coord3D crossProduct(const Coord3D& rhs) { ! Coord3D result(0, 0, 0); ! ! //(aybz - azby)i+ (azbx - axbz)j+ (axby - aybx)k; ! result.m_x = m_y * rhs.m_z - m_z * rhs.m_y; ! result.m_y = m_z * rhs.m_x - m_x * rhs.m_z; ! result.m_z = m_x * rhs.m_y - m_y * rhs.m_x; ! ! return result; ! }; ! ! Coord3D distance(const Coord3D& rhs) { ! Coord3D result(0, 0, 0); ! ! result.m_x = m_x - rhs.m_x; ! result.m_y = m_y - rhs.m_y; ! result.m_z = m_z - rhs.m_z; ! ! return result; ! }; ! ! void normalise() { ! pos_t vectorLength = length(); ! ! if(vectorLength != 0) { ! m_x /= vectorLength; ! m_y /= vectorLength; ! m_z /= vectorLength; ! } else { ! m_x = 0; ! m_y = 0; ! m_z = 0; ! } ! }; ! ! bool isParallel(const Coord3D& rhs, bool& sameDirection) { ! pos_t x = m_x / rhs.m_x; ! pos_t y = m_y / rhs.m_y; ! pos_t z = m_z / rhs.m_z; ! ! //cout << "<::isParallel>\tx [" << x << "] y [" << y << "] z [" << z << "]" << endl; ! ! /* ! if((m_x == rhs.m_x) && (m_x == 0)) { ! cout << "x is zero" << endl; ! } else if((m_y == rhs.m_y) && (m_y == 0)) { ! cout << "y is zero" << endl; ! } else if((m_z == rhs.m_z) && (m_z == 0)) { ! cout << "z is zero" << endl; ! } ! */ ! ! sameDirection = true; ! ! if((!((m_x == rhs.m_x) && (m_x == 0))) && (!((m_y == rhs.m_y) && (m_y == 0))) && (x != y)) { ! cout << "1" << endl; ! return false; ! } else if((!((m_x == rhs.m_x) && (m_x == 0))) && (!((m_z == rhs.m_z) && (m_z == 0))) && (x != z)) { ! cout << "2" << endl; ! return false; ! } else if((!((m_z == rhs.m_z) && (m_z == 0))) && (!((m_y == rhs.m_y) && (m_y == 0))) && (z != y)) { ! cout << "3" << endl; ! return false; ! } else { ! ! //cout << "parallel" << endl; ! ! if((x < 0) || (y < 0) || (z < 0)) { ! //cout << "\topposite direction" << endl; ! sameDirection = false; ! } ! ! return true; ! } ! }; ! ! pos_t length() const { ! return (pos_t)sqrt(m_x * m_x + m_y * m_y + m_z * m_z); ! } ! ! pos_t length() { ! return (pos_t)sqrt(m_x * m_x + m_y * m_y + m_z * m_z); ! } ! ! pos_t m_x; ! pos_t m_y; ! pos_t m_z; ! }; ! ! Coord3D operator*(long double lhs, const Coord3D& rhs); class Object3D { --- 9,13 ---- #include "model.h" ! #include "coord3d.h" class Object3D { Index: polygon.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/polygon.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** polygon.cpp 21 Jul 2004 19:32:44 -0000 1.2 --- polygon.cpp 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 9,13 **** : SceneObject(parent) { ! cout << "<Mesh::Mesh>\tcalled" << endl; } --- 9,13 ---- : SceneObject(parent) { ! //cout << "<Polygon::Polygon>\tcalled" << endl; } *************** *** 16,38 **** Polygon::Polygon(const Polygon& rhs) { ! cout << "<Polygon::Polygon(copy)>\tcalled" << endl; } ! /* ! bool Polygon::setNormal(double normal) { ! m_normal = normal; return true; } ! bool setCoord(Coord3D& coord) { ! m_coord = coord; return true; } - */ /* $Log$ Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' --- 16,74 ---- Polygon::Polygon(const Polygon& rhs) { ! //cout << "<Polygon::Polygon(copy)>\tcalled" << endl; ! m_coords = rhs.m_coords; ! m_normals = rhs.m_normals; } ! bool Polygon::addNormal(Coord3D& normal) { ! m_normals.push_back(normal); return true; } ! bool Polygon::addCoord(Coord3D& coord) { ! m_coords.push_back(coord); ! ! return true; ! } ! ! bool Polygon::_draw() { ! vector<Coord3D>::size_type verticeCount = m_coords.size(); ! ! // start of drawing ! if(verticeCount == 3) { ! glBegin(GL_TRIANGLES); ! //glBegin(GL_LINES); ! } else if(verticeCount == 4) { ! glBegin(GL_QUADS); ! //glBegin(GL_LINES); ! } else { ! cout << "<Polygon::_draw>\tbad vertice count [" << verticeCount << "]" << endl; ! return false; ! } ! ! ! for(vector<Coord3D>::size_type i = 0; i < verticeCount; i++) { ! glNormal3f(m_normals[i].m_x, m_normals[i].m_y, m_normals[i].m_z); ! glVertex3f(m_coords[i].m_x, m_coords[i].m_y, m_coords[i].m_z); ! } ! ! glEnd(); ! ! glBegin(GL_LINES); ! glVertex3f(0, 1, 0); ! glVertex3f(0, 3, 0); ! glEnd(); ! // end of drawing return true; } /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' Index: polygon.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/polygon.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** polygon.h 21 Jul 2004 19:32:44 -0000 1.2 --- polygon.h 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 8,12 **** #include "scene_object.h" ! //#include "coord3d.h" #include <iostream> --- 8,12 ---- #include "scene_object.h" ! #include "coord3d.h" #include <iostream> *************** *** 18,30 **** virtual ~Polygon(); ! //bool setNormal(double normal); ! //bool setCoord(Coord3D& coord); private: ! double m_normal; ! //Coord3D m_coord; }; /* $Log$ Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' --- 18,36 ---- virtual ~Polygon(); ! bool addNormal(Coord3D& normal); ! bool addCoord(Coord3D& coord); ! protected: ! virtual bool _draw(); private: ! vector<Coord3D> m_normals; ! vector<Coord3D> m_coords; }; /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' Index: scene_object.h =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/scene_object.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** scene_object.h 21 Jul 2004 19:32:44 -0000 1.2 --- scene_object.h 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 9,12 **** --- 9,15 ---- #include <vector> #include <string> + #include <iostream> + + #include "opengl_includes.h" using namespace std; *************** *** 18,31 **** bool addChild(SceneObject* child); ! bool draw(bool drawChildren = true); virtual SceneObject& operator=(const SceneObject& rhs); private: SceneObject* m_parent; vector<SceneObject*> m_children; }; /* $Log$ Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' --- 21,45 ---- bool addChild(SceneObject* child); ! bool makeDisplayList(); ! virtual bool draw(); virtual SceneObject& operator=(const SceneObject& rhs); + protected: + virtual bool _draw(); private: SceneObject* m_parent; vector<SceneObject*> m_children; + bool m_displayListCreated; + GLuint m_displayListIndex; + + bool _makeDisplayList(); }; /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' Index: mesh.cpp =================================================================== RCS file: /cvsroot/grappelmann/spaceplane/mesh.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mesh.cpp 21 Jul 2004 19:32:44 -0000 1.2 --- mesh.cpp 23 Jul 2004 05:43:48 -0000 1.3 *************** *** 12,15 **** --- 12,21 ---- } + Mesh::Mesh(const Mesh& rhs) + : SceneObject(rhs) + { + m_polygons = rhs.m_polygons; + } + Mesh::~Mesh() { } *************** *** 24,34 **** SceneObject::operator=(rhs); ! //m_polygons = rhs.m_polygons; return *this; } /* $Log$ Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' --- 30,55 ---- SceneObject::operator=(rhs); ! m_polygons = rhs.m_polygons; return *this; } + bool Mesh::_draw() { + // first draw myself + + // then draw the children + for(vector<Polygon>::iterator i = m_polygons.begin(); i != m_polygons.end(); i++) { + (*i).draw(); + } + + return true; + } + /* $Log$ + Revision 1.3 2004/07/23 05:43:48 o3dozone + - now correctly parses x3d vertice arrays + - does *not* parse transforms etc + Revision 1.2 2004/07/21 19:32:44 o3dozone - mesh and associated classes now 'work' |