I am currently working on a full Cocos3d Box2d Game. I have had a hard time Finding resources on how to integrate them, so here it is. As I figure things out I will post them so all who needs can enjoy. I apologies in advance that my style and skill level is fair from perfect but hopefully this will help the newbie programer like myself :).
Getting Box2d Debug Draw to work on Cocos3d. There is another great sample app in this forum that show how to integrate the two, this will help you see the debug draw.
My Temp Solutions:
Created a b2World in the delegate or in a singleton
AppDelegate.h
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow* window;
CCNodeController* viewController;
b2World* world;
}
@property (nonatomic, retain) UIWindow* window;
@property (nonatomic) b2World* world;
AppDelegate.mm
@synthesize window, world;
In your CC3Layer add
CC3Layer.mm
-(void) draw
{
[super draw];
AppDelegate* mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
mainDelegate.world->DrawDebugData();
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
and in your CC3World.mm add this after you setup your b2world
// Debug Draw functions
m_debugDraw = new GLESDebugDraw( PTM_RATIO);
_world->SetDebugDraw(m_debugDraw);
uint32 flags = 0;
flags += b2DebugDraw::e_shapeBit;
// flags += b2DebugDraw::e_jointBit;
// flags += b2DebugDraw::e_aabbBit;
// flags += b2DebugDraw::e_pairBit;
// flags += b2DebugDraw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
AppDelegate* mainDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
mainDelegate.world = _world;
If someone has a better way I am all ears :)