From 3e8427799c27b1e0bca22759ae434e23b06547ae Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 11 Jun 2016 10:56:20 +0200 Subject: Corrected bug on cubemap generation --- src/models.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/models.c') diff --git a/src/models.c b/src/models.c index 15565c98..8d9219e3 100644 --- a/src/models.c +++ b/src/models.c @@ -739,7 +739,7 @@ Model LoadCubicmap(Image cubicmap) { Model model = { 0 }; - model.mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0, 1.0, 1.5f }); + model.mesh = GenMeshCubicmap(cubicmap, (Vector3){ 1.0f, 1.5f, 1.0f }); rlglLoadMesh(&model.mesh, false); // Upload vertex data to GPU (static model) -- cgit v1.2.3 From 68a02e567d5fea42d1593e7932a0e052cf244d52 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 11 Jun 2016 12:41:03 +0200 Subject: Avoid external variable whiteTexture To get it, use GetDefaultTexture() --- src/models.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/models.c') diff --git a/src/models.c b/src/models.c index 8d9219e3..8deabcb0 100644 --- a/src/models.c +++ b/src/models.c @@ -50,7 +50,7 @@ //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -extern unsigned int whiteTexture; +// ... //---------------------------------------------------------------------------------- // Module specific Functions Declaration @@ -811,7 +811,7 @@ void UnloadMaterial(Material material) // Link a texture to a model void SetModelTexture(Model *model, Texture2D texture) { - if (texture.id <= 0) model->material.texDiffuse.id = whiteTexture; // Use default white texture + if (texture.id <= 0) model->material.texDiffuse = GetDefaultTexture(); // Use default white texture else model->material.texDiffuse = texture; } -- cgit v1.2.3 From 5f7ac64c44543383b10ec6a56e5ec1db5706276e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 24 Jun 2016 19:49:36 +0200 Subject: Removed function SetModelTexture() It's more educational to go through new material system, so, I decide to remove this function to avoid students confusion... --- src/models.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/models.c') diff --git a/src/models.c b/src/models.c index 8deabcb0..a4bcde8f 100644 --- a/src/models.c +++ b/src/models.c @@ -808,13 +808,6 @@ void UnloadMaterial(Material material) rlDeleteTextures(material.texSpecular.id); } -// Link a texture to a model -void SetModelTexture(Model *model, Texture2D texture) -{ - if (texture.id <= 0) model->material.texDiffuse = GetDefaultTexture(); // Use default white texture - else model->material.texDiffuse = texture; -} - // Generate a mesh from heightmap static Mesh GenMeshHeightmap(Image heightmap, Vector3 size) { -- cgit v1.2.3 From 2f9abe6e1388a84d662eb12e62bbcccc7eccd9d0 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 4 Jul 2016 01:30:07 +0200 Subject: Review ResolveCollisionCubicmap() This function needs to be redesigned or removed... --- src/models.c | 71 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'src/models.c') diff --git a/src/models.c b/src/models.c index a4bcde8f..b194a0db 100644 --- a/src/models.c +++ b/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,15 +1558,15 @@ 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)) + if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) && + (cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius)) @@ -1576,10 +1579,10 @@ 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)) + if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) && + (cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius)) @@ -1592,10 +1595,10 @@ 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)) + if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) && + (cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius)) @@ -1608,10 +1611,10 @@ 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)) + if ((cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) && + (cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius)) @@ -1628,7 +1631,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p // Axis x- if (locationCellX > 0) { - if (cubicmapPixels[locationCellY * cubicmap.width + (locationCellX - 1)].r != 0) + if (cubicmapPixels[locationCellY*cubicmap.width + (locationCellX - 1)].r != 0) { if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) { @@ -1640,7 +1643,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p // Axis x+ if (locationCellX < cubicmap.width - 1) { - if (cubicmapPixels[locationCellY * cubicmap.width + (locationCellX + 1)].r != 0) + if (cubicmapPixels[locationCellY*cubicmap.width + (locationCellX + 1)].r != 0) { if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) { @@ -1652,7 +1655,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p // Axis y- if (locationCellY > 0) { - if (cubicmapPixels[(locationCellY - 1) * cubicmap.width + (locationCellX)].r != 0) + if (cubicmapPixels[(locationCellY - 1)*cubicmap.width + (locationCellX)].r != 0) { if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius) { @@ -1664,7 +1667,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p // Axis y+ if (locationCellY < cubicmap.height - 1) { - if (cubicmapPixels[(locationCellY + 1) * cubicmap.width + (locationCellX)].r != 0) + if (cubicmapPixels[(locationCellY + 1)*cubicmap.width + (locationCellX)].r != 0) { if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius) { @@ -1677,11 +1680,11 @@ 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) && - (cubicmapPixels[(locationCellY - 1) * 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 - 1)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius)) @@ -1700,11 +1703,11 @@ 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) && - (cubicmapPixels[(locationCellY + 1) * 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 - 1)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius)) @@ -1723,11 +1726,11 @@ 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) && - (cubicmapPixels[(locationCellY - 1) * 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 + 1)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius)) @@ -1746,11 +1749,11 @@ 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) && - (cubicmapPixels[(locationCellY + 1) * 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 + 1)].r != 0)) { if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius)) -- cgit v1.2.3