A quad-tree algorithm
暂无分享,去创建一个
In this chapter we introduce a quad-tree algorithm for drawing an orthographic view of a scene that is modelled as a list of objects, each of which is stored in OBSERVED position. In our restricted version of the quad-tree algorithm we will in fact only be considering spheres (primitive_type=1), the simplest of all three-dimensional objects. Nevertheless, the approach is valid for many other types of primitive object, provided that the relevant functions have been written and the Analytic_scene class has been extended to contain sufficient parameters. You will see that the algorithm we use has close similarities to the recursive techniques used to draw mathematical functions (listing 10.6) and fractal maps (listings 1.6 and 10.9). The application program that initiates the quad-tree approach is given in listing 14.1, and consists of a simple build_it function that links the quad-tree application to all the other functions in our collection of files; the link with “model.cpp”, “display.cpp” and “window.cpp” will be achieved using the C++ Project mechanism. Function build_it, called from draw_a_picture, takes the description of every sphere from file “quadtree.dat”: this data is given in the order of their integer labels and a sample file is shown in listing 14.1. The data is used to instantiate an Analytic_scene object named scene. The data concerning the material used by the spherical objects in the scene is stored in a file “material.dat”: see listing 11.2c for an example. As usual, function draw_a_picture (listing 13.1b) models the scene (build_it), sets up the observer and light source (look_at_it) and finally displays the scene (draw_it). The data structure that brings all this together to form a complete description of the three-dimensional scene is an implied list of integer labels of all objects in the scene.