From 42f8714eb6fff83456e3f54c273821e5a994c1df Mon Sep 17 00:00:00 2001 From: JonasJan2 Date: Fri, 7 Jun 2024 15:58:46 +0200 Subject: [PATCH] Fixed limit of drawable objects (oops), load functions now access the same object count --- src/main.c | 30 ++++++++++++------------------ src/objectHandler.c | 6 ++++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/main.c b/src/main.c index bea53f8..33a231b 100644 --- a/src/main.c +++ b/src/main.c @@ -59,18 +59,12 @@ vec3 cameraPosition = {0.0f, 3.0f, 5.5f}; vec3 objectPosition = {0.0f, 0.0f, 0.0f}; GLfloat radius = 1.0f; -int numModels = 4; +int numModels = 0; char* models[] = { - //"../obj/Yblock.obj", - //"../obj/Zblock.obj", - //"../obj/Yblock_rotated.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj", - "../obj/chair_test.obj" + "../obj/Xblock.obj", + "../obj/Yblock.obj", + "../obj/Yblock_rotated.obj", + "../obj/Zblock.obj", }; // input handler for camera movement @@ -87,10 +81,10 @@ void handleInputs(double deltaTime) { if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { cameraPosition.x -= deltaTime * 10; } - if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { + if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) { cameraPosition.y += deltaTime * 10; } - if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) { + if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { cameraPosition.y -= deltaTime * 10; } @@ -106,10 +100,10 @@ void handleInputs(double deltaTime) { if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) { objectPosition.z -= deltaTime * 10; } - if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) { + if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) { radius += deltaTime * 10; } - if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) { + if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) { radius -= deltaTime * 10; } } @@ -223,9 +217,9 @@ void init(void) { //objectData = readObjFiles(&models, numModels); char* c = "../obj/Yblock.obj"; - int count = 0; - objectData = readSingleObjFile(&c, 20, &count); - printf("%d", count); + objectData = readSingleObjFile(&c, 10, &numModels); + printf("\nAmount %d\n", numModels); + fflush(stdout); /* objectData = malloc(numModels * sizeof(ObjectData)); for (int i = 0; i < numModels; i++) { diff --git a/src/objectHandler.c b/src/objectHandler.c index 7d526ff..89c1b04 100644 --- a/src/objectHandler.c +++ b/src/objectHandler.c @@ -78,9 +78,9 @@ void load_object(ObjectData* objectData) { * Takes a string-pointer and a number of files to read. * Returns an array of objects. */ -ObjectData* readObjFiles(char** path, int numModels) { +ObjectData* readObjFiles(char** path, int numModels, int* count) { ObjectData* objects = (ObjectData*) malloc(sizeof(ObjectData) * numModels); - + *count += numModels; if (!objects) { printf("ERROR in objectHandler: Failed to allocate memory for objects\n"); return NULL; @@ -100,9 +100,11 @@ ObjectData* readObjFiles(char** path, int numModels) { */ ObjectData* readSingleObjFile(char** path, int numModels, int* count) { ObjectData* objects = (ObjectData*) malloc(sizeof(ObjectData) * numModels); + *count += numModels; if (!objects) { printf("ERROR in objectHandler: Failed to allocate memory for objects\n"); + fflush(stdout); return NULL; }