diff --git a/include/neural.h b/include/neural.h index ab406ed..1d53b72 100644 --- a/include/neural.h +++ b/include/neural.h @@ -21,6 +21,7 @@ typedef struct _neural_network { Neural_Network *neural_new(size_t, size_t, size_t); void neural_randomize(Neural_Network *); float *neural_process(Neural_Network *, float *); +int neural_getMesh(ModelRegistry *, Neural_Network *); #endif diff --git a/src/cx.c b/src/cx.c index ca1af3b..fc3ac48 100644 --- a/src/cx.c +++ b/src/cx.c @@ -135,59 +135,18 @@ cx_nnrun(Neural_Network *nn) { int cx_run(GLFWwindow *window, Neural_Network *nn) { - Model *model; ModelRegistry *mr; - Model *neural_network_model; GLuint VertexArrayID; GLuint programID; + if (cx_loadShaders(&VertexArrayID, &programID)) { return -1; } - // Establish a model registry mr = modelRegistry_new(); // Fill the model registry with mesh models - for (int j = 0; j < nn->layer_count; j++) { - Neural_Layer *nl = nn->layers[j]; - for (int i = 0; i < nl->layer_size; i++) { - // Load model to render from file - //Model *model = model_load("../3d_assets/triangle.obj"); - for (int k = 0; k < nl->layer_size_next; k++) { - model = model_line((-.90) - + ((GLfloat)2 * i * .90/(nl->layer_size-1)), - - .90 - ((GLfloat)2 * j *.90/(nn->layer_count)), - - (-.90) - + ((GLfloat)2 * k * .90/(nl->layer_size_next-1)), - - .90 - ((GLfloat)2 * (j+1) *.90/(nn->layer_count)), - - .001 // girth - ); - modelRegistry_register(mr, model); - } - - model = model_circle(0, (GLfloat)1/64); - GLfloat *translation_matrix = matrix_new(); - GLfloat *aspectRatio_matrix = matrix_new(); - aspectRatio_matrix[0] = (GLfloat)9/16; - - translation_matrix[3] = (((GLfloat)-1*16/9)*.90) - + ((GLfloat)1/(nl->layer_size-1)*2 * i * (((GLfloat)16/9))*.90); - - translation_matrix[7] = .90 - ((GLfloat)1/(nn->layer_count)*2 * j *.90); - - model->transformations[0] = translation_matrix; - model->transformations[1] = aspectRatio_matrix; - model->transformation_count = 2; - model_colorWhite(model); - - modelRegistry_register(mr, model); - - } - } + neural_getMesh(mr, nn); // Remainder from cursor experiments, might be useful later double xpos, ypos; diff --git a/src/neural.c b/src/neural.c index 0bde71e..012f29a 100644 --- a/src/neural.c +++ b/src/neural.c @@ -31,7 +31,6 @@ neural_new(size_t input_size, size_t output_size, size_t layer_count) { // The difference between layer sizes, hidden layers step between the two // sizes in linear fashion. ssize_t layer_diff; - ssize_t layer_step; self->layer_count = layer_count; self->layers = malloc(layer_count * sizeof(Neural_Layer *)); @@ -71,6 +70,8 @@ neural_process(Neural_Network *self, float *input) { float *retval = NULL; Neural_Layer *nl = self->layers[0]; + retval = malloc(self->layers[self->layer_count-1]->layer_size * sizeof(float)); + for (int i = 0; i < self->layers[0]->layer_size; i++) { nl->neurons[i].value = input[i]; } @@ -92,3 +93,46 @@ neural_process(Neural_Network *self, float *input) { return retval; } +int +neural_getMesh(ModelRegistry *mr, Neural_Network *nn) { + Model *model; + for (int j = 0; j < nn->layer_count; j++) { + Neural_Layer *nl = nn->layers[j]; + for (int i = 0; i < nl->layer_size; i++) { + for (int k = 0; k < nl->layer_size_next; k++) { + model = model_line((-.90) + + ((GLfloat)2 * i * .90/(nl->layer_size-1)), + + .90 - ((GLfloat)2 * j *.90/(nn->layer_count)), + + (-.90) + + ((GLfloat)2 * k * .90/(nl->layer_size_next-1)), + + .90 - ((GLfloat)2 * (j+1) *.90/(nn->layer_count)), + + .001 // girth + ); + modelRegistry_register(mr, model); + } + + model = model_circle(0, (GLfloat)1/64); + GLfloat *translation_matrix = matrix_new(); + GLfloat *aspectRatio_matrix = matrix_new(); + aspectRatio_matrix[0] = (GLfloat)9/16; + + translation_matrix[3] = (((GLfloat)-1*16/9)*.90) + + ((GLfloat)1/(nl->layer_size-1)*2 * i * (((GLfloat)16/9))*.90); + + translation_matrix[7] = .90 - ((GLfloat)1/(nn->layer_count)*2 * j *.90); + + model->transformations[0] = translation_matrix; + model->transformations[1] = aspectRatio_matrix; + model->transformation_count = 2; + model_colorWhite(model); + + modelRegistry_register(mr, model); + + } + } + return 0; +}