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
+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;
}