Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

masak (6289)

  (email not shown publicly)

Been programming Perl since 2001. Found Perl 6 somewhere around 2004, and fell in love. Now developing November (a Perl 6 wiki), Druid (a Perl 6 board game), pls (a Perl 6 project installer), GGE (a regex engine), and Yapsi (a Perl 6 implementation). Heavy user of and irregular committer to Rakudo.

Journal of masak (6289)

Friday June 19, 2009
04:20 PM

3D, baby!

[ #39152 ]

Last night I had one of those rapid prototyping sprints where everything goes just right. I wanted to scout the terrain for drawing a 3D Druid board using SVG.

The result is this. Yup, Perl 6 did that, with a little help from me.

It was very pleasing to see this image grow step by step. I literally started with a grey rectangle. Then I programmatically massaged the coordinates, adding projections, translations, scalings and rotations until I had what I wanted. Here's the code.

I still feel two things are missing.

  • Real perspective. Because I currently project the 3D coordinates flatly onto the canvas, the result is isometric perspective. For some reason I don't like that — to me, the furthermost corner looks like it's sloping upwards from the plane of the board. I think I'd be happy with this kind of perspective, so I'll try that next. I was offline today, and had a couple of minutes to sit down and do the (really simple) math. I'm glad to see Wikipedia agrees with what I got. 哈哈 [Update: Fixed, see comment.]
  • Non-cheating with the piece order. I cheat right now in the sense that I placed the pieces in an order which looks good when drawn. The moves in a real game will not abide by such a restriction. I've already realized that I can draw all the horizontal surfaces in a separate pass, and don't need to sort those. I keep wondering whether I need to sort all the vertical surfaces separately, or whether it's enough to sort the pieces. Also, I'm thinking there might be nice, fast ways to determine that a surface will be completely covered by other surfaces, and can be thrown away. (Apart from the very simple case with the three surfaces on the back of each piece. I know about that one already.) [Update: Fixed, see comment.]

Anyway, I've been wanting to do this for a long time, and I'm glad that when I finally sat down to do it, not only was the result quite satisfactory, but also the process of getting there. It's 2009, and I'm using Perl 6 to rapid-prototype 3D board games. Cool!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I added real perspective [], too. The small patch required for that is here [].

  • Sorting of pieces is now in, too. The algorithm randomly places a few pieces on the board and then draws them correctly []. The patch [] this time is perhaps not the height of legibility, but it gets the job done with surprisingly little code.

    As for hiding surfaces, I'm not really sure at present if it's worth the trouble. But if it turns out to be, I now think I have a pretty good grasp on what can be done. There's a well-defined "directly behind" relation between pieces that can be used to weed out vertical sur

  • The little kid in me is always appreciative of the shiny. Nice seeing this :)