Fixed limit of drawable objects (oops), load functions now access the same object count
This commit is contained in:
parent
40af75ad94
commit
42f8714eb6
30
src/main.c
30
src/main.c
|
@ -59,18 +59,12 @@ vec3 cameraPosition = {0.0f, 3.0f, 5.5f};
|
||||||
vec3 objectPosition = {0.0f, 0.0f, 0.0f};
|
vec3 objectPosition = {0.0f, 0.0f, 0.0f};
|
||||||
GLfloat radius = 1.0f;
|
GLfloat radius = 1.0f;
|
||||||
|
|
||||||
int numModels = 4;
|
int numModels = 0;
|
||||||
char* models[] = {
|
char* models[] = {
|
||||||
//"../obj/Yblock.obj",
|
"../obj/Xblock.obj",
|
||||||
//"../obj/Zblock.obj",
|
"../obj/Yblock.obj",
|
||||||
//"../obj/Yblock_rotated.obj",
|
"../obj/Yblock_rotated.obj",
|
||||||
"../obj/chair_test.obj",
|
"../obj/Zblock.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"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// input handler for camera movement
|
// input handler for camera movement
|
||||||
|
@ -87,10 +81,10 @@ void handleInputs(double deltaTime) {
|
||||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
|
||||||
cameraPosition.x -= deltaTime * 10;
|
cameraPosition.x -= deltaTime * 10;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) {
|
||||||
cameraPosition.y += deltaTime * 10;
|
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;
|
cameraPosition.y -= deltaTime * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,10 +100,10 @@ void handleInputs(double deltaTime) {
|
||||||
if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_K) == GLFW_PRESS) {
|
||||||
objectPosition.z -= deltaTime * 10;
|
objectPosition.z -= deltaTime * 10;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_R) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) {
|
||||||
radius += deltaTime * 10;
|
radius += deltaTime * 10;
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_F) == GLFW_PRESS) {
|
if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) {
|
||||||
radius -= deltaTime * 10;
|
radius -= deltaTime * 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,9 +217,9 @@ void init(void) {
|
||||||
|
|
||||||
//objectData = readObjFiles(&models, numModels);
|
//objectData = readObjFiles(&models, numModels);
|
||||||
char* c = "../obj/Yblock.obj";
|
char* c = "../obj/Yblock.obj";
|
||||||
int count = 0;
|
objectData = readSingleObjFile(&c, 10, &numModels);
|
||||||
objectData = readSingleObjFile(&c, 20, &count);
|
printf("\nAmount %d\n", numModels);
|
||||||
printf("%d", count);
|
fflush(stdout);
|
||||||
/*
|
/*
|
||||||
objectData = malloc(numModels * sizeof(ObjectData));
|
objectData = malloc(numModels * sizeof(ObjectData));
|
||||||
for (int i = 0; i < numModels; i++) {
|
for (int i = 0; i < numModels; i++) {
|
||||||
|
|
|
@ -78,9 +78,9 @@ void load_object(ObjectData* objectData) {
|
||||||
* Takes a string-pointer and a number of files to read.
|
* Takes a string-pointer and a number of files to read.
|
||||||
* Returns an array of objects.
|
* 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);
|
ObjectData* objects = (ObjectData*) malloc(sizeof(ObjectData) * numModels);
|
||||||
|
*count += numModels;
|
||||||
if (!objects) {
|
if (!objects) {
|
||||||
printf("ERROR in objectHandler: Failed to allocate memory for objects\n");
|
printf("ERROR in objectHandler: Failed to allocate memory for objects\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -100,9 +100,11 @@ ObjectData* readObjFiles(char** path, int numModels) {
|
||||||
*/
|
*/
|
||||||
ObjectData* readSingleObjFile(char** path, int numModels, int* count) {
|
ObjectData* readSingleObjFile(char** path, int numModels, int* count) {
|
||||||
ObjectData* objects = (ObjectData*) malloc(sizeof(ObjectData) * numModels);
|
ObjectData* objects = (ObjectData*) malloc(sizeof(ObjectData) * numModels);
|
||||||
|
*count += numModels;
|
||||||
|
|
||||||
if (!objects) {
|
if (!objects) {
|
||||||
printf("ERROR in objectHandler: Failed to allocate memory for objects\n");
|
printf("ERROR in objectHandler: Failed to allocate memory for objects\n");
|
||||||
|
fflush(stdout);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue