Merge branch 'main' of git.h3cx.dev:h3cx/fphysics
This commit is contained in:
5 files changed
+74
-4
No files matched your search
@@ -0,0 +1,8 @@
|
||||
#include "cphysics.h"
|
||||
|
||||
void gravity(universe_t* univ){
|
||||
|
||||
}
|
||||
void magnetism(universe_t* univ){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef CPHYSICS_H_
|
||||
#define CPHYSICS_H_
|
||||
#include "objects.h"
|
||||
void gravity(universe_t* univ);
|
||||
void magnetism(universe_t* univ);
|
||||
void mechanics(universe_t* univ);
|
||||
#endif // CPHYSICS_H_
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <bits/time.h>
|
||||
#include <math.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -130,10 +131,6 @@ bool vec2_is_null(Vector2 v) {
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef struct universe {
|
||||
unsigned int num_bodies;
|
||||
mass_body_t *bodies;
|
||||
} universe_t;
|
||||
|
||||
long long timespec_diff_ns(struct timespec end, struct timespec start) {
|
||||
return (end.tv_sec - start.tv_sec) * 1000000000LL +
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef OBJECTS_H_
|
||||
#define OBJECTS_H_
|
||||
#include "vec_util.h"
|
||||
|
||||
typedef struct {
|
||||
float mass;
|
||||
float radius;
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
} mass_body_t;
|
||||
|
||||
typedef struct universe {
|
||||
unsigned int num_bodies;
|
||||
mass_body_t *bodies;
|
||||
} universe_t;
|
||||
#endif // OBJECTS_H_
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#ifndef VEC_UTIL_H_
|
||||
#define VEC_UTIL_H_
|
||||
#include <raylib.h>
|
||||
#include <math.h>
|
||||
static const Vector2 NULL_VEC2 = {0, 0};
|
||||
|
||||
|
||||
|
||||
Vector2 transform_to_center(Vector2 v) {
|
||||
int width = GetRenderWidth();
|
||||
int height = GetRenderHeight();
|
||||
Vector2 result = {v.x + width / 2.0, v.y + height / 2.0};
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector2 vec2_sum(const Vector2 *a, const Vector2 *b) {
|
||||
Vector2 result = {a->x + b->x, a->y + b->y};
|
||||
return result;
|
||||
}
|
||||
Vector2 vec2_diff(const Vector2 *a, const Vector2 *b) {
|
||||
Vector2 result = {a->x - b->x, a->y - b->y};
|
||||
return result;
|
||||
}
|
||||
|
||||
float vec2_len(Vector2 v) { return sqrtf(v.x * v.x + v.y * v.y); }
|
||||
|
||||
Vector2 vec2_normalize(const Vector2 v) {
|
||||
float len = vec2_len(v);
|
||||
Vector2 result = {v.x / len, v.y / len};
|
||||
return result;
|
||||
}
|
||||
|
||||
Vector2 vec2_scale(const Vector2 *normal, const float len) {
|
||||
Vector2 result = {len * normal->x, len * normal->y};
|
||||
return result;
|
||||
}
|
||||
|
||||
float vec2_dot(const Vector2 *a, const Vector2 *b) {
|
||||
return a->x * b->x + a->y * b->y;
|
||||
}
|
||||
|
||||
#endif // VEC_UTIL_H_
|
||||
Reference in new issue
Block a user