Implement line meshes

This commit is contained in:
Marcel Plch 2024-10-13 22:43:43 +02:00
parent 109c94a865
commit 1f4565c0a5
Signed by: dormouse
GPG key ID: 2CA77596BC4BDFFE
3 changed files with 47 additions and 7 deletions

View file

@ -28,6 +28,7 @@ void model_colorBlue(Model *);
void model_colorWhite(Model *); void model_colorWhite(Model *);
void model_colorBlack(Model *); void model_colorBlack(Model *);
Model *model_circle(int, GLfloat); Model *model_circle(int, GLfloat);
Model *model_line(GLfloat, GLfloat, GLfloat, GLfloat, GLfloat);
#endif #endif

View file

@ -124,16 +124,17 @@ cx_glinit(GLFWwindow **window) {
int int
cx_glrun(GLFWwindow *window) { cx_glrun(GLFWwindow *window) {
ModelRegistry *mr;
Model *neural_network_model;
GLuint VertexArrayID; GLuint VertexArrayID;
GLuint programID; GLuint programID;
if (cx_loadShaders(&VertexArrayID, &programID)) { if (cx_loadShaders(&VertexArrayID, &programID)) {
return -1; 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 // Fill the model registry with mesh models
for (int j = 0; j < 8; j++) { for (int j = 0; j < 8; j++) {
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
@ -147,7 +148,7 @@ cx_glrun(GLFWwindow *window) {
translation_matrix[3] = (((GLfloat)-1*16/9)*.90) translation_matrix[3] = (((GLfloat)-1*16/9)*.90)
+ ((GLfloat)1/32 * i * (((GLfloat)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[0] = translation_matrix;
model->transformations[1] = aspectRatio_matrix; model->transformations[1] = aspectRatio_matrix;

View file

@ -179,11 +179,49 @@ model_circle(int detail, GLfloat scale) {
} }
Model * 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) { 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 * Model *