"geometry.pf" load # CUBE # generating a cube, we start from the most basic square # spanning (0,0) to (1,1) traversing the vertices counterclockwize ((0 0) (1 0) (1 1) (0 1)) constant 2Dsquare # orthogonal coordinate transforms which transform the # front of a cube to the 5 other faces # compute inverse of 90 degree rotation by applying 3 times : inv dup dup * * ; : front ; : bottom Rx * ; : top [ Rx inv ]L * ; : right Ry * ; : left [ Ry inv ]L * ; : back Ry * Ry * ; # 0/1 -> -/+ .5 : bit>float >float .5 - ; # turn a 2D coord into a 3D coord : 3Dfy ' bit>float map 1 bit>float 1 pack concat ; # now we need to generate the display lists # 1000. sleep # now, to convert a 2D coord to 3 matrices 2Dsquare >matrix constant tc # texture coordinates 2Dsquare ' 3Dfy map >matrix constant v # vertices (0 0 1) 1 pack dup concat dup concat >matrix constant n # normals # draw a face : face find >r v n 2 pack r> map # transform v & n unpack tc 3 pack "tnv" quads ; # add tc and draw quads # compile function that draws all faces in displaylist :: (left right bottom top back front) ' face for-each ; displaylist 1cube # ( float -- ) : cube m-push scale 1cube m-pop ;