mirror of
				https://github.com/raysan5/raylib.git
				synced 2025-10-26 12:27:01 +00:00 
			
		
		
		
	Review ResolveCollisionCubicmap()
This function needs to be redesigned or removed...
This commit is contained in:
		
							
								
								
									
										23
									
								
								src/models.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								src/models.c
									
									
									
									
									
								
							| @@ -40,7 +40,7 @@ | ||||
| //---------------------------------------------------------------------------------- | ||||
| // Defines and Macros | ||||
| //---------------------------------------------------------------------------------- | ||||
| #define CUBIC_MAP_HALF_BLOCK_SIZE           0.5 | ||||
| // ... | ||||
|  | ||||
| //---------------------------------------------------------------------------------- | ||||
| // Types and Structures Definition | ||||
| @@ -1542,8 +1542,11 @@ BoundingBox CalculateBoundingBox(Mesh mesh) | ||||
|  | ||||
| // Detect and resolve cubicmap collisions | ||||
| // 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) | ||||
| { | ||||
|     #define CUBIC_MAP_HALF_BLOCK_SIZE   0.5 | ||||
|      | ||||
|     Color *cubicmapPixels = GetImageData(cubicmap); | ||||
|      | ||||
|     // 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); | ||||
|     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 -------------------------------------------------------------------------------------------- | ||||
|  | ||||
|         // Axis x-, y- | ||||
|         if (locationCellX > 0 && locationCellY > 0) | ||||
|         if ((locationCellX > 0) && (locationCellY > 0)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].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+ | ||||
|         if (locationCellX > 0 && locationCellY < cubicmap.height - 1) | ||||
|         if ((locationCellX > 0) && (locationCellY < cubicmap.height - 1)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].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- | ||||
|         if (locationCellX < cubicmap.width - 1 && locationCellY > 0) | ||||
|         if ((locationCellX < cubicmap.width - 1) && (locationCellY > 0)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].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+ | ||||
|         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) && | ||||
|                 (cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0)) | ||||
| @@ -1677,7 +1680,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p | ||||
|         // Diagonals ------------------------------------------------------------------------------------------------------- | ||||
|  | ||||
|         // Axis x-, y- | ||||
|         if (locationCellX > 0 && locationCellY > 0) | ||||
|         if ((locationCellX > 0) && (locationCellY > 0)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].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+ | ||||
|         if (locationCellX > 0 && locationCellY < cubicmap.height - 1) | ||||
|         if ((locationCellX > 0) && (locationCellY < cubicmap.height - 1)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].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- | ||||
|         if (locationCellX < cubicmap.width - 1 && locationCellY > 0) | ||||
|         if ((locationCellX < cubicmap.width - 1) && (locationCellY > 0)) | ||||
|         { | ||||
|             if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].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+ | ||||
|         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) && | ||||
|                 (cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r == 0) && | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ray
					Ray