Day 29, Groups
Transforming each object in the scene in global world reference space quickly becomes tiresome, so let’s introduce a new group “shape”. A group takes any number of objects and provides a common reference space for its children via its own transform. A group also helps reduce the search space in large scenes, by aggregating the bounding boxes of its children into a bounding box for the entire group. That way ray intersection tests against the children of the group only needs to happen when the group bounding box is intersected. Neat.
Oh, and why not let shapes inherit the material from their parent group, when they have no material of their own?
world << Group.new do |g|
g.material = Material.new do |m|
m.color = Color[1.0, 0.8, 0.5]
m.shininess = 300
m.reflective = 0.9
end
0.upto(5) do |n|
g << hexagon_side(n)
end
end
Next related
Day 30, Triangles and teapots
The last of the primitive shapes, the triangle. By them selves they’re pretty boring, but when you stick loads of them together they make pretty teapots. Very. Slowly. And quite chunky, because low-polygon model. It sums up to 240 triangles after dividing some larger polygons, and takes about 20–30 minutes to render at the whopping resulution of 320x256 and no reflections. I probably need to research some kind of bounding hierarchy algorithm to automagically subdivide large groups of objects.
Previous related
Day 28, Celebratory cocktails
The latest addition to the supported shapes is the cone, a deformed kind of cylinder, also optionally capped and restricted to an interval along its length. With all these things we can make a cocktail to celebrate. With all these transparent parts, it takes more than 8 minutes to render.
Day 27, Cylinders part 2
To celebrate that cylinders can be constrained and capped at the ends, we have a remake of the cubemas scene from a few days ago, but with today’s shiny new cylinders instead of cubes.
Day 26, Cylinders part 1
Devember is rapidly coming to an end, but so is the book. Just a few more shapes to go, and we’re done. Except the easy shapes are already done, so things get more complicated from here. Cylinders seem pretty easy, just a XZ-planar circle, extruded along the Y axis. Done. Except that it gets infinitely long that way, so it needs to be constrained. But then it’s hollow, so it needs to support optional end caps for when you need a closed cylinder and not just a very thin walled tube. So it’s not done yet, but probably new pixels tomorrow.