Review ResolveCollisionCubicmap()
This function needs to be redesigned or removed...
This commit is contained in:
parent
ee72654b55
commit
2f9abe6e13
1 changed files with 37 additions and 34 deletions
23
src/models.c
23
src/models.c
|
@ -40,7 +40,7 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define CUBIC_MAP_HALF_BLOCK_SIZE 0.5
|
// ...
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
@ -1542,8 +1542,11 @@ BoundingBox CalculateBoundingBox(Mesh mesh)
|
||||||
|
|
||||||
// Detect and resolve cubicmap collisions
|
// Detect and resolve cubicmap collisions
|
||||||
// NOTE: player position (or camera) is modified inside this function
|
// NOTE: player position (or camera) is modified inside this function
|
||||||
|
// TODO: This functions needs to be completely reviewed!
|
||||||
Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius)
|
Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius)
|
||||||
{
|
{
|
||||||
|
#define CUBIC_MAP_HALF_BLOCK_SIZE 0.5
|
||||||
|
|
||||||
Color *cubicmapPixels = GetImageData(cubicmap);
|
Color *cubicmapPixels = GetImageData(cubicmap);
|
||||||
|
|
||||||
// Detect the cell where the player is located
|
// Detect the cell where the player is located
|
||||||
|
@ -1555,12 +1558,12 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
locationCellX = floor(playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE);
|
locationCellX = floor(playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE);
|
||||||
locationCellY = floor(playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE);
|
locationCellY = floor(playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE);
|
||||||
|
|
||||||
if (locationCellX >= 0 && locationCellY >= 0 && locationCellX < cubicmap.width && locationCellY < cubicmap.height)
|
if ((locationCellX >= 0) && (locationCellY >= 0) && (locationCellX < cubicmap.width) && (locationCellY < cubicmap.height))
|
||||||
{
|
{
|
||||||
// Multiple Axis --------------------------------------------------------------------------------------------
|
// Multiple Axis --------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Axis x-, y-
|
// Axis x-, y-
|
||||||
if (locationCellX > 0 && locationCellY > 0)
|
if ((locationCellX > 0) && (locationCellY > 0))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) &&
|
||||||
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0))
|
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0))
|
||||||
|
@ -1576,7 +1579,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x-, y+
|
// Axis x-, y+
|
||||||
if (locationCellX > 0 && locationCellY < cubicmap.height - 1)
|
if ((locationCellX > 0) && (locationCellY < cubicmap.height - 1))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) &&
|
||||||
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0))
|
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0))
|
||||||
|
@ -1592,7 +1595,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x+, y-
|
// Axis x+, y-
|
||||||
if (locationCellX < cubicmap.width - 1 && locationCellY > 0)
|
if ((locationCellX < cubicmap.width - 1) && (locationCellY > 0))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) &&
|
||||||
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0))
|
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0))
|
||||||
|
@ -1608,7 +1611,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x+, y+
|
// Axis x+, y+
|
||||||
if (locationCellX < cubicmap.width - 1 && locationCellY < cubicmap.height - 1)
|
if ((locationCellX < cubicmap.width - 1) && (locationCellY < cubicmap.height - 1))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) &&
|
||||||
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0))
|
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0))
|
||||||
|
@ -1677,7 +1680,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
// Diagonals -------------------------------------------------------------------------------------------------------
|
// Diagonals -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Axis x-, y-
|
// Axis x-, y-
|
||||||
if (locationCellX > 0 && locationCellY > 0)
|
if ((locationCellX > 0) && (locationCellY > 0))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r == 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r == 0) &&
|
||||||
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
||||||
|
@ -1700,7 +1703,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x-, y+
|
// Axis x-, y+
|
||||||
if (locationCellX > 0 && locationCellY < cubicmap.height - 1)
|
if ((locationCellX > 0) && (locationCellY < cubicmap.height - 1))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r == 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r == 0) &&
|
||||||
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
||||||
|
@ -1723,7 +1726,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x+, y-
|
// Axis x+, y-
|
||||||
if (locationCellX < cubicmap.width - 1 && locationCellY > 0)
|
if ((locationCellX < cubicmap.width - 1) && (locationCellY > 0))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r == 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r == 0) &&
|
||||||
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
(cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
||||||
|
@ -1746,7 +1749,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Axis x+, y+
|
// Axis x+, y+
|
||||||
if (locationCellX < cubicmap.width - 1 && locationCellY < cubicmap.height - 1)
|
if ((locationCellX < cubicmap.width - 1) && (locationCellY < cubicmap.height - 1))
|
||||||
{
|
{
|
||||||
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r == 0) &&
|
if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r == 0) &&
|
||||||
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
(cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r == 0) &&
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue