Chipmunk / Ruby

Official forum for the Chipmunk2D Physics Library.
Post Reply
ippa
Posts: 14
Joined: Mon Aug 25, 2008 4:53 am
Contact:

Chipmunk / Ruby

Post by ippa »

First off, damn, chipmunk is cool, thanks for your work on it! Now, I'm a longtime rubyist playing around with rubygame/gosu over the last year.
Recently I started on a small "moonlander"-game in Gosu/chipmunk to learn more.

I made the the planetsurface a big polygon (painted in / imported from inkscape) but soon bumped into the "cant have pointy polygons" limit.
Now i ponder over how to continue. I guess I could paint the surface as alot of convex polygons..

Skimming through the C-documentation / forum there's talk about "lines", maybe this what I should construct my planet-surface from?

I cant find anything about lines in the rdocs though so either it's not supported in the rubybindings yet (if not, is this planned ..hm, during 2008 or simular :) ?) or the it's just missing from the docs?
http://rubylicio.us/ - tasty links for the ruby connoisseur.
User avatar
tartley
Posts: 37
Joined: Thu Jun 12, 2008 5:01 pm
Location: London, England
Contact:

Re: Chipmunk / Ruby

Post by tartley »

Hey. I can't help you with the Ruby aspects (I use the Python bindings to Chipmunk myself) but:

Yes, both the approaches you describe sound like very viable workarounds to the 'no convex polys' limitation.

You could create line segments to describe any surface you like. You could still render them as a painted (or textured) area. The one 'gotcha' that I've encountered with this technique is that any small, fast-moving object might slip entirely through a line segment between one simulation cycle and the next. It doesn't sound like that should be a problem in a 'lunar lander' game, unless you have some fast-moving entities in the mix (ie. moving their own diameter or more within a single frame.)

Using many convex polygon shapes, all attached to the same static body, would also work. I understand that the collision detection is fastest using line segments and circles, so maybe using polygons like this would slow down your framerate if you included an awful lot of them - but I imagine your biggest performance bottleneck is in the Ruby code, rather than in the Chipmunk simulation code, so I don't imagine this will be a problem at all.
[color=#808080]Tartley - Jonathan Hartley, [url]http://tartley.com[/url]
Using Pymunk (Chipmunk's Python bindings) for a game project:
[url]http://code.google.com/p/sole-scion[/url][/color]
ippa
Posts: 14
Joined: Mon Aug 25, 2008 4:53 am
Contact:

Re: Chipmunk / Ruby

Post by ippa »

Thanks for your reply tartley.. I never understood that segments could be lines :) (the rdocs are very sparse, and in segments case, also missing the last argument that's needed, but found out the "radius"-argument from pymunks docs :] ).


I tried getting my spaceship to collide with a "segment".

Code: Select all

body = CP::Body.new(100, 100)
shape = CP::Shape::Segment.new(body, vec2(0,400), vec2(600,500), 30)
@space.add_static_shape(shape)
This would be the right way of drawing a collidable line right across the screen right? The ship doesn't seem to collide with it even though I move the ship very slow. I got collides with simple polygons working easily...
http://rubylicio.us/ - tasty links for the ruby connoisseur.
User avatar
tartley
Posts: 37
Joined: Thu Jun 12, 2008 5:01 pm
Location: London, England
Contact:

Re: Chipmunk / Ruby

Post by tartley »

Is your ship made of lines, or of polygons? As I understand it, lines don't collide with each other. Only polys with polys and polys with lines. (where circles are a type of poly)
[color=#808080]Tartley - Jonathan Hartley, [url]http://tartley.com[/url]
Using Pymunk (Chipmunk's Python bindings) for a game project:
[url]http://code.google.com/p/sole-scion[/url][/color]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk / Ruby

Post by slembcke »

Yes, that is true, cpSegments don't collide against other cpSegments. Historically this was because I hadn't added the thickness parameter yet and colliding shapes with no volume is a recipe for disaster. Making an object with a single segment shape, or a collection of only segment shapes would both work very poorly. You'd end up with segments trivially passing through each other or just getting tangled in each other as Chipmunk does not support swept collisions, and shapes are collided individually instead of a whole object.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ippa
Posts: 14
Joined: Mon Aug 25, 2008 4:53 am
Contact:

Re: Chipmunk / Ruby

Post by ippa »

my ship is a polygon that collided fine with some static testpolygons, but I get nothing with the above "segment-line" right across the screen.
http://rubylicio.us/ - tasty links for the ruby connoisseur.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Chipmunk / Ruby

Post by slembcke »

Is the polygon winding correct? Try reversing the order of the vertexes.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ippa
Posts: 14
Joined: Mon Aug 25, 2008 4:53 am
Contact:

Re: Chipmunk / Ruby

Post by ippa »

Code: Select all

shape_array = [vec2(-25.0, -25.0), vec2(-25.0, 25.0), vec2(25.0, 1.0), vec2(25.0, -1.0)]
or

Code: Select all

shape_array = [vec2(-25.0, -25.0), vec2(-25.0, 25.0), vec2(25.0, 1.0), vec2(25.0, -1.0)].reverse
for the spaceship doesn't make a difference with regards to colliding the linesegment. i've naturally played with various other parameters (mass, inertia etc etc) without luck. Even line_segment.body.p / body.v etc though I dont know how they matter in this case (since I add it as a static_shape and it's a linesegment). I've also reversed the linesegments vec2s.
http://rubylicio.us/ - tasty links for the ruby connoisseur.
ippa
Posts: 14
Joined: Mon Aug 25, 2008 4:53 am
Contact:

Re: Chipmunk / Ruby

Post by ippa »

Ok, changing

Code: Select all

body = CP::Body.new(100, 100)
to

Code: Select all

body = CP::Body.new(Float::MAX, Float::MAX)
(the body for the linesegment)

made it work.
http://rubylicio.us/ - tasty links for the ruby connoisseur.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests