Draw the first line
Correct line girth calculation. (sin <-> -sin)
This commit is contained in:
parent
1f4565c0a5
commit
c83039098c
2 changed files with 34 additions and 7 deletions
5
src/cx.c
5
src/cx.c
|
@ -124,6 +124,7 @@ cx_glinit(GLFWwindow **window) {
|
|||
|
||||
int
|
||||
cx_glrun(GLFWwindow *window) {
|
||||
Model *model;
|
||||
ModelRegistry *mr;
|
||||
Model *neural_network_model;
|
||||
GLuint VertexArrayID;
|
||||
|
@ -140,7 +141,7 @@ cx_glrun(GLFWwindow *window) {
|
|||
for (int i = 0; i < 64; i++) {
|
||||
// Load model to render from file
|
||||
//Model *model = model_load("../3d_assets/triangle.obj");
|
||||
Model *model = model_circle(0, (GLfloat)1/64);
|
||||
model = model_circle(0, (GLfloat)1/64);
|
||||
GLfloat *translation_matrix = matrix_new();
|
||||
GLfloat *aspectRatio_matrix = matrix_new();
|
||||
aspectRatio_matrix[0] = (GLfloat)9/16;
|
||||
|
@ -158,6 +159,8 @@ cx_glrun(GLFWwindow *window) {
|
|||
modelRegistry_register(mr, model);
|
||||
}
|
||||
}
|
||||
model = model_line(-0.5, 0, 0.5, 0, 0.015);
|
||||
modelRegistry_register(mr, model);
|
||||
|
||||
|
||||
// Remainder from cursor experiments, might be useful later
|
||||
|
|
36
src/model.c
36
src/model.c
|
@ -83,10 +83,15 @@ model_applyTransformations(Model *self) {
|
|||
// Temporary storage of transformation results
|
||||
GLfloat *temp_buffer[2] = {NULL};
|
||||
|
||||
|
||||
// BANANA, ROH-TAH-TEH
|
||||
temp_buffer[1] = malloc(self->bufsize * 4 * sizeof(GLfloat));
|
||||
memcpy(temp_buffer[1], self->object, self->bufsize * 4 * sizeof(GLfloat));
|
||||
|
||||
if (!self->transformation_count) {
|
||||
return temp_buffer[1];
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
temp_buffer[i%2] = matrix_transform(temp_buffer[(i+1)%2],
|
||||
|
@ -187,16 +192,17 @@ model_line(float x1, float y1, float x2, float y2, float girth) {
|
|||
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)
|
||||
float normal_x = (cos(M_PI/2) * x_diff
|
||||
-(sin(M_PI/2) * y_diff))
|
||||
/ line_length * girth / 2;
|
||||
|
||||
float normal_y = (-sin(M_PI/4) * x_diff
|
||||
+cos(M_PI/4) * y_diff)
|
||||
|
||||
float normal_y = (sin(M_PI/2) * x_diff
|
||||
+(cos(M_PI/2) * y_diff))
|
||||
/ line_length * girth / 2;
|
||||
|
||||
printf("%f, ", normal_x);
|
||||
printf("%f,\n", normal_y);
|
||||
|
||||
self = model_new(6);
|
||||
|
||||
|
@ -206,21 +212,39 @@ model_line(float x1, float y1, float x2, float y2, float girth) {
|
|||
|
||||
self->object[0] = x1 + normal_x;
|
||||
self->object[1] = y1 + normal_y;
|
||||
self->object[3] = 1;
|
||||
printf("%f, ", self->object[0]);
|
||||
printf("%f,\n", self->object[1]);
|
||||
|
||||
self->object[4] = x1 - normal_x;
|
||||
self->object[5] = y1 - normal_y;
|
||||
self->object[7] = 1;
|
||||
printf("%f, ", self->object[4]);
|
||||
printf("%f,\n", self->object[5]);
|
||||
|
||||
self->object[8] = x2 + normal_x;
|
||||
self->object[9] = y2 + normal_y;
|
||||
self->object[11] = 1;
|
||||
printf("%f, ", self->object[8]);
|
||||
printf("%f,\n", self->object[9]);
|
||||
|
||||
self->object[12] = x1 - normal_x;
|
||||
self->object[13] = y1 - normal_y;
|
||||
self->object[15] = 1;
|
||||
printf("%f, ", self->object[12]);
|
||||
printf("%f,\n", self->object[13]);
|
||||
|
||||
self->object[16] = x2 + normal_x;
|
||||
self->object[17] = y2 + normal_y;
|
||||
self->object[19] = 1;
|
||||
printf("%f, ", self->object[16]);
|
||||
printf("%f,\n", self->object[17]);
|
||||
|
||||
self->object[20] = x2 - normal_x;
|
||||
self->object[21] = y2 - normal_y;
|
||||
self->object[23] = 1;
|
||||
printf("%f, ", self->object[20]);
|
||||
printf("%f,\n", self->object[21]);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue