Posts Tagged ‘code’

Z-Sorted Sprites in 3d

Monday, October 6th, 2008

Sprite3D Z-Sorting

On a recent job, I had a need for a 3d scene with lots of sprites. I decided to use Papervision3d but couldn't find an easy way of having an interactive sprite in the scene. There are classes for billboard planes, but that seemed like too much calculation. This means you can do anything you would normally do with a sprite, but in 2.5d.

The solution turned out to be pretty simple. Just use the screen.x, y and z variables in the DisplayObject3D class to align some sprites to their projected 3d locations, and then z-sort the whole lot of them.

  • Works with Papervision3D 2.0 (GreatWhite)
  • The z-sorting for each SpriteGroup3D completely circumvents papervision's internal sorting so this won't work in conjunction with other types of scene objects (like polygons)

Hopefully someone will find them useful =) View the rest of this post for the code.


Projection Transform

Monday, May 26th, 2008

A few weeks ago Robert Hodgin of flight404 posed a question to the OooShiny group. You've probably already seen the LASER Tag project by Graffiti Research Lab.

So if you want to do something similar in Processing, the first thing you need to do is transform the point on your surface (building, wall, etc) to a point on your texture. After a lot of valiant help from Keith, the math was still confusing me. Then I stumbled on the PerspectiveTransform class. Given 4 points unTransformQuad() will map any value inside to a point on a unit (0 to 1) square. Anyway, I hope this helps someone =)