From 3b4d8442e049f969c737722cb72f1c8ad66621a7 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 13 Jan 2016 19:30:35 +0100 Subject: [PATCH] Corrected some float values --- src/core.c | 16 +++++++------- src/models.c | 62 ++++++++++++++++++++++++++-------------------------- src/rlgl.c | 36 +++++++++++++++--------------- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/core.c b/src/core.c index 8b61aaf7..6314941b 100644 --- a/src/core.c +++ b/src/core.c @@ -309,8 +309,8 @@ void InitWindow(int width, int height, const char *title) emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenInputCallback); #endif - mousePosition.x = screenWidth/2; - mousePosition.y = screenHeight/2; + mousePosition.x = (float)screenWidth/2.0f; + mousePosition.y = (float)screenHeight/2.0f; // raylib logo appearing animation (if enabled) if (showLogo) @@ -577,7 +577,7 @@ void Begin3dMode(Camera camera) // Setup perspective projection float aspect = (float)screenWidth/(float)screenHeight; - double top = 0.1f*tan(45.0f*PI / 360.0f); + double top = 0.1f*tan(45.0f*PI/360.0f); double right = top*aspect; // NOTE: zNear and zFar values are important when computing depth buffer values @@ -608,7 +608,7 @@ void End3dMode(void) // Set target FPS for the game void SetTargetFPS(int fps) { - targetTime = 1 / (double)fps; + targetTime = 1.0/(double)fps; TraceLog(INFO, "Target time per frame: %02.03f milliseconds", (float)targetTime*1000); } @@ -625,7 +625,7 @@ float GetFrameTime(void) // As we are operate quite a lot with frameTime, // it could be no stable, so we round it before passing it around // NOTE: There are still problems with high framerates (>500fps) - double roundedFrameTime = round(frameTime*10000)/10000; + double roundedFrameTime = round(frameTime*10000)/10000.0; return (float)roundedFrameTime; // Time in seconds to run a frame } @@ -806,8 +806,8 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) // Calculate normalized device coordinates // NOTE: y value is negative - float x = (2.0f * mousePosition.x) / GetScreenWidth() - 1.0f; - float y = 1.0f - (2.0f * mousePosition.y) / GetScreenHeight(); + float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f; + float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight(); float z = 1.0f; // Store values in a vector @@ -880,7 +880,7 @@ Vector2 WorldToScreen(Vector3 position, Camera camera) Vector3 ndcPos = { worldPos.x / worldPos.w, -worldPos.y / worldPos.w, worldPos.z / worldPos.z }; // Calculate 2d screen position vector - Vector2 screenPosition = { (ndcPos.x + 1.0f) / 2.0f * GetScreenWidth(), (ndcPos.y + 1.0f) / 2.0f * GetScreenHeight() }; + Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() }; return screenPosition; } diff --git a/src/models.c b/src/models.c index dd170e0b..8b49731d 100644 --- a/src/models.c +++ b/src/models.c @@ -741,8 +741,8 @@ Model LoadCubicmap(Image cubicmap) // Map cube size will be 1.0 float mapCubeSide = 1.0f; - int mapWidth = cubicmap.width * (int)mapCubeSide; - int mapHeight = cubicmap.height * (int)mapCubeSide; + int mapWidth = cubicmap.width*(int)mapCubeSide; + int mapHeight = cubicmap.height*(int)mapCubeSide; // NOTE: Max possible number of triangles numCubes * (12 triangles by cube) int maxTriangles = cubicmap.width*cubicmap.height*12; @@ -753,11 +753,11 @@ Model LoadCubicmap(Image cubicmap) float w = mapCubeSide; float h = mapCubeSide; - float h2 = mapCubeSide * 1.5; // TODO: Review walls height... + float h2 = mapCubeSide*1.5f; // TODO: Review walls height... - Vector3 *mapVertices = (Vector3 *)malloc(maxTriangles * 3 * sizeof(Vector3)); - Vector2 *mapTexcoords = (Vector2 *)malloc(maxTriangles * 3 * sizeof(Vector2)); - Vector3 *mapNormals = (Vector3 *)malloc(maxTriangles * 3 * sizeof(Vector3)); + Vector3 *mapVertices = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3)); + Vector2 *mapTexcoords = (Vector2 *)malloc(maxTriangles*3*sizeof(Vector2)); + Vector3 *mapNormals = (Vector3 *)malloc(maxTriangles*3*sizeof(Vector3)); // Define the 6 normals of the cube, we will combine them accordingly later... Vector3 n1 = { 1.0f, 0.0f, 0.0f }; @@ -775,12 +775,12 @@ Model LoadCubicmap(Image cubicmap) float height; } RectangleF; - RectangleF rightTexUV = { 0, 0, 0.5, 0.5 }; - RectangleF leftTexUV = { 0.5, 0, 0.5, 0.5 }; - RectangleF frontTexUV = { 0, 0, 0.5, 0.5 }; - RectangleF backTexUV = { 0.5, 0, 0.5, 0.5 }; - RectangleF topTexUV = { 0, 0.5, 0.5, 0.5 }; - RectangleF bottomTexUV = { 0.5, 0.5, 0.5, 0.5 }; + RectangleF rightTexUV = { 0.0f, 0.0f, 0.5f, 0.5f }; + RectangleF leftTexUV = { 0.5f, 0.0f, 0.5f, 0.5f }; + RectangleF frontTexUV = { 0.0f, 0.0f, 0.5f, 0.5f }; + RectangleF backTexUV = { 0.5f, 0.0f, 0.5f, 0.5f }; + RectangleF topTexUV = { 0.0f, 0.5f, 0.5f, 0.5f }; + RectangleF bottomTexUV = { 0.5f, 0.5f, 0.5f, 0.5f }; for (int z = 0; z < mapHeight; z += mapCubeSide) { @@ -1147,7 +1147,7 @@ void SetModelTexture(Model *model, Texture2D texture) void DrawModel(Model model, Vector3 position, float scale, Color tint) { Vector3 vScale = { scale, scale, scale }; - Vector3 rotationAxis = { 0, 0, 0 }; + Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f }; DrawModelEx(model, position, 0.0f, rotationAxis, vScale, tint); } @@ -1163,7 +1163,7 @@ void DrawModelEx(Model model, Vector3 position, float rotationAngle, Vector3 rot void DrawModelWires(Model model, Vector3 position, float scale, Color color) { Vector3 vScale = { scale, scale, scale }; - Vector3 rotationAxis = { 0, 0, 0 }; + Vector3 rotationAxis = { 0.0f, 0.0f, 0.0f }; rlglDrawModel(model, position, 0.0f, rotationAxis, vScale, color, true); } @@ -1188,7 +1188,7 @@ void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, //Vector3 up = { viewMatrix.m1, viewMatrix.m5, viewMatrix.m9 }; // NOTE: Billboard locked to axis-Y - Vector3 up = { 0, 1, 0 }; + Vector3 up = { 0.0f, 1.0f, 0.0f }; /* a-------b | | @@ -1366,7 +1366,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p Color *cubicmapPixels = GetImageData(cubicmap); // Detect the cell where the player is located - Vector3 impactDirection = { 0, 0, 0 }; + Vector3 impactDirection = { 0.0f, 0.0f, 0.0f }; int locationCellX = 0; int locationCellY = 0; @@ -1389,7 +1389,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p { playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1405,7 +1405,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p { playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1421,7 +1421,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p { playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1437,7 +1437,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p { playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1452,7 +1452,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius) { playerPosition->x = locationCellX + mapPosition.x - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 0}; + impactDirection = (Vector3){ 1.0f, 0.0f, 0.0f }; } } } @@ -1464,7 +1464,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if ((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius) { playerPosition->x = locationCellX + mapPosition.x + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 1, 0, 0}; + impactDirection = (Vector3){ 1.0f, 0.0f, 0.0f }; } } } @@ -1476,7 +1476,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius) { playerPosition->z = locationCellY + mapPosition.z - (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 0, 0, 1}; + impactDirection = (Vector3){ 0.0f, 0.0f, 1.0f }; } } } @@ -1488,7 +1488,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius) { playerPosition->z = locationCellY + mapPosition.z + (CUBIC_MAP_HALF_BLOCK_SIZE - radius); - impactDirection = (Vector3) { 0, 0, 1}; + impactDirection = (Vector3){ 0.0f, 0.0f, 1.0f }; } } } @@ -1512,7 +1512,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius / 3) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius / 3)) { - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1535,7 +1535,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX < radius / 3) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius / 3)) { - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1558,7 +1558,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius / 3) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY < radius / 3)) { - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1581,7 +1581,7 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p if (((playerPosition->x - mapPosition.x + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellX > 1 - radius / 3) && ((playerPosition->z - mapPosition.z + CUBIC_MAP_HALF_BLOCK_SIZE) - locationCellY > 1 - radius / 3)) { - impactDirection = (Vector3) { 1, 0, 1}; + impactDirection = (Vector3){ 1.0f, 0.0f, 1.0f }; } } } @@ -1591,13 +1591,13 @@ Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *p // Floor collision if (playerPosition->y <= radius) { - playerPosition->y = radius + 0.01; + playerPosition->y = radius + 0.01f; impactDirection = (Vector3) { impactDirection.x, 1, impactDirection.z}; } // Roof collision - else if (playerPosition->y >= 1.5 - radius) + else if (playerPosition->y >= (1.5f - radius)) { - playerPosition->y = (1.5 - radius) - 0.01; + playerPosition->y = (1.5f - radius) - 0.01f; impactDirection = (Vector3) { impactDirection.x, 1, impactDirection.z}; } diff --git a/src/rlgl.c b/src/rlgl.c index e3c763be..7afa374e 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -821,10 +821,10 @@ void rlDeleteBuffers(unsigned int id) void rlClearColor(byte r, byte g, byte b, byte a) { // Color values clamp to 0.0f(0) and 1.0f(255) - float cr = (float)r / 255; - float cg = (float)g / 255; - float cb = (float)b / 255; - float ca = (float)a / 255; + float cr = (float)r/255; + float cg = (float)g/255; + float cb = (float)b/255; + float ca = (float)a/255; glClearColor(cr, cg, cb, ca); } @@ -1104,12 +1104,12 @@ void rlglInitPostpro(void) quadData.vertexCount = 6; - float w = screenWidth; - float h = screenHeight; + float w = (float)screenWidth; + float h = (float)screenHeight; - float quadPositions[6*3] = { w, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, h, 0.0, 0, h, 0.0, w, h, 0.0, w, 0.0, 0.0 }; - float quadTexcoords[6*2] = { 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0 }; - float quadNormals[6*3] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; + float quadPositions[6*3] = { w, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, h, 0.0f, 0.0f, h, 0.0f, w, h, 0.0f, w, 0.0f, 0.0f }; + float quadTexcoords[6*2] = { 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f }; + float quadNormals[6*3] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }; unsigned char quadColors[6*4] = { 255 }; quadData.vertices = quadPositions; @@ -1667,7 +1667,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height) // NOTE: Using global variables: screenWidth, screenHeight Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view) { - Vector3 result = { 0, 0, 0 }; // Object coordinates + Vector3 result = { 0.0f, 0.0f, 0.0f }; // Object coordinates //GLint viewport[4]; //glGetIntegerv(GL_VIEWPORT, viewport); // Not available on OpenGL ES 2.0 @@ -1698,11 +1698,11 @@ Vector3 rlglUnproject(Vector3 source, Matrix proj, Matrix view) quat.x = ((source.x - (float)x)/(float)width)*2.0f - 1.0f; quat.y = ((source.y - (float)y)/(float)height)*2.0f - 1.0f; quat.z = source.z*2.0f - 1.0f; - quat.w = 1.0; + quat.w = 1.0f; QuaternionTransform(&quat, modelviewprojection); - if (quat.w != 0.0) + if (quat.w != 0.0f) { quat.x /= quat.w; quat.y /= quat.w; @@ -2171,7 +2171,7 @@ void *rlglReadTexturePixels(Texture2D texture) // Render texture to fbo glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); - glClearColor(0.0, 0.0, 0.0, 0.0); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); @@ -2189,7 +2189,7 @@ void *rlglReadTexturePixels(Texture2D texture) quad.transform = MatrixIdentity(); quad.shader = simpleShader; - DrawModel(quad, (Vector3){ 0, 0, 0 }, 1.0f, WHITE); + DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE); pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char)); @@ -3239,19 +3239,19 @@ static pixel *GenNextMipmap(pixel *srcData, int srcWidth, int srcHeight) int x2, y2; pixel prow, pcol; - int width = srcWidth / 2; - int height = srcHeight / 2; + int width = srcWidth/2; + int height = srcHeight/2; pixel *mipmap = (pixel *)malloc(width*height*sizeof(pixel)); // Scaling algorithm works perfectly (box-filter) for (int y = 0; y < height; y++) { - y2 = 2 * y; + y2 = 2*y; for (int x = 0; x < width; x++) { - x2 = 2 * x; + x2 = 2*x; prow.r = (srcData[y2*srcWidth + x2].r + srcData[y2*srcWidth + x2 + 1].r)/2; prow.g = (srcData[y2*srcWidth + x2].g + srcData[y2*srcWidth + x2 + 1].g)/2;