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
show bodies and joints
-
- Posts: 13
- Joined: Sat Sep 26, 2009 9:41 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: show bodies and joints
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 13
- Joined: Sat Sep 26, 2009 9:41 am
- Contact:
Re: show bodies and joints
Thanks, you are great!
edit: hm, currently this doesn't work with opengles and the iPhone(only for opengl)
edit: hm, currently this doesn't work with opengles and the iPhone(only for opengl)
-
- Posts: 40
- Joined: Fri Aug 28, 2009 8:36 am
- Contact:
Re: show bodies and joints
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:
Check the official khronos site for a quick reference about OpenGL VS OpenGL ES.
Regards.
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
}
Regards.
-
- Posts: 13
- Joined: Sat Sep 26, 2009 9:41 am
- Contact:
Re: show bodies and joints
thanks, but now i use cocos2D to draw the things, this is a little bit easier
-
- Posts: 40
- Joined: Fri Aug 28, 2009 8:36 am
- Contact:
Re: show bodies and joints
Good for you nitro. Remember that cocos-2d doesn't use the trunk code of chipmunk.
Regards.
Regards.
Who is online
Users browsing this forum: No registered users and 15 guests