// // DebugDrawNode.m // BallTest // // Created by Juraj Hlavac on 4/5/10. // Copyright 2010 Apple. All rights reserved. // #import "DebugDrawNode.h" @implementation DebugDrawNode static void eachBody(cpBody *body, void *unused) { cpBodyEachShape(body, drawEachShape, nil); } static void drawEachShape(cpBody* body, cpShape* shape, void* data) { if (shape) { if (shape->klass_private->type == CP_CIRCLE_SHAPE) { glColor4f(0.5f, 0.5f, 0.5f, 1.0); cpCircleShape* crc = (cpCircleShape*)shape; cpVect c = cpvadd(shape->body->p, cpvrotate(crc->c, shape->body->rot)); ccDrawCircle(c, crc->r, shape->body->a, 10, true); } else if (shape->klass_private->type == CP_POLY_SHAPE) { glColor4f(1.0f, 0.0f, 0.0f, 1.0); cpPolyShape* poly = (cpPolyShape*)shape; ccDrawPoly(poly->tVerts, poly->numVerts, YES); } else if (shape->klass_private->type == CP_SEGMENT_SHAPE) { glColor4f(1.0f, 0.0f, 0.0f, 1.0); cpSegmentShape* segment = (cpSegmentShape*)shape; ccDrawLine(segment->ta, segment->tb); } else { glColor4f(0.0f, 0.0f, 1.0f, 1.0); cpSegmentShape* seg = (cpSegmentShape*)shape; ccDrawLine(seg->ta, seg->tb); } } } +(id) nodeWithSpace:(cpSpace*)space { return [[[DebugDrawNode alloc] initWithSpace:space] autorelease]; } -(id) initWithSpace:(cpSpace*)space { if ((self == [super init])) { _space = space; // weak ref } return self; } -(void) draw { if (visible_ && _space) { cpSpaceEachBody(_space, &eachBody, self); } } @end