I'm making a game and I have an array of floats that make a 3D models that I've placed in with opengl. What I want to do is separate the x,y&z coords and make them into a multi-dimensional array. I want to do this so I can adjust the y position in relation to the terrain. The for loop that I have placed in my init function is as follows:
for (int x = 0; x < sizeof(desert_scene_plainVerts); x++) {
if (((x + 3)%3) == 0) {
//x coord
terrainxPos[x/3] = desert_scene_plainVerts[x];
}
else if (((x + 1)%3) == 0) {
//z coord
terrainzPos[(x-2)/3] = desert_scene_plainVerts[x];
}
else{
//y coord
terrainzPos[(x-1)/3] = desert_scene_plainVerts[x];
}
}
I am getting an error on this line:
terrainzPos[(x-1)/3] = desert_scene_plainVerts[x];
The error goes as follows:
Thread 1: EXC_BAD_ACCESS (code=2, address= 0x10 etc.)
Does anybody know what I am doing wrong.
ceil((x-1)/3)or(x-1)/3 >> 0y coordbut you typedterrainzPos.xis anint, and the C dialects won't convert any integers to floats unless one of the operands is a float.