I've hacked together some ruby code that draws primitives to represent collision shapes in Chipmunk, but I can't get how to get coordinates and angles between gosu and chipmunk to match up. Basically, every single object is rotated 90 degrees, but correctly placed in the coordinate system. The only way I've found to make that happen is by rotating all shapes -90 degrees before they are drawn, but that seems like a cheap hack. The chipmunk/gosu tutorial does nothing like that but seems to work anyway. Because it uses draw_rot and images instead of window.rotate and primitives? I have also tried with triangles and other polygons, not only the quad class below. Same problem...
Below is relevant parts of the code. $game is a global instance of a sub-class of Window.
class Quad < Shape
def initialize(body, x, y, width, height)
@points = [CP::Vec2.new(-width/2, -height/2), CP::Vec2.new(-width/2, height/2), CP::Vec2.new(width/2, height/2), CP::Vec2.new(width/2, -height/2)]
# ...
@collision_shape = CP::Shape::Poly.new(body, @points, CP::Vec2.new(x,y))
end
def draw()
color = Gosu::Color.argb(0xffffffff)
$game.translate(draw_x, draw_y) { #draw_x and draw_y add global vectors of body with locals of the shape
$game.draw_quad(@points[0].x, @points[0].y, color, @points[1].x, @points[1].y, color, @points[2].x, @points[2].y, color, @points[3].x, @points[3].y, color)
}
end
end
class GameObject
# ...
def draw
# Note the -90! This seems to make things work...?
$game.rotate(@body.a.radians_to_gosu-90, @body.p.x, @body.p.y) {
@shapes.each { |shape|
shape.draw
}
}
end
end
Loading...