Obj C object level arrays question
Is there a way to declare an array in the header, so it's an object data member and local to the whole object, and yet not populate it till some initialize method in the .m body?
I know that you could do it like this:
.h
GLfloat squareVertices[3];
.m
squareVertices[0] = 1.0f;
squareVertices[1] = 1.0f;
squareVertices[2] = 1.0f;
but is there any way you know of to do it SOMETHING LIKE this: (because obviously this doesn't work... what would?)
.h
GLfloat squareVertices[3];
.m
squareVertices = {1.0f , 1.0f, 1.0f};
I know that you could do it like this:
.h
GLfloat squareVertices[3];
.m
squareVertices[0] = 1.0f;
squareVertices[1] = 1.0f;
squareVertices[2] = 1.0f;
but is there any way you know of to do it SOMETHING LIKE this: (because obviously this doesn't work... what would?)
.h
GLfloat squareVertices[3];
.m
squareVertices = {1.0f , 1.0f, 1.0f};
About the best you'll be able to do is to write a convenience function.
Code:
#include <stdarg.h>
void populateGLfloatArray(GLfloat * array, unsigned int count, ...) {
va_list args;
unsigned int argIndex;
va_start(args, count);
for (argIndex = 0; argIndex < count; argIndex++) {
array[argIndex] = va_arg(args, GLfloat);
}
va_end(args);
}
...
populateGLfloatArray(squareVertices, 3, 1.0f, 1.0f, 1.0f);
Why not just define it in a single file and put an extern declaration in your header?
thing.h:
extern GLfloat thing[3];
thing.m:
GLfloat thing[3] = {1.0f, 2.0f, 3.0f};
If you can't do that because you are using not static values to initialize it, fill it in the class's + initialize method.
thing.h:
extern GLfloat thing[3];
thing.m:
GLfloat thing[3] = {1.0f, 2.0f, 3.0f};
If you can't do that because you are using not static values to initialize it, fill it in the class's + initialize method.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Thank you both for replying and your ideas.
Skorche - I really like your idea, but it's something I've never done before - using external files etc..
Could you please make it a little clearer or point me to an example that you know of?
Thank you both very much.
Skorche - I really like your idea, but it's something I've never done before - using external files etc..
Could you please make it a little clearer or point me to an example that you know of?
Thank you both very much.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| question regarding releasing an object | Gillissie | 1 | 1,551 |
Mar 16, 2009 02:10 AM Last Post: maximile |
|
| Quick question on using arrays with CGFloats | duncster | 5 | 3,850 |
Dec 30, 2008 09:59 AM Last Post: AnotherJake |
|

