Browse Source

updating repo

Iver 6 days ago
parent
commit
778cbcc00c

BIN
builds/libfizzix.so


BIN
builds/main.bin


BIN
resolution_research.png


+ 13 - 0
src/headers/FZ_functions.h

@@ -0,0 +1,13 @@
+#ifndef FZ_FUNCTIONS_H
+#define FZ_FUNCTIONS_H
+
+#include "FZ_structs.h"
+
+FZ_scene* FZ_new_scene();
+FZ_shape* FZ_new_shape();
+int FZ_init();
+int FZ_tick(FZ_scene* scene, double deltatime); // ticks a scene
+int FZ_render_debug(FZ_scene* scene); // renders a debug window
+FZ_context* FZ_get_context();
+
+#endif

+ 95 - 0
src/headers/FZ_math.h

@@ -0,0 +1,95 @@
+#ifndef FZ_MATH_H
+#define FZ_MATH_H
+
+#include "FZ_structs.h"
+
+double distance_2(FZ_vector_2 a, FZ_vector_2 b){
+    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
+}
+
+FZ_vector_2 v2_mul(FZ_vector_2 vector, double value){
+    vector.x *= value;
+    vector.y *= value;
+
+    return vector;
+}
+
+// element-wise add
+FZ_vector_2 v2_ew_add(FZ_vector_2 vector_a, FZ_vector_2 vector_b){
+    vector_a.x += vector_b.x;
+    vector_a.y += vector_b.y;
+
+    return vector_a;
+}
+
+// element-wise subtract
+FZ_vector_2 v2_ew_sub(FZ_vector_2 vector_a, FZ_vector_2 vector_b){
+    vector_a.x -= vector_b.x;
+    vector_a.y -= vector_b.y;
+
+    return vector_a;
+}
+
+// element-wise multiply
+FZ_vector_2 v2_ew_mul(FZ_vector_2 vector_a, FZ_vector_2 vector_b){
+    vector_a.x *= vector_b.x;
+    vector_a.y *= vector_b.y;
+
+    return vector_a;
+}
+
+FZ_vector_2 vector_2_lerp(FZ_vector_2 vector_a, FZ_vector_2 vector_b, double w1){
+    double w0 = 1.0 - w1;
+
+    FZ_vector_2 result = (FZ_vector_2){0, 0};
+
+    vector_a = v2_mul(vector_a, w0);
+    vector_b = v2_mul(vector_b, w1);
+
+    result = v2_ew_add(result, vector_a);
+    result = v2_ew_add(result, vector_b);
+
+    return result;
+}
+
+FZ_vector_2 v2_rot(FZ_vector_2 vector, FZ_vector_2 origin, double angle){
+    FZ_vector_2 new_vec = vector;
+
+    new_vec = v2_ew_sub(new_vec, origin);
+
+    new_vec.x = vector.x * cos(angle) - vector.y * sin(angle);
+    new_vec.y = vector.x * sin(angle) + vector.y * cos(angle);
+
+    new_vec = v2_ew_add(new_vec, origin);
+
+    return new_vec;
+}
+
+double v2_dot(FZ_vector_2 vector_a, FZ_vector_2 vector_b){
+    double result = vector_a.x * vector_b.x + vector_a.y * vector_b.y;
+
+    return result;
+}
+
+FZ_vector_2 v2_normalize(FZ_vector_2 vector){
+    return v2_mul(vector, 1 / sqrt(v2_dot(vector, vector)));
+}
+
+FZ_vector_2 v2_rotate_neg_90(FZ_vector_2 vector){
+    return (FZ_vector_2){-vector.y, vector.x};
+}
+
+FZ_vector_2 v2_rotate_90(FZ_vector_2 vector){
+    return (FZ_vector_2){vector.y, -vector.x};
+}
+
+// where a and b form line a, project c onto line a, return the scalar
+double project_along_vectors_normal(FZ_vector_2 a, FZ_vector_2 b, FZ_vector_2 c){
+    b = (FZ_vector_2){b.y - a.y, -(b.x - a.x)};
+    
+    c = v2_ew_sub(c, a);
+
+    return (v2_dot(c, b) / v2_dot(b, b));
+}
+
+#endif

+ 61 - 0
src/headers/FZ_structs.h

@@ -0,0 +1,61 @@
+#ifndef FZ_STRUCTS
+#define FZ_STRUCTS
+
+#include <stdint.h>
+#include <SDL2/SDL.h>
+
+typedef struct {
+    double x, y;
+} FZ_vector_2;
+
+enum {
+    FZ_SHAPE_IS_STATIC = 1 << 0,
+    FZ_SHAPE_IS_COLLIDING = 1 << 1,
+};
+
+typedef struct {
+    FZ_vector_2* points;
+    FZ_vector_2* transformed_points;
+    uint16_t point_count;
+    FZ_vector_2 scale;
+    FZ_vector_2 position;
+    FZ_vector_2 velocity;
+    double angle;
+    double angular_veclocity;
+    double mass;
+    double moment_of_intertia;
+    void (*tick_transform_function)(FZ_vector_2 position, double angle);
+    void (*tick_points_function)(FZ_vector_2* points, uint16_t point_count);
+    uint16_t flags; 
+} FZ_shape;
+
+typedef struct {
+    double penetration;
+    FZ_vector_2 contact_point;
+    int reference_line_index;
+    int incident_line_index;
+    FZ_shape* reference_shape;
+    FZ_shape* incident_shape;
+} projected_points_data;
+
+typedef struct {
+    FZ_shape** shapes;
+    uint16_t shape_count;
+    FZ_vector_2 gravity;
+} FZ_scene; 
+
+typedef struct {
+    uint16_t width, height, half_width, half_height;
+    SDL_Window* window;
+    SDL_Renderer* renderer;
+    SDL_Texture* frame_buffer_texture;
+    uint32_t* frame_buffer;
+} FZ_SDL;
+
+typedef struct {
+    uint16_t flags;
+    FZ_SDL sdl;
+    uint8_t is_running;
+} FZ_context;
+
+#endif 

+ 8 - 0
src/headers/fizzix.h

@@ -0,0 +1,8 @@
+#ifndef FIZZIX_H
+#define FIZZIX_H
+
+#include "FZ_functions.h"
+#include "FZ_structs.h"
+#include "FZ_math.h"
+
+#endif