1
votes

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

1
I'm new to cocos2d/3d and getting position would really help me understand how it works since I'm converting a collada file from blender into a pod. I'm trying to see what cocos3d is doing with the coordinates. I would really appreciate it if someone could help me out, even if it's an entirely different approach to getting position.davis
are x,y,z strings in the location object ? maybe your %@'s in the NSLog statement should be instead some kind of numeric %f or %d depending on whether they are float or double).YvesLeBorg

1 Answers

3
votes

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".