Ray tracing Rubik's cube skeleton


The following figure was done with a hand made ray tracer:

d3


The code

I cannot post the code of the raytracer because it was part of the homeworks for the course CS184.1x: Foundations of Computer Graphics. The text file with the scripts that I used as input for the raytracer perhaps can give some idea about the building blocks:


size 640 480
maxdepth 1

camera 0 0 25 0 0 0 1 0 0 30
#camera 0 20 0 0 0 0 1 0 0 30
camera 10 -20 -26 0 0 0 1 0 0 30
camera 25 0 0 0 0 0 0 0 1 30
camera 0 0 25 0 0 0 0 1 0 30
#camera 32 -32 12 0 0 0 0 0 1 30
#directional 0 10 7 0.3 0.3 0.3
#directional 0 -10 7 0.4 0.4 0.4
#directional 5 17 -7 0.9 0.9 0.9
directional 1 1 2 0.7 0.7 0.7

output borri.png

#ambient 0.1 0.2 0.1

shininess 10

scale 3 3 3

rotate 0 1 0 40
rotate 1 0 0 -30

diffuse 0.5 0.5 0.5
specular 1.0 1.0 1.0
emission 0.0 0.1 0.0

########################
## CENTER AND LINKAGE ##
sphere 0 0 0 0.2

pushTransform
scale 0.5 0.1 0.1
sphere -1 0 0 1
sphere 1 0 0 1
popTransform

pushTransform
scale 0.1 0.5 0.1
sphere 0 -1 0 1
sphere 0 1 0 1
popTransform

pushTransform
scale 0.1 0.1 0.5
sphere 0 0 -1 1
sphere 0 0 1 1
popTransform
########################


vertex 1 1 1
vertex -1 1 1
vertex -1 -1 1
vertex 1 -1 1
vertex 1 1 -1
vertex -1 1 -1
vertex -1 -1 -1
vertex 1 -1 -1

pushTransform
diffuse 0.76586 0.1176 0.2275
translate 0 1 0
scale 0.3333 0.1 0.3333
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform

pushTransform
diffuse 0 1 0
translate 0 -1 0
scale 0.3333 0.1 0.3333
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform

pushTransform
diffuse 0 0.3176 0.7294
translate 0 0 1
scale 0.3333 0.3333 0.1
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform

pushTransform
diffuse 1 0.3451 0
translate 0 0 -1
scale 0.3333 0.3333 0.1
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform


pushTransform
diffuse 1 0.8353 0
translate 1 0 0
scale 0.1 0.3333 0.3333
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform


pushTransform
diffuse 1 1 1
translate -1 0 0
scale 0.1 0.3333 0.3333
# UNIT CUBE #
tri 0 1 2
tri 0 2 3
tri 4 6 5
tri 4 7 6
tri 0 3 7
tri 7 4 0
tri 1 6 2
tri 6 1 5
tri 2 6 3
tri 6 7 3
tri 1 0 5
tri 5 0 4
popTransform