|★ APPLICATIONS ★ CREATION GRAPHIQUE ★ Delve into 3D surface plotting ★|
|3D Surface Plotter (Computing with the Amstrad)||Applications Creation Graphique|
Experiment with IAN SHARPE's fascinating graphics program
HAVE you seen computer generated pictures of objects in 3D with full shading and hidden line removal? These can almost be mistaken for photographs and produce striking animated effects when several thousand are strung together.
Amstrad graphics, good as they are, will not duplicate these effects but for an insight into how they are achieved why not develop the following idea for yourself?
Program I will draw 3D surfaces such as the one shown in Figure I. There are eight surfaces built in and you can easily add more.
The surfaces are all graphs of functions with three axes - x and y are the horizontal axes, z the vertical.
The program calculates the z values as a function of x and y. This means that the x and y values used in the calculations remain the same every time the program is run - only z varies.
The z coordinates are held in a 2D array z and the values are calculated from the x and y indices of the array.
To translate the values into a 3D image on the screen, the z value is taken as a vertical distance above a point on the screen corresponding to z=0.
This point is determined by applying a transformation to the x and y values: Rotate to give the corner view, flatten to give a 3D effect and magnify to fill the screen.
Figure II gives you some idea of how the shape changes to create the 3D effect.
The program gains speed by only calculating these base coordinates once during initialisation rather than each time a surface is drawn.
They are held in the array scrd, and the number of individual points on the x and y axes are held in the variable sc. The higher the value of sc the higher the resolution of the grid but the slower the program runs.
When drawing the surface the graphics cursor is moved to the calculated point and lines drawn to the points at x-1,y and x,y+1.
To remove areas of the surface hidden by the foreground, the drawing works towards the viewer from the point furthest away. At each point before the visible lines are drawn, a section of screen is blanked out underneath them by drawing lines in ink 0 as illustrated in Figure III. The extent of hidden line removal is controlled by the variable hlr.
An overall magnification factor mag, is applied to scale the whole thing up and the z values are exaggerated vertically by multiplying by a scale factor vex. Other corrections may be applied within each function to make z big enough to be visible without being over exaggerated.
There is plenty of scope for further development. Try adding more functions and altering the values of the variables that control the size and orientation of the display. You can restore line 400, presently deactivated with a REM, for a more solid surface.
Each surface is composed of rectangles. Imagine a line drawn from the centre of each rectangle projecting at right angles from its surface. This line can be defined as having an angle with two components, one from the horizontal (the x-y plane) and the other from the vertical plane (x-z or y-z).
If the surface is drawn in Mode 1 or 0 to give a choice of colours and the colours were selected to give a range of shades, each rectangle could be filled with a colour dependent on the values of the two angles.
In this way a surface could be generated that appeared to be solid and shaded as if there were a single light source.
If you find filling in the rectangles difficult, interesting effects can be obtained by just drawing the lines in a colour dependent on their angle from the horizontal.