Cocos3d + Box2d – Debug Draw & All you need to know

Forums Programming cocos3d Cocos3d + Box2d – Debug Draw & All you need to know

This topic contains 1 reply, has 1 voice, and was last updated by  FazMan 2 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
Author Posts
Author Posts
September 30, 2011 at 7:53 am #235700

FazMan
Participant
@fazman

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 :)

October 4, 2011 at 5:20 am #349609

FazMan
Participant
@fazman

Thought? how could i get the debug draw to draw onto CC3Billboard?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.