new 'toss just dropped

This commit is contained in:
anon
2024-12-20 00:35:59 +01:00
parent 707a0bd9b1
commit da9f31ee67
2 changed files with 82 additions and 37 deletions

@ -1,46 +1,91 @@
#error "Not implemented."
#ifndef PHYSICS_HEADER
#define PHYSICS_HEADER
#if 0
const float G = 9.8f;
const float mass = 10.0f;
const float x0 = 400.0f;
const float y0 = 500.0f;
class BlockProjectile {
public:
const int block_size = 30;
float v0 = 50.0f;
float angle = 45.0f;
float v = v0;
float x = x0;
float y = y0;
float t0 = GetTime();
const float G = 98.0f * 2;
vector<Vector2> trajectory;
Vector2 display_offset;
Vector2 position;
Vector2 velocity;
double last_update;
float dt = GetTime() - t0;
v = (G/mass) * dt;
x = x0 + (v0*sin(radians(angle + 90.0f))) * dt;
y = y0 + (v0*cos(radians(angle + 90.0f)) + G*dt) * dt * v;
/* Used for tracing the block visually,
* not for calculations
*/
vector<Vector2> trajectory;
trajectory.push_back((Vector2) { .x = x, .y = y });
void reset(void) {
position = { 0, 0 };
velocity.y = (rand() % 400) + 3;
velocity.x = (rand() % (150*2)) - 150;
trajectory.clear();
}
if (y > screenHeight) {
v0 = (rand() % 100) + 20.0f;
angle = rand() % 180;
v = v0;
y = y0;
x = x0;
t0 = GetTime();
trajectory.clear();
}
BlockProjectile() {
display_offset.x = (screenWidth / 2) - (block_size - 2);
display_offset.y = screenHeight - 100 - (block_size - 2);
reset();
}
------
double speed(Vector2 velocity) {
return sqrt(pow(velocity.x, 2) + pow(velocity.y, 2));
}
for (const auto &v : trajectory) {
DrawPixel(v.x, v.y, BLUE);
}
void display(void) {
for (auto &p : trajectory) {
DrawPixelV(
(Vector2) {
.x = p.x + display_offset.x,
.y = p.y + display_offset.y,
},
BLUE
);
}
DrawCircleV((Vector2){x, y}, 10, RED);
DrawCircleV(display_offset, 7, GREEN);
DrawRectangle(
position.x + display_offset.x - (block_size/2),
position.y + display_offset.y - (block_size/2),
block_size,
block_size,
RED
);
// HUD
DrawText("Stone Trajectory Simulation", 10, 10, 20, DARKGRAY);
DrawText(TextFormat("Time: %.2f s", last_update), 10, 40, 20, DARKGRAY);
DrawText(TextFormat("Speed: %.2f", speed(velocity)), 10, 70, 20, DARKGRAY);
}
void control(Vector2 click) {
/* NOTE: this module is automatic*/;
}
void update(void) {
if (position.y + display_offset.y > screenHeight) {
reset();
return;
}
trajectory.push_back(position);
double update_time = GetTime();
Vector2 delta;
delta.x = velocity.x * (update_time - last_update);
delta.y = velocity.y * (update_time - last_update);
position.x += delta.x;
position.y -= delta.y;
velocity.y -= G * (update_time - last_update);
last_update = update_time;
}
} content;
DrawText("Stone Trajectory Simulation", 10, 10, 20, DARKGRAY);
DrawText(TextFormat("Time: %.2f s", dt), 10, 40, 20, DARKGRAY);
DrawText(TextFormat("Velocity: %.2f Angle: %.2f", v, angle), 10, 70, 20, DARKGRAY);
#endif

@ -24,8 +24,8 @@ using namespace std;
*/
//#include "Block1D.hpp"
//#include "BouncyBlock1D.hpp"
#include "Block2D.hpp"
//#inline "BlockProjectile.hpp"
//#include "Block2D.hpp"
#include "BlockProjectile.hpp"
int main() {
InitWindow(screenWidth, screenHeight, "Physics Simulation");