Fixed limit of drawable objects (oops), load functions now access the same object count

This commit is contained in:
JonasJan2 2024-06-07 15:58:46 +02:00
parent 40af75ad94
commit 42f8714eb6
2 changed files with 16 additions and 20 deletions

View File

@ -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++) {

View File

@ -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;
}