diff options
author | aap <aap@papnet.eu> | 2021-02-09 17:35:41 +0100 |
---|---|---|
committer | aap <aap@papnet.eu> | 2021-02-09 17:45:02 +0100 |
commit | 031df369351eebc5fe8c5e77d9de7f5525831c92 (patch) | |
tree | bd961e6d524150d16f2d0b7affd1cf1dd1ad526a /src/core/FileLoader.cpp | |
parent | Merge pull request #1013 from Nick007J/lcs (diff) | |
download | re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.gz re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.bz2 re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.lz re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.xz re3-031df369351eebc5fe8c5e77d9de7f5525831c92.tar.zst re3-031df369351eebc5fe8c5e77d9de7f5525831c92.zip |
Diffstat (limited to 'src/core/FileLoader.cpp')
-rw-r--r-- | src/core/FileLoader.cpp | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index 2818007b..f2d925fc 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -291,7 +291,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) { int i; - model.boundingSphere.radius = *(float*)(buf); + model.boundingSphere.radius = Max(*(float*)(buf), 0.1f); model.boundingSphere.center.x = *(float*)(buf+4); model.boundingSphere.center.y = *(float*)(buf+8); model.boundingSphere.center.z = *(float*)(buf+12); @@ -304,10 +304,13 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.numSpheres = *(int16*)(buf+40); buf += 44; if(model.numSpheres > 0){ - model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere)); + model.spheres = new CColSphere[model.numSpheres]; REGISTER_MEMPTR(&model.spheres); for(i = 0; i < model.numSpheres; i++){ - model.spheres[i].Set(*(float*)buf, *(CVector*)(buf+4), buf[16], buf[17]); + float radius = *(float*)buf; + if(radius > model.boundingSphere.radius) + model.boundingSphere.radius = radius + 0.01f; + model.spheres[i].Set(radius, *(CVector*)(buf+4), buf[16], buf[17]); buf += 20; } }else @@ -316,7 +319,8 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.numLines = *(int16*)buf; buf += 4; if(model.numLines > 0){ - //model.lines = (CColLine*)RwMalloc(model.numLines*sizeof(CColLine)); + //model.lines = new CColLine[model.numLines];; + REGISTER_MEMPTR(&model.lines); for(i = 0; i < model.numLines; i++){ //model.lines[i].Set(*(CVector*)buf, *(CVector*)(buf+12)); buf += 24; @@ -329,7 +333,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.numBoxes = *(int16*)buf; buf += 4; if(model.numBoxes > 0){ - model.boxes = (CColBox*)RwMalloc(model.numBoxes*sizeof(CColBox)); + model.boxes = new CColBox[model.numBoxes]; REGISTER_MEMPTR(&model.boxes); for(i = 0; i < model.numBoxes; i++){ model.boxes[i].Set(*(CVector*)buf, *(CVector*)(buf+12), buf[24], buf[25]); @@ -341,7 +345,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) int32 numVertices = *(int16*)buf; buf += 4; if(numVertices > 0){ - model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector)); + model.vertices = new CompressedVector[numVertices]; REGISTER_MEMPTR(&model.vertices); for(i = 0; i < numVertices; i++){ model.vertices[i].Set(*(float*)buf, *(float*)(buf+4), *(float*)(buf+8)); @@ -359,14 +363,64 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname) model.numTriangles = *(int16*)buf; buf += 4; if(model.numTriangles > 0){ - model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle)); + model.triangles = new CColTriangle[model.numTriangles]; REGISTER_MEMPTR(&model.triangles); for(i = 0; i < model.numTriangles; i++){ model.triangles[i].Set(*(int32*)buf, *(int32*)(buf+4), *(int32*)(buf+8), buf[12]); buf += 16; + + // skip small triangles + CVector vA = model.vertices[model.triangles[i].a].Get(); + CVector vB = model.vertices[model.triangles[i].b].Get(); + CVector vC = model.vertices[model.triangles[i].c].Get(); + float area = CrossProduct(vA - vB, vA - vC).Magnitude(); + if(area < 0.001f || vA == vB || vA == vB || vB == vC){ + i--; + model.numTriangles--; + } } }else model.triangles = nil; + + SplitColTrianglesIntoSections(model); +} + +void +CFileLoader::SplitColTrianglesIntoSections(CColModel &model) +{ + if(model.triangles == nil || model.numTriangles == 0) + return; + + model.numTriBBoxes = 1; + model.triBBoxes = new CColTriBBox[1]; + model.triBBoxes[0].first = 0; + model.triBBoxes[0].last = model.numTriangles-1; + CVector v = model.vertices[model.triangles[0].a].Get(); + model.triBBoxes[0].Set(v, v); + + for(int i = 0; i < model.numTriangles; i++){ + CVector vA = model.vertices[model.triangles[i].a].Get(); + CVector vB = model.vertices[model.triangles[i].b].Get(); + CVector vC = model.vertices[model.triangles[i].c].Get(); + model.triBBoxes[0].min.x = Min(vA.x, model.triBBoxes[0].min.x); + model.triBBoxes[0].min.y = Min(vA.y, model.triBBoxes[0].min.y); + model.triBBoxes[0].min.z = Min(vA.z, model.triBBoxes[0].min.z); + model.triBBoxes[0].min.x = Min(vB.x, model.triBBoxes[0].min.x); + model.triBBoxes[0].min.y = Min(vB.y, model.triBBoxes[0].min.y); + model.triBBoxes[0].min.z = Min(vB.z, model.triBBoxes[0].min.z); + model.triBBoxes[0].min.x = Min(vC.x, model.triBBoxes[0].min.x); + model.triBBoxes[0].min.y = Min(vC.y, model.triBBoxes[0].min.y); + model.triBBoxes[0].min.z = Min(vC.z, model.triBBoxes[0].min.z); + model.triBBoxes[0].max.x = Max(vA.x, model.triBBoxes[0].max.x); + model.triBBoxes[0].max.y = Max(vA.y, model.triBBoxes[0].max.y); + model.triBBoxes[0].max.z = Max(vA.z, model.triBBoxes[0].max.z); + model.triBBoxes[0].max.x = Max(vB.x, model.triBBoxes[0].max.x); + model.triBBoxes[0].max.y = Max(vB.y, model.triBBoxes[0].max.y); + model.triBBoxes[0].max.z = Max(vB.z, model.triBBoxes[0].max.z); + model.triBBoxes[0].max.x = Max(vC.x, model.triBBoxes[0].max.x); + model.triBBoxes[0].max.y = Max(vC.y, model.triBBoxes[0].max.y); + model.triBBoxes[0].max.z = Max(vC.z, model.triBBoxes[0].max.z); + } } static void |