I have an OpenGL ES based app which parses in information from an xml file using NSXMLParser. As the vertice information comes in for each scene object in the file, I am saving it in an NSMutableArray as follows :
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (floatArray) {
if (currentlyParsing == kVerticeInformation) {
if (currentParserTagType == kGeometry) {
//NSLog(@"Loaded Vertices %@", string);
NSArray * nums = [string componentsSeparatedByString:@" "];
culmunativeCount += [nums count];
//NSLog(@"Culm Count is %d", culmunativeCount);
[fullParseString appendString : string];
if (checkSumCount <= culmunativeCount) {
//NSLog(@"Full Parse String is %@", fullParseString);
NSArray * finishedArray = [fullParseString componentsSeparatedByString:@" "];
//NSLog(@"Finihsed ARray is %d", [finishedArray count]);
[finishedParsingArray addObjectsFromArray:finishedArray];
//NSLog(@" FINISHED PARSING = %d", [finishedParsingArray count]);
NSUInteger baseIndex;
for (baseIndex=0; baseIndex <[finishedParsingArray count]; baseIndex +=3) {
NSString * xPoint = [finishedParsingArray objectAtIndex:baseIndex];
NSDecimalNumber * errorCheckX = [NSDecimalNumber decimalNumberWithString:xPoint];
float x = [errorCheckX floatValue];
NSString * yPoint = [finishedParsingArray objectAtIndex:baseIndex +1];
NSDecimalNumber * errorCheckY = [NSDecimalNumber decimalNumberWithString:yPoint];
float y = [errorCheckY floatValue];
NSString * zPoint = [finishedParsingArray objectAtIndex:baseIndex+2];
NSDecimalNumber * errorCheckZ = [NSDecimalNumber decimalNumberWithString:zPoint];
float z = [errorCheckZ floatValue];
vertex3D = [[Vertex3D alloc]init];
vertex3D.value1 = x;
vertex3D.value2 = y;
vertex3D.value3 = z;
[verticesArray addObject:vertex3D];
//NSLog(@"Vertices stored are %f, %f, %f", x,y,z);
}
currentlyParsing = kNilSetting;
checkSumCount = 0;
[finishedParsingArray removeAllObjects];
//Set object to adds vertice array to verticesArray;
vertex3D = nil;
objectToAdd.Vertices = verticesArray;
[verticesArray removeAllObjects];
//[finishedArray release];
culmunativeCount = 0;
[fullParseString setString:@""];
}
}
}
}
Vertex3D is a custom class to store the x,y,z points :
#import <Foundation/Foundation.h>
@interface Vertex3D : NSObject
{
float value1;
float value2;
float value3;
}
@property (assign) float value1;
@property (assign) float value2;
@property (assign) float value3;
@end
What I am then doing is passing this array to a SceneObject class which is instantiated for every object in the file. The idea is then to use these SceneObject objects to feed the OpenGL ES engine. I am using glDrawElements as the xml file uses indices.
The problem is that I cannot pass an NSMutable array into the OpenGL ES calls (such as glVertexPointer).
From an example I have been following at http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone, it looks like I need to structure the vertices data as follows in order to use indices :
const Vertex3D tigerBottomPositions[] = {
{0.176567, 0.143711, 0.264963},
{0.176567, 0.137939, 0.177312},
{0.198811, 0.135518, 0.179324},
…
};
This is where I get a bit confused - I think this is an array of C structs which contains 3 Vertex3D objects, each of which contains three floats.
Can anybody advise me on how I can convert my NSMutableArray into a C struct in the correct format for use with OpenGL ES ? I'd also appreciate help on how to setup this C struct in code as my C knowledge is not as strong as my obj c.
Thank you in advance !