Here's the goal:
Draw multiple objects in OpenGL from a single template.
I followed a tutorial that ended with me drawing a single cube on screen. I played around with that to change the cube into a more star-like shape. Now I'd like to make several of these stars with me only providing the X, Y, Z coordinates of where each should appear.
Looking back over the code, the way it worked was a C array of structs defined the vertices and the colors and textures attached to the vertices, and a second C array of ints defined which vertices should be attached to each other.
So I'm thinking the way to do this is create a subclass of NSObject, I'll call it ModelGenerator and give it a method starAtX:Y:Z:. This method would return a C array full of vertices. I'd append this to the end of the current vertices array. I was thinking using it would look something like this:
Would this work at all? Would it cause problems (IE, would Vertices end up overflowing and writing itself ontop of other things in memory?) Or would it not work (maybe because Obj-C methods can't return C arrays? I feel like this may be the case but I can't remember.) Maybe I'm going about this all wrong... suggestions, anyone?
Draw multiple objects in OpenGL from a single template.
I followed a tutorial that ended with me drawing a single cube on screen. I played around with that to change the cube into a more star-like shape. Now I'd like to make several of these stars with me only providing the X, Y, Z coordinates of where each should appear.
Looking back over the code, the way it worked was a C array of structs defined the vertices and the colors and textures attached to the vertices, and a second C array of ints defined which vertices should be attached to each other.
So I'm thinking the way to do this is create a subclass of NSObject, I'll call it ModelGenerator and give it a method starAtX:Y:Z:. This method would return a C array full of vertices. I'd append this to the end of the current vertices array. I was thinking using it would look something like this:
Code:
Vertices[sizeof(Vertices)] = [ModelGenerator starAtX:2 Y:2 Z:2];
Would this work at all? Would it cause problems (IE, would Vertices end up overflowing and writing itself ontop of other things in memory?) Or would it not work (maybe because Obj-C methods can't return C arrays? I feel like this may be the case but I can't remember.) Maybe I'm going about this all wrong... suggestions, anyone?