Changeset 3012


Ignore:
Timestamp:
10/08/08 10:45:08 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj

    r2961 r3012  
    197197                                > 
    198198                        </File> 
     199                        <File 
     200                                RelativePath=".\Converter\SimpleTri.cpp" 
     201                                > 
     202                        </File> 
     203                        <File 
     204                                RelativePath=".\Converter\SimpleVec.cpp" 
     205                                > 
     206                        </File> 
    199207                </Filter> 
    200208                <Filter 
     
    211219                                > 
    212220                        </File> 
     221                        <File 
     222                                RelativePath=".\Converter\SimpleTri.h" 
     223                                > 
     224                        </File> 
     225                        <File 
     226                                RelativePath=".\Converter\SimpleVec.h" 
     227                                > 
     228                        </File> 
    213229                </Filter> 
    214230        </Files> 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.cpp

    r2965 r3012  
    11#include "ObjConverter.h" 
     2#include "SimpleTri.h" 
     3#include "SimpleVec.h" 
    24#include "gzstream.h" 
    35#include <iostream> 
     
    3537        for (size_t i = 0; i < substrings.size(); ++ i) 
    3638        { 
    37                 // vertex, normal and texture indices 
     39                // vertex, normal, texture indices 
    3840                char *str = strtok_s(substrings[i], "/", &next_token);     
    3941                int index = (int)strtol(str, NULL, 10) - 1; 
     
    4244                int nIndex = index; 
    4345 
    44                 /*str = strtok_s(substrings[i], "/", &next_token);         
    45                 int tIndex = (int)strtol(str, NULL, 10) - 1; 
    46  
    4746                str = strtok_s(substrings[i], "/", &next_token);           
    48                 int nIndex = (int)strtol(str, NULL, 10) - 1; 
    49 */ 
     47 
     48                if (str != NULL) 
     49                { 
     50                        int idx = (int)strtol(str, NULL, 10) - 1; 
     51                        if (idx) tIndex = idx; 
     52                } 
     53                str = strtok_s(substrings[i], "/", &next_token);           
     54 
     55                if (str != NULL) 
     56                { 
     57                        int idx = (int)strtol(str, NULL, 10) - 1; 
     58                        if (idx) nIndex = idx; 
     59                } 
     60 
    5061                // store indices 
    5162                if (index >= 0) 
     
    5970                if (indices.size() > 2) 
    6071                { 
    61 #if 1 
     72#if 0 
    6273                        int idx1 = 0; 
    6374                        int idx2 = (int)indices.size() - 2; 
     
    7182                        faceVertices.push_back(vertices[indices[idx2]]); 
    7283                        faceVertices.push_back(vertices[indices[idx3]]); 
    73          
    74                         Vector3 dummy(1, 0, 0); 
    75                         faceNormals.push_back(dummy); 
    76                         faceNormals.push_back(dummy); 
    77                         faceNormals.push_back(dummy); 
    78  
    79                         /* 
    80                         const Vector3 v2 = mVertices[2] - mVertices[1]; 
    81                         Normalize(CrossProd(v2, v1)); 
    82  
    83                         faceNormals.push_back(normals[nIndices[idx1]]); 
    84                         faceNormals.push_back(normals[nIndices[idx2]]); 
    85                         faceNormals.push_back(normals[nIndices[idx3]]); 
    86  
    87                         faceTexcoords.push_back(texcoords[tIndices[idx1]]); 
    88                         faceTexcoords.push_back(texcoords[tIndices[idx2]]); 
    89                         faceTexcoords.push_back(texcoords[tIndices[idx3]]); 
    90                         */ 
     84 
     85                        if (!normals.empty()) 
     86                        { 
     87                                faceNormals.push_back(normals[nIndices[idx1]]); 
     88                                faceNormals.push_back(normals[nIndices[idx2]]); 
     89                                faceNormals.push_back(normals[nIndices[idx3]]); 
     90                        } 
     91                        else 
     92                        { 
     93                                // no face normals? 
     94                                const SimpleTri tri(vertices[indices[idx1]], vertices[indices[idx2]], vertices[indices[idx3]]); 
     95                                const SimpleVec n = tri.GetNormal(); 
     96 
     97                                faceNormals.push_back(n); 
     98                                faceNormals.push_back(n); 
     99                                faceNormals.push_back(n); 
     100                        } 
     101 
     102                        if (!texcoords.empty()) 
     103                        { 
     104                                faceTexcoords.push_back(texcoords[tIndices[idx1]]); 
     105                                faceTexcoords.push_back(texcoords[tIndices[idx2]]); 
     106                                faceTexcoords.push_back(texcoords[tIndices[idx3]]); 
     107                        } 
    91108                } 
    92109        } 
     
    121138 
    122139        // convert the triangles to geometry 
    123         geom->mVertices = new Vector3[numElements]; 
    124         geom->mNormals = new Vector3[numElements]; 
     140        geom->mVertices = new SimpleVec[numElements]; 
     141        geom->mNormals = new SimpleVec[numElements]; 
    125142        geom->mTexcoords = new Texcoord[numElements]; 
    126143 
     
    132149        for (int i = 0; i < numElements; ++ i) 
    133150        { 
     151#if 0 
    134152                geom->mVertices[i].x = faceVertices[i].x; 
    135153                geom->mVertices[i].y = -faceVertices[i].z; 
    136154                geom->mVertices[i].z = faceVertices[i].y; 
    137  
     155         
    138156                geom->mNormals[i].x = faceNormals[i].x; 
    139157                geom->mNormals[i].y = -faceNormals[i].z; 
    140158                geom->mNormals[i].z = faceNormals[i].y; 
    141  
     159#else 
     160                geom->mVertices[i].x = faceVertices[i].x; 
     161                geom->mVertices[i].y = faceVertices[i].y; 
     162                geom->mVertices[i].z = faceVertices[i].z; 
     163         
     164                geom->mNormals[i].x = faceNormals[i].x; 
     165                geom->mNormals[i].y = faceNormals[i].y; 
     166                geom->mNormals[i].z = faceNormals[i].z; 
     167 
     168#endif 
    142169                if (i < geom->mTexcoordCount) 
    143170                { 
     
    220247                                case 'n' : 
    221248                                        sscanf(str + 2, "%f %f %f", &x, &y, &z); 
    222                                         normals.push_back(Vector3(x, y, z)); 
     249                                        normals.push_back(SimpleVec(x, y, z)); 
    223250                                        break; 
    224251                                case 't': 
     
    228255                                default: 
    229256                                        sscanf(str + 1, "%f %f %f", &x, &y, &z); 
    230                                         vertices.push_back(Vector3(x, y, z)); 
     257                                        vertices.push_back(SimpleVec(x, y, z)); 
    231258                                        //cout <<"v " << x << " " << y << " "<< z << " "; 
    232259                                } 
     
    242269                                                faceVertices, faceNormals, faceTexcoords); 
    243270 
    244                                 if (((line % 1000) == 999) &&  
    245                                         !faceVertices.empty()) 
     271                                if (0 && 
     272                                        (((line % 1000) == 999) && !faceVertices.empty())) 
    246273                                { 
    247274                                        ++ mNumShapes; 
     
    299326        str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 
    300327   
    301         str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(Vector3) * vertexCount); 
    302         str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(Vector3) * vertexCount); 
     328        str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(SimpleVec) * vertexCount); 
     329        str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(SimpleVec) * vertexCount); 
    303330 
    304331        int texCoordCount = geom->mTexcoordCount; 
     
    330357        if (hasMaterial) 
    331358        { 
    332                 Vector3 ambient, diffuse, black; 
     359                SimpleVec ambient, diffuse, black; 
    333360 
    334361                ambient.x = ambient.y = ambient.z = 0.2f; 
     
    337364 
    338365                // only write rgb part of the material 
    339                 str.write(reinterpret_cast<char *>(&ambient), sizeof(Vector3)); 
    340                 str.write(reinterpret_cast<char *>(&diffuse), sizeof(Vector3)); 
    341                 str.write(reinterpret_cast<char *>(&black), sizeof(Vector3)); 
    342                 str.write(reinterpret_cast<char *>(&black), sizeof(Vector3)); 
     366                str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec)); 
     367                str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec)); 
     368                str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
     369                str.write(reinterpret_cast<char *>(&black), sizeof(SimpleVec)); 
    343370        } 
    344371} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/ObjConverter.h

    r2961 r3012  
    22#define _OBJCONVERTER_H 
    33 
     4#include "SimpleVec.h" 
    45#include <string> 
    56#include <vector> 
    67 
    7 struct Vector3 
     8/*struct SimpleVec 
    89{ 
    9         Vector3() {} 
    10         Vector3(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 
     10        SimpleVec() {} 
     11        SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {} 
    1112 
    1213        float x, y, z; 
    13 }; 
     14};*/ 
    1415 
    15 typedef std::vector<Vector3> VertexArray; 
     16typedef std::vector<SimpleVec> VertexArray; 
    1617typedef std::pair<float, float> Texcoord; 
    1718 
     
    3637        struct Geometry 
    3738        { 
    38                 Vector3 *mVertices; 
    39                 Vector3 *mNormals; 
     39                SimpleVec *mVertices; 
     40                SimpleVec *mNormals; 
    4041                Texcoord *mTexcoords; 
    4142 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter/main.cpp

    r2963 r3012  
    1515        cout << "converting obj to dem format" << endl; 
    1616 
    17 /*      if (!converter.Convert(model_path + argv[1], model_path + argv[2])) 
     17        if (!converter.Convert(model_path + argv[1], model_path + argv[2])) 
    1818        { 
    1919                cerr << "conversion failed" << endl; 
    2020                exit(0); 
    2121        } 
    22 */ 
    23         //if (!converter.Convert(model_path + "toyplane.obj", model_path + "toyplane.dem")) 
    24         //      cerr << "conversion failed" << endl; 
    25  
    26         //if (!converter.Convert(model_path + "sky.obj", model_path + "sky.dem")) 
    27         //      cerr << "conversion failed" << endl; 
    28  
    29         if (!converter.Convert(model_path + "city_full.obj", model_path + "city_full.dem")) 
    30                 cerr << "conversion failed" << endl; 
    3122 
    3223        cout << "conversion successful" << endl; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln

    r3010 r3012  
    66Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Converter", "Converter.vcproj", "{93A522E1-76F0-4D46-9C97-30DC2DDB531D}" 
    77EndProject 
    8 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FriendlyCulling", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}" 
     8Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MainApp", "MainApp.vcproj", "{A564071F-D054-4556-883B-999D7F9CC58C}" 
    99        ProjectSection(ProjectDependencies) = postProject 
    1010                {03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023} 
    1111        EndProjectSection 
     12EndProject 
     13Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IrradianceMapping", "IrradianceMapping.vcproj", "{91680C49-A358-48AE-A02C-66CB884B7D7F}" 
    1214EndProject 
    1315Global 
     
    2931                {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.ActiveCfg = Release|Win32 
    3032                {A564071F-D054-4556-883B-999D7F9CC58C}.Release|Win32.Build.0 = Release|Win32 
     33                {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.ActiveCfg = Debug|Win32 
     34                {91680C49-A358-48AE-A02C-66CB884B7D7F}.Debug|Win32.Build.0 = Debug|Win32 
     35                {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32 
     36                {91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32 
    3137        EndGlobalSection 
    3238        GlobalSection(SolutionProperties) = preSolution 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj

    r3011 r3012  
    33        ProjectType="Visual C++" 
    44        Version="8,00" 
    5         Name="FriendlyCulling" 
     5        Name="MainApp" 
    66        ProjectGUID="{A564071F-D054-4556-883B-999D7F9CC58C}" 
    77        RootNamespace="MainApp" 
     
    143143                                Name="VCLinkerTool" 
    144144                                AdditionalDependencies="DemoEngine.lib glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib zlib.lib cg.lib cgGL.lib" 
     145                                OutputFile="$(OutDir)\FriendlyCulling.exe" 
    145146                                LinkIncremental="1" 
    146147                                AdditionalLibraryDirectories="&quot;lib/$(ConfigurationName)&quot;;libs;&quot;$(CG_LIB_PATH)&quot;;libs/GL;libs/Devil/lib;libs/Zlib/lib" 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3010 r3012  
    5959/// the renderable scene geometry 
    6060SceneEntityContainer sceneEntities; 
     61SceneEntityContainer sceneEntities2; 
     62 
    6163// traverses and renders the hierarchy 
    6264RenderTraverser *traverser = NULL; 
     
    440442        loader = new ResourceManager(); 
    441443 
    442         //const string filename("data/city/model/city.dem"); 
    443444        const string filename = string(model_path + "city.dem"); 
    444445 
    445446        if (loader->Load(filename, sceneEntities)) 
    446                 cout << "scene " << filename << " loaded" << endl; 
     447                cout << "model " << filename << " loaded" << endl; 
    447448        else 
    448449        { 
    449                 cerr << "loading scene " << filename << " failed" << endl; 
     450                cerr << "loading model " << filename << " failed" << endl; 
    450451                CleanUp(); 
    451452                exit(0); 
     
    463464        } 
    464465         
    465 #if 0 
    466  
    467         int merged = 0; 
    468  
    469         SceneEntity *oldEnt = NULL; 
    470  
    471         cout << "merging entities .. " << endl; 
    472         SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 
    473  
    474         for (sit = sceneEntities.begin(); sit < sit_end; ++ sit) 
    475         { 
    476                 SceneEntity *newEnt = (*sit); 
    477  
    478                 if (!newEnt->GetTransform()->IsIdentity()) 
    479                 { 
    480                         sceneEntities2.push_back(newEnt); 
    481                         continue; 
    482                 } 
    483  
    484                 if (oldEnt) 
    485                 { 
    486                         EntityMerger merger(newEnt, oldEnt); 
    487                         SceneEntity *ent = merger.Merge(); 
    488  
    489                         sceneEntities2.push_back(ent); 
    490  
    491                         oldEnt = NULL; 
    492  
    493                         ++ merged; 
    494                 } 
    495                 else 
    496                 { 
    497                         oldEnt = newEnt; 
    498                 } 
    499         } 
    500  
    501         if (oldEnt && oldEnt->GetTransform()->IsIdentity()) 
    502                 sceneEntities2.push_back(oldEnt); 
    503  
    504         cout << "merged " << merged << " of " << (int)sceneEntities.size() << " entities " << endl; 
    505 #endif 
    506466 
    507467        // set far plane based on scene extent 
     
    11711131                // actually render the scene geometry using the specified algorithm 
    11721132                traverser->RenderScene(); 
    1173                 //renderQueue->Apply(); 
    11741133        } 
    11751134 
Note: See TracChangeset for help on using the changeset viewer.