Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Map converter part
- logger.logDebug("Scanning tree...");
- std::vector<int> leafIds;
- exploreTree(nodes, models[0].node, leafIds); //Model 0 is the "world" model, without entities
- logger.logDebug("Found %i leaves", leafIds.size());
- std::vector<unsigned short> okBrushes;
- unsigned int oldPos = bb.getCursorPos();
- unsigned int pObjs = 0;
- bb << pObjs;
- for(int i = 0; i < leafIds.size(); i++) {
- int lbCnt = leafs[leafIds[i]].leafBrushCnt;
- for(int j = 0; j < lbCnt; j++) {
- int lbId = leafs[leafIds[i]].leafBrushId + j;
- unsigned short bId = lbrushes[lbId];
- Brush br = brushes[bId];
- if((br.contents & BRUSH_FLAG_SOLID) > 0 && br.sideCount > 0) { //BRUSH_FLAG_SOLID = 1
- bool hasBeenDone = false;
- for(int k = 0; k < okBrushes.size(); k++) {
- if(okBrushes[k] == bId) {
- hasBeenDone = true;
- break;
- }
- }
- if(hasBeenDone)
- continue;
- bb << (unsigned short) br.sideCount;
- pObjs++;
- for(int k = 0; k < br.sideCount; k++) {
- Plane pl = planes[bsides[br.sideStart + k].planeId];
- bb << pl.normal;
- bb << (float) -pl.distance;
- }
- okBrushes.push_back(bId);
- }
- }
- }
- bb.setCursorPos(oldPos, ByteBuffer::CR_Begin);
- bb << pObjs;
- bb.setCursorPos(0, ByteBuffer::CR_End);
- logger.logDebug("Leaves OK; found %i solid brushes!", (int) pObjs);
- //Map loader part
- reader.readData<unsigned int>(&poCnt);
- for(int i = 0; i < poCnt; i++) {
- btAlignedObjectArray<btVector3> poNormals;
- unsigned short nrmCnt;
- reader.readData<unsigned short>(&nrmCnt);
- for(int j = 0; j < nrmCnt; j++) {
- float nx, ny, nz, nw;
- reader.readData<float>(&nx);
- reader.readData<float>(&ny);
- reader.readData<float>(&nz);
- reader.readData<float>(&nw);
- btVector3 nrm;
- nrm.setValue(nx, ny, nz);
- nrm[3] = nw;
- poNormals.push_back(nrm);
- }
- btAlignedObjectArray<btVector3> poVertices;
- btGeometryUtil::getVerticesFromPlaneEquations(poNormals, poVertices);
- for(int j = 0; j < poVertices.size(); j++) {
- poVertices[j] *= LEVEL_SCALE; //LEVEL_SCALE is .25f; for rendering I scale the matrix using the same value
- //swap
- float vz = poVertices[j].z();
- poVertices[j].setZ(-poVertices[j].y());
- poVertices[j].setY(vz);
- }
- btConvexHullShape *shape = new btConvexHullShape(&poVertices[0].x(), poVertices.size());
- btRigidBody *body = new btRigidBody(.0f, new btDefaultMotionState, shape);
- m_shapes.push_back(shape);
- m_bodies.push_back(body);
- }
Advertisement
Add Comment
Please, Sign In to add comment