aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-10-08 12:04:17 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-10-08 12:04:17 +0300
commitd0741351d3872eb9a1ce697984337f99daf82b59 (patch)
treeb4a7addb1cec6c4f97db30da2710af6381117026
parente41af6679dae3f4c69b46962a6bf1a1f81bee600 (diff)
works now
-rw-r--r--src/display.c5
-rw-r--r--src/main.c97
2 files changed, 38 insertions, 64 deletions
diff --git a/src/display.c b/src/display.c
index 57acf86..a1ee9f7 100644
--- a/src/display.c
+++ b/src/display.c
@@ -16,6 +16,7 @@ void dspl_start()
{
BeginDrawing();
ClearBackground(RAYWHITE);
+ DrawFPS(10, 10);
info.update_func();
EndDrawing();
}
@@ -28,10 +29,10 @@ void dspl_destroy()
void dspl_draw_circle(int cx, int cy, int r)
{
- DrawCircle((info.width/2) + cx, cy, 5, RED);
+ DrawCircle((info.width/2) + cx, (info.height/2) + cy, r, RED);
}
void dspl_draw_line(int x1, int y1, int x2, int y2, int c)
{
- DrawLine((info.width/2) + x1, y1, (info.width/2) + x2, y2 , (c == 0) ? BLUE : RED);
+ DrawLine((info.width/2) + x1, (info.height/2) + y1, (info.width/2) + x2, (info.height/2) + y2 , (c == 0) ? BLUE : RED);
}
diff --git a/src/main.c b/src/main.c
index 53b4edf..3fd6447 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,92 +1,65 @@
#include <stdio.h>
+#include <time.h>
#include <math.h>
#include "display.h"
#define W 1600
#define H 900
-#define FPS 60
-#define RFPS 1/600
+#define FPS 460
+#define RFPS 1/FPS
#define PI 3.141592654
-typedef struct{
- float x;
- float y;
-} vec;
+const float s = (PI/180 * 25); // rad
+const int l = 500; // mm
+const int m = 1; // kg
+const float g = -9810.0f; // mm/s^2
-
-const float s = (PI/180 * 10); // rad
-const int l = 250; // mm
-const int m = 25; // kg
-// const vec g = {0.0f, -9.81f}; // m/s^2
-const float g = -9.81f;
-
-// vec p;
-// vec v;
-// vec a;
float t;
float v;
float a;
-// vec rotate_grav(float angle, int d) // d = 0-clock, 1-anti
-// {
-// // vec rg = {0, g.y*m*sinf(angle)};
-// vec rg = {0, g.y};
-// if(d == 0) {
-// rg.x = (rg.y*sinf(angle));
-// rg.y = -(rg.y*cosf(angle));
-// } else if(d == 1) {
-// rg.x = -(rg.y*sinf(angle));
-// rg.y = (rg.y*cosf(angle));
-// }
-
-// printf("grav transform: %f %f %f\n", rg.x, rg.y, sqrt((rg.x*rg.x) + (rg.y*rg.y)));
-// return rg;
-// }
+float secs = 0.0f;
+int cycles = 20;
+int has_reached_starting_amp(float old_t)
+{
+ if(cycles % 2 == 0 && t < 0) {
+ if(old_t < t) return 1;
+ } else if(cycles % 2 == 1 && t > 0) {
+ if(old_t > t) return 1;
+ } return 0;
+}
void update()
{
+ float old_t = t;
+ a = (g/l) * sinf(t);
+ v += a * RFPS;
+ t += v * RFPS;
- // float sinamp = p.x / l;
- // vec rg = rotate_grav((PI/2) - asinf(sinamp), (p.x > 0) ? 0 : 1);
-
- // printf("amp: %f\n", asinf(sinamp)*180/PI);
- // printf("lenght: %f\n", sqrt((p.x*p.x) + (p.y*p.y)));
-
- // p.x = sinf(t) * l;
- // p.y = cosf(t) * l;
+ if(has_reached_starting_amp(old_t)) {
+ puts("new cycle");
+ cycles += 1;
+ }
+ if(cycles == 20) {
+ printf("sec: %f\n", secs);
+ secs = 0.0f;
+ cycles = 0;
+ }
- // a.x += rg.x;
- // a.y += rg.y;
- // v.x += a.x * RFPS;
- // v.y += a.y * RFPS;
- // p.x += v.x * RFPS;
- // p.y += v.y * RFPS;
+ secs += (float)RFPS;
- // dspl_draw_line(p.x, p.y, v.x + p.x, v.y + p.y, 0);
- // dspl_draw_line(p.x, p.y, a.x + p.x, a.y + p.y, 1);
- // dspl_draw_line(p.x, p.y, 0, 0, 0);
- // dspl_draw_circle(p.x, p.y, 5);
- a += g * cosf(t) * m;
- printf("%f %f\n", sinf(t), a);
- v += a * RFPS;
- t += v * RFPS;
-
- int px = sinf(t) * l;
- int py = cosf(t) * l;
+ float px = sinf(t) * l;
+ float py = cosf(t) * l;
dspl_draw_line(px, py, 0, 0, 0);
- dspl_draw_circle(px, py, 5);
+ dspl_draw_circle(px, py, m*5);
+
}
int main(void)
{
- // p.x = sinf(t) * l;
- // p.y = cosf(t) * l;
- // v.x = 0; v.y = 0;
- // a.x = 0; a.y = 0;
-
t = s;
v = 0;
a = 0;