From 1f4565c0a5075880bc926ad2f0c8a4250a72e8de Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Sun, 13 Oct 2024 22:43:43 +0200 Subject: [PATCH] Implement line meshes --- include/model.h | 1 + src/cx.c | 9 +++++---- src/model.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/include/model.h b/include/model.h index cf1fae3..7ca91ac 100644 --- a/include/model.h +++ b/include/model.h @@ -28,6 +28,7 @@ void model_colorBlue(Model *); void model_colorWhite(Model *); void model_colorBlack(Model *); Model *model_circle(int, GLfloat); +Model *model_line(GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); #endif diff --git a/src/cx.c b/src/cx.c index d3fc044..9ac5fe0 100644 --- a/src/cx.c +++ b/src/cx.c @@ -124,16 +124,17 @@ cx_glinit(GLFWwindow **window) { int cx_glrun(GLFWwindow *window) { + ModelRegistry *mr; + Model *neural_network_model; GLuint VertexArrayID; GLuint programID; if (cx_loadShaders(&VertexArrayID, &programID)) { return -1; } - // Establish a model registry - ModelRegistry *mr; - mr = modelRegistry_new(); + // Establish a model registry + mr = modelRegistry_new(); // Fill the model registry with mesh models for (int j = 0; j < 8; j++) { for (int i = 0; i < 64; i++) { @@ -147,7 +148,7 @@ cx_glrun(GLFWwindow *window) { translation_matrix[3] = (((GLfloat)-1*16/9)*.90) + ((GLfloat)1/32 * i * (((GLfloat)16/9))*.90); - translation_matrix[7] = .90 + ((GLfloat)1/8 * j *.90); + translation_matrix[7] = .90 - ((GLfloat)1/4 * j *.90); model->transformations[0] = translation_matrix; model->transformations[1] = aspectRatio_matrix; diff --git a/src/model.c b/src/model.c index 9acb9fd..78af7e2 100644 --- a/src/model.c +++ b/src/model.c @@ -179,11 +179,49 @@ model_circle(int detail, GLfloat scale) { } Model * -model_line(Model *self, int detail) { +model_line(float x1, float y1, float x2, float y2, float girth) { + Model *self; + float x_diff, y_diff, line_length; + + x_diff = x2 - x1; + y_diff = y2 - y1; + line_length = sqrt((x_diff*x_diff) + (y_diff*y_diff)); + + printf("%f, ", girth); + printf("%f,\n", -girth); + float normal_x = (cos(M_PI/4) * x_diff + +sin(M_PI/4) * y_diff) + / line_length * girth / 2; + + float normal_y = (-sin(M_PI/4) * x_diff + +cos(M_PI/4) * y_diff) + / line_length * girth / 2; + + + self = model_new(6); + if (self == NULL) { - self = model_new(6); + return NULL; } - return 0; + + self->object[0] = x1 + normal_x; + self->object[1] = y1 + normal_y; + + self->object[4] = x1 - normal_x; + self->object[5] = y1 - normal_y; + + self->object[8] = x2 + normal_x; + self->object[9] = y2 + normal_y; + + self->object[12] = x1 - normal_x; + self->object[13] = y1 - normal_y; + + self->object[16] = x2 + normal_x; + self->object[17] = y2 + normal_y; + + self->object[20] = x2 - normal_x; + self->object[21] = y2 - normal_y; + return self; } Model *