Question

I'm trying to get the position of my camera in cocos3d, but am having trouble. Here's what my initializeWorld looks like

[self addContentFromPODFile: @"leggo.pod"];

CC3Camera* cam2 = (CC3Camera*) [self getNodeNamed:@"Camera"];
[self addChild:cam2];

//the location and rotation is just for testing
//cam2.location = cc3v(0,57.101,71.694);
//cam2.rotation = cc3v(-38,0,0);

CC3Vector camLoc = cam2.location;
NSLog(@"cam2 position is x=%@ y=%@ z=%@", camLoc.x, camLoc.y, camLoc.z );

Can anyone tell me why the value of camLoc.x, camLoc.y, and camLoc.z are always null? I tried getting the location after a delay, but they are still null. I'm out of ideas. It seemed like I was getting close with this similar issue, but I still can't figure it out. Thanks

Was it helpful?

Solution

They're null because you use the wrong format string. %@ is only for id types but the coordinates are simple float values. Instead use this:

NSLog(@"cam2 position is x=%f y=%f z=%f", camLoc.x, camLoc.y, camLoc.z);

PS: learn to use the debugger. If you had set a simple breakpoint and had a look at the local variables you would have seen right away that the values aren't really "null".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top