Commits

Frederic De Groef committed 8ecbbfb

added namespace qualifiers

Comments (0)

Files changed (2)

ogre-lib3ds/Test3DSViewerApp.cpp

 
     return out;
 }
-
-
-
-
+//------------------------------------------------------------------------------
 Test3DSViewerApp::Test3DSViewerApp(void)
     :OgreApplication("3DS loader")
     ,mDummyCnt(0)
 //------------------------------------------------------------------------------
 void Test3DSViewerApp::_build3dsModel()
 {
-    SceneNode *modelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("3ds model");
+    Ogre::SceneNode *modelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("3ds model");
  
     //m3dsFile =  lib3ds_file_open("../media/3ds/test3.3DS");
     //m3dsFile =  lib3ds_file_open("../media/3ds/indochine.3DS");
 
 
 
-    Real width = mAABB.getSize()[0];
-    Real scale = 1000.0/width;
+    Ogre::Real width = mAABB.getSize()[0];
+    Ogre::Real scale = 1000.0/width;
     modelNode->scale(scale, scale, scale);
     modelNode->pitch(Degree(-90));
 
  
 }
 //------------------------------------------------------------------------------
-void Test3DSViewerApp::_dumpNode(Log *_log, Lib3dsNode *_node
-                                , int _level, std::string _basename)
+void Test3DSViewerApp::_dumpNode(
+                                 Ogre::Log *_log
+                                 , Lib3dsNode *_node
+                                 , int _level
+                                 , std::string _basename)
 {
     boost::format fmt("%s [mesh : %s]");
     std::stringstream s;
 //------------------------------------------------------------------------------
 void Test3DSViewerApp::_buildSubtree(Lib3dsNode *_node
                                     ,const std::string &_basename
-                                    ,SceneNode *_parentNode)
+                                    ,Ogre::SceneNode *_parentNode)
 {
     boost::format fullNameFmt("%s/%06d%s");
 
     }
 }
 //------------------------------------------------------------------------------
-MeshPtr Test3DSViewerApp::_convert3dsMeshToOgreMesh(Lib3dsMesh *_mesh
-                                                    , Lib3dsMeshInstanceNode *_node
-                                                    , const std::string &_basename)
+Ogre::MeshPtr Test3DSViewerApp::_convert3dsMeshToOgreMesh(
+    Lib3dsMesh *_mesh
+    , Lib3dsMeshInstanceNode *_node
+    , const std::string &_basename)
 {
     boost::format fmt("%s -- %s");
     fmt % _basename % _mesh->name;
     std::string fullMeshName = fmt.str();
 
     m3dsBuildLog->logMessage(std::string("building new mesh : ") + fullMeshName+".mesh");
-    ManualObject *newObject = mSceneMgr->createManualObject(fullMeshName);
+    Ogre::ManualObject *newObject = mSceneMgr->createManualObject(fullMeshName);
     Lib3dsMesh *mesh = _mesh;
     Lib3dsMeshInstanceNode *node = _node;
 
     
     // create translated ogre manualobject
 
-        float inv_matrix[4][4], M[4][4];
-        float tmp[3];
-        //int i;
+    float inv_matrix[4][4], M[4][4];
+    float tmp[3];
+    //int i;
 
-        lib3ds_matrix_copy(M, node->base.matrix);
-        lib3ds_matrix_translate(M, -node->pivot[0], -node->pivot[1], -node->pivot[2]);
-        lib3ds_matrix_copy(inv_matrix, mesh->matrix);
-        lib3ds_matrix_inv(inv_matrix);
-        lib3ds_matrix_mult(M, M, inv_matrix);
+    lib3ds_matrix_copy(M, node->base.matrix);
+    lib3ds_matrix_translate(M, -node->pivot[0], -node->pivot[1], -node->pivot[2]);
+    lib3ds_matrix_copy(inv_matrix, mesh->matrix);
+    lib3ds_matrix_inv(inv_matrix);
+    lib3ds_matrix_mult(M, M, inv_matrix);
 
-        for (int i = 0; i < mesh->nvertices; ++i) {
-            lib3ds_vector_transform(tmp, M, mesh->vertices[i]);
-            lib3ds_vector_copy(mesh->vertices[i], tmp);
+    for (int i = 0; i < mesh->nvertices; ++i) 
+    {
+        lib3ds_vector_transform(tmp, M, mesh->vertices[i]);
+        lib3ds_vector_copy(mesh->vertices[i], tmp);
+    }
+    
+    float (*normals)[3] = (float(*)[3])malloc(sizeof(float) * 9 * mesh->nfaces);
+    lib3ds_mesh_calculate_vertex_normals(mesh, normals);
+        
+    // copy everything to vertex buffers
+    newObject->begin("Shading/Phong", RenderOperation::OT_TRIANGLE_LIST);
+
+    int idx = 0;
+
+    // foreach tri
+    for(int tri_idx = 0 ; tri_idx < mesh->nfaces ; ++tri_idx)
+    {
+           
+        // foreach vertex in tri
+        for(int j=0 ; j<3 ; ++j)
+        {
+            Ogre::Vector3 pos, norm;
+            Ogre::Vector2 tc;
+                   
+            pos = Ogre::Vector3(mesh->vertices[mesh->faces[tri_idx].index[j]]);
+            newObject->position(pos);
+                                
+            if(mesh->texcos)
+                tc = Ogre::Vector2(mesh->texcos[mesh->faces[tri_idx].index[j]]);
+            norm = Ogre::Vector3(normals[idx]);
+
+            newObject->normal(norm);
+
+            newObject->index(idx++);
         }
-        float (*normals)[3] = (float(*)[3])malloc(sizeof(float) * 9 * mesh->nfaces);
-        lib3ds_mesh_calculate_vertex_normals(mesh, normals);
-        
-        // copy everything to vertex buffers
-        newObject->begin("Shading/Phong", RenderOperation::OT_TRIANGLE_LIST);
+    }
 
-        int idx = 0;
-
-        // foreach tri
-        for(int tri_idx = 0 ; tri_idx < mesh->nfaces ; ++tri_idx)
-        {
-           
-            // foreach vertex in tri
-            for(int j=0 ; j<3 ; ++j)
-            {
-                Vector3 pos, norm;
-                Vector2 tc;
-                   
-                pos = Vector3(mesh->vertices[mesh->faces[tri_idx].index[j]]);
-                newObject->position(pos);
-                                
-                if(mesh->texcos)
-                    tc = Vector2(mesh->texcos[mesh->faces[tri_idx].index[j]]);
-                norm = Vector3(normals[idx]);
-
-
-                newObject->normal(norm);
-
-                newObject->index(idx++);
-            }
-        }
-
-        newObject->end();
-        free(normals); 
+    newObject->end();
+    free(normals); 
 
     //restore mesh for future use
     memcpy(mesh->vertices, orig_vertices, sizeof(float) * 3 * mesh->nvertices);
     free(orig_vertices);
-
     
     MeshPtr newMesh;
     if(idx)
     for(int i=0 ; i<_3dsfile->nmeshes ; ++i)
     {
         Lib3dsMesh *mesh = _3dsfile->meshes[i];
-        ManualObject *newObject = mSceneMgr->createManualObject(boost::str(boost::format("%d_%s")% i % mesh->name));
+        Ogre::ManualObject *newObject = 
+            mSceneMgr->createManualObject(boost::str(boost::format("%d_%s")% i % mesh->name));
 
         m3dsBuildLog->logMessage(std::string("building new mesh : ") + newObject->getName());
 
 
         // create an ogre object for easy OgreMesh conversion
         // TODO: better default material
-        newObject->begin("Shading/Phong", RenderOperation::OT_TRIANGLE_LIST);
+        newObject->begin("Shading/Phong", Ogre::RenderOperation::OT_TRIANGLE_LIST);
 
         int idx = 0;
         // foreach tri
             // foreach vertex in tri
             for(int j=0 ; j<3 ; ++j)
             {
-                Vector3 pos, norm;
-                Vector2 tc;
+                Ogre::Vector3 pos, norm;
+                Ogre::Vector2 tc;
 
-                pos = Vector3(mesh->vertices[mesh->faces[tri_idx].index[j]]);
+                pos = Ogre::Vector3(mesh->vertices[mesh->faces[tri_idx].index[j]]);
                 newObject->position(pos);
 
                 if(mesh->texcos)
                 {
-                    tc = Vector2(mesh->texcos[mesh->faces[tri_idx].index[j]]);
+                    tc = Ogre::Vector2(mesh->texcos[mesh->faces[tri_idx].index[j]]);
                     newObject->textureCoord(tc);
                 }
 
-                norm = Vector3(normals[idx]);
+                norm = Ogre::Vector3(normals[idx]);
 
                 newObject->normal(norm);
                 newObject->index(idx++);
         free(orig_vertices);
 
 
-        MeshPtr newMesh;
+        Ogre::MeshPtr newMesh;
         if(idx)
         {
             boost::format fmt("creating new Ogre::Mesh %s [%d vertices]");
     m3dsBuildLog->logMessage("----------------  building meshes ended");
 }
 //------------------------------------------------------------------------------
-void Test3DSViewerApp::_buildSceneFromNode(Lib3dsNode *_3dsNode
-                                           ,SceneNode *_parentNode
-                                           ,const std::string &_basename
-                                           ,int _level
-                                           ,bool _show)
+void Test3DSViewerApp::_buildSceneFromNode(
+    Lib3dsNode *_3dsNode
+    ,Ogre::SceneNode *_parentNode
+    ,const std::string &_basename
+    ,int _level
+    ,bool _show)
 {
     
     boost::format fullNameFmt("%s/%06d%s");
   
-    
     for(Lib3dsNode *p = _3dsNode ; p ; p=p->next)
     {
-        SceneNode *newNode;
-        std::stringstream spaces;
-        for(int i=0 ; i<_level*4 ; ++i)
-        {
-            if ((i%4) == 0)
-                spaces << ".";
-            else
-                spaces << " ";
-        }
+        Ogre::SceneNode *newNode;
+        std::stringstream spaces = _makeIndentSpaces(_level);
+
         boost::format fmt("%s (%d) \t %s \t [%s]");
         fmt % spaces.str() % p->node_id % p->name;
         switch(p->type)
 
         m3dsBuildLog->logMessage(fmt.str());    
         
-        Matrix4 baseMatrix = createMatrix4FromArray(p->matrix);
+        Ogre::Matrix4 baseMatrix = createMatrix4FromArray(p->matrix);
         _logXformMatrix(baseMatrix, spaces, "node->base.matrix : ", true);
     
 
                  
 
             {
-                Matrix4 nodeMatrix = newNode->_getFullTransform();
+                Ogre::Matrix4 nodeMatrix = newNode->_getFullTransform();
                 _logXformMatrix(nodeMatrix, spaces, "SceneNode before xform");
             
                 Matrix4 localXform(Matrix4::IDENTITY);
                 m3dsBuildLog->logMessage(spaces.str() + "    3dsMeshNode->scl : "
                     + StringConverter::toString(scl));
 
-                Matrix4 xform(Matrix4::IDENTITY);
+                Ogre::Matrix4 xform(Matrix4::IDENTITY);
                 xform.setScale(scl);
                 _logXformMatrix(xform, spaces, "mesh instance scale");
 
-                Matrix4 nodeMatrix = newNode->_getFullTransform();
+                Ogre::Matrix4 nodeMatrix = newNode->_getFullTransform();
                 _logXformMatrix(nodeMatrix, spaces, "SceneNode after scale : ");
                 m3dsBuildLog->logMessage("");
             }
                 m3dsBuildLog->logMessage(spaces.str() + "    3dsMeshNode->rot : "
                                                       + StringConverter::toString(rot));
 
-                Matrix4 xform(rot);
+                Ogre::Matrix4 xform(rot);
                 _logXformMatrix(xform, spaces, "mesh instance rotation");
-                Matrix4 nodeMatrix = newNode->_getFullTransform();
+                Ogre::Matrix4 nodeMatrix = newNode->_getFullTransform();
                 _logXformMatrix(nodeMatrix, spaces, "SceneNode after scale & rotate : ");
                 m3dsBuildLog->logMessage("");
             }
                 m3dsBuildLog->logMessage(spaces.str() + "    3dsMeshNode->pos : "
                                                       + StringConverter::toString(pos));
 
-                Matrix4 xform(Matrix4::IDENTITY);
+                Ogre::Matrix4 xform(Matrix4::IDENTITY);
                 xform.makeTrans(pos);
                 _logXformMatrix(xform, spaces, "mesh instance translation");
 
-                Matrix4 nodeMatrix = newNode->_getFullTransform();
+                Ogre::Matrix4 nodeMatrix = newNode->_getFullTransform();
                 _logXformMatrix(nodeMatrix, spaces, "SceneNode after translate");
                 m3dsBuildLog->logMessage("");
             }
                     + StringConverter::toString(Vector3(-n->pivot[0]
                                                         ,-n->pivot[1]
                                                         ,-n->pivot[2])));
-                Matrix4 nodeMatrix = newNode->_getFullTransform();
+                Ogre::Matrix4 nodeMatrix = newNode->_getFullTransform();
                 _logXformMatrix(nodeMatrix, spaces, "SceneNode after pivot");
                 m3dsBuildLog->logMessage("");
             }
             {
                 std::string meshName = mesh->name;
                 
-                Matrix4 meshMatrix = createMatrix4FromArray(mesh->matrix);
+                Ogre::Matrix4 meshMatrix = createMatrix4FromArray(mesh->matrix);
                 _logXformMatrix(meshMatrix, spaces, "mesh matrix : ", true);
 
-                MeshPtr meshToAdd = mCenteredMeshes[meshName];
+                Ogre::MeshPtr meshToAdd = mCenteredMeshes[meshName];
 
                 if(! meshToAdd.isNull())
                 {
                     if(1)//_show)
                     {
 
-                        Entity *ent = mSceneMgr->createEntity(fullName+" Ent"
-                                                            , mCenteredMeshes[meshName]->getName());
+                        Ogre::Entity *ent; 
+                        ent = mSceneMgr->createEntity(
+                            fullName+" Ent"
+                            , mCenteredMeshes[meshName]->getName());
+
                         newNode->attachObject(ent);
 
                         {
     }
 }
 //------------------------------------------------------------------------------
-void Test3DSViewerApp::_logXformMatrix(const Matrix4 &_matrix
+void Test3DSViewerApp::_logXformMatrix(const Ogre::Matrix4 &_matrix
                                       ,const std::stringstream &_spaces
                                       ,const std::string &_title
                                       ,bool _transpose)
     m3dsBuildLog->logMessage("");
 }
 //------------------------------------------------------------------------------
+// upper dupper special test case for one special model
 void Test3DSViewerApp::_buildRadiator()
 {
     mSceneMgr->setFlipCullingOnNegativeScale(false);
     M = Matrix4::IDENTITY;
     M.makeTransform(box210Pos, box210Scl, box210Rot);
     boxMatrix2 = baseMatrix2 * M;
+}
+
+std::string Test3DSViewerApp::_makeIndentSpaces(int _level)
+{
+    std::stringstream spaces;
+    for(int i=0 ; i<_level*4 ; ++i)
+    {
+        if ((i%4) == 0)
+            spaces << ".";
+        else
+            spaces << " ";
+    }
+    return spaces;
 }

ogre-lib3ds/Test3DSViewerApp.h

 #include "OgreApplication.h"
 
 
-    
-
-using namespace Ogre;
-
-class Test3DSViewerApp :
-    public OgreApplication
+class Test3DSViewerApp : public OgreApplication
 {
 public:
     Test3DSViewerApp(void);
     Lib3dsFile *m3dsFile;
     Lib3dsIo m3dsIo;
 
-    ManualObject *mObjectBuilder;
+    Ogre::ManualObject *mObjectBuilder;
 
-    std::map<std::string, MeshPtr> mMeshes;
-    std::list<MeshPtr> mMeshVect;
+    std::map<std::string, Ogre::MeshPtr> mMeshes;
+    std::list<Ogre::MeshPtr> mMeshVect;
 
-    Log *m3dsBuildLog;
+    Ogre::Log *m3dsBuildLog;
     int mDummyCnt, mNodeCnt;
 
     typedef boost::shared_ptr<MovableText> MovableTextPtr;
-    std::map<std::string, MeshPtr> mCenteredMeshes;
+    std::map<std::string, Ogre::MeshPtr> mCenteredMeshes;
     std::map<std::string, MovableTextPtr> mNodeLabels;
 
     Ogre::AxisAlignedBox mAABB;