Pro OpenGL ES for iOS

(singke) #1

274 CHAPTER 8: Putting It All Together^


if (self)
{
[self init:@"stars"];
}

return self;
}

-(void)init:(NSString *)filename
{
NSArray *fatData;
NSDictionary *dict;
NSNumber *ra,*dec;
starData *sd;
float mag;
float x,y,z;
int i,j;

m_TotalStars=0;

NSString *thePath = [[NSBundle mainBundle] pathForResource:filename
ofType:@"plist"];

fatData = [[NSArray alloc] initWithContentsOfFile:thePath]; //2

m_TotalStars=[fatData count];

m_Data=(struct starData *)malloc([fatData count]*sizeof(struct starData));

for(i=0;i<m_TotalStars;i++)
{
dict=(NSDictionary *)[fatData objectAtIndex:i];

ra=(NSNumber *)[dict objectForKey:@"ra"]; //3
dec=(NSNumber *)[dict objectForKey:@"dec"];

[[OpenGLUtils getObject]sphereToRectTheta:[ra floatValue]/DEGREES_PER_RADIAN
phi:[dec floatValue]/DEGREES_PER_RADIAN radius:STANDARD_RADIUS
xprime:&x yprime:&y zprime:&z];

//Create nice compressed data array.

sd=(struct starData *)&m_Data[i];

sd->x=x;
sd->y=y;
sd->z=z;
sd->mag=[[dict objectForKey:@"mag"]floatValue];

mag=1.0-sd->mag/4.0; //4
Free download pdf