Init Commit
This commit is contained in:
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug with CodeLLDB",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"cwd": "${fileDirname}",
|
||||
"preLaunchTask": "C/C++: gcc build active file"
|
||||
}
|
||||
]
|
||||
}
|
||||
59
.vscode/settings.json
vendored
Normal file
59
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
26
.vscode/tasks.json
vendored
Normal file
26
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/gcc",
|
||||
"args": [
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
1743
include/raylib.h
Executable file
1743
include/raylib.h
Executable file
File diff suppressed because it is too large
Load Diff
BIN
lib/libraylib.a
Executable file
BIN
lib/libraylib.a
Executable file
Binary file not shown.
117
ray.c
Normal file
117
ray.c
Normal file
@@ -0,0 +1,117 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "raylib.h"
|
||||
|
||||
const float g = -9.81;
|
||||
float obj_x = 100; // Starting X (pixels)
|
||||
float obj_y = 100; // Starting Y (pixels)
|
||||
float obj_vel_x = 50; // Velocity X (pixels/second)
|
||||
float obj_vel_y = 0; // Velocity Y (pixels/second)
|
||||
float ground_y = 550; // Ground at 550 pixels (assuming 600px screen height)
|
||||
float time_step = 0.0f;
|
||||
float rect_size = 40; // Size of the rectangle
|
||||
|
||||
int main(void) {
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 600;
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "Physics Engine - Falling Rectangle");
|
||||
SetTargetFPS(60); // 60 frames per second
|
||||
|
||||
float deltaTime = 0.0f;
|
||||
bool isSimulating = true;
|
||||
|
||||
printf(">= SIMULATION PARAMETERS =<\n");
|
||||
printf("g= %f\nX= %.2f Y= %.2f GROUND_Y= %.2f\nVEL_X= %.2f VEL_Y= %.2f\n\n",
|
||||
g, obj_x, obj_y, ground_y, obj_vel_x, obj_vel_y);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
// Calculate delta time (time since last frame)
|
||||
deltaTime = GetFrameTime();
|
||||
|
||||
// Control simulation with spacebar
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
isSimulating = !isSimulating;
|
||||
}
|
||||
|
||||
// Reset with R key
|
||||
if (IsKeyPressed(KEY_R)) {
|
||||
obj_x = 100;
|
||||
obj_y = 100;
|
||||
obj_vel_x = 50;
|
||||
obj_vel_y = 0;
|
||||
time_step = 0.0f;
|
||||
isSimulating = true;
|
||||
printf("\n>= SIMULATION RESET =<\n");
|
||||
}
|
||||
|
||||
// Update physics if simulating and object is above ground
|
||||
if (isSimulating && obj_y + rect_size/2 < ground_y) {
|
||||
// Your original physics logic with deltaTime
|
||||
obj_vel_y += deltaTime * g; // v = u + at
|
||||
obj_y += obj_vel_y * deltaTime; // s = ut + 1/2 at^2 is handled by this
|
||||
obj_x += obj_vel_x * deltaTime;
|
||||
|
||||
time_step += deltaTime;
|
||||
|
||||
// Real-time console output (optional)
|
||||
if ((int)(time_step * 60) % 30 == 0) { // Print every ~0.5 seconds
|
||||
printf("\r[%.2fs] X: %.2f Y: %.2f VEL_X: %.2f VEL_Y: %.2f",
|
||||
time_step, obj_x, obj_y, obj_vel_x, obj_vel_y);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp to ground (prevent going through)
|
||||
if (obj_y + rect_size/2 >= ground_y) {
|
||||
obj_y = ground_y - rect_size/2;
|
||||
if (isSimulating) {
|
||||
printf("\n\n>= Object Hit Ground =<\n");
|
||||
printf("X: %.2f, Y: %.2f, VEL_X: %.2f, VEL_Y: %.2f TIME: %.2f\n",
|
||||
obj_x, obj_y, obj_vel_x, obj_vel_y, time_step);
|
||||
isSimulating = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep rectangle in screen bounds horizontally
|
||||
if (obj_x - rect_size/2 < 0) obj_x = rect_size/2;
|
||||
if (obj_x + rect_size/2 > screenWidth) obj_x = screenWidth - rect_size/2;
|
||||
|
||||
// Drawing
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw ground line
|
||||
DrawLine(0, ground_y, screenWidth, ground_y, DARKGRAY);
|
||||
|
||||
// Draw ground label
|
||||
DrawText("GROUND", 10, ground_y + 5, 20, DARKGRAY);
|
||||
|
||||
// Draw the falling rectangle
|
||||
Rectangle rect = { obj_x - rect_size/2, obj_y - rect_size/2, rect_size, rect_size };
|
||||
DrawRectangleRec(rect, RED);
|
||||
DrawRectangleLinesEx(rect, 2, MAROON);
|
||||
|
||||
// Draw info text
|
||||
DrawText(TextFormat("Time: %.2f s", time_step), 10, 10, 20, DARKGRAY);
|
||||
DrawText(TextFormat("Position: (%.1f, %.1f)", obj_x, obj_y), 10, 35, 20, DARKGRAY);
|
||||
DrawText(TextFormat("Velocity: (%.1f, %.1f)", obj_vel_x, obj_vel_y), 10, 60, 20, DARKGRAY);
|
||||
DrawText(TextFormat("Status: %s", isSimulating ? "SIMULATING" : "PAUSED"), 10, 85, 20, isSimulating ? GREEN : RED);
|
||||
|
||||
// Draw controls help
|
||||
DrawText("Controls:", screenWidth - 200, 10, 20, DARKGRAY);
|
||||
DrawText("SPACE: Pause/Resume", screenWidth - 200, 35, 15, DARKGRAY);
|
||||
DrawText("R: Reset", screenWidth - 200, 55, 15, DARKGRAY);
|
||||
DrawText("ESC: Exit", screenWidth - 200, 75, 15, DARKGRAY);
|
||||
|
||||
// Draw velocity vector (optional visualization)
|
||||
Vector2 velocityEnd = { obj_x + obj_vel_x * 0.1f, obj_y + obj_vel_y * 0.1f };
|
||||
DrawLineEx((Vector2){obj_x, obj_y}, velocityEnd, 3, BLUE);
|
||||
DrawText("Velocity Vector", obj_x + 5, obj_y - 10, 15, BLUE);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
38
test.c
Normal file
38
test.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define cross_sleep(ms) Sleep(ms) // Windows Sleep takes milliseconds
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#define cross_sleep(ms) usleep(ms * 1000) // POSIX usleep takes microseconds
|
||||
#endif
|
||||
|
||||
const float g = -9.81;
|
||||
float obj_x = 0;
|
||||
float obj_y = 100;
|
||||
float obj_vel_x = 3;
|
||||
float obj_vel_y = 0;
|
||||
float ground_y = 0;
|
||||
float time = 0;
|
||||
|
||||
int main() {
|
||||
printf(">= SIMULATION PARAMETERS =<\n");
|
||||
printf("g= %f\nX= %f Y= %f GROUND_Y= %f\nVEL_X= %.f VEL_Y= %f\n\n", g, obj_x, obj_y, ground_y, obj_vel_x, obj_vel_y);
|
||||
while (obj_y > ground_y){
|
||||
// Add to the vel;
|
||||
obj_vel_y += 0.001 * g;
|
||||
|
||||
// calculate change based on new vel
|
||||
obj_y += obj_vel_y * 0.001;
|
||||
obj_x += obj_vel_x * 0.001;
|
||||
printf("\r[%.2fs] X: %.2f Y: %.2f VEL_X: %.2f VEL_Y: %.2f", time, obj_x, obj_y, obj_vel_x, obj_vel_y);
|
||||
fflush(stdout);
|
||||
|
||||
cross_sleep(1);
|
||||
time += 0.001;
|
||||
}
|
||||
printf("\n\n>= Object End Stats =<\n");
|
||||
printf("X: %.2f, Y: %.2f, VEL_X: %.2f, VEL_Y: %.2f TIME: %f\n", obj_x, obj_y, obj_vel_x, obj_vel_y, time);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user