poly->verts, poly.verts are different? (chipmunk rb extension)

17 views
Skip to first unread message

LucJ

unread,
Oct 24, 2007, 5:16:46 PM10/24/07
to ShatteredRuby
With chipmunk.so, how do I loop through the vertices of a poly shape?

In trying to translate some of the C demos into Ruby, I'm trying to
write my own drawPolyShape function. However, I can't seem to get at
the verts property of a Shape::Poly object!

In C, shape->verts appears to be an array of vectors, which makes
sense.

In Ruby, poly.verts is a method that apparently expects the same
arguments as the Poly.new, which doesn't make sense. I initially
assumed that from the plural name and similarity to the C property
that it would let me get at the vertices. Instead, it says that I need
to give it 3 args: a Body, an array, and a vector.

In the C demos, looping through poly->verts is the method used to draw
the poly shapes.
In Ruby, I don't know how to do this.

Any information is appreciated! As always, keep up the great work!

JeremyW...@gmail.com

unread,
Oct 24, 2007, 9:06:05 PM10/24/07
to ShatteredRuby
Wow, sounds complicated. I don't know anything about chipmunk. Sorry I
can't help, but I'm sure someone here knows. Good luck.

~Jeremy

LucJ

unread,
Oct 24, 2007, 10:12:02 PM10/24/07
to ShatteredRuby
Heh, thanks for giving it a look anyway!

The ShatteredRuby guys are the ones who put together the windows port
of the Chipmunk extension. But a lot of their demo videos use it, so I
figure -- bingo, they made the extension and they're putting it to
good use, so if anyone knows, it's them!

I've got a sort of sandbox file I'm using to try and feel around in
Chipmunk, and since I'm just trying to see what's possible it's
bloating up to around 100 lines, but I've already determined that you
can use it and sdl to make ... things.

What I've got drawing right now are the bounding boxes for objects,
but not their shape, because that data is in an array of xy pairs ...
in Chipmunk. I can't seem to find it with the ruby extension! So all I
can draw at the moment are some pretty weird little animations of lots
of boxes that all collide realistically, but their shape morphs around
and never rotates (as it's just the bounding box).

Heh, I mean, it's all just for fun anyway. But that's what I'm sort of
stuck at right now. I guess I could also draw lines and circles, but
darn it, I want my polyshapes. I want boxes, man. I want dominoes!


On Oct 24, 8:06 pm, "JeremyWoert...@gmail.com"

Mikkel Garcia

unread,
Oct 28, 2007, 4:51:29 PM10/28/07
to shatte...@googlegroups.com
I ran into that same issue - my solution was to store the vertices in a ruby array for my later use. (options[:vertices] below)

      def outline(parent_node, scene_manager, options)
@outline || @outline = create_outline(parent_node, options[:vertices], scene_manager, options[:offset] || v2(0,0))
end

For the circle, I created a polygon with a set amount of vertices with a simple sin/cos combination.
All the code for the shape creation and rendering (in Ogre) can be found at http://svn.shatteredruby.com/plugins/chipmunk/lib/extensions/shape_rendering.rb


To keep the rotations in sync, I use this every frame:
      q = Ogre::Quaternion.new
q.from_angle_axis( Ogre:: Radian.new(body.a), :z.to_v )
view.node.set_orientation(q)
The quaternions are only necessary for 3d.  The radian angle of the polygon is contained in body.a.

-Mikkel
Reply all
Reply to author
Forward
0 new messages