From 1e1061d5c7582090df0851c08359d7c7847f9559 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 30 Jun 2024 11:37:58 +0200 Subject: [PATCH] REVIEWED: Formatting, follow raylib coding conventions --- src/platforms/rcore_android.c | 16 ++++---- src/platforms/rcore_desktop_rgfw.c | 6 +-- src/platforms/rcore_desktop_sdl.c | 59 ++++++++++++++---------------- src/platforms/rcore_drm.c | 8 ++-- src/platforms/rcore_web.c | 6 ++- src/raylib.h | 2 +- src/raymath.h | 22 +++++------ src/rcamera.h | 4 +- src/rlgl.h | 2 +- src/rshapes.c | 16 ++++---- src/rtextures.c | 14 +++---- 11 files changed, 77 insertions(+), 78 deletions(-) diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index dc8724d8f61c..8fc51d0e1f9f 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -81,7 +81,7 @@ static PlatformData platform = { 0 }; // Platform specific data // Local Variables Definition //---------------------------------------------------------------------------------- #define KEYCODE_MAP_SIZE 162 -static const KeyboardKey KeycodeMap[KEYCODE_MAP_SIZE] = { +static const KeyboardKey mapKeycode[KEYCODE_MAP_SIZE] = { KEY_NULL, // AKEYCODE_UNKNOWN 0, // AKEYCODE_SOFT_LEFT 0, // AKEYCODE_SOFT_RIGHT @@ -1133,9 +1133,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_Y] = AMotionEvent_getAxisValue( event, AMOTION_EVENT_AXIS_RZ, 0); CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_LEFT_TRIGGER] = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_BRAKE, 0) * 2.0f - 1.0f; + event, AMOTION_EVENT_AXIS_BRAKE, 0)*2.0f - 1.0f; CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_TRIGGER] = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_GAS, 0) * 2.0f - 1.0f; + event, AMOTION_EVENT_AXIS_GAS, 0)*2.0f - 1.0f; // dpad is reported as an axis on android float dpadX = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_HAT_X, 0); @@ -1201,7 +1201,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) return 1; // Handled gamepad button } - KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : KEY_NULL; + KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE)? mapKeycode[keycode] : KEY_NULL; if (key != KEY_NULL) { // Save current key and its state @@ -1252,10 +1252,10 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) }; // Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height - float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x) / (float)CORE.Window.display.width; - float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y) / (float)CORE.Window.display.height; - CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE.Window.renderOffset.x / 2; - CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE.Window.renderOffset.y / 2; + float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x)/(float)CORE.Window.display.width; + float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y)/(float)CORE.Window.display.height; + CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2; + CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y*heightRatio - (float)CORE.Window.renderOffset.y/2; } int32_t action = AMotionEvent_getAction(event); diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index dbbbe10cc6c2..d53237fcdb88 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -1097,16 +1097,16 @@ void PollInputEvents(void) } #ifdef __linux__ - float value = (event->axis[i].x + event->axis[i].y) / (float) 32767; + float value = (event->axis[i].x + event->axis[i].y)/(float)32767; #else - float value = (event->axis[i].x + -event->axis[i].y) / (float) 32767; + float value = (event->axis[i].x + -event->axis[i].y)/(float)32767; #endif CORE.Input.Gamepad.axisState[event->joystick][axis] = value; // Register button state for triggers in addition to their axes if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER)) { - int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; + int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; int pressed = (value > 0.1f); CORE.Input.Gamepad.currentButtonState[event->joystick][button] = pressed; if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 8a0fea81a33b..d9637f705cbf 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -80,7 +80,7 @@ static PlatformData platform = { 0 }; // Platform specific data // Local Variables Definition //---------------------------------------------------------------------------------- #define SCANCODE_MAPPED_NUM 232 -static const KeyboardKey ScancodeToKey[SCANCODE_MAPPED_NUM] = { +static const KeyboardKey mapScancodeToKey[SCANCODE_MAPPED_NUM] = { KEY_NULL, // SDL_SCANCODE_UNKNOWN 0, 0, @@ -476,9 +476,9 @@ void ClearWindowState(unsigned int flags) // Set icon for window void SetWindowIcon(Image image) { - SDL_Surface* iconSurface = NULL; + SDL_Surface *iconSurface = NULL; - Uint32 rmask, gmask, bmask, amask; + unsigned int rmask = 0, gmask = 0, bmask = 0, amask = 0; int depth = 0; // Depth in bits int pitch = 0; // Pixel spacing (pitch) in bytes @@ -492,72 +492,67 @@ void SetWindowIcon(Image image) case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: rmask = 0xFF, gmask = 0xFF00; bmask = 0, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R5G6B5: rmask = 0xF800, gmask = 0x07E0; bmask = 0x001F, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // Uses BGR for 24-bit rmask = 0x0000FF, gmask = 0x00FF00; bmask = 0xFF0000, amask = 0; - depth = 24, pitch = image.width * 3; + depth = 24, pitch = image.width*3; break; case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: rmask = 0xF800, gmask = 0x07C0; bmask = 0x003E, amask = 0x0001; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: rmask = 0xF000, gmask = 0x0F00; bmask = 0x00F0, amask = 0x000F; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: rmask = 0xFF000000, gmask = 0x00FF0000; bmask = 0x0000FF00, amask = 0x000000FF; - depth = 32, pitch = image.width * 4; + depth = 32, pitch = image.width*4; break; case PIXELFORMAT_UNCOMPRESSED_R32: rmask = 0xFFFFFFFF, gmask = 0; bmask = 0, amask = 0; - depth = 32, pitch = image.width * 4; + depth = 32, pitch = image.width*4; break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32: rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0; - depth = 96, pitch = image.width * 12; + depth = 96, pitch = image.width*12; break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0xFFFFFFFF; - depth = 128, pitch = image.width * 16; + depth = 128, pitch = image.width*16; break; case PIXELFORMAT_UNCOMPRESSED_R16: rmask = 0xFFFF, gmask = 0; bmask = 0, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16: rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0; - depth = 48, pitch = image.width * 6; + depth = 48, pitch = image.width*6; break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16A16: rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0xFFFF; - depth = 64, pitch = image.width * 8; + depth = 64, pitch = image.width*8; break; - default: - // Compressed formats are not supported - return; + default: return; // Compressed formats are not supported } - iconSurface = SDL_CreateRGBSurfaceFrom( - image.data, image.width, image.height, depth, pitch, - rmask, gmask, bmask, amask - ); + iconSurface = SDL_CreateRGBSurfaceFrom( image.data, image.width, image.height, depth, pitch, rmask, gmask, bmask, amask ); if (iconSurface) { @@ -599,7 +594,7 @@ void SetWindowMonitor(int monitor) // 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3, // see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba // 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again. - const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false; + const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0)? true : false; const int screenWidth = CORE.Window.screen.width; const int screenHeight = CORE.Window.screen.height; @@ -941,11 +936,11 @@ int SetGamepadMappings(const char *mappings) // Set gamepad vibration void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) { - //Limit input values to between 0.0f and 1.0f - leftMotor = (0.0f > leftMotor) ? 0.0f : leftMotor; - rightMotor = (0.0f > rightMotor) ? 0.0f : rightMotor; - leftMotor = (1.0f < leftMotor) ? 1.0f : leftMotor; - rightMotor = (1.0f < rightMotor) ? 1.0f : rightMotor; + // Limit input values to between 0.0f and 1.0f + leftMotor = (0.0f > leftMotor)? 0.0f : leftMotor; + rightMotor = (0.0f > rightMotor)? 0.0f : rightMotor; + leftMotor = (1.0f < leftMotor)? 1.0f : leftMotor; + rightMotor = (1.0f < rightMotor)? 1.0f : rightMotor; if (IsGamepadAvailable(gamepad)) { @@ -1365,13 +1360,13 @@ void PollInputEvents(void) if (axis >= 0) { // SDL axis value range is -32768 to 32767, we normalize it to RayLib's -1.0 to 1.0f range - float value = event.jaxis.value / (float) 32767; + float value = event.jaxis.value/(float)32767; CORE.Input.Gamepad.axisState[event.jaxis.which][axis] = value; // Register button state for triggers in addition to their axes if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER)) { - int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER) ? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; + int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2; int pressed = (value > 0.1f); CORE.Input.Gamepad.currentButtonState[event.jaxis.which][button] = pressed; if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; @@ -1554,6 +1549,7 @@ int InitPlatform(void) for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++) { platform.gamepad[i] = SDL_JoystickOpen(i); + if (platform.gamepad[i]) { CORE.Input.Gamepad.ready[i] = true; @@ -1608,8 +1604,9 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode) { if (sdlScancode >= 0 && sdlScancode < SCANCODE_MAPPED_NUM) { - return ScancodeToKey[sdlScancode]; + return mapScancodeToKey[sdlScancode]; } + return KEY_NULL; // No equivalent key in Raylib } // EOF diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 17a8e4d005e8..f888d0e4735f 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -1028,7 +1028,7 @@ int InitPlatform(void) // If graphic device is no properly initialized, we end program if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } - else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2); + else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2); // Set some default window flags CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false @@ -1614,7 +1614,7 @@ static void PollKeyboardEvents(void) } } - TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0) ? "UP " : "DOWN", event.code, keycode); + TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0)? "UP " : "DOWN", event.code, keycode); } } } @@ -1641,7 +1641,7 @@ static void PollGamepadEvents(void) { short keycodeRaylib = linuxToRaylibMap[event.code]; - TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0) ? "UP " : "DOWN", event.code, keycodeRaylib); + TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0)? "UP" : "DOWN", event.code, keycodeRaylib); if ((keycodeRaylib != 0) && (keycodeRaylib < MAX_GAMEPAD_BUTTONS)) { @@ -1666,7 +1666,7 @@ static void PollGamepadEvents(void) int range = platform.gamepadAbsAxisRange[i][event.code][1]; // NOTE: Scaling of event.value to get values between -1..1 - CORE.Input.Gamepad.axisState[i][axisRaylib] = (2 * (float)(event.value - min) / range) - 1; + CORE.Input.Gamepad.axisState[i][axisRaylib] = (2*(float)(event.value - min)/range) - 1; } } } diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index afe8adfb1736..47b8d42d6abe 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -190,7 +190,8 @@ void ToggleFullscreen(void) if (enterFullscreen) { // NOTE: The setTimeouts handle the browser mode change delay - EM_ASM( + EM_ASM + ( setTimeout(function() { Module.requestFullscreen(false, false); @@ -298,7 +299,8 @@ void ToggleBorderlessWindowed(void) { // NOTE: 1. The setTimeouts handle the browser mode change delay // 2. The style unset handles the possibility of a width="value%" like on the default shell.html file - EM_ASM( + EM_ASM + ( setTimeout(function() { Module.requestFullscreen(false, true); diff --git a/src/raylib.h b/src/raylib.h index 3f6b61f8a733..2c7a6a573556 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1332,7 +1332,7 @@ RLAPI Image GenImageText(int width, int height, const char *text); // Image manipulation functions RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) RLAPI Image ImageFromImage(Image image, Rectangle rec); // Create an image from another image piece -RLAPI Image ImageFromChannel(Image image, int selectedChannel); // Create an image from a selected channel of another image (GRAYSCALE/R16/R32) +RLAPI Image ImageFromChannel(Image image, int selectedChannel); // Create an image from a selected channel of another image (GRAYSCALE) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font) RLAPI void ImageFormat(Image *image, int newFormat); // Convert image data to desired format diff --git a/src/raymath.h b/src/raymath.h index 0a0b05803b83..0b69519384c4 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -175,7 +175,7 @@ typedef struct float16 { // Clamp float value RMAPI float Clamp(float value, float min, float max) { - float result = (value < min) ? min : value; + float result = (value < min)? min : value; if (result > max) result = max; @@ -962,12 +962,12 @@ RMAPI Vector3 Vector3CubicHermite(Vector3 v1, Vector3 tangent1, Vector3 v2, Vect { Vector3 result = { 0 }; - float amountPow2 = amount * amount; - float amountPow3 = amount * amount * amount; + float amountPow2 = amount*amount; + float amountPow3 = amount*amount*amount; - result.x = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.x + (amountPow3 - 2 * amountPow2 + amount) * tangent1.x + (-2 * amountPow3 + 3 * amountPow2) * v2.x + (amountPow3 - amountPow2) * tangent2.x; - result.y = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.y + (amountPow3 - 2 * amountPow2 + amount) * tangent1.y + (-2 * amountPow3 + 3 * amountPow2) * v2.y + (amountPow3 - amountPow2) * tangent2.y; - result.z = (2 * amountPow3 - 3 * amountPow2 + 1) * v1.z + (amountPow3 - 2 * amountPow2 + amount) * tangent1.z + (-2 * amountPow3 + 3 * amountPow2) * v2.z + (amountPow3 - amountPow2) * tangent2.z; + result.x = (2*amountPow3 - 3*amountPow2 + 1)*v1.x + (amountPow3 - 2*amountPow2 + amount)*tangent1.x + (-2*amountPow3 + 3*amountPow2)*v2.x + (amountPow3 - amountPow2)*tangent2.x; + result.y = (2*amountPow3 - 3*amountPow2 + 1)*v1.y + (amountPow3 - 2*amountPow2 + amount)*tangent1.y + (-2*amountPow3 + 3*amountPow2)*v2.y + (amountPow3 - amountPow2)*tangent2.y; + result.z = (2*amountPow3 - 3*amountPow2 + 1)*v1.z + (amountPow3 - 2*amountPow2 + amount)*tangent1.z + (-2*amountPow3 + 3*amountPow2)*v2.z + (amountPow3 - amountPow2)*tangent2.z; return result; } @@ -2218,11 +2218,11 @@ RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount) // as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic RMAPI Quaternion QuaternionCubicHermiteSpline(Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t) { - float t2 = t * t; - float t3 = t2 * t; - float h00 = 2 * t3 - 3 * t2 + 1; - float h10 = t3 - 2 * t2 + t; - float h01 = -2 * t3 + 3 * t2; + float t2 = t*t; + float t3 = t2*t; + float h00 = 2*t3 - 3*t2 + 1; + float h10 = t3 - 2*t2 + t; + float h01 = -2*t3 + 3*t2; float h11 = t3 - t2; Quaternion p0 = QuaternionScale(q1, h00); diff --git a/src/rcamera.h b/src/rcamera.h index 9c19556c4a6e..d3042d3064bc 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -490,8 +490,8 @@ void UpdateCamera(Camera *camera, int mode) if (IsGamepadAvailable(0)) { // Gamepad controller support - CameraYaw(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget); - CameraPitch(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp); + CameraYaw(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_X)*2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget); + CameraPitch(camera, -(GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_Y)*2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp); if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_Y) <= -0.25f) CameraMoveForward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane); if (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_X) <= -0.25f) CameraMoveRight(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane); diff --git a/src/rlgl.h b/src/rlgl.h index 98d43ea57dac..5ab677d98c7b 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -1560,7 +1560,7 @@ void rlNormal3f(float x, float y, float z) float length = sqrtf(normalx*normalx + normaly*normaly + normalz*normalz); if (length != 0.0f) { - float ilength = 1.0f / length; + float ilength = 1.0f/length; normalx *= ilength; normaly *= ilength; normalz *= ilength; diff --git a/src/rshapes.c b/src/rshapes.c index fd6ff7d23533..16e80b17e0e4 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -2235,10 +2235,10 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa float dx = center2.x - center1.x; // X distance between centers float dy = center2.y - center1.y; // Y distance between centers - float distanceSquared = dx * dx + dy * dy; // Distance between centers squared + float distanceSquared = dx*dx + dy*dy; // Distance between centers squared float radiusSum = radius1 + radius2; - collision = (distanceSquared <= (radiusSum * radiusSum)); + collision = (distanceSquared <= (radiusSum*radiusSum)); return collision; } @@ -2329,17 +2329,17 @@ RLAPI bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Ve return CheckCollisionCircles(p1, 0, center, radius); } - float lengthSQ = ((dx * dx) + (dy * dy)); - float dotProduct = (((center.x - p1.x) * (p2.x - p1.x)) + ((center.y - p1.y) * (p2.y - p1.y))) / (lengthSQ); + float lengthSQ = ((dx*dx) + (dy*dy)); + float dotProduct = (((center.x - p1.x)*(p2.x - p1.x)) + ((center.y - p1.y)*(p2.y - p1.y)))/(lengthSQ); if (dotProduct > 1.0f) dotProduct = 1.0f; else if (dotProduct < 0.0f) dotProduct = 0.0f; - float dx2 = (p1.x - (dotProduct * (dx))) - center.x; - float dy2 = (p1.y - (dotProduct * (dy))) - center.y; - float distanceSQ = ((dx2 * dx2) + (dy2 * dy2)); + float dx2 = (p1.x - (dotProduct*(dx))) - center.x; + float dy2 = (p1.y - (dotProduct*(dy))) - center.y; + float distanceSQ = ((dx2*dx2) + (dy2*dy2)); - return (distanceSQ <= radius * radius); + return (distanceSQ <= radius*radius); } // Get collision rectangle for two rectangles collision diff --git a/src/rtextures.c b/src/rtextures.c index b6d331385134..ccfa12ecbd92 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3599,7 +3599,7 @@ void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int en } // Calculate fixed-point increment for shorter length - int decInc = (longLen == 0)? 0 : (shortLen<<16) / longLen; + int decInc = (longLen == 0)? 0 : (shortLen << 16)/longLen; // Draw the line pixel by pixel if (yLonger) @@ -3608,7 +3608,7 @@ void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int en for (int i = 0, j = 0; i != endVal; i += sgnInc, j += decInc) { // Calculate pixel position and draw it - ImageDrawPixel(dst, startPosX + (j>>16), startPosY + i, color); + ImageDrawPixel(dst, startPosX + (j >> 16), startPosY + i, color); } } else @@ -3617,7 +3617,7 @@ void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int en for (int i = 0, j = 0; i != endVal; i += sgnInc, j += decInc) { // Calculate pixel position and draw it - ImageDrawPixel(dst, startPosX + i, startPosY + (j>>16), color); + ImageDrawPixel(dst, startPosX + i, startPosY + (j >> 16), color); } } } @@ -3815,10 +3815,10 @@ void ImageDrawTriangle(Image *dst, Vector2 v1, Vector2 v2, Vector2 v3, Color col { // Calculate the 2D bounding box of the triangle // Determine the minimum and maximum x and y coordinates of the triangle vertices - int xMin = (int)((v1.x < v2.x)? ((v1.x < v3.x) ? v1.x : v3.x) : ((v2.x < v3.x) ? v2.x : v3.x)); - int yMin = (int)((v1.y < v2.y)? ((v1.y < v3.y) ? v1.y : v3.y) : ((v2.y < v3.y) ? v2.y : v3.y)); - int xMax = (int)((v1.x > v2.x)? ((v1.x > v3.x) ? v1.x : v3.x) : ((v2.x > v3.x) ? v2.x : v3.x)); - int yMax = (int)((v1.y > v2.y)? ((v1.y > v3.y) ? v1.y : v3.y) : ((v2.y > v3.y) ? v2.y : v3.y)); + int xMin = (int)((v1.x < v2.x)? ((v1.x < v3.x)? v1.x : v3.x) : ((v2.x < v3.x)? v2.x : v3.x)); + int yMin = (int)((v1.y < v2.y)? ((v1.y < v3.y)? v1.y : v3.y) : ((v2.y < v3.y)? v2.y : v3.y)); + int xMax = (int)((v1.x > v2.x)? ((v1.x > v3.x)? v1.x : v3.x) : ((v2.x > v3.x)? v2.x : v3.x)); + int yMax = (int)((v1.y > v2.y)? ((v1.y > v3.y)? v1.y : v3.y) : ((v2.y > v3.y)? v2.y : v3.y)); // Clamp the bounding box to the image dimensions if (xMin < 0) xMin = 0;