show bodies and joints

Official forum for the Chipmunk2D Physics Library.
Post Reply
nitrorazor
Posts: 13
Joined: Sat Sep 26, 2009 9:41 am
Contact:

show bodies and joints

Post by nitrorazor »

Hello,
i am developing on the iPhone with chipmunk physics, and now i have a question: in the chipmunk examples there are always objects showen in different colors. but how can i unhide the joints, bodies and circles... i dont see them? when i draw a cpBody i can only show it on the screen by attach a image on it. in the chipmunk wiki there is no description how to do this.

regards
nitrorazor
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: show bodies and joints

Post by slembcke »

In the Chipmunk demo code, I wrote some low level code that pulls data out of the Chipmunk shapes and joints in order to draw them. The file you are looking for is drawspace.c. I usually drop it into projects that I'm working on and hack on it a bit as a debugging tool to draw shapes and joints over the top of my game scene. It's an easy way to make sure that sprites are lining up properly.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
nitrorazor
Posts: 13
Joined: Sat Sep 26, 2009 9:41 am
Contact:

Re: show bodies and joints

Post by nitrorazor »

Thanks, you are great!

edit: hm, currently this doesn't work with opengles and the iPhone(only for opengl) :cry:
zaerl
Posts: 40
Joined: Fri Aug 28, 2009 8:36 am
Contact:

Re: show bodies and joints

Post by zaerl »

Porting the OpenGL code used in trunk demos to OpenGL ES is trivial. Start with the OpenGL ES template and then replace the few functions that are different in OpenGL ES (for example glOrthof VS glOrtho or glBegin and glEnd that aren't implemented on the embedded counterpart). In my current project I have my iPhone game and a simulator built as a Cocoa program that is used by my artists. I use the same code for simulator and the real game. I use the template EAGLView class provided by Apple with some #define here and there. One quick example:

Code: Select all

#if TARGET_OS_IPHONE
@interface EAGLView : UIView
#else
@interface EAGLView : NSOpenGLView
#endif
{    
@private
#if TARGET_OS_IPHONE
    GLint backingWidth;
    GLint backingHeight;
    EAGLContext *context;
    GLuint viewRenderbuffer, viewFramebuffer;
    GLuint depthRenderbuffer;
#endif
	
    // Other stuffs
}

- (void)drawView;

@end

- (void)drawView
{
#if TARGET_OS_IPHONE
    [EAGLContext setCurrentContext:context];
    
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);
#endif
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

#if TARGET_OS_IPHONE
	glOrthof(...);
#else
	glOrtho(...);
#endif

    // drawing stuff

#if TARGET_OS_IPHONE
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
#else
    [[self openGLContext] flushBuffer];
#endif
}
Check the official khronos site for a quick reference about OpenGL VS OpenGL ES.

Regards.
nitrorazor
Posts: 13
Joined: Sat Sep 26, 2009 9:41 am
Contact:

Re: show bodies and joints

Post by nitrorazor »

thanks, but now i use cocos2D to draw the things, this is a little bit easier :D
zaerl
Posts: 40
Joined: Fri Aug 28, 2009 8:36 am
Contact:

Re: show bodies and joints

Post by zaerl »

Good for you nitro. Remember that cocos-2d doesn't use the trunk code of chipmunk.

Regards.
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests