fixed floors sample

This commit is contained in:
Sandro Sobczyński
2020-11-03 16:44:39 +01:00
parent 5aa2a9bdb5
commit b75b2d6e4f
30 changed files with 331 additions and 224 deletions
+6 -13
View File
@@ -238,19 +238,11 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals
return addedFaces;
}
void Mesh::getCurrentBoundingBoxVertex(Vector3 &o_result, const u32 &t_index)
{
o_result.set(
frames[animState.currentFrame].getBoundingBox(t_index).x + position.x,
frames[animState.currentFrame].getBoundingBox(t_index).y + position.y,
frames[animState.currentFrame].getBoundingBox(t_index).z + position.z);
}
u8 Mesh::isInFrustum(Plane *t_frustumPlanes)
{
Vector3 boxCalcTemp;
int boxResult = 1, boxIn = 0, boxOut = 0;
u8 boxResult = 1, boxIn = 0, boxOut = 0;
Vector3 *currentBoundingBox = getCurrentBoundingBox();
for (int i = 0; i < 6; i++)
{
boxOut = 0;
@@ -260,7 +252,10 @@ u8 Mesh::isInFrustum(Plane *t_frustumPlanes)
// both inside and out of the frustum
for (int y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
{
getCurrentBoundingBoxVertex(boxCalcTemp, y);
boxCalcTemp.set(
currentBoundingBox[y].x + position.x,
currentBoundingBox[y].y + position.y,
currentBoundingBox[y].z + position.z);
if (t_frustumPlanes[i].distanceTo(boxCalcTemp) < 0)
boxOut++;
else
@@ -288,7 +283,6 @@ void Mesh::setDefaultColor()
/** Sets texture level of details settings and CLUT settings */
void Mesh::setDefaultLODAndClut()
{
PRINT_LOG("Setting LOD, CLUT");
lod.calculation = LOD_USE_K;
lod.max_level = 0;
lod.mag_filter = LOD_MAG_NEAREST;
@@ -301,5 +295,4 @@ void Mesh::setDefaultLODAndClut()
clut.psm = 0;
clut.load_method = CLUT_NO_LOAD;
clut.address = 0;
PRINT_LOG("LOD, CLUT set!");
}
+3 -1
View File
@@ -91,13 +91,15 @@ void MeshFrame::allocateMaterials(const u32 &t_val)
_areMaterialsAllocated = true;
}
void MeshFrame::calculateBoundingBox()
void MeshFrame::calculateBoundingBoxes()
{
if (!_areVerticesAllocated)
{
PRINT_ERR("Can't calculate bounding box, because vertices were not allocated!");
return;
}
for (u32 i = 0; i < materialsCount; i++)
materials->calculateBoundingBox(vertices, vertexCount);
float lowX, lowY, lowZ, hiX, hiY, hiZ;
lowX = hiX = vertices[0].x;
lowY = hiY = vertices[0].y;
+67
View File
@@ -23,6 +23,7 @@ MeshMaterial::MeshMaterial()
facesCount = 0;
_isNameSet = false;
_areFacesAllocated = false;
_isBoundingBoxCalculated = false;
}
MeshMaterial::~MeshMaterial()
@@ -65,3 +66,69 @@ void MeshMaterial::setName(char *t_val)
name = String::createCopy(t_val);
_isNameSet = true;
}
u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position)
{
Vector3 boxCalcTemp;
u8 boxResult = 1, boxIn = 0, boxOut = 0;
for (int i = 0; i < 6; i++)
{
boxOut = 0;
boxIn = 0;
// for each corner of the box do ...
// get out of the cycle as soon as a box as corners
// both inside and out of the frustum
for (int y = 0; y < 8 && (boxIn == 0 || boxOut == 0); y++)
{
boxCalcTemp.set(
boundingBox[y].x + position.x,
boundingBox[y].y + position.y,
boundingBox[y].z + position.z);
if (t_frustumPlanes[i].distanceTo(boxCalcTemp) < 0)
boxOut++;
else
boxIn++;
}
//if all corners are out
if (boxIn == 0)
return 0;
else if (boxOut)
boxResult = 1;
}
return boxResult;
}
void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount)
{
float lowX, lowY, lowZ, hiX, hiY, hiZ;
lowX = hiX = t_vertices[vertexFaces[0]].x;
lowY = hiY = t_vertices[vertexFaces[0]].y;
lowZ = hiZ = t_vertices[vertexFaces[0]].z;
for (u32 i = 0; i < facesCount; i++)
{
if (lowX > t_vertices[vertexFaces[i]].x)
lowX = t_vertices[vertexFaces[i]].x;
if (hiX < t_vertices[vertexFaces[i]].x)
hiX = t_vertices[vertexFaces[i]].x;
if (lowY > t_vertices[vertexFaces[i]].y)
lowY = t_vertices[vertexFaces[i]].y;
if (hiY < t_vertices[vertexFaces[i]].y)
hiY = t_vertices[vertexFaces[i]].y;
if (lowZ > t_vertices[vertexFaces[i]].z)
lowZ = t_vertices[vertexFaces[i]].z;
if (hiZ < t_vertices[vertexFaces[i]].z)
hiZ = t_vertices[vertexFaces[i]].z;
}
boundingBox[0].set(lowX, lowY, lowZ);
boundingBox[1].set(lowX, lowY, hiZ);
boundingBox[2].set(lowX, hiY, lowZ);
boundingBox[3].set(lowX, hiY, hiZ);
boundingBox[4].set(hiX, lowY, lowZ);
boundingBox[5].set(hiX, lowY, hiZ);
boundingBox[6].set(hiX, hiY, lowZ);
boundingBox[7].set(hiX, hiY, hiZ);
_isBoundingBoxCalculated = true;
}