- Timestamp:
- 06/13/08 18:06:32 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
r2755 r2756 2 2 #include "Matrix4x4.h" 3 3 #include "Geometry.h" 4 #include "SceneEntity.h" 4 5 #include "Material.h" 6 #include "Texture.h" 5 7 //#include "gzstream.h" 6 8 … … 66 68 67 69 68 //SceneEntity *BinaryLoader::LoadS hape(igzstream &str)69 SceneEntity *BinaryLoader::LoadS hape(ifstream &str)70 //SceneEntity *BinaryLoader::LoadSceneEntity(igzstream &str) 71 SceneEntity *BinaryLoader::LoadSceneEntity(ifstream &str) 70 72 { 71 73 Geometry *geom = LoadGeometry(str); 72 74 Material *mat = LoadMaterial(str); 73 74 Matrix4x4 *m; 75 SceneEntity *sceneGeom = new SceneEntity(geom, m , mat);75 Matrix4x4 *trafo = NULL;//IdentityMatrix(); 76 77 SceneEntity *sceneGeom = new SceneEntity(geom, mat, trafo); 76 78 77 79 return sceneGeom; … … 82 84 Material *BinaryLoader::LoadMaterial(ifstream &str) 83 85 { 86 // default material 84 87 Material *mat = new Material(); 85 /*88 86 89 // texture 87 90 int texnameSize; … … 91 94 if (texnameSize) 92 95 { 93 TextureAttributes *texAttr;94 96 char *texname = new char[texnameSize]; 95 str.read(texname, sizeof(char) * texnameSize); 96 97 Texture *tex = get_texture(texname, texAttr); 98 app->setTexture(tex); 99 app->setTextureAttributes(texAttr); 100 } 97 str.read(texname, sizeof(char) *texnameSize); 98 99 100 cout << "loading texture " << texname << " with len " << texnameSize << endl; 101 Texture *tex = new Texture(texname); 102 103 mat->SetTexture(tex); 104 } 105 else 106 cout << "no texture " << texnameSize << endl; 101 107 102 108 // material 103 char hasMaterial;109 /*char hasMaterial; 104 110 str.read(&hasMaterial, sizeof(char)); 105 111 … … 137 143 Geometry *BinaryLoader::LoadGeometry(ifstream &str) 138 144 { 139 /* 145 Vector3 *vertices; 146 Vector3 *normals; 147 float *texcoords; 148 149 150 ////////////// 151 //-- read in vertices 152 140 153 int vertexCount; 141 int stripCount; 142 143 Point3f *vertices; 144 Vector3f *normals = NULL; 145 Point2f *texCoords = NULL; 146 147 int *stripIndexCounts; 148 int *indices; 149 int *normalIndices; 150 151 // todo 152 int colorCount = 0; 153 int normalCount = 0; 154 int texCount = 0; 155 156 int format; 157 158 // read in format 159 str.read(reinterpret_cast<char *>(&format), sizeof(int)); 160 161 format = IndexedTriangleStripArray::COORDINATES 162 | IndexedTriangleStripArray::NORMALS 163 ; 164 165 //OUT1("new format: " << format); 166 154 str.read(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 155 167 156 // end of file reached 168 157 if (str.eof()) 169 158 return NULL; 170 159 171 172 ////////////// 173 // read in vertices 174 175 str.read(reinterpret_cast<char *>(&vertexCount), sizeof(int)); 176 177 vertices = new Point3f[vertexCount]; 178 str.read(reinterpret_cast<char *>(vertices), sizeof(Point3f) * vertexCount); 179 180 181 ///////////////// 182 // read in strip counters 183 184 str.read(reinterpret_cast<char *>(&stripCount), sizeof(int)); 185 186 stripIndexCounts = new int[stripCount]; 187 str.read(reinterpret_cast<char *>(stripIndexCounts), sizeof(int) * stripCount); 188 189 190 ////////// 191 // read in indices 192 193 int indexCount; 194 str.read(reinterpret_cast<char *>(&indexCount), sizeof(int)); 195 indices = new int[indexCount]; 196 str.read(reinterpret_cast<char *>(indices), sizeof(int) * indexCount); 197 198 199 /////////////// 200 // read in normals 201 202 str.read(reinterpret_cast<char *>(&normalCount), sizeof(int)); 203 204 if (normalCount) 205 { 206 normals = new Vector3f[normalCount]; 207 str.read(reinterpret_cast<char *>(normals), sizeof(Vector3f) * normalCount); 208 normalIndices = new int[indexCount]; 209 str.read(reinterpret_cast<char *>(normalIndices), sizeof(int) * indexCount); 210 } 211 212 213 ////////////// 214 // read in texCoords 215 216 str.read(reinterpret_cast<char *>(&texCount), sizeof(int)); 217 if (texCount) 218 { 219 texCoords = new Point2f[texCount]; 220 str.read(reinterpret_cast<char *>(texCoords), sizeof(Point2f) * texCount); 221 } 222 223 IndexedTriangleStripArray *geom = 224 new IndexedTriangleStripArray(vertexCount, 225 normalCount, 226 texCount, 227 colorCount, 228 format, 229 indexCount, 230 stripIndexCounts, 231 stripCount); 232 233 geom->setCoordinates(0, vertices, vertexCount); 234 geom->setCoordinateIndices(0, indices, indexCount); 235 236 237 if (texCount) 238 { 239 geom->setTextureCoordinateIndices(0, indices, indexCount); 240 geom->setTextureCoordinates(0, texCoords, texCount); 241 } 242 243 if (normalCount) 244 { 245 geom->setNormals(0, normals, normalCount); 246 geom->setNormalIndices(0, normalIndices, indexCount); 247 } 248 249 250 /////// 251 //-- cleanup 252 253 DELAPTR(stripIndexCounts); 254 DELAPTR(vertices); 255 DELAPTR(normals); 256 DELAPTR(texCoords); 257 DELAPTR(indices); 258 DELAPTR(normalIndices); 259 260 261 return geom; 262 */ 263 return 0; 160 cout << "vertexcount: " << vertexCount << endl; 161 162 vertices = new Vector3[vertexCount]; 163 str.read(reinterpret_cast<char *>(vertices), sizeof(Vector3) * vertexCount); 164 165 normals = new Vector3[vertexCount]; 166 str.read(reinterpret_cast<char *>(normals), sizeof(Vector3) * vertexCount); 167 168 int texCoordCount; 169 str.read(reinterpret_cast<char *>(&texCoordCount), sizeof(int)); 170 171 if (texCoordCount) 172 { 173 cout << "loading texcoords of size " << texCoordCount << endl; 174 texcoords = new float[texCoordCount * 2]; 175 str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2); 176 } 177 else 178 texcoords = NULL; 179 180 for (int i = 0; i < vertexCount; i += 3) 181 { 182 Triangle3 tri(vertices[i], vertices[i + 1], vertices[i + 2]); 183 Vector3 n = tri.GetNormal(); 184 185 normals[i + 0] = n; 186 normals[i + 1] = n; 187 normals[i + 2] = n; 188 } 189 190 return new Geometry(vertices, normals, texcoords, vertexCount); 264 191 } 265 192 … … 267 194 bool BinaryLoader::Load(const std::string &filename, SceneEntityContainer &geometry) 268 195 { 269 #if 0 270 clear_textures(); // clear the texture table 271 272 BranchGroup *root = new BranchGroup(); 273 //root->setName("start"); 274 igzstream str(filename.c_str());//, ios::binary); 275 276 if (!str.is_open()) 196 //clear_textures(); // clear the texture table 197 198 //igzstream str(filename.c_str());//, ios::binary); 199 ifstream istr(filename.c_str(), ios::binary); 200 201 if (!istr.is_open()) 277 202 return false; 278 203 279 204 // #shapes 280 205 int shapeCount; 281 str.read(reinterpret_cast<char *>(&shapeCount), sizeof(int));206 istr.read(reinterpret_cast<char *>(&shapeCount), sizeof(int)); 282 207 283 208 int progress = 0; 284 209 285 GeometryProcessor geomConv(500000, NULL);286 287 210 for (int i = 0; i < shapeCount; ++ i) 288 211 { 289 Shape3D *shape = LoadShape(str); 290 291 vector<Shape3D *> newShapes; 292 ShapePair shapePair = ShapePair(shape, -1); 293 294 // check, if this node actually contains any geometry 295 CalcNumTrianglesVisitor triangleVisitor; 296 triangleVisitor.Apply(shape); 297 const int numTriangles = triangleVisitor.GetNumTriangles(); 298 299 // the shape should be subdivided => replace old shape 300 if (geomConv.SubdivideShape(newShapes, shapePair, numTriangles)) 301 { 302 OUT1("triangleCount: " << numTriangles << " => subdividing to " << newShapes.size() << " shapes"); 303 delete shape;//shape->unref(); 304 } 305 else 306 { 307 newShapes.push_back(shape); 308 } 309 310 VisibilityGroup * visGrp = new VisibilityGroup(); 311 root->addChild(visGrp); 312 313 for (size_t j = 0; j < newShapes.size(); ++ j) 314 { 315 Shape3D *sh = newShapes[j]; 316 visGrp->addChild(sh); 317 } 318 319 int p = i * 100 / shapeCount; 212 SceneEntity *ent = LoadSceneEntity(istr); 213 geometry.push_back(ent); 214 215 int p = (i + 1) * 100 / shapeCount; 320 216 321 217 if (p >= progress) 322 218 { 323 OUT1("% loaded: " << p);219 cout << "% loaded: " << p << endl; 324 220 progress += 10; 325 221 } 326 222 } 327 223 328 OUT1("bin loading finished"); 329 330 return root; 331 #endif 332 } 333 334 } 224 cout << "bin loading finished" << endl; 225 226 return true; 227 } 228 229 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h
r2755 r2756 26 26 protected: 27 27 28 SceneEntity *LoadS hape(std::ifstream &str);28 SceneEntity *LoadSceneEntity(std::ifstream &str); 29 29 Material *LoadMaterial(std::ifstream &str); 30 30 Geometry *LoadGeometry(std::ifstream &str); -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2755 r2756 10 10 #include "glInterface.h" 11 11 #include "Triangle3.h" 12 12 #include "SceneEntity.h" 13 #include "Geometry.h" 13 14 14 15 namespace CHCDemo … … 557 558 558 559 559 /*560 560 void Bvh::ComputeIds() 561 561 { 562 // collect all nodes, also the nodes from local bvh 563 // warning: root nodes local bvh are not in there, as they 564 // are equivalent geometry bvh leaves 562 // collect all nodes 565 563 BvhNodeContainer nodes; 566 Collect AllNodes(mRoot, nodes);564 CollectNodes(mRoot, nodes); 567 565 568 566 // assign ids to all nodes of the "regular" hierarchy 569 567 int i = 0; 570 HierarchyNodeContainer::const_iterator lit, lit_end = nodes.end();568 BvhNodeContainer::const_iterator lit, lit_end = nodes.end(); 571 569 572 570 for (lit = nodes.begin(); lit != lit_end; ++ lit, ++ i) … … 575 573 } 576 574 } 577 */ 575 578 576 579 577 void Bvh::PrepareVertices() … … 819 817 820 818 for (int i = node->mFirst; i <= node->mLast; ++ i) 821 {822 819 numTriangles += mGeometry[i]->GetGeometry()->CountTriangles(); 823 } 824 820 825 821 return numTriangles; 826 822 } 827 823 828 824 829 float Bvh::Get GeometryArea(BvhNode *node) const825 float Bvh::GetArea(BvhNode *node) const 830 826 { 831 827 return node->mArea; -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2755 r2756 4 4 #define __BVH_H 5 5 6 #include "Geometry.h" 6 #include "common.h" 7 #include "Vector3.h" 8 #include "AxisAlignedBox3.h" 9 //#include "SceneEntity.h" 7 10 8 11 … … 436 439 public: 437 440 441 /** Destructor. 442 */ 443 ~Bvh(); 438 444 /** Returns number of bvh nodes. 439 445 */ 440 inline int GetNumNodes() const { return mNumNodes;}446 inline int GetNumNodes() const { return mNumNodes; } 441 447 /** Returns number of bvh leaves. 442 448 */ 443 inline int GetNumLeaves() const { return mNumNodes / 2 + 1;}449 inline int GetNumLeaves() const { return mNumNodes / 2 + 1;} 444 450 /** Returns root node of the bvh. 445 451 */ … … 505 511 */ 506 512 int CountTriangles(BvhNode *node) const; 507 /** Returns area of the geometry contained in the node. 508 */ 509 float GetGeometryArea(BvhNode *node) const; 513 /** Returns area of the the node. 514 */ 515 float GetArea(BvhNode *node) const; 516 /** Compute unique ids for the nodes. 517 */ 518 void ComputeIds(); 510 519 511 520 … … 534 543 */ 535 544 Bvh(); 536 /** Destructor. 537 */ 538 ~Bvh(); 539 545 540 546 541 547 ///////////// -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
r2755 r2756 29 29 mDirection.Normalize(); 30 30 31 Vector3 side = CrossProd(Vector3(0, 1,0), mDirection);32 mUp = Normalize(CrossProd(side, mDirection));33 mRight = Normalize(CrossProd(mDirection, mUp));31 Vector3 side = CrossProd(Vector3(0, 1, 0), mDirection); 32 mUp = -Normalize(CrossProd(side, mDirection)); 33 mRight = -Normalize(CrossProd(mDirection, mUp)); 34 34 35 35 float k = tan(mFovy/2); … … 55 55 void Camera::LookInBox(const AxisAlignedBox3 &box) 56 56 { 57 mDirection = Vector3(0, 0,1);57 mDirection = Vector3(0, 0, 1); 58 58 mPosition = box.Center(); 59 mPosition.y += 50; 59 60 60 61 Precompute(); … … 64 65 void Camera::LookAtBox(const AxisAlignedBox3 &box) 65 66 { 66 mDirection = box.M ax() - box.Min();67 mPosition = box.M in() - mDirection;67 mDirection = box.Min() - box.Max(); 68 mPosition = box.Max() - mDirection; 68 69 69 70 Precompute(); … … 152 153 153 154 155 void Camera::SetupCameraView() 156 { 157 glLoadIdentity(); 158 gluLookAt(mPosition.x, mPosition.y, mPosition.z, 159 mPosition.x + mDirection.x, mPosition.y + mDirection.y, mPosition.z + mDirection.z, 160 mUp.x, mUp.y, mUp.z); 161 162 //std::cout << "dir: " << mDirection << " pos: " << mPosition << " up: " << mUp << std::endl; 154 163 } 155 164 165 166 } 167 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h
r2755 r2756 49 49 inline float GetAspect() const { return (float) mWidth / mHeight; } 50 50 51 void SetupCameraView(); 51 52 void GetProjectionMatrix(Matrix4x4 &mat); 52 53 void GetModelViewMatrix(Matrix4x4 &mat); -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.cpp
r2755 r2756 1 1 #include "Geometry.h" 2 2 #include "Triangle3.h" 3 #include "glInterface.h" 3 4 4 5 … … 6 7 { 7 8 8 Geometry::Geometry(const TriangleContainer &triangles) 9 {} 10 11 12 SceneEntity::SceneEntity(Geometry *geometry, 13 Matrix4x4 *trafo, 14 Material *mat): 15 mGeometry(geometry), mTransform(trafo), mMaterial(mat) 9 Geometry::Geometry(Vector3 *vertices, 10 Vector3 *normals, 11 float *texcoords, 12 int numVertices): 13 mVertices(vertices), 14 mNormals(normals), 15 mTexCoords(texcoords), 16 mNumVertices(numVertices), 17 mVboId(-1) 16 18 { 19 Prepare(); 17 20 } 18 21 19 22 20 void SceneEntity::Render()23 void Geometry::Prepare() 21 24 { 25 CalcBoundingBox(); 26 27 int dataSize = mNumVertices * 6; 28 29 if (mTexCoords) 30 dataSize += mNumVertices * 2; 31 32 float *data = new float[dataSize]; 33 34 for (int i = 0; i < mNumVertices; ++ i) 35 { 36 ((Vector3 *)data)[i] = mVertices[i]; 37 ((Vector3 *)data)[i + mNumVertices] = mNormals[i]; 38 } 39 40 if (mTexCoords) 41 { 42 for (int i = 0; i < mNumVertices * 2; ++ i) 43 data[mNumVertices * 6 + i] = mTexCoords[i]; 44 } 45 46 glGenBuffersARB(1, &mVboId); 47 48 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 49 50 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 51 glNormalPointer(GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 52 53 if (mTexCoords) 54 { 55 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 56 } 57 glBufferDataARB(GL_ARRAY_BUFFER_ARB, 58 dataSize * sizeof(float), 59 (float *)data, 60 GL_STATIC_DRAW_ARB); 61 62 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 63 64 // data handled by graphics driver from now on 65 delete [] data; 22 66 } 23 67 24 68 25 void SceneEntity::SetGeometry(Geometry *geom)69 void Geometry::Render() 26 70 { 27 mGeometry = geom; 71 glBindBufferARB(GL_ARRAY_BUFFER_ARB, mVboId); 72 73 glVertexPointer(3, GL_FLOAT, 0, (char *)NULL); 74 glNormalPointer(GL_FLOAT, 0, (char *)NULL + mNumVertices * sizeof(Vector3)); 75 76 if (mTexCoords) 77 glTexCoordPointer(2, GL_FLOAT, 0, (char *)NULL + 2 * mNumVertices * sizeof(Vector3)); 78 79 // don't render first degenerate index 80 glDrawArrays(GL_TRIANGLES, 0, mNumVertices); 28 81 } 29 82 30 83 31 void SceneEntity::SetTransformation(Matrix4x4 *trafo)84 void Geometry::CalcBoundingBox() 32 85 { 33 mTransform = trafo; 86 mBoundingBox.Initialize(); 87 88 for (int i = 0; i < mNumVertices; ++ i) 89 { 90 mBoundingBox.Include(mVertices[i]); 91 } 34 92 } 35 93 36 94 37 void SceneEntity::SetMaterial(Material *mat) 38 { 39 mMaterial = mat; 40 } 41 42 43 const AxisAlignedBox3& SceneEntity::GetBoundingVolume() 95 const AxisAlignedBox3& Geometry::GetBoundingBox() const 44 96 { 45 97 return mBoundingBox; … … 47 99 48 100 49 void SceneEntity::SetLastVisited(int lastVisited)50 {51 mLastVisited = lastVisited;52 101 } 53 54 55 int SceneEntity::GetLastVisited() const56 {57 return mLastVisited;58 }59 60 61 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Geometry.h
r2755 r2756 10 10 { 11 11 12 class Material;13 14 15 16 12 /** Represents drawable geometry consisting of triangles 17 13 */ … … 19 15 { 20 16 public: 21 /** Constructor taking a triangle container.17 /** Constructor taking an array of triangles. 22 18 */ 23 Geometry(const TriangleContainer &triangles); 19 Geometry(Vector3 *vertices, Vector3 *normals, float *texcoords, int numVertices); 20 /** Render the geometry 21 */ 22 void Render(); 24 23 25 int CountTriangles() const { return (int)mTriangles.size(); }24 int CountTriangles() const { return mNumVertices / 3; } 26 25 26 inline bool HasTexture() const { return mTexCoords != NULL; } 27 const AxisAlignedBox3& GetBoundingBox() const; 27 28 28 29 protected: 29 30 31 void CalcBoundingBox(); 32 /** Prepare vbos for rendering 33 */ 34 void Prepare(); 35 36 37 ////////// 38 39 unsigned int mVboId; 40 41 Vector3 *mVertices; 42 43 Vector3 *mNormals; 44 45 float *mTexCoords; 46 47 int mNumVertices; 48 30 49 AxisAlignedBox3 mBoundingBox; 31 TriangleContainer mTriangles;32 50 }; 33 51 34 35 /** Class representing a scene entity.36 A scene entity basicly consists of geometry, transformation, and a material37 */38 class SceneEntity39 {40 public:41 42 /** Create scene entity.43 */44 SceneEntity(Geometry *geometry, Matrix4x4 *trafo, Material *mat);45 /** Renders this geometry.46 */47 void Render();48 /** Set pointer to the geometry49 */50 void SetGeometry(Geometry *geom);51 /** See set52 */53 Geometry *GetGeometry() const { return mGeometry; }54 /** Set pointer to the geometry55 */56 void SetTransformation(Matrix4x4 *trafo);57 /** Set pointer to the material58 */59 void SetMaterial(Material *mat);60 /** Returns the transformed bounding box.61 */62 const AxisAlignedBox3& GetBoundingVolume();63 /** set frame where we last visitied this node64 */65 void SetLastVisited(int lastVisited);66 /** returns frame where we last visited this node67 */68 int GetLastVisited() const;69 70 71 protected:72 73 /// transform matrix74 Matrix4x4 *mTransform;75 Geometry *mGeometry;76 Material *mMaterial;77 78 AxisAlignedBox3 mBoundingBox;79 80 int mLastVisited;81 };82 52 83 53 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
r2755 r2756 1 1 #include "common.h" 2 2 #include "Material.h" 3 #include "Texture.h" 4 #include "glInterface.h" 5 3 6 4 7 namespace CHCDemo 5 8 { 6 9 7 RgbColor RandomColor( const float a, constfloat b)10 RgbColor RandomColor(float a, float b) 8 11 { 9 12 return RgbColor(a + Random(b), a + Random(b), a + Random(b)); … … 11 14 12 15 13 14 Material::Material(): mId(0) 15 {} 16 16 void Material::InitMaterial() 17 { 18 mTexture = NULL; 17 19 18 Material::Material(const int id): mId(id) 19 { 20 mAmbientColor = RgbColor(0, 0, 0); 21 mDiffuseColor = RgbColor(1, 1, 1); 22 mSpecularColor = RgbColor(0, 0, 0); 20 23 } 21 24 22 25 23 Material::Material(const RgbColor &color):mDiffuseColor(color), 26 Material::Material(): mId(0) 27 { 28 InitMaterial(); 29 } 30 31 32 Material::Material(int id): 33 mId(id) 34 { 35 InitMaterial(); 36 } 37 38 39 Material::Material(const RgbColor &color): 40 mDiffuseColor(color), 24 41 mAmbientColor(color), 25 mSpecularColor(0,0,0), mId(0) 42 mSpecularColor(0, 0, 0), 43 mId(0), 44 mTexture(NULL) 26 45 { 27 46 } … … 45 64 } 46 65 66 67 void Material::Render() 68 { 69 if (mTexture) 70 mTexture->Bind(); 71 else 72 glBindTexture(GL_TEXTURE_2D, 0); 73 74 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 75 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 76 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r); 47 77 } 78 79 80 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
r2755 r2756 6 6 { 7 7 8 class Texture; 8 9 9 10 class RgbColor … … 54 55 Material(); 55 56 56 Material( constint id);57 Material(int id); 57 58 58 59 Material(const RgbColor &color); … … 63 64 friend Material RandomMaterial(); 64 65 66 Texture *GetTexture() const { return mTexture; } 67 68 void SetTexture(Texture *texture) { mTexture = texture; } 69 /** Renders this material. 70 */ 71 void Render(); 72 65 73 protected: 66 74 67 // unique material id 75 /** Initialize the material with default values 76 */ 77 void InitMaterial(); 78 79 /// unique material id 68 80 int mId; 81 /// the assciated texture 82 Texture *mTexture; 69 83 }; 70 84 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Matrix4x4.h
r2751 r2756 8 8 { 9 9 10 11 10 class Vector3; 12 13 11 14 12 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h
r2753 r2756 7 7 8 8 9 namespace CHCDemo 10 { 11 9 12 // Forward-declare some other classes. 10 13 class Matrix4x4; 11 14 12 13 namespace CHCDemo14 {15 15 16 16 /** Vector class. -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2755 r2756 41 41 Name="VCCLCompilerTool" 42 42 Optimization="0" 43 AdditionalIncludeDirectories=" GL"43 AdditionalIncludeDirectories="Devil/include;GL" 44 44 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" 45 45 MinimalRebuild="true" … … 63 63 <Tool 64 64 Name="VCLinkerTool" 65 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib "65 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib" 66 66 LinkIncremental="2" 67 AdditionalLibraryDirectories="GL "67 AdditionalLibraryDirectories="GL;Devil/lib" 68 68 GenerateDebugInformation="true" 69 69 SubSystem="1" … … 126 126 OmitFramePointers="true" 127 127 EnableFiberSafeOptimizations="true" 128 AdditionalIncludeDirectories="GL "128 AdditionalIncludeDirectories="GL;Devil/include" 129 129 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" 130 130 RuntimeLibrary="2" … … 147 147 <Tool 148 148 Name="VCLinkerTool" 149 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib "149 AdditionalDependencies="glut32.lib glew32s.lib glew32.lib DevIL.lib ILUT.lib" 150 150 LinkIncremental="1" 151 AdditionalLibraryDirectories="GL "152 GenerateDebugInformation=" true"151 AdditionalLibraryDirectories="GL;Devil/lib" 152 GenerateDebugInformation="false" 153 153 SubSystem="1" 154 154 OptimizeReferences="2" … … 186 186 <Files> 187 187 <Filter 188 Name="Source Files"189 Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"190 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"191 >192 <File193 RelativePath=".\Bvh.cpp"194 >195 </File>196 <File197 RelativePath=".\Camera.cpp"198 >199 </File>200 <File201 RelativePath=".\chcdemo.cpp"202 >203 </File>204 <File205 RelativePath=".\Geometry.cpp"206 >207 </File>208 <File209 RelativePath=".\Material.cpp"210 >211 </File>212 <File213 RelativePath=".\OcclusionQuery.cpp"214 >215 </File>216 </Filter>217 <Filter218 Name="Header Files"219 Filter="h;hpp;hxx;hm;inl;inc;xsd"220 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"221 >222 <File223 RelativePath=".\Bvh.h"224 >225 </File>226 <File227 RelativePath=".\Camera.h"228 >229 </File>230 <File231 RelativePath=".\Geometry.h"232 >233 </File>234 <File235 RelativePath=".\Material.h"236 >237 </File>238 <File239 RelativePath=".\OcclusionQuery.h"240 >241 </File>242 </Filter>243 <Filter244 188 Name="utils" 245 189 > … … 324 268 Name="traversal" 325 269 > 326 <File 327 RelativePath=".\CHCPlusPlusTraverser.cpp" 328 > 329 </File> 330 <File 331 RelativePath=".\CHCPlusPlusTraverser.h" 332 > 333 </File> 334 <File 335 RelativePath=".\CHCTraverser.cpp" 336 > 337 </File> 338 <File 339 RelativePath=".\CHCTraverser.h" 340 > 341 </File> 342 <File 343 RelativePath=".\FrustumCullingTraverser.cpp" 344 > 345 </File> 346 <File 347 RelativePath=".\FrustumCullingTraverser.h" 348 > 349 </File> 350 <File 351 RelativePath=".\RenderTraverser.cpp" 352 > 353 </File> 354 <File 355 RelativePath=".\RenderTraverser.h" 356 > 357 </File> 358 <File 359 RelativePath=".\StopAndWaitTraverser.cpp" 360 > 361 </File> 362 <File 363 RelativePath=".\StopAndWaitTraverser.h" 364 > 365 </File> 270 <Filter 271 Name="Header Files" 272 > 273 <File 274 RelativePath=".\CHCPlusPlusTraverser.h" 275 > 276 </File> 277 <File 278 RelativePath=".\CHCTraverser.h" 279 > 280 </File> 281 <File 282 RelativePath=".\FrustumCullingTraverser.h" 283 > 284 </File> 285 <File 286 RelativePath=".\RenderTraverser.h" 287 > 288 </File> 289 <File 290 RelativePath=".\StopAndWaitTraverser.h" 291 > 292 </File> 293 </Filter> 294 <Filter 295 Name="Source Files" 296 > 297 <File 298 RelativePath=".\CHCPlusPlusTraverser.cpp" 299 > 300 </File> 301 <File 302 RelativePath=".\CHCTraverser.cpp" 303 > 304 </File> 305 <File 306 RelativePath=".\FrustumCullingTraverser.cpp" 307 > 308 </File> 309 <File 310 RelativePath=".\RenderTraverser.cpp" 311 > 312 </File> 313 <File 314 RelativePath=".\StopAndWaitTraverser.cpp" 315 > 316 </File> 317 </Filter> 318 </Filter> 319 <Filter 320 Name="render" 321 > 322 <Filter 323 Name="Header Files" 324 Filter="h;hpp;hxx;hm;inl;inc;xsd" 325 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" 326 > 327 <File 328 RelativePath=".\Bvh.h" 329 > 330 </File> 331 <File 332 RelativePath=".\Camera.h" 333 > 334 </File> 335 <File 336 RelativePath=".\Geometry.h" 337 > 338 </File> 339 <File 340 RelativePath=".\Material.h" 341 > 342 </File> 343 <File 344 RelativePath=".\OcclusionQuery.h" 345 > 346 </File> 347 <File 348 RelativePath=".\SceneEntity.h" 349 > 350 </File> 351 <File 352 RelativePath=".\Texture.h" 353 > 354 </File> 355 </Filter> 356 <Filter 357 Name="Source Files" 358 Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" 359 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" 360 > 361 <File 362 RelativePath=".\Bvh.cpp" 363 > 364 </File> 365 <File 366 RelativePath=".\Camera.cpp" 367 > 368 </File> 369 <File 370 RelativePath=".\chcdemo.cpp" 371 > 372 </File> 373 <File 374 RelativePath=".\Geometry.cpp" 375 > 376 </File> 377 <File 378 RelativePath=".\Material.cpp" 379 > 380 </File> 381 <File 382 RelativePath=".\OcclusionQuery.cpp" 383 > 384 </File> 385 <File 386 RelativePath=".\SceneEntity.cpp" 387 > 388 </File> 389 <File 390 RelativePath=".\Texture.cpp" 391 > 392 </File> 393 </Filter> 366 394 </Filter> 367 395 <File -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2753 r2756 1 1 // occquery.cpp : Defines the entry point for the console application. 2 2 // 3 #if TOIMPLEMENT4 5 3 #include <math.h> 6 4 #include <time.h> 5 #include "common.h" 7 6 #include "glInterface.h" 8 7 #include "RenderTraverser.h" 9 10 11 12 bool arbQuerySupport = false; 13 bool nvQuerySupport = false; 14 15 double nearDist = 0.1; // eye near plane distance 8 #include "SceneEntity.h" 9 #include "Vector3.h" 10 #include "Matrix4x4.h" 11 #include "BinaryLoader.h" 12 #include "Bvh.h" 13 #include "Camera.h" 14 #include "Geometry.h" 15 16 17 using namespace std; 18 using namespace CHCDemo; 19 20 21 22 /// the renderable scene geometry 23 SceneEntityContainer sceneEntities; 24 // traverses and renders the hierarchy 25 RenderTraverser *traverser; 26 /// the hierarchy 27 Bvh *bvh; 28 /// the scene camera 29 Camera *camera; 30 /// the scene bounding box 31 AxisAlignedBox3 sceneBox; 32 33 // eye near plane distance 34 float nearDist = 0.1f; 16 35 int winWidth, winHeight; 17 int objectType = Geometry::TEAPOT;18 int nextObjectType = objectType;19 36 20 37 float visZoomFactor = 1.5f; … … 26 43 bool showCreateParams = false; 27 44 28 // traverses and renders the hierarchy 29 RenderTraverser traverser; 30 31 Vector3 eyePos = {0.0, 0.0, 3.0}; // eye position 32 Vector3 viewDir = {0.0, 0.0, -1.0}; // eye view dir 33 Vector3 lightDir = {0.0, 0.0, 1.0}; // light dir 45 46 Vector3 eyePos = Vector3(0.0f, 0.0f, 3.0f); // eye position 47 Vector3 viewDir = Vector3(0.0f, 0.0f, -1.0f); // eye view dir 48 Vector3 lightDir = Vector3(0.0f, 0.0f, 1.0f); // light dir 34 49 35 50 Matrix4x4 eyeView; // eye view matrix … … 41 56 //mouse navigation state 42 57 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 43 int renderMode = RenderTraverser::RENDER_COHERENT;58 //int renderMode = RenderTraverser::RENDER_COHERENT; 44 59 45 60 // relative size of an object … … 51 66 52 67 // this defines the volume where objects can be drawn 53 Vector3 minTranslation = {-2.5f, -2.5f, -3.0f};54 Vector3 maxTranslation = {2.5f, 2.5f, -3.0 - zLength};68 Vector3 minTranslation(-2.5f, -2.5f, -3.0f); 69 Vector3 maxTranslation(2.5f, 2.5f, -3.0 - zLength); 55 70 56 71 const float minAngle = 0; … … 62 77 int renderTimesValid = 0; 63 78 64 typedef vector<Geometry *> GeometryList;65 GeometryList geometry;66 67 79 bool useOptimization = true; 68 bool useArbQueries = false; 80 69 81 70 82 Vector3 amb[2]; … … 72 84 Vector3 spec[2]; 73 85 86 void InitExtensions(void); 87 void DisplayVisualization(); 88 void InitGLstate(void); 89 void CleanUp(void); 90 void SetupEyeView(void); 91 void UpdateEyeMtx(void); 92 93 74 94 void begin2D(void); 75 95 void end2D(void); 76 void output(const int x, const int y, const char *string); 77 void initGLstate(void); 78 void keyboard(const unsigned char c, const int x, const int y); 96 void output(int x, int y, const char *string); 97 void keyboard(const unsigned char c, int x, int y); 79 98 void drawHelpMessage(void); 80 99 void drawStatistics(void); 81 100 void display(void); 82 void special( const int c, const int x, constint y);83 void reshape( const int w, constint h);101 void special(int c, int x, int y); 102 void reshape(int w, int h); 84 103 void mouse(int button, int state, int x, int y); 85 void initExtensions(void);86 104 void leftMotion(int x, int y); 87 //void rightMotion(int x, int y);88 105 void middleMotion(int x, int y); 89 106 void drawEyeView(void); 90 void setupEyeView(void);91 107 void setupVisView(void); 92 void updateEyeMtx(void);93 108 long calcRenderTime(void); 94 109 void resetTimer(void); 95 void cleanUp(void); 96 void calcDecimalPoint(string &str, int d); 97 98 HierarchyNode* generateHierarchy(int numObjects); 99 Geometry *generateGeometry(Vector3 translateRatio, float xRotRatio, 100 float yRotRatio, float zRotRatio, int materialIdx); 101 void displayVisualization(); 102 103 void deleteGeometry(); 104 105 #endif 110 void calcDecimalPoint(std::string &str, int d); 111 112 113 114 void SetupProjection(int w, int h, float angle, const AxisAlignedBox3 &sceneBox) 115 { 116 glViewport(0, 0, w, h); 117 glMatrixMode(GL_PROJECTION); 118 glLoadIdentity(); 119 120 gluPerspective(angle, 1.0, 1.0f, 2.0 * Magnitude(sceneBox.Diagonal())); 121 glMatrixMode(GL_MODELVIEW); 122 } 123 106 124 107 125 int main(int argc, char* argv[]) 108 126 { 109 #if 0 110 glutInitWindowSize(800,600); 111 glutInit(&argc,argv); 127 glutInitWindowSize(800, 600); 128 glutInit(&argc, argv); 112 129 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); 113 130 114 131 glutCreateWindow("Coherent Hierarchical Culling"); 115 132 … … 120 137 glutMouseFunc(mouse); 121 138 glutIdleFunc(display); 122 initExtensions(); 123 initGLstate(); 124 125 leftMotion(0,0); 126 middleMotion(0,0); 127 128 HierarchyNode *hierarchy = generateHierarchy(numObjects); 129 traverser.SetHierarchy(hierarchy); 139 140 InitExtensions(); 141 InitGLstate(); 142 143 leftMotion(0, 0); 144 middleMotion(0, 0); 145 146 BinaryLoader loader; 147 148 const string filename("house_test.dem"); 149 //const string filename("city.dem"); 150 151 camera = new Camera(800, 600); 152 153 if (loader.Load(filename, sceneEntities)) 154 cout << "scene " << filename << " loaded" << endl; 155 else 156 cerr << "loading scene " << filename << " failed" << endl; 157 158 sceneBox.Initialize(); 159 160 SceneEntityContainer::const_iterator it, it_end = sceneEntities.end(); 161 162 for (it = sceneEntities.begin(); it != it_end; ++ it) 163 sceneBox.Include((*it)->GetBoundingBox()); 164 165 Debug << "scene box: " << sceneBox << endl; 166 167 SetupProjection(800, 600, 60, sceneBox); 168 camera->LookAtBox(sceneBox); 169 //camera->LookInBox(sceneBox); 170 //camera->SetPosition(Vector3(0, 0, -3)); 171 //camera->SetDirection(Vector3(0, 0, 1)); 130 172 131 173 /// initialise rendertime array … … 136 178 137 179 // clean up 138 cleanUp();139 #endif 180 CleanUp(); 181 140 182 return 0; 141 183 } 142 184 143 #if 0 144 void initGLstate(void)145 { 146 glClearColor(0. 6, 0.6, 0.8, 1.0);185 186 void InitGLstate(void) 187 { 188 glClearColor(0.0f, 1.0f, 0.0f, 0.0); 147 189 148 190 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 149 191 glPixelStorei(GL_PACK_ALIGNMENT,1); 150 192 151 glDepthRange(0.0, 1.0);152 glClearDepth(1.0);153 193 glDepthFunc(GL_LESS); 154 194 155 195 glEnable(GL_LIGHTING); 156 196 glEnable(GL_LIGHT0); 157 197 //glDisable(GL_LIGHTING); 198 199 glColor3f(1.0f, 0.0f, 0.0f); 158 200 glShadeModel(GL_SMOOTH); 159 201 160 GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0};161 GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0};162 GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0};163 GLfloat position[] = { 0.0, 3.0, 3.0, 0.0};202 GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0}; 203 GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; 204 GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; 205 GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; 164 206 165 GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0};166 GLfloat local_view[] = { 0.0};207 GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; 208 GLfloat local_view[] = {0.0}; 167 209 168 210 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); … … 179 221 glCullFace(GL_BACK); 180 222 glEnable(GL_CULL_FACE); 181 182 glClearColor(0.2, 0.2, 0.8, 0.0); 183 184 setupVisView(); 223 //glDisable(GL_CULL_FACE); 224 225 GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0}; 226 GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0}; 227 GLfloat specularColor[] = {1.0, 1.0, 1.0, 1.0}; 228 229 glMaterialfv(GL_FRONT, GL_AMBIENT, ambientColor); 230 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor); 231 glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); 232 233 glColor3f(1.0f, 0.0f, 0.0f); 234 //setupVisView(); 185 235 } 186 236 … … 226 276 }; 227 277 228 int i;278 229 279 int x = 40, y = 42; 280 230 281 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 231 282 glEnable(GL_BLEND); 232 glColor4f(0.0 ,1.0,0.0,0.2); // 20% green.283 glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green. 233 284 234 285 // Drawn clockwise because the flipped Y axis flips CCW and CW. … … 237 288 glDisable(GL_BLEND); 238 289 239 240 glColor3f(1.0,1.0,1.0); 241 for(i = 0; message[i] != 0; i++) { 242 if(message[i][0] == '\0') { 290 glColor3f(1.0f, 1.0f, 1.0f); 291 292 for(int i = 0; message[i] != 0; i++) 293 { 294 if(message[i][0] == '\0') 295 { 243 296 y += 7; 244 } else { 245 output(x,y,message[i]); 297 } 298 else 299 { 300 output(x, y, message[i]); 246 301 y += 14; 247 302 } … … 250 305 } 251 306 252 // generates a teapot, all parameters between zero and one 253 Geometry *generateGeometry(Vector3 translationRatio, float xRotRatio, 254 float yRotRatio, float zRotRatio, int materialIdx) 255 { 256 float xRot = minAngle + xRotRatio * (maxAngle - minAngle); 257 float yRot = minAngle + yRotRatio * (maxAngle - minAngle); 258 float zRot = minAngle + zRotRatio * (maxAngle - minAngle); 259 260 Vector3 translation; 261 translation[0] = minTranslation[0] + translationRatio[0] * (maxTranslation[0] - minTranslation[0]); 262 translation[1] = minTranslation[1] + translationRatio[1] * (maxTranslation[1] - minTranslation[1]); 263 translation[2] = minTranslation[2] + translationRatio[2] * (maxTranslation[2] - minTranslation[2]); 264 265 Geometry *result = new Geometry(translation, xRot, yRot, zRot, objectSize, objectType); 266 267 result->SetAmbientColor(amb[materialIdx][0], amb[materialIdx][1], amb[materialIdx][2]); 268 result->SetDiffuseColor(dif[materialIdx][0], dif[materialIdx][1], dif[materialIdx][2]); 269 result->SetSpecularColor(spec[materialIdx][0], spec[materialIdx][1], spec[materialIdx][2]); 270 271 return result; 272 } 273 274 // generates a the scene hierarchy with random values 275 HierarchyNode* generateHierarchy(int numObjects) 276 { 277 HierarchyNode *hierarchy = new HierarchyNode(); 278 279 // initialise materials 280 copyVector3Values(amb[0], 0.0215, 0.1745, 0.0215); 281 copyVector3Values(dif[0], 0.727811, 0.633, 0.6); 282 copyVector3Values(spec[0], 0.633, 0.727811, 0.633); 283 284 copyVector3Values(amb[1], 0.1745, 0.01175, 0.01175); 285 copyVector3Values(dif[1], 0.61424, 0.04136, 0.04136); 286 copyVector3Values(spec[1], 0.727811, 0.626959, 0.626959); 287 288 srand (time (0)); 289 290 printf("generating geometry with random position and orientation ... "); 291 292 for(int i=0; i < numObjects; i++) 293 { 294 float xRotRatio = rand() / (float) RAND_MAX; 295 float yRotRatio = rand() / (float) RAND_MAX; 296 float zRotRatio = rand() / (float) RAND_MAX; 297 298 Vector3 translationRatio = {rand() / (float) RAND_MAX, 299 rand() / (float) RAND_MAX, 300 rand() / (float) RAND_MAX}; 301 302 int materialIdx = int(2 * rand() / (float) RAND_MAX); 303 304 Geometry *geo = generateGeometry(translationRatio, xRotRatio, 305 yRotRatio, zRotRatio, materialIdx); 306 hierarchy->AddGeometry(geo); 307 308 // put into global geometry list for later deletion 309 geometry.push_back(geo); 310 } 311 312 printf("finished\n"); 313 printf("generating new kd-tree hierarchy ... "); 314 HierarchyNode::InitKdTree(hierarchy); 315 hierarchy->GenerateKdTree(); 316 printf("finished\n"); 317 318 return hierarchy; 319 } 320 321 322 void updateEyeMtx(void) 323 { 324 const Vector3 up = {0.0, 1.0, 0.0}; 307 308 void UpdateEyeMtx(void) 309 { 310 /*const Vector3 up(0.0, 1.0, 0.0); 325 311 326 312 look(eyeView, eyePos, viewDir, up); 327 313 mult(eyeProjView, eyeProjection, eyeView); //eyeProjView = eyeProjection*eyeView 328 314 invert(invEyeProjView, eyeProjView); //invert matrix 329 } 330 331 332 void setupEyeView(void) 333 { 334 glMatrixMode(GL_PROJECTION); 335 glLoadMatrixd(eyeProjection); 336 315 */ 316 } 317 318 319 void SetupEyeView(void) 320 { 321 SetupProjection(800,600,60,sceneBox); 337 322 glMatrixMode(GL_MODELVIEW); 338 glLoadMatrixd(eyeView); 323 camera->SetupCameraView(); 324 325 /* glMatrixMode(GL_PROJECTION); 326 glLoadMatrixf((float *)eyeProjection.x); 327 328 glMatrixMode(GL_MODELVIEW); 329 glLoadMatrixf((float *)eyeView.x); 330 */ 339 331 } 340 332 … … 353 345 char msg8[100]; 354 346 347 /* 355 348 sprintf_s(msg2, "Traversed: %4d, frustum culled: %4d, query culled: %4d (of %d nodes)", 356 349 traverser.GetNumTraversedNodes(), traverser.GetNumFrustumCulledNodes(), 357 350 traverser.GetNumQueryCulledNodes(), 358 351 traverser.GetHierarchy()->GetNumHierarchyNodes()); 359 352 360 353 char *optstr[2] = {"", ", using optimization"}; 361 354 char *querystr[2] = {"NV", "ARB"}; … … 384 377 sprintf_s(msg7, "Next object type: %s", objectTypeStr[nextObjectType]); 385 378 sprintf_s(msg8, "Next object size: %3.3f", objectSize); 379 */ 386 380 387 381 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 388 382 389 updateEyeMtx(); // bring eye modelview matrix up-to-date 390 setupEyeView(); 391 383 // bring eye modelview matrix up-to-date 384 UpdateEyeMtx(); 385 SetupEyeView(); 386 387 glEnableClientState(GL_VERTEX_ARRAY); 388 glEnableClientState(GL_NORMAL_ARRAY); 389 390 bool usesTextures = false; 391 392 SceneEntityContainer::const_iterator sit, sit_end = sceneEntities.end(); 393 394 for (sit = sceneEntities.begin(); sit != sit_end; ++ sit) 395 { 396 SceneEntity *entity = *sit; 397 398 if (!usesTextures && entity->GetGeometry()->HasTexture()) 399 { 400 glEnable(GL_TEXTURE_2D); 401 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 402 usesTextures = true; 403 } 404 else if (usesTextures && !entity->GetGeometry()->HasTexture()) 405 { 406 glDisable(GL_TEXTURE_2D); 407 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 408 usesTextures = false; 409 } 410 411 entity->Render(); 412 } 413 414 glDisableClientState(GL_VERTEX_ARRAY); 415 glDisableClientState(GL_NORMAL_ARRAY); 416 417 glDisable(GL_TEXTURE_2D); 418 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 419 420 /* 392 421 traverser.SetViewpoint(eyePos); 393 422 traverser.SetProjViewMatrix(eyeProjView); 394 423 traverser.Render(renderMode); 395 396 424 // cycle through rendertime array 397 425 renderTimes[renderTimesIdx] = traverser.GetRenderTime(); … … 402 430 403 431 if(visMode) 404 {405 432 displayVisualization(); 406 } 433 */ 434 407 435 408 436 begin2D(); 437 409 438 if(showHelp) 439 { 410 440 drawHelpMessage(); 441 } 411 442 else 412 443 { 413 444 glColor3f(1.0,1.0,1.0); 414 output(10,winHeight-10, msg[renderMode]);445 //output(10, winHeight-10, msg[renderMode]); 415 446 416 447 if(showStatistics) … … 428 459 } 429 460 } 461 430 462 end2D(); 431 463 … … 437 469 void keyboard(const unsigned char c, const int x, const int y) 438 470 { 439 int threshold;440 HierarchyNode *hierarchy;471 //int threshold; 472 //HierarchyNode *hierarchy; 441 473 442 474 switch(c) … … 446 478 break; 447 479 case 32: //space 448 renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 480 481 // renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 449 482 450 483 resetTimer(); 451 traverser.Render(renderMode); // render once so stats are updated484 //traverser.Render(renderMode); // render once so stats are updated 452 485 break; 453 486 case 'h': … … 458 491 case 'V': 459 492 showBoundingVolumes = !showBoundingVolumes; 460 HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes);493 //HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 461 494 break; 462 495 case 's': … … 465 498 break; 466 499 case '+': 467 threshold = traverser.GetVisibilityThreshold() + 10;468 traverser.SetVisibilityThreshold(threshold);500 //threshold = traverser.GetVisibilityThreshold() + 10; 501 //traverser.SetVisibilityThreshold(threshold); 469 502 break; 470 503 case '-': 471 threshold = traverser.GetVisibilityThreshold() - 10;472 if(threshold < 0) threshold = 0;473 474 traverser.SetVisibilityThreshold(threshold);504 //threshold = traverser.GetVisibilityThreshold() - 10; 505 //if(threshold < 0) threshold = 0; 506 507 //traverser.SetVisibilityThreshold(threshold); 475 508 break; 476 509 case '1': … … 495 528 case 'G': 496 529 useOptimization = !useOptimization; 497 traverser.SetUseOptimization(useOptimization); 498 break; 499 case 'n': 500 case 'N': 501 useArbQueries = !useArbQueries; 502 traverser.SetUseArbQueries(useArbQueries); 503 break; 530 //traverser.SetUseOptimization(useOptimization); 531 break; 532 /* 504 533 case 'c': 505 534 case 'C': 506 507 535 hierarchy = traverser.GetHierarchy(); 508 536 // delete old hierarchy 509 if (hierarchy) delete hierarchy;537 if (hierarchy) delete hierarchy; 510 538 deleteGeometry(); 511 539 … … 522 550 resetTimer(); 523 551 break; 524 552 */ 525 553 default: 526 554 return; … … 534 562 { 535 563 // used to avoid vertical motion with the keys 536 Vector3 hvec = {viewDir[0], 0, viewDir[2]};564 Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]); 537 565 538 566 switch(c) … … 542 570 break; 543 571 case GLUT_KEY_F2: 544 numNextObjects -= 100;545 if(numNextObjects < 100) numNextObjects = 100;572 //numNextObjects -= 100; 573 //if(numNextObjects < 100) numNextObjects = 100; 546 574 break; 547 575 case GLUT_KEY_F3: 548 numNextObjects += 100;576 // numNextObjects += 100; 549 577 break; 550 578 case GLUT_KEY_F4: … … 563 591 break; 564 592 case GLUT_KEY_F8: 565 nextObjectType = (nextObjectType + 1) % Geometry::NUM_OBJECTS;593 //nextObjectType = (nextObjectType + 1) % Geometry::NUM_OBJECTS; 566 594 break; 567 595 case GLUT_KEY_LEFT: 568 rotateVectorY(viewDir, 0.2);596 // rotateVectorY(viewDir, 0.2); 569 597 break; 570 598 case GLUT_KEY_RIGHT: 571 rotateVectorY(viewDir, -0.2);599 //rotateVectorY(viewDir, -0.2); 572 600 break; 573 601 case GLUT_KEY_UP: 574 linCombVector3(eyePos, eyePos, hvec, 0.6);602 // linCombVector3(eyePos, eyePos, hvec, 0.6); 575 603 break; 576 604 case GLUT_KEY_DOWN: 577 linCombVector3(eyePos, eyePos, hvec, -0.6);605 //linCombVector3(eyePos, eyePos, hvec, -0.6); 578 606 break; 579 607 default: … … 598 626 if(w) winAspectRatio = (double) h / (double) w; 599 627 600 perspectiveDeg(eyeProjection, 60.0, 1.0/winAspectRatio, nearDist, 150.0);628 //perspectiveDeg(eyeProjection, 60.0, 1.0/winAspectRatio, nearDist, 150.0); 601 629 602 630 glutPostRedisplay(); … … 631 659 static double eyeXAngle = 0.0; 632 660 // not move in the vertical direction 633 Vector3 horView = {viewDir[0], 0, viewDir[2]}; 634 635 eyeXAngle = 0.6 * PI * (xEyeBegin - x) / 180.0; 661 Vector3 horView = Vector3(viewDir[0], 0, viewDir[2]); 662 663 eyeXAngle = 0.6 * M_PI * (xEyeBegin - x) / 180.0; 664 665 /* 636 666 linCombVector3(eyePos, eyePos, horView, (yMotionBegin - y) * 0.1); 637 667 … … 640 670 xEyeBegin = x; 641 671 yMotionBegin = y; 642 672 */ 643 673 glutPostRedisplay(); 644 674 } … … 649 679 // the 90 degree rotated view vector 650 680 // y zero so we don't move in the vertical 651 Vector3 rVec = {viewDir[0], 0, viewDir[2]};652 653 rotateVectorY(rVec, PI / 2.0);681 Vector3 rVec = Vector3(viewDir[0], 0, viewDir[2]); 682 683 /*rotateVectorY(rVec, PI / 2.0); 654 684 linCombVector3(eyePos, eyePos, rVec, (horizontalMotionBegin - x) * 0.1); 655 685 … … 658 688 horizontalMotionBegin = x; 659 689 verticalMotionBegin = y; 660 690 */ 661 691 glutPostRedisplay(); 662 692 } 663 693 664 694 665 void initExtensions(void)695 void InitExtensions(void) 666 696 { 667 697 GLenum err = glewInit(); 698 668 699 if (GLEW_OK != err) 669 700 { … … 672 703 exit(1); 673 704 } 674 675 if (GLEW_ARB_occlusion_query) 676 arbQuerySupport = true; 677 678 if (GLEW_NV_occlusion_query) 679 nvQuerySupport = true; 680 681 682 if (!arbQuerySupport && !nvQuerySupport) 683 { 684 printf("I require the GL_ARB_occlusion_query or the GL_NV_occlusion_query OpenGL extension to work.\n"); 705 if (!GLEW_ARB_occlusion_query) 706 { 707 printf("I require the GL_ARB_occlusion_query to work.\n"); 685 708 exit(1); 686 709 } … … 729 752 } 730 753 731 // explicitly deletes geometry generated for hierarchy732 // (deleting the hierarchy does not delete the geometry)733 void deleteGeometry()734 {735 for (GeometryList::iterator it = geometry.begin(); it != geometry.end(); it++)736 if(*it) delete (*it);737 738 geometry.clear();739 }740 741 754 // displays the visualisation of the kd tree node culling 742 755 void displayVisualization() … … 753 766 glViewport(winWidth / 2, winHeight / 2, winWidth, winHeight); 754 767 glPushMatrix(); 755 glLoadMatrix d(visView);768 glLoadMatrixf((float *)visView.x); 756 769 757 770 glClear(GL_DEPTH_BUFFER_BIT); 758 771 759 772 // --- visualization of the occlusion culling 760 HierarchyNode::SetRenderBoundingVolume(true);773 /*HierarchyNode::SetRenderBoundingVolume(true); 761 774 traverser.RenderVisualization(); 762 775 HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 763 776 */ 764 777 glPopMatrix(); 765 778 glViewport(0, 0, winWidth, winHeight); 766 779 } 767 780 768 /** 769 sets up view matrix in order to get a good position 781 /** Sets up view matrix in order to get a good position 770 782 for viewing the kd tree node culling 771 783 */ 772 784 void setupVisView() 773 785 { 774 const Vector3 up = {0.0, 1.0, 0.0};775 776 Vector3 visPos = {24, 23, -6};786 const Vector3 up(0.0, 1.0, 0.0); 787 788 Vector3 visPos(24, 23, -6); 777 789 778 790 visPos[0] *= visZoomFactor; … … 780 792 visPos[2] *= visZoomFactor; 781 793 782 Vector3 visDir = {-1.3,-1,-1};783 784 normalize(visDir);785 look(visView, visPos, visDir, up);794 Vector3 visDir = Vector3(-1.3, -1, -1); 795 796 //normalize(visDir); 797 //look(visView, visPos, visDir, up); 786 798 } 787 799 … … 810 822 811 823 // cleanup routine after the main loop 812 void cleanUp() 813 { 814 if(traverser.GetHierarchy()) 815 delete traverser.GetHierarchy(); 816 817 deleteGeometry(); 818 819 Geometry::CleanUp(); 824 void CleanUp() 825 { 826 CLEAR_CONTAINER(sceneEntities); 827 DEL_PTR(traverser); 828 829 DEL_PTR(bvh); 820 830 } 821 831 … … 846 856 } 847 857 } 848 849 #endif -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.cpp
r2753 r2756 35 35 36 36 37 37 38 Real Random(Real max) 38 39 { … … 57 58 } 58 59 59 void 60 Randomize(const unsigned int seed)61 { 62 60 61 void Randomize(const unsigned int seed) 62 { 63 srand(seed); 63 64 } 64 65 … … 299 300 } 300 301 301 302 #if TOIMPLEMENT 303 304 bool 305 CreateDir(char *dir) 306 { 307 #ifdef _MSC_VER 308 HANDLE fFile; // File Handle 309 WIN32_FIND_DATA fileinfo; // File Information Structure 310 int n = strlen(dir) - 1; 311 312 if (dir[n] == '\\' || dir[n] == '/') 313 dir[n]=0; 314 315 fFile = FindFirstFile(dir, &fileinfo); 316 317 // if the file exists and it is a directory 318 if (fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { 319 // Directory Exists close file and return 320 FindClose(fFile); 321 return true; 322 } 323 324 FindClose(fFile); 325 326 // Now lets cycle through the String Array and create each directory in turn 327 if (CreateDirectory(dir, 0)) { 328 SetFileAttributes(dir, FILE_ATTRIBUTE_NORMAL); 329 return true; 330 } else { 331 char *temp = GetPath(dir); 332 333 if (strcmp(temp, dir)!=0) { 334 CreateDir(temp); 335 if (CreateDirectory(dir, 0)) { 336 SetFileAttributes(dir, FILE_ATTRIBUTE_NORMAL); 337 return true; 338 } 339 } 340 delete temp; 341 } 342 Debug << "cannot create directory " << dir << endl; 343 #endif 344 return false; 345 } 346 347 348 #endif 349 350 } 302 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
r2755 r2756 285 285 286 286 Real Random(Real max); 287 int 287 int Random(int max); 288 288 void Randomize(); 289 void 290 Randomize(const unsigned int seed); 289 void Randomize(unsigned int seed); 291 290 292 291 … … 473 472 typedef std::queue<OcclusionQuery *> QueryQueue; 474 473 475 } 476 477 #endif 478 479 480 481 482 483 484 485 474 static std::ofstream Debug("debug.log"); 475 476 } 477 478 #endif 479 480 481 482 483 484 485 486
Note: See TracChangeset
for help on using the changeset viewer.