pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
Vizier-Xrects

Vizier-Xrects

Chandler Armstrong (omnirizon)

Tags:

Description

Much thanks to pymike and saluk for the Retro Game Library. The 'seperating axis theorem' function was sourced from this library (with some minor modifications)

vizier: a package for managing sprites and the screen, provides scrolling, scaling, and collision response.

xrects: a package for polygons. uses the pygame rect as the axis aligned bounding box (AABB), and subclasses the rect to add the polygon object and methods for collision detection.

Add the files in the zip to your python path. The files include the 'glyph' module which is used in the demo. glyph is a module for handling text. View the demo by running 'vizier_unittest.py'. Once the demo is running, press and hold space bar to let the sprites be updated. Release the space bar to pause everything and get a chance to look around. Clicking on sprites will display some information about them (it was stuff I was using to debug a physics system). The sprite update does use some physics. Feel free to replace the sprite object with one of your own.

Links

Home Page: https://sourceforge.net/projects/pyvizier/

Screenshot


click to view original size

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

December 15, 2010 10:45pm - Gummbum - nickname: (gummbum)
Aha. I see your http://www.pygame.org/project-pylogon-1718-2984.html.

Thanks!
December 12, 2010 1:21pm - Gummbum - nickname: (gummbum)
You're alive! :)

I sent a message to your sourceforge mailbox a few months back; I guessed it got et or you don't check it often. I've been working on my own world/map/camera implementation using pymunk for the physics--just for it's polygon and line collision detection. It hasn't been going as well as I liked, and I'm looking forward to seeing your progress.

I agree with your take on the polygon origins. I just wanted to point out for the benefit of others that it was different from pygame's rects in that respect.

Also, I saw your query another project about game clocks. I recently did some study which resulted in a cookbook recipe. Almost as easy as pygame's Clock, quite accurate, and adds independent render frames and interpolation. See http://www.pygame.org/wiki/ConstantGameSpeed.

Gumm
December 12, 2010 12:53am - Chandler Armstrong - nickname: (omnirizon)
Gummbum,

thanks for your comments. I was not aware of those gotchas! I'll check them out and see if the class can be modified to behave more like a rect.

I think I designated the center, rather than the topleft of the bounding rect, as the origin because it is easier to imagine what points you would need to obtain a desired polygon that way.

I definitely need to add more documentation. that's a goal for this winter break.
September 25, 2010 1:58pm - Gummbum - nickname: (gummbum) - 4/5
This is great, Chandler. It is exactly what I've been scouring the Internet for. =)

I just wish for better documentation! The inline comments are not enough to enable me to wring more than the basics out of the math voodoo in xrects. Some features I think I may never be able to figure out, like 1) the purpose of the projections returned by xrect.CollisionDetector.sat, and how to use them; and 2) how to rotate a polygon and test the rotated shape for collision.

I discovered some things that new users of this need to be aware of.

Because xrect.Polygon subclasses pygame.Rect, I was tempted to use it in place of Rect. Unfortunately Pygame sometimes checks "==" or "is" Rect, rather than "isinstance", and blows up on xrect.Polygon. This means I need to maintain a Rect to feed Pygame and a Polygon to feed vizier-xrects. Not a major problem, as the model and view often use different structs anyway.

The other gotcha not documented is that the points argument of the Polygon constructor need to be designed with a 0,0 center or they don't turn out right. By contrast, Pygame shapes typically have 0,0 as the topleft coordinate.

With psyco this performs exceptionally well. Better documentation and a few demos that build up from xrect and vizier basics to the too-advanced-for-me vizier_unittest.py would have motivated a 5-star rating.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Dec 16, 2014


Dec 14, 2014

Dec 9, 2014

Dec 6, 2014

Dec 5, 2014

Dec 3, 2014

Nov 27, 2014


Nov 13, 2014

Nov 11, 2014


... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)