Thursday, February 27, 2014

A cube simulator

How I love Qt. Here's something I wrote during lunch break:
It's a cube simulator! Sort of. I pasted one of Kevin Darrah's animations (the first one in this video) into my code and it worked pretty much straight out of the box.
LED information is stored in a 8x8x8 three dimensional array in RGB444 format. The render loop simply iterates over all x/y/z values and reads the color information. X and Y are decremented by 3.5 (to put the origin in the center of the cube) and then put in a 2D point after which a rotation matrix is applied. The resulting X and Y and the original Z are translated to 2D coordinates using the formula: Xwin = X + Y, Ywin = Z - 0.5X + 0.5Y.
Translucency is calculated by using the highest 4 bit R/G/B component, multiply by 4, add 192. So LEDs that are off are more transparent than LEDs that are on.

No comments:

Post a Comment