Is there a quicker way to convert the following data into a c style pointer array?
GLfloat verticalLines [] = {
0.59, 0.66, 0.0,
0.59, -0.14, 0.0
}
My current approach is to manually iterate over the data using the method below:
-(GLfloat *)updateLineVertices{
int totalVertices = 6;
GLfloat *lineVertices = (GLfloat *)malloc(sizeof(GLfloat) * (totalVertices));
for (int i = 0; i<totalVertices; i++) {
lineVertices[i] = verticalLines[i];
}
return lineVertices;
}
Some additional info.
Ultimately I will need the data in a format which can be easily manipulated, for example:
-(void)scaleLineAnimation{
GLfloat *lineVertices = [self updateLineVertices];
for (int i = 0; i<totalVertices; i+=3) {
lineVertices[i+1] += 0.5; //scale y axis
}
}
It depends on if verticalLines is going to stick around or not. If it’s defined like it is above and it’s not going to change, you can forgo the whole malloc and just point lineVertices to it.
if verticalLines is going to change, you probably want your own copy, so you’ve got no choice but to copy the actual data from one part of memory to another as you are doing, that being said, this might be a bit more elegant
or the preferred method is probably to use memcopy(), here is some working code