Live data from Hacker News

Deciphering the Business Card Raytracer

fabiensanglard.net

51–60 of 68 posts

Re: Deciphering the Business Card Raytracer

#51

Earlier quoted context omitted.

I could have coded something to generate customized versions of the original source, given three ASCII initials.

Come on, Chris. I'm a big fan of the humblebrag, but you would still have to draw the binary pixel version of each letter (because C doesn't come with binary pixel array versions of the 26 letters) - so it would be 8 times as much work at an absolute minimum (26 characters versus the 3 that you did), even if the code to embed them in the array were a completely obvious 1-liner, and so was the code to clean up the jus…

Render a Small Fonts text to a text-based monochrome image format with e.g. Imagemagick, read file, and parse each line as binary. Reverse array and separate by commas.

Re: Deciphering the Business Card Raytracer

#52
I like this extremely short postscript raytracer I saw quite a few years ago:

http://www.is.titech.ac.jp/~sadayosi/lab/h-takasi/ops.html

  %!IOPSC-1993 %%Creator: HAYAKAWA Takashi 
  /C/neg/d/mul/R/rlineto/E/exp/H{{cvx def}repeat}def/T/dup/g/gt/r/roll/J/ifelse 8
  H/A/copy(z&v4QX&93r9AxYQOZomQalxS2w!!O&vMYa43d6r93rMYvx2dca!D&cjSnjSnjjS3o!v&6A
  X&55SAxM1CD7AjYxTTd62rmxCnTdSST0g&12wECST!&!J0g&D1!&xM0!J0g!l&544dC2Ac96ra!m&3A
  F&&vGoGSnCT0g&wDmlvGoS8wpn6wpS2wTCpS1Sd7ov7Uk7o4Qkdw!&Mvlx1S7oZES3w!J!J!Q&7185d
  Z&lx1CS9d9nE4!k&X&MY7!&1!J!x&jdnjdS3odS!N&mmx1C2wEc!G&150Nx4!n&2o!j&43r!U&0777d
  ]&2AY2A776ddT4oS3oSnMVC00VV0RRR45E42063rNz&v7UX&UOzF!F!J![&44ETCnVn!a&1CDN!Y&0M
  V1c&j2AYdjmMdjjd!o&1r!M){( )T 0 4 3 r put T(/)g{T(9)g{cvn}{cvi}J}{($)g{[}{]}J}J
  cvx}forall/moveto/p/floor/w/div/S/add 29 H[{[{]setgray fill}for Y}for showpage

Re: Deciphering the Business Card Raytracer

#53

Earlier quoted context omitted.

Come on, Chris. I'm a big fan of the humblebrag, but you would still have to draw the binary pixel version of each letter (because C doesn't come with binary pixel array versions of the 26 letters) - so it would be 8 times as much work at an absolute minimum (26 characters versus the 3 that you did), even if the code to embed them in the array were a completely obvious 1-liner, and so was the code to clean up the jus…

Didn't mean to come off as arrogant but there are existing tools that would make this a lot easier. figlet(1) would make the pixel conversion pretty easy. Pixels to binary really isn't that hard. You could do it with a regex.

Another way is to use the netpbm toolkit. First, use its ppmdraw command to rasterize each character to a canvas, then convert that canvas to xpm format (you have a separate canvas / picture for each character). The xpm format has the nice property that it is also a valid C structure. Real easy to then convert to whatever you want.

Oh, and the netpbm toolkit has not only stand alone binaries, but it also has a C library for each of the conversions that it includes. Seems to be an older under-rated toolkit.

Re: Deciphering the Business Card Raytracer

#54
There are two other small ray tracers that can be examined. Both are winners of the International Obfuscated C Code Contest.

Matt Zucker won in 2011 and Anders Gavare won in 2004.

They can be found here, http://www.ioccc.org/years-spoiler.html

(The 22nd IOCCC is open for entries until 2013-Oct-03)

Re: Deciphering the Business Card Raytracer

#55
post #32

Earlier quoted context omitted.

In non-programming math contexts, it's pretty standard for Z to point up. I have no idea why, as it seems to me like the typical way it works in graphics programming is the more obvious extension of 2D plotting into 3D.

As far as I know, in the CAD world Z is typically up/down. It makes sense if you look at the scene from above, like an architect a floor plan - world-space X and Y map to screen-space X and Y, and Z is then the depth. In a 3D virtual world, on the other hand, the perspective is usually of a person embedded in the world, in which case "Y is up" is more intuitive.

OK, thinking about the architecture angle finally made it click for me.

Re: Deciphering the Business Card Raytracer

#56

Earlier quoted context omitted.

In non-programming math contexts, it's pretty standard for Z to point up. I have no idea why, as it seems to me like the typical way it works in graphics programming is the more obvious extension of 2D plotting into 3D.

When I took Calculus III, Z was up. When I took Engineering Physics the same semester, Y was up. According to legend, this is why the Math and Physics departments hate each other.

With the right rotation, any direction can be pointing "up".

Re: Deciphering the Business Card Raytracer

#58

Earlier quoted context omitted.

How come you decided for a coordinate system with Z pointing up instead of the traditional right hand/left hands coordinate systems ?

In non-programming math contexts, it's pretty standard for Z to point up. I have no idea why, as it seems to me like the typical way it works in graphics programming is the more obvious extension of 2D plotting into 3D.

I always use Z for up/down even though I'm a programmer. For some reason I just find it easier to reason about. In fairness, my first forays into 3D were extending a 2D top-down game with an "altitude".

Re: Deciphering the Business Card Raytracer

#59
post #33
post #9

Earlier quoted context omitted.

If you're using Linux or OSX, run it like this: ./aek > aek.ppm That will produce an image in .ppm format. ('The world's second-dumbest picture format.') You'll probably have to convert it to a more widely supported format. Make sure you have the netpbm package installed, and then run, say: pbmtopng aek.ppm > aek.bmp

What is the worlds dumbest picture format then?

pbm

    P1
    # feep.pbm
    24 7
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
    0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
    0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Re: Deciphering the Business Card Raytracer

#60
post #9

Earlier quoted context omitted.

If you're using Linux or OSX, run it like this: ./aek > aek.ppm That will produce an image in .ppm format. ('The world's second-dumbest picture format.') You'll probably have to convert it to a more widely supported format. Make sure you have the netpbm package installed, and then run, say: pbmtopng aek.ppm > aek.bmp

The correct command is actually pnmtopng , FWIW.

Oops!
Post reply on HN