Added scale factor for accurate calculations.

This commit is contained in:
2026-06-15 11:54:39 -04:00
parent 123063b3c5
commit e8d29b7f6b

6
ray.c
View File

@@ -4,12 +4,14 @@
// Changes: // Changes:
// Reversing gravity makes it work?!!! // Reversing gravity makes it work?!!!
// Added scale factor, mathed the shit out of that.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "raylib.h" #include "raylib.h"
const float g = 9.81; // Gravity is inversed cause raylib uses top right corner as origin const float scale=43.7445319335; // We must find a scale factor, as gravity is calculated based on PIXELS rather than METERS. We say the character is 3 ft so we divide 40 pixels by the equvalent amount of meters for 3ft which is .9144. so 40/.9144 to get what one pixel is in terms of meters. Left as a variable because this will probably be recalculated eventually.
const float g = 9.81*scale; // Gravity is inversed cause raylib uses top right corner as origin.
float obj_x = 100; // Starting X (pixels) float obj_x = 100; // Starting X (pixels)
float obj_y = 100; // Starting Y (pixels) float obj_y = 100; // Starting Y (pixels)
float obj_vel_x = 50; // Velocity X (pixels/second) float obj_vel_x = 50; // Velocity X (pixels/second)
@@ -22,7 +24,7 @@ int main(void) {
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 600; const int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "Physics Engine - Falling Rectangle"); InitWindow(screenWidth, screenHeight, "WrldBox // ray.c");
SetTargetFPS(60); // 60 frames per second SetTargetFPS(60); // 60 frames per second
float deltaTime = 0.0f; float deltaTime = 0.0f;