Atari ST-3D Graphics Programming Text
Atari ST-3D Graphics Programming Text
8
O
PROGRAMMING
Concepts and Techniques
w
3
c
3
/?////* / /11 jjp
Published by
A I IlMWSIIlj) r c-
Abacus iiiiiiisnl Software
First Printing, Aug. 1986
Printed in U.S.A.
Copyright © 1985 Data Becker GmbH
Merowingerstr.30
4000 Dusseldorf, West Germany
Copyright © 1985 Abacus Software, Inc.
P.O.Box 7219
Grand Rapids, MI 49510
Every effort has been made to insure complete and accurate information
concerning the material presented in this book. However Abacus Software
can neither guarantee nor be held legally responsible for any mistakes in
printing or faulty instructions contained in this book. The authors will
always appreciate receiving notice of subsequent mistakes.
1. Introduction 3
2.3 Clipping 26
D Bibliography 348
Index 349
L_
Abacus Software ST 3D Graphics
1. Introduction
Of course, even the largest mainframes are getting faster as well. The
fastest computer at this time, the Cray II, has a throughput capacity of
2000 megaflops (200 million floating-point operations per second). Such
high computing speeds are needed to closely simulate natural world
processes with computer models. Examples are the simulation of
3
ST 3D Graphics Abacus Software
For the problem of depicting and representing the 3-D wire models
presented here, maximum processor speed is crucial. Machine language is
clearly superior to any higher-level language in fulfilling this
requirement. With these applications for the Atari ST, real-time three-
dimensional graphics can be achieved. The removal of hidden lines and
the shading of areas requires a considerable amount of processor time.
The Cray II requires 8 minutes to create a single picture with a resolution
of 2000 by 3000 pixels, with up to 30 bits of color information per picture
point. In contrast, the ST manages only 640 by 400 pixels and only one
bit of color information. Of course, it is possible to increase the
computational capabilities of the ST with programming tricks, fast mass
storage (hard disk) and large amounts of memory to solve more complex
graphic problems.
This book provides you with help in solving the complex programming
problems of three-dimensional graphics. While the sample programs are
directly tailored for the Atari ST, the techniques can be used without too
much difficulty on other computers. Only the routines for hardware
communication and display control (keyboard input, line drawing, surface
shading (if possible) and switching between two screens) need to be
tailored to another computer using an MC68000 CPU (i.e., the Apple
Macintosh and Commodore’s Amiga). The subroutines for generating
and handling three-dimensional graphic objects can be run on any
computer with an MC68000 microprocessor.
4
Abacus Software ST 3D Graphics
T-1-1-1-1-r—i r r i i r»
I ST display coordinate system
7
ST 3D Graphics Abacus Software
an object defined in the first system is inverted in the system on the right,
and is also displaced on the y-axis.
Individual objects are defined in the world coordinate system, where the
calibration of the coordinate axis may be any desired unit of
measurement—for example, millimeters, kilometers, years, etc.
This concept can be explained very simply with an example. Two objects
are defined in a world coordinate system, the outlines of a house and of a
church. The two outlines represent all objects that can be depicted on a
plane. For example, an architect would use the outline of the house in a
world coordinate system to define individual rooms and furniture.
Abacus Software ST 3D Graphics
Our task is to transform the observation window, together with the house
that fills its surface, to the specific picture window for display on the ST’s
screen.
Here’s the preferred solution to the problem, using the view coordinate
system: The origin of the world coordinate system is moved to the lower
left comer of the observation window and scaled by a suitable factor. It
now represents all points in the picture coordinate system. If the points
are in the field of picture coordinates, they can be drawn and connected
with lines.
9
ST 3D Graphics Abacus Software
Scaling and (as we shall see later) rotation are both related to the
coordinate base. To scale an object in relation to another point, or to
rotate it around an arbitrary point, the coordinate origin must first be
moved to the relative origin. We can illustrate this again using the house
example.
nx
Fig. 2.1.1
One way to describe the house is to list the coordinates of the end points
and to list the points which are connected with lines. For this example,
the two lists are as follows:
10
Abacus Software ST 3D Graphics
Connection list:
Line from Point A to Point B
LI: PI P2
L2 : P2 P3
L3: P3 P4
L4 : P4 P5
L5: P5 PI
As we shall see later, the polygon is also perfectly acceptable for the
description of complex, three-dimensional objects. Any physical object
can be closely approximated by chaining various polygons. Also, natural
asymmetrical bodies such as mountains, forests, lakes and animals can be
represented in a realistic manner with polygons created through fractional
geometry, i.e. fractals. In addition, most man-made objects are
constructed in a symmetrical manner and are easier to represent
graphically.
11
ST 3D Graphics Abacus Software
12
Abacus Software ST 3D Graphics
13
ST 3D Graphics Abacus Software
Figure 2.1.3
Scaling with factors greater than one enlarges the object. If we select
different scaling factors for the X and Y axes, a distorted picture of the
object results.
At this point let’s briefly return to the example, at Figure 2.1, and alter
the scaling factors for converting to view coordinates. With the maximum
coordinates of the observation:
[wxmin,wymin]; [wxmax,wymax],
and the display window
[vxmin,vymin]; [vxmax,vymax]
one can give differing scaling factors for the two axes, Sx and Sy. In our
example:
Sx=(vxmax-vxmin)/(wxmax-wxmin)
Sy=(vymax-vymin)/(wymax-wymin)
14
Abacus Software ST 3D Graphics
Before scaling, the origin of the world system is moved to the left lower
comer of the observation window [wxmin, wymin], since this point is
the data point of the scaling. The result of the conversions is therefore:
The third step of converting the Y values to the screen display of the ST
is always the same. During the description we shall limit ourselves to the
view system. If during subsequent discussions no special reference is
made to this step, you should remember that if it is not performed, all
objects appear inverted on the screen after the drawing is completed.
The location of the picture window in the view system is not fixed to the
origin, but is movable in the total view system. However, the three
conversions must be followed by another conversion-moving the
window to point VI [vxmin,vymin] . Basically the conversion of an
object is the opposite of the conversion of a coordinate system. Therefore,
when moving the picture window and the object to the point
VI [vxmin, vymin] , the coordinates of this point (vxmin and
vymin) must be added to all object coordinates.
Summarizing the conversion of the world system into the view system:
15
ST 3D Graphics Abacus Software
16
Abacus Software ST 3D Graphics
the angles as positive when the rotation moves the positive X axis to the
positive Y axis. Expressed differently, positive angles are measured in the
counterclockwise direction. For the angle between the connecting line
from 0,0 to P1 and the X-axis, the relationships are:
1) SIN(alpha) = Yl/C
2) COS(alpha) = Xl/C
3) SIN (alpha+beta)=Y2/C
4) COS(alpha+beta)=X2/C
5) SIN(Alpha+Beta)=SIN(Alpha)*COS
(Beta)+COS(Alpha)*SIN(Beta)
6) COS(Alpha+Beta)=COS(Alpha)*COS(Beta)-
SIN(Alpha)*SIN(Beta)
7) X2/C=COS(Alpha)*C0S(Beta)-
SIN(Alpha)*SIN(Beta)
gives us
from 1) follows
9) X2=Xl*COS(Beta)-Y1*SIN(Beta)
17
ST 3D Graphics Abacus Software
R1X=P1X*C0S (30)-P1Y*SIN(30)
R1Y=P1Y*COS(30)+P1X*SIN (30)
Figure 2.1.5
18
Abacus Software ST 3D Graphics
Right now we’ll combine these conversion operations into a single matrix
operation. (Explanations of matrix operations are found in the Appendix).
Therefore it becomes possible to apply the conversions to the array and
then to multiply the resulting array with every point of the object. To
make the array operations usable for the point coordinates of the plane,
the point coordinates are first converted to array form.
There are basically two ways to convert these: with column vectors (2,1),
or with line vector (1,2) arrays. A conversion array (2,2) is used to
multiply a line vector with the transformation array, where the
transformation array must be multiplied with the column vector, (number
of columns A = number of rows B).
In this book we shall write the point coordinates as line vectors P and the
multiply this line vector with the transformation array. This sequence of
multiplication simplifies, purely subjectively, the creation of the
transformation matrices. If you multiply a line vector (1,2) with a
quadratic array (2,2), you will obtain as a result another line vector (1,2),
which represents point coordinates. The individual point operations can
be expressed by a suitable transformation matrix T. For scaling the X axis
by the factor 2, the array S1 is valid. It is also possible to quadruple the Y
values using transformation array S2. The two scaling steps can be by
multiplying SI and S2 with array S3.
Si 2 0 S2 = 1 0
0 1 0 4
S3 = S1 * S2 = 2 0 ★ 1 0
0 1 0 4
s3 0
4
19
ST 3D Graphics Abacus Software
Rl = cos(b) sin(b)
-sin(b) cos(b)
In a three dimensional space there are infinite possibilities for laying out
the X-Y plane we have just observed. The additional dimension is known
as Z coordinate of the X-Y plane. For two dimensional objects, its value
is always one. The X and Y coordinates remain unchanged: the line
vector [x,y] becomes the line vector [x,y,l]. The array for the translation
of the source at point D is as follows:
110
T = 0 10
-DX -DY 1
Every point of the object must be multiplied with this array to move the
origin of the world coordinate system to the point (DX, DY). For the point
P [ x, y, 1 ] the result is: new point in world coordinates p' =p*T
10 0
P'[x',y',l] = [x,y,1] *010= [x-dx,y-dy,1]
-DX -DY 1
20
Abacus Software ST 3D Graphics
10 0 10 0
T1=010 T2=010
DX -DY 1 -AX -AY 1
10 0 10 0
t3=t1*t2= 0 1 0 * 0 1 0
-DX -DY 1 -AX -AY 1
10 0
T3 = 0 1 0
-DX-AX -DY-AY 1
SX 0 0
S = 0 SY 0 and P' = P * S
0 0 1
21
ST 3D Graphics Abacus Software
1) Translation * Translation
2) Scaling * Scaling
3) Rotation * Rotation around
the same axis
4) Scaling •k
Rotating
Type 4 (scaling and rotating) is only valid when both scale factors
(Sx, Sy) are identical.
l 0 0 co3(a) sin(a) 0
Ti - 0 1 0 Rl = -sin (a) cos(a) 0
-vx -vy 1 0 0 1
1 0 0
t2 = 0 1 0
vx vy 1
22
Abacus Software ST 3D Graphics
0 0 cos(a) sin(a) 0
1 0 * -sin(a) cos (a) 0
-vy 1 0 0 1
cos(a) sin(a) 0
Mx = -sin(a) cos(a) 0 *
-vx*cos(a)+vy*sin(a) -vx*sin(a)-vy*cos(a) 1
10 0
0 1 0 =
vx vy 1
cos(a) sin(a) 0
-sin(a) cos(a) 0
-vx*cos(a)+vy*sin(a)+vx vx*sin(a)-vy*cos(a)+vy 1
23
ST 3D Graphics Abacus Software
You can see that when the rotation point and the point to be rotated are
identical, therefore x=vx and y=vy, the expression for the line vector of
the point at [ vx, vy, 1 ] = [ x, y, 1 ] degenerates. That means that the
point coordinates do not change.
24
Abacus Software ST 3D Graphics
The house already familiar in Figure 2.2.1 shall be rotated by the angle
alpha=30 degrees around the point VI [ vx, vy, 1 ] = [ 12 0,8 0, 1 ]. As
an example this is carried out on point P2[100,90,l].
P2x'=100*cos(30)-90*sin(30)-120*cos(30)+80*sin(a)+120
P2y'=100*sin(30)+90*cos(30)-120*sin(30)-80*cos (30)+80
PI'=[117.68,44.02,1]
P2'=[97.68,78.66,1]
P3'=[95,123.30,1]
P4'=[132,32,98,66,l]
P5'=[143.66,59.02,1]
This procedure also permits you to change the point for scaling to any
location in the coordinate system. In the following, you can see the
buildup of the transformation array. First the coordinate origin is moved
to point K1 [ kx,ky,1] with translation array T1? then scaling with array
Si, using scaling factor Sx and Sy, and finally moving the origin to its
original location using translation array T2. For every single point this
means p' [x' ,y', 1] = p [x,y, 1] *T1*S1*T2.
0 0 Sx 0 0 1 0 0
1 0 Si- 0 Sy 0 t2= 0 1 0
-kx -ky 1 0 0 1 kx ky 1
Sx 0 0
T-l* Si* T2 = 0 Sy 0
kx*(l-Sx) ky*(1-Sy) 1
P'[x,y,1] =P'[x*Sx+kx(1-Sx),y*Sy+ky(1-Sy),1]
25
ST 3D Graphics Abacus Software
2.3 Clipping
Figure 2.3.1
26
Abacus Software ST 3D Graphics
Figure 2.3.2:CIip-Window
bit position
27
ST 3D Graphics Abacus Software
The code [0,1,0,1] means the following: the point is to the left and below
the window. With this information, it is possible to calculate the points of
intersection of the lines with the window edges by including them in the
equation. This leads to a quadratic equation system whose solution
requires several multiplications and divisions. For our purposes, we want
to limit the number of multiplications and to replace them when possible
with other mathematical operations. We do this for two reasons. The first
is for speed since multiplication requires about eight to ten times the
calculation time of addition. The second is the fact that the result of
multiplication, with the same number of significant positions of the
operands, has a larger relative error.
The starting point of the algorithm is to divide the plane into the nine
areas previously illustrated. For every line which is to be "clipped”, you
must determine a center point and on the basis of its position relative to
the window.
The calculation of the center point of a line AB is simple. Just add the X
and Y coordinates of the end points and divide them by two.
Mx= (ax+bx) /2, My= (ay+by) /2. Division by two is performed by
microcomputers easily by a single right shift and this explains the speed
of the algorithm.
The 8 different positions of the end points relative to the window are
illustrated in Figure 2.3.2. Before calling the clip-routine, you must first
test to see if the two end points are visible. If any of the bits are set, then
some portion of the line is not visible. In Figure 2.3.2 both A and B are
above the upper window edge, and therefore the line AB is not visible and
no longer needs to be considered. You can calculate the position of the
points by "ANDing" their codes and then testing for a "not zero”
condition. For lines which have no common position parameter, for
example the line CD, positions are determined with two separate
procedures. First the right and then the left intersecting points with the
clip-window.
28
Abacus Software ST 3D Graphics
First calculate the midpoint Ml of line CD. After determining the position
code of the point Ml, it is compared with the code of the right endpoint D.
If a single bit of these codes is the same, then the partial line MID does
not have to be considered further, and the right endpoint D is replaced
with the point Ml which was just determined. Now the midpoint of line
CM1 (M2), is calculated and tested again with the right endpoint, this
time Ml. If both points are not on one side, M2 becomes the new left
endpoint and the right endpoint remains Ml. Next search the midpoint of
the line M2M1. This procedure is continued until a new calculated
midpoint is equal to one of the two end points used for calculation.
After completing the algorithm, the last left endpoint is the desired
intersecting point with the window. The intersecting point is stored and
the two starting points C and D are interchanged. With the same
procedure the intersection with the left window edge is determined. At
the start of the routine, if you find that an endpoint is already inside the
window, this endpoint must be stored. The line ST causes a problem. The
two end points S and T are not on the same window side and the line does
not intersect the window. A comparison of the first center point T1 shows
it matching both end points. The points T1 and T are both to the right of
the window and point S below the window. You can thus define a new
ending criteria--# a new midpoint lies outside of the window and matches
both end points of the line, then the line is not visible.
29
ST 3D Graphics Abacus Software
Starting with the two dimensional X-Y-coordinate system, there are two
ways to introduce a right angle coordinate system to describe three
dimensional space. They are the right-hand and the left-hand coordinate
system which differ only in the orientation of the negative Z axis.
30
Abacus Software ST 3D Graphics
z z
Right-hand Left-hand
Figure 2.4.2
1 0 0 0
Ti = 0 1 0 0
0 0 1 0
•vx ■vy -vz 1
31
ST 3D Graphics Abacus Software
The scaling matrix is similar. A scaling factor for the Z axis (Sz) is
added:
Sx 0 0 0
S1 = 0 Sy 0 0
0 0 Sz 0
0 0 0 1
Rotation is limited to the three rotation axis: X,Y, and Z. We are already
familiar with rotation about the Z axis from the earlier 2D description.
The 3D description is derived by assuming that the positive Z axis
projects from the drawing surface. The coordinates of the axis about
which rotation takes place, does not change, in this case the Z coordinates
retain their values.
cos(zw) sin(zw) 0 0
Rz = -sin(zw) cos (zw) 0 0
0 0 10
0 0 0 1
32
Abacus Software ST 3D Graphics
Figure 2.4.3
We must also allow for setting a positive turning angle for the rotation
about the X and Y axes. A solution which can be applied to both the left-
hand and right-hand coordinate systems uses the following definitions:
Z-axis X- to Y-axis
Y-axis Z- to X-axis
X-axis Y- to Z-axis
From this follow the matrices for rotation around the X and Y axis Rx and
Ry.
33
ST 3D Graphics Abacus Software
10 0 0
Rx= 0 cos(xw) sin(xw) 0
0 -sin(xw) cos(xw) 0
0 0 0 1
cos(yw) 0 -sin(yw) 0
Ry= 0 10 0
sin(yw) 0 cos(yw) 0
0 0 0 1
For the coordinate system this means that if you look from a positive axis
in the direction of the coordinate origin, a positive angle describes a
counterclockwise rotation. In a left-hand coordinate system a positive
angle describes a rotation in the clockwise direction. This definition
applies to a fixed coordinate system in which the objects are rotated. The
other type of representation would be the fixed placement of the object
and the rotation of the coordinate system. The two types differ only in the
sign of the rotation angles. This means that if the object is rotated about
the angle alpha, or the coordinate system is rotated about angle alpha,
the result in both cases will be the same. In three dimensional space the
point of the rotation, as in the two dimensional plane, is the origin. If you
want to rotate an object around another point, it is first necessary to move
the origin to that point. The required steps are:
10 00 cos(a) -sin(a) 0 0
T]_= 0 1 0 0 Rl= -sin (a) cos (a) 0 0
0010 0 0 10
-bx -by -bz 1 0 0 01
10 0 0
T2 = 0 1 0 0
0 0 10
bx by bz 1
34
Abacus Software ST 3D Graphics
Figure 2.4.4
Let’s assume that you want to rotate an object about around all three
axes. It is then possible to combine the rotation matrices Rx, Ry and Rz
by multiplying with Rg. In contrast with the combination of rotations
about the same axis in this example the sequence of multiplications is
important, i.e. Rx*Ry*Rz yields a result different from Rz*Ry*Rx. A
point with a positive Z value is rotated 90 degrees around both the Z and
X axes. If the rotation is first made about the Z axis, the coordinates do
not change, X- and Y-coordinates are equal to zero, and the subsequent
rotation about the X axis rotates the point to the Z=0 level; which is the
X-Y plane.
If the first rotation is about the X axis, the point is transferred to the Z=0
level and the subsequent rotation about the Z axis rotates the point into
the Y=0 level, which is the level between the X and Z axes. This example
shows why it is necessary to follow the sequence of rotations during
program generation.
35
ST 3D Graphics Abacus Software
x = xl + t*(x2-xl)
y = yl + t*(y2-yl) with t elements from R
z = zl + t*(z2-zl)
36
Abacus Software ST 3D Graphics
Since the problem for rotation about one coordinate axis has already been
solved, we want to transform a rotation axis in such a way that it will
coincide with the negative Z axis. The sequence of the transformation
looks like this:
It is now possible to rotate the desired angle zw about the Z axis since it
matches the rotation axis. If one looks from PI to P2 a positive angle
will rotate an object in a counterclockwise direction.
37
ST 3D Graphics Abacus Software
The only problem is the determination of the angles xw, yw, which can be
derived from the equation. As in Figure 2.4.7 we imagine that the
coordinate origin is already moved to point P1. Then the coordinates of
the point P2' [x2-xl,y2-yl, z2-zl] represent the direction vector
of the lines. This vector is now projected on the Y-Z plane, whereby the
term projection should be taken literally. In addition you should imagine
the vector G [gx, gy, gz] = G [x2-xl, y2-yl, z2-zl] illuminated
by light rays, parallel to the X axis and originating from the positive X
axis. The shadow created in the Y-Z plane is the vector L [0, gy, gz]
and the angle alpha between vector L and the positive axis Z is the
desired angle xw.
10 0 0
Rx 0 cos(a) sin (a) 0
0 -sin(a) cos (a) 0
0 0 0 1
38
Abacus Software ST 3D Graphics
1 0 0 0
rx — 0 gz/l gy/i 0
0 -gy/l gz/1 0
0 0 0 1
After this transformation, the vector G (P IP2) lies in the plane located
between the positive Y and positive X axis. The angle gamma, which we
defined to be positive, is the desired angle (yw), which rotates the vector
G with one rotation about the Y axis on the negative Z axis. The rotation
matrix Ry:
39
ST 3D Graphics Abacus Software
It is possible to divide the angle gamma into the partial angles beta and
the right angle alpha’ (90 degrees), between the positive X and negative Z
axes. Through rotation about the X axis the X coordinate of the point P2
has not changed, whereas the Y coordinate has become zero. The sum of
the vector G [gx, gy, gz ] g =V~(gx2+gy2+gz^) is therefore identical
to g =V"(gx^+zlz). From this follows z' =V”[gz-gx2) and from
1 =V (gy2+gz2) = V (g2-gx2) results in z' : z' = 1.
40
Abacus Software ST 3D Graphics
sin <ga)=sin(b+90)=sin(b)*cos(90))+sin(90)*cos(b)
cos(ga)=cos(b+90)=cos(b)*cos(90)-sin(90)*sin(b)
-sin(b) 0 -cos(b) 0
0 1 0 0
cos (b) 0 -sin(b) 0
0 0 0 1
-1/g 0 -gx/g 0
0 10 0
gx/g 0 -1/g 0
0 0 0 1
After these preparatory transformations, the rotation takes place about the
desired angle za about the rotation axis, which is the connecting line
between PI to P2. The matrix for this is:
cos(zw) sin(zw) 0 0
Rz =- sin(zw) cos(zw) 0 0
0 0 10
0 0 0 1
41
ST 3D Graphics Abacus Software
-1/g 0 gx/g 0
Ry-1 =0 1 0 0
-gx/g 0 -1/g 0
0 0 0 1
10 0 0
Rx 1 = 0 gz/1 -gy/1 0
0 gy/l gz/1 0
0 0 0 1
10 0 0
T-1 =0100
0 0 10
xl yl zl 1
P'[x',y', z',l]=[x,y,z,1]*T*Rx*Ry*Rz*Ry-1*Rx-1*T~1
42
Abacus Software ST 3D Graphics
43
ST 3D Graphics Abacus Software
Let us combine the steps again, considering the steps necessary for
rotation around any desired axis.
44
ST 3D Graphics Abacus Software
1 0 0 0
0 1 0 0
0 0 10
-orx -ory -orz 1
10 0 0
Rx= 0 gz/i gy/i 0
0 -gy/i gz/i 0
0 0 0 1
with 1 = V(gy2+gz2)
-1/g 0 -gx/g 0
0 10 0
gx/g 0 -1/g 0
0 0 0 1
with g = V (gx2+gy2+gz2)
l = V7gy2+gz2)
z' = 1
cos(zw) sin(zw) 0 0
Rz -sin(zw) cos(zw) 0 0
0 0 10
0 0 0 1
46
Abacus Software ST 3D Graphics
10 0 0
Mi 0 10 0
0 0-10
0 0 0 1
The object now lies in the left-hand coordinate system U-V-Z’ and can be
projected on the display, the plane suspended between the U and V axis
via a suitable perspective transformation.
47
ST 3D Graphics Abacus Software
l i
*z
The coordinate system from Figure 2.6.1 is, as already indicated, another
coordinate system and the plane suspended between the positive U and
the positive V axis at point z’=0 will represent the screen. The center of
the projection (focal point) is located on the negative Z axis at point
PROZ[prozx, prozy, prozz' ] = [0, 0, prozz' ]. The position of the
point tc be viewed P[pu,pv,pz], appears to be located behind the
48
Abacus Software ST 3D Graphics
observation plane. The line through these two points is described by the
following equation:
u = plu + (prozu-plu)*t
v = plv + (prozv-plv)*t
t “ -plz'/(prozz'-plz')
u = plu - (prou-plu)*plz'/(prozz'-plz')
v = plv - (prozv-plv)*plz'/(prozz'-plz')
z' =0
with prozu=prozv=0:
u = plu + plu*plz'/(prozz'-plz')
v = plv + plv*plz'/(prozz'-plz')
z = 0
49
ST 3D Graphics Abacus Software
In this illustration the projection center is at the point PROZ, while the
object to be projected is the connecting line between the points PI P2.
d designates the location of the projection plane on the Z’-axis, which
can be moved arbitrarily in either direction. If the projection center and
projection plane (d=PROZ) match, all objects degenerate to a single
point, the center of the projection. The size of the projection can be
changed by moving the projection plane. For the line between projection
center PROZ and object point P1 the two point equation holds:
u = plu + (prozu-plu)*t
v = plv + (prozv-plv)*t
50
Abacus Software ST 3D Graphics
The Z’-coordinate of the projection plane is d, and from the equation for
the Z’-coordinate it follows:
z' = d
The equation derived from Figure 2.6.1 comes from the special case
where the projection center lies on the Z axis prozu=prozv=0 and
when the projection plane is on the z'=0 plane, d=0. The following
illustrations show how the selection of the various observation parameters
(ORP, PROZ, d) influence the appearance of the projection. The
coordinate origin of the display is in the lower left comer of the screen.
51
ST 3D Graphics Abacus Software
• projection center
Figure 2.6.3
52
Abacus Software ST 3D Graphics
+Z
resulting projection
Figure 2.6.5
54
Figure 2.6.6
ST 3D Graphics Abacus Software
56
Abacus Software ST 3D Graphics
With convex polygons the line connecting two points on the polygon lies
within the polygon, whereas in convex bodies the connecting line
between two points on the surface passes through the body or runs along
the surface. Formulated differently, convex polygons have at least one
inner angle which is larger than 180 degrees.
For these surface algorithms we must expand the object definition, which
up to now consisted of the point and line list, to include a surface list. The
surface list contains a description of each surface by the lines which
border the surface.
57
ST 3D Graphics Abacus Software
You probably noticed that the line direction is reversed in the description
of the surfaces. The line vectors of surface I describe the surface as seen
from the negative Z axis in a clockwise direction, while surface 11 is
described in a counterclockwise direction. This small difference contains
the solution to the hidden-line-problem. If you imagine the surfaces I and
II as outer surfaces of a block, then SI is the front surface and SI I the
rear surface of the block. The observation point is still on the negative Z
axis. SI I is not visible from the observation point since it is hidden by
the other surfaces.
58
Abacus Software ST 3D Graphics
You can see that the description of the surface is always done in the
clockwise direction from outside the cube and looking toward the current
surface center. For the definition of the surface one wanders around the
object to be described and determines the direction of the connection
lines of the points belonging to the surface. As one can see in the next
illustration, the visibility of the surfaces can be determined through the
direction of the connection lines with a little vector algebra.
To do this, start from any point on the surface and form the vector to the
next point
P= [px,py,pz] = [p2x-plx,p2y-ply,p2z-plz] ,
PI,S[sx,sy,sz] = [ax-plx,ay-ply,az-plz].
The direction of this vector results from the system in which the vector
product was performed. In the left coordinate system used here, the
vector d points in the same direction in which a screw with a left-handed
thread would move from P to Q when turned, that is, it points with
surface I in the direction of the positive Z axis and with surface II in the
direction of the negative Z axis.
Now we can say this about the visibility of surface I: if the vectors S and
R are pointing in the same direction, the surface is visible from the
observation point. If the vectors S and R point in different directions, the
surface is not visible. As mentioned earlier, this process is limited to
closed convex bodies, but the error is not very large with concave bodies.
59
ST 3D Graphics Abacus Software
60
Abacus Software ST 3D Graphics
Figure 2.7.5
61
ST 3D Graphics Abacus Software
Figure 2.7.6
Figure 2.7.7
62
Abacus Software ST 3D Graphics
The error with concave bodies is that surfaces which are visible from the
observation point are hidden by other surfaces but are not recognized.
Now only the "direction comparison criterium" between two vectors is
missing. This is accomplished by the scalar product of two vectors
(S *R) which is defined as follows:
cos(alpha) > 0
Figure 2.7.8
63
ST 3D Graphics Abacus Software
64
Abacus Software ST 3D Graphics
You probably want to know what computer graphics and a painter who
died in 1669 have in common. An oil painting is created from back to the
front, that is to say, the painter first draws the background and then
objects are placed further to the front simply by covering the background
with oil paint. This method, carried over to the computer, is another
solution of the hidden surface problem. A middle Z coordinate is
calculated for each surface and, as an example, all Z coordinates of the
comer points can be added and divided by the number of comer points
which are stored for the surface. Then the surfaces are sorted according to
size and drawn from the largest to the smallest Z coordinates.
To insure that the surfaces which are painted over have really been
covered, we can’t just to draw the outer lines of the surface. It is
necessary to fill the surfaces with color. The surface construction from
the back to the front is shown in the following illustrations.
Figure 2.8.1
65
ST 3D Graphics Abacus Software
Figure 2.8.2
Figure 2.8.3
66
Abacus Software ST 3D Graphics
ST 3D Graphics Abacus Software
Figure 2.8.6
Figure 2.8.7
68
Abacus Software ST 3D Graphics
Figure 2.8.8
Of course, the two methods for the removal of hidden surfaces can be
combined. First the visible surfaces can be determined through scalar
products. Followed by sorting the surfaces according to descending Z
coordinates, and then drawing them.
69
ST 3D Graphics Abacus Software
In general, there are two types of illumination, direct and indirect. With
indirect illumination the intensity of the light is equal on all places in
space. The indirect light is created through diffuse reflection from other
objects, such as walls and ceilings. The appearance of an object in space
under this illumination is dependent only on the reflection coefficient of
the object. This reflection coefficient is the relationship of reflected light
rays to the total striking the surface. Its value runs from zero for a black
body (all light rays which strike are absorbed) and one for a white body
(all light rays which strike are reflected). A body whose reflection
coefficients are between zero and one is designated as a gray body. A
reflection coefficient R can be given for every surface which determines
the intensity of the surface.
with the reflection coefficient R and the intensity of the direct light source
DL, which is between zero and one.
70
Abacus Software ST 3D Graphics
71
r
Machine Language Fundamentals
for Graphic Programming
Abacus Software ST 3D Graphics
75
ST 3D Graphics Abacus Software
Before starting a project in machine language, you should think about the
number format to be used. For all the following applications we can
perform all calculations with 16-bit integers. Another problem is the sine
function, whose function values can range from -1 and +1. The function
values can be approximated on computers using the Taylor series, which
approximates the exact function value through repeated summation of the
terms of a sequence. In practice, the summation can be terminated after 3
or 4 terms. As an example, we have here the Taylor series for the sine
function.
The accuracy can be set as desired since the function values are
calculated before the actual program application and the time factor does
not play a role. In our example, all sine values between 0 and 360 degrees
are entered in steps of one degree. This is quite adequate for almost all
applications which require trigonometric functions. Should an
intermediate value be required, it can be interpolated from the table.
Since the cosine function is the same as the sine function shifted by 90
degrees, the cosine functions can also be taken from the sine table.
The function values of the angle functions are real numbers which are
floating point numbers with several places after the decimal point. Since
all our calculations involve only integers, it is necessary to transform the
values of the sine function. This is done by multiplying by a sufficiently
large number-in our example with 214 = 16384.
76
Abacus Software ST 3D Graphics
The length of the line c and the angle alpha are already known, and we
want to find the length of b. According to the definition of the angle
function, the length of the distance =c* sin (a) = 20*sin(45). The
sine of 45 degrees is 0.707106781 with nine-place precision. In our table
we have the value 0.707106781 * 16384 = 11585 for 45 degrees. After
multiplying by 20 we got the number 231700 as a result. We don’t have
to worry that this number will exceed the value range of 16-bit integer
arithmetic because the processor always produces a 32-bit product as the
result of a 16-bit multiplication. This 32-bit result, the number 231700,
can now be adapted to the original value range by dividing by 16384, and
we get 14 as the result.
You may ask yourself why 16384 was used for the multiplication: first of
all the number is large enough to extend the range of the sine function.
Numbers between -1 and 1 become numbers between -16384 and
+ 16384. Second, the multiplication can be performed with two very fast
commands of the processor. Multiplications by a multiple of two can be
replaced in all microprocessors with shift commands which don’t take
much more time than an addition.
77
ST 3D Graphics Abacus Software
At this point I would like to briefly discuss the possibilities of the table
representation in the computer. The sine table is the simplest form of a
table, a linear list. The individual table values are stored sequentially in
memory. Our sine table for the first values looks like this:
Since the gradations of the angles are in 1 degree steps, the first table
value gives the sine of 0 degrees, the second the sine of one degree, the
third the sine of two degrees, etc. The 91st table value is the sine of 90.
table value and the sine of 360 degrees is represented by the 361st value.
Zero is chosen as the start to match the table numbers to the
corresponding angle. This means that table value zero represents the sine
of zero degrees. Value number 90 corresponds to 90 degrees and 180 to
180 degrees. The 68000 computer makes access to this table very easy
through its excellent addressing capabilities. The initial address of the
table is loaded into the address register. This is the address where the zero
element is stored. With the number of the desired table value in a data
register it is possible to access the location using the addressing mode
"address register indirect with index." In this table format it is absolutely
necessary to pay attention to the data length of individual entries. The
address of the zero value is equal to the beginning address of the table
plus zero, but the address of the first value is the beginning address of the
table plus two, since each value occupies two bytes. This means that the
index number in the data register must be multiplied by the number of
bytes for one entry. In this case it is two bytes. This multiplication by two
is very fast with one left shift of the bits in the index number.
78
Abacus Software ST 3D Graphics
$780A0
$780F0 $780F1
1 r
Figure 3.2.1
The only routines required for screen manipulation are those for
displaying a point and for drawing and erasing lines. A line of the video
picture is formed from 80 bytes and the total picture is made up of 400
lines. The address of a picture point can be calculated as follows:
79
ST 3D Graphics Abacus Software
The bit number of the byte can be obtained with the following formula:
number = 7 - (X MOD 8)
The function I NT truncates the positions after the decimal point of a real
number, while the function MOD returns the remainder of the operand by
the second. For example, 9 MOD 2 returns 1 as the result Screen start is
the starting address of the screen memory, which is $78000 on the 520 ST
and 8F8000 on the 1040 ST
80
Abacus Software ST 3D Graphics
Xi
Figure 3.2.2
Starting from point PI, you have the problem of deciding which points
must be set, in order to reach point P3. Note that it is possible to set the
points only at the intersections of the raster lines. The line is formed when
either the X coordinate is retained and a point drawn with an incremented
Y coordinate or you can increment the X coordinate while the Y
coordinate retains its value.
m = dy / dx
81
ST 3D Graphics Abacus Software
Figure 3.2.3
See Figure 3.2.4 for an explanation of the algorithm for drawing of lines.
82
Abacus Software ST 3D Graphics
Figure 3.2.4
83
ST 3D Graphics Abacus Software
D = (dy/dx)-(wy/wx)
D*dx*wx = (wx*dy)-(wy*dx)
D = (wx*dy) - (wy*dx)
ND = (wx+l)*dy - wy*dx
ND = wx*dy + dy - wy*dx
ND = wx*dy - (wy+l)*dx
ND = wx*dy - wy*dx - dx
Step in Y direction ND = D - dx
Step in X direction ND = D + dy
84
Abacus Software ST 3D Graphics
Furthermore, we have only considered lines with a positive slope, that is,
those where py3 is smaller than pyl. To retain the decision method in
this form, it is necessary to make negative dx and dy values positive
through multiplication with -1, and to decrease the X and Y coordinates
by one instead of increasing them for every step in the X or Y direction.
The algorithm for drawing a line between the points PI [xl, yl] and
P 3[x3,y3] appears like this in a structogram:
85
ST 3D Graphics Abacus Software
86
Abacus Software ST 3D Graphics
Since we will use only operating system functions for the 3-D graphics
programming, some should be explained before they are used. One of
these functions is the routine for switching the beginning address for the
video controller. All computers which which can display animated
graphics quickly and flicker free have the ability to work with two logical
screen pages internally.
Fast drawing and erasing of objects on the screen and the rapid accesses
to the screen RAM by the computer and the video controller, causes the
monitor picture to be unstable and to flicker. If the hardware has the
ability to tell the video controller where in RAM the screen memory
starts, the strategy for the creation of flicker free graphic is very simple.
87
ST 3D Graphics Abacus Software
The called program can calculate the memory actually required and
declare the unused area as vacant to the operating system. Note:
sufficient space must be reserved for the processor stack. From the
Digital Research documentation, it is not clear how much stack space is
required for the GEM functions, but the 4K bytes reserved for this
purpose in the example should be sufficient for all purposes. To make it
possible to use all GEM functions, it is recommended that the program
call the functions Application-Init and then Open-Virtual-
Workstation when it starts. After these two calls, GEM-DOS, the
BIOS, Extended-BIOS and the AES and VDI functions are available to
the program. An overview of these functions are available in the two
Abacus Software books Atari ST Internals and the large Atari ST GEM
Programmer’s Reference.
All programs in this book were written using the assembler from Digital
Research. For users of other home computers the assembler is probably
new, and so I want to discuss it briefly. The assembler is completely disk
oriented, i.e. all input and output comes from and goes to the diskette.
First you create the source text of the program with an editor, store it on a
diskette and call the assembler with name of the source text The
assembler processes the source text by creating several auxiliary files on
the diskette. Finally it writes the desired object file on the diskette.
88
Abacus Software ST 3D Graphics
which then creates the desired run-time program file. In this you can
write manner machine language programs whose length is limited only by
the storage capacity of the computer and the floppy disk. It is impossible
to combine two programs which are already object files with this method,
however.
For this reason, one usually adds an intermediate step, as is also done
with higher level languages, called linking. The linker permits several
separately-assembled object files to be combined into one single file.
89
ST 3D Graphics Abacus Software
To assemble and link the main program, it is best to create a batch file,
which contains the individual command sequences. The batch file could
look like this:
as68 -1 -u %2. s
wait.prg
link68 [u] %2.68k=%l.o,%2.o
relmod %2.68k %2.prg
rm %2.68k
rm % 2.o
wait.prg
This batch file might be stored under the name aslink.bat on the
diskette. The batch file is made very flexible through the use of two place
holders, %1 and %2. To assemble the main program with the name
mainl. s and the subsequent linking with the basic module basicl. o
You call the program batch.ttp and pass the command sequence in
the dialog box:
As a practical test of all this, we have here the first version of the
basicl. s program and the first demo program. The basic program
contains only the initialization of the program and the basic routines for
screen manipulation such as screen erasing, and drawing of points and
lines. Assembly is done with:
as68 -1 -u basicl.s
90
Abacus Software ST 3D Graphics
The file mainl. prg can be started by clicking with the mouse after the
file Relmod, the two files mainl. o and mainl. 68k, which are no
longer needed, are erased with the program RM.
91
ST 3D Graphics Abacus Software
***********************************************************************
* Link file basicl.s, is linked with the main program whose entry *
* routine must have the name main. *
* U.B. 11.85 *
***********************************************************************
.globl wait,wait1,drawl,ddrawl,inlinea
.globl grafhand
•globl grhandle
.globl global,contrl,intin,intout,ptsin,ptsout,addrin,addrout
.globl apinit,openwork,clwork,aes,vdi
.globl inkey
.globl mouse_on,mouse_off,printf
.text
*******************
* Entry to the program, initialization of all operating system *
* functions and creation of the Y-tables (For computers with color *
* monitors, replace "jsr startl" with "jsr start2". *
* Furthermore when using a color monitor/ replace all *
* "jsr drawl" calls in the main program with "jsr ddrawl".
**********************
92
Abacus Software ST 3D Graphics
trap #1
add. 1 #12,sp ★ old stack address restored again
********************************************************************
* Call a AES-Routine, where the parameters are passed to *
* to the various arrays (contrl,etc.) *
********************************************************************
************************************************************************
* Call a VDI-Routine *
ft********************************************************************
**********************************************************************
* Announce the program *
**********************************************************************
93
ST 3D Graphics Abacus Software
***********************************************************************
* Check on screen handler and store for other functions *
***********************************************************************
***********************************************************************
* Open a Virtual Screen Work Station where all GEM drawing functions *
* will occur. *
***********************************************************************
move.w #0,contrl+2
move.w #11,contrl+6
move.w dO,intin+2
move.w dO,intin+4
move.w dO,intin+6
move. w dO,intin+8
move.w dO,intin+10
move. w dO,intin+12
move.w dO,intin+14
move.w dO,intin+16
move.w dO,intin+18
move.w #2,intin+20
jsr vdi
rts
94
Abacus Software ST 3D Graphics
*'*******★★*******★***★**★★★**’***★***★*★★**★**★***★**★★**★★★★★*******★★*
* Clear the workstation *
***********************************************************************
move.w #1,contrl+6
move.w grhandle,contrl+12
jsr vdi
rt s
move.w #1,contrl+6
move.w grhandle,contrl+12
move.w #0,intin
jsr vdi
rts
***********************************************************************
* Turn off the mouse and control. *
***********************************************************************
move.w #0,contrl+6
move.w grhandle,contrl+12
jsr vdi
rts
95
ST 3D Graphics Abacus Software
********************************* *************************************
*
* Write a string on the screen
********************************* *************************************
rts * zero.
rts * down to -1
trap #1 * GEM-DOS-Call
addq.1 #2,a7
rts
* Sense keyboard status (does not wait for keypress) and return key *
inkey: move.w #2,-(a7) ★ Sense keyboard, does not wait for key
addq.1 #4,a7 ★ of the long word of DO, and the scan code
endkey ★ DO.
bpl
move.w #7,-(a7)
trap #1
addq.1 #2,a7
endkey: rts
96
Abacus Software ST 3D Graphics
e********************************************************************
* Draw-line-routine, draws directly into the screen storage and is *
* used only for the high resolution mode {640*400 Points ). For color *
************************************ **********************************
clr. 1 d4
move. w a2,d6
sub. w d2,d6 * DX in d6 = X2 - XI
bge dxispos
sub.w d3,d7 * DY in d7
bra plotit
tst. w d3
bmi draw_it
cmp. w #639,d2
bhi draw_it
cmp. w #399,d3
bhi draw_it
not. w dO * -X
97
ST 3D Graphics Abacus Software
**********************************
* Here the point is drawn *
**********************************
bset dO, 0(al,dl.w) * 7-(X MOD 8) with the bset-command
bne notend * no
beq endit * no
★ D > 0 => Y step
notend: tst .w d4
bge ystep
add. w d7,d4 ★ ND = D + DY
bra plotit
sub. w d6, d4 * ND = D - DX
bra plotit
drawend:
* restore register
endit: movem. 1 (a7)+,d7
**********************************************************************
* This Draw-line-routine is universal for all monitor types and *
move.1 d7,-(a7)
move.1 tlineavar,aO
move.w d3,40(aO) * Yl
move.w a3,44(aO) * Y2
move.1 (a7)+,d7
rts
98
Abacus Software ST 3D Graphics
**********************************************************************
* Initialize the Line-A variables and store the address of the *
move.1 aO,lineavar
rts
startl:
addq. 1 #2,a7
dbra dl,stloopl
rts
* Line-A initialization *
rts
99
ST 3D Graphics Abacus Software
********************************************************************
* Variables of the basic program *
********************************************************************
.even
.bss
lineavar: .ds. 1 1 * Storage for address of Line-A variable
physbase: .ds. 1 1 * Storage for screen address.
global:
apversion: .ds.w 1
apcount: .ds.w 1
apid: -ds.w 1
apprivate: .ds. 1 1
apptree: .ds. 1 1
aplresv: .ds.l 1
ap2resv: .ds. 1 1
ap3resv: .ds.l 1
ap4resv: .ds.l 1
.data
vdipb: .dc. 1 contrl,intin,ptsin,intout,ptsout
aespb: .dc. 1 contrl,global,intin,intout,addrin,addrout
.end
100
0
Abacus Software ST 3D Graphics
***********************************************************************
* Main program for link file basicl.o , runs only in connection with *
* this link file . U.B. 11.85
* Draws random line in coordinate area 0-255. The value area
.globl main
.text
*
* Entry point from the linkfile
move.1 loopc,d7
and. w border,dO
move. w dO, yO
jsr random
and. w border,dO
move.w dO, xl
jsr random
and.w border,dO
move.w d0,yl
move.w y0,d3
101
ST 3D Graphics Abacus Software
move.w yl,a3
jsr drawl * Draw line from XO,YO to XI,Y1 sketch
***********************************************************************
* Call the operating system function for creation of a 4-byte integer*
* random number, the number is returned to DO. *
***********************************************************************
.data
.even
**********************************************************************
* Variables for the Main program *
* *
**********************************************************************
**********************************************************************
* Text for the printf function, 27 Y 34 96 positions the cursor *
* Sequence is column, line, both with an offset of 32 *
**********************************************************************
102
Abacus Software ST 3D Graphics
**********************************************************************
.bss
.even
.end
103
Abacus Software ST 3D Graphics
The programs presented in the following part of the book can be used
with monochrome as well as color monitors, since the line drawing is
performed by the operating system, or to be more accurate, by the LINE-
A-routines. Of course it would be possible to convert the draw-line-
algorithm from the first link file for the various picture formats, but this
process has the disadvantage of requiring a subroutine for every picture
format. The programs described here can be executed on all kinds of
computer-monitor combinations. During program start, the main program
recognizes what type of monitor is attached and what resolution is desired
and on the basis of this information provides some variables with the
required data. For example, the coordinate origin of the picture system is
placed in the middle of the display. The larger memory capacity of the ST
permits it to handle significantly larger quantities of data. Once the
operating system of the smaller models is placed in ROM, the area
released in RAM will be sufficient even for the largest applications.
When calling the Metacombco Editor for input of the larger source files
(grlinkl, menul, rotatel, paintl) you have to specify
more memory space for listing to be entered along with the filename. To
do this, enter grlinkl. s 23000 in the dialog box that appears. This
reserves about 80k for the source text. If you enter source text without
comments the space reserved in the basic version of the editor should be
sufficient.
107
ST 3D Graphics Abacus Software
The program modules presented here have the ability to represent on the
screen any object in a user defined world in any position, as seen from
various positions. The single disadvantage is the limitation of the valid
value range to ±32000; this means that for the definition of the world a
right angle three dimensional Cartesian coordinate system (right system)
is available whose three coordinate axes (X-Y-Z) are labeled with values
between +32000 and -32000. Whether these values are in meters,
kilometers or the number of corrupt politicians in the Senate depends on
the individual user and the application. For example, using the number of
corrupt politicians is a questionable value, since it changes from moment
to moment, and is far from constant.
Joking aside, a very simple object should suffice to describe the data
structure. We will use simple house as in Figure 4.1.1.
108
Abacus Software ST 3D Graphics
The individual steps during the "construction” of the house therefore are:
109
ST 3D Graphics Abacus Software
2. Draw the object in the various possible aspects with the current
coordinate axis for accurate specification of the points.
110
Abacus Software ST 3D Graphics
ill
ST 3D Graphics Abacus Software
Figure 4.1.6
Figure 4.1.7
112
Abacus Software ST 3D Graphics
Figure 4.1.9
113
ST 3D Graphics Abacus Software
1. -30 30 60
2. 30 30 60
3. 30 -30 60
4. -30 -30 60
5. 30 30 -60
6. -30 30 -60
7. -30 -30 -60
8. 30 -30 -60
9. 0 70 60
10. 0 70 -60
11. -10 -30 60
12. -10 0 60
13. 10 0 60
14. 10 -30 60
15. 30 20 40
16. 30 20 10
17. 30 0 10
18. 30 0 40
19. 30 20 -10
20. 30 20 -40
21. 30 0 -40
22. 30 0 -10
23. 30 -10 0
24. 30 -10 -20
25. 30 -30 -20
26. 30 -30 0
Total of 26 points.
114
Abacus Software ST 3D Graphics
Line list:
1. 1 2
2. 2 3
3. 3 4
4. 4 1
5. 2 5
6. 5 8
7. 8 3
8. 8 7
9. 7 6
10. 6 5
11. 6 1
12. 7 4
13. 9 10
14. 1 9
15. 9 2
16. 5 10
17. 6 10
18. 11 12
19. 12 13
20. 13 14
21. 15 16
22. 16 17
23. 17 18
24. 18 15
25. 19 20
26. 20 21
27. 21 22
28. 22 19
29. 23 24
30. 24 25
31. 25 26
32. 26 23
Total of 32 lines.
115
ST 3D Graphics Abacus Software
To help explain the coordinate systems and viewing points, we have here
Figure 4.1.10 with the world system and the observation factors defined
in it.
116
Abacus Software ST 3D Graphics
Figure 4.1.10
Summary:
117
ST 3D Graphics Abacus Software
118
Abacus Software ST 3D Graphics
As you will see, all transformations can be carried out with a single
routine. Our application combines almost all of the rotations with matrix
multiplication and performs displacements before and after these
multiplications. The displacements are not included in the matrix
multiplications and our point coordinates are therefore not extended
119
ST 3D Graphics Abacus Software
In this model the axes are not scaled. The size manipulation of the
objects, i.e. their pictured size on the screen, is performed during the
projection through movement of the projection plane. If different values
are selected for the subtraction occurring at the beginning and the
concluding addition, the movement of an observer in the world system is
simulated. If the angles of the normal surface vector in relation to the
world system are provided (in section 2.5 we calculated the angles
through projection on the various surfaces) the position of the observer
can be determined in space through one point and three angles.
Let us assume that a person is moving our world system, where the house
discussed in the first example is located at the coordinate origin. The eye
of this person, or actually the retina of the eye, is the projection plane. It
is irrelevant that the projection center in the human eye is in front of the
projection plane, since the reversed picture resulting from this is turned
around by the brain. For the simulation of this moving observer the
120
Abacus Software ST 3D Graphics
coordinate origin of the world system must be moved to the center of the
retina, but we are limiting ourselves to a single eye. The coordinates of
the eye in the world system must be known; furthermore the head of the
observer can be moved through three different axis. You can easily
determine the axis yourself. The rotation about the first axis in our
coordinate system corresponds to the X axis, described by the observer
nodding his head up and down. The Y axis rotation is shaking his head.
The head rotates on the Z axis when the observer attempts to touch his ear
to his shoulder. If the three rotaion angles are known, the coordinate
origin will be rotated about this angle and the observed object lies in the
coordinate system of the observer. It is not necessary to reverse the
movement of the coordinate origin which is similar to the example of the
airplane.
And now, the description of the transformations of our data structure for
the first, fairly simple transformation program. The concrete object
(house) is defined in a coordinate system (housdatx, housdaty,
housdatz). During the initialization of the program, the subroutine
makewrld moves the house to any desired location in the world system
(wrldx, wrldy, wrldz), with possible rotation. In the first program it
is moved to the point [0,0,0] without rotation.
All further operations concerning the house relate only to the world
system. For example, the house can be rotated around any point of this
world system, or only the position of the house can be changed by
displacement. But now the initial scenario of our model changes through
these transformations, so we store the data for the rotation of the world
system in a new coordinate system (viewx, viewy, viewz), where
the initial scene (in wrldx, wrldy, wrldz) is available at any time
and can be reproduced at any time.
121
ST 3D Graphics Abacus Software
In case you did not understand a few details, you can relax while typing
in the following program listings. You should consider that the material
discussed here corresponds to about a half a semester of lectures for
upper-class computer science students and therefore requires intense
consideration, even with the aid of the additional literature cited in the
beginning.
Just as in the first small program (random lines) this program is also
divided into a link file and main program. The new link file has the name
grlinkl. s and was enhanced with the sine and cosine routines, the
clip algorithm, the screen switch routine, the matrix operations and the
perspective transform routine. The main program housel.s contains
the data of the house and the main loop in which the rotation angles of the
house are changed in cycle and can be altered by the user. The steps for
creating a ready-to-run program are the same as in the third chapter. You
need only to replace basicl. s with grlinkl. s and mainl. s with
house 1. s in the command sequences. You should start typing in the
first program since the following programs build on the first two files.
That way you only have to type in the additional subroutines and data
sections. The link file grlinkl . s is the same for all following main
programs and does not have to be changed.
122
Abacus Software ST 3D Graphics
***********************************************************************
* grlinkl.s Graphic Driver Version 4.0 *
* The main program must begin with the label " main *
***********************************************************************
***********************************************************************
.globl drawl,sin,sincos,physbase
.globl logbase
.globl sinx,siny,sinz,cosx,cosy,cosz,wait
.globl waitl,drawnl
.globl pers,grafhand
•globl nummark,xangle,yangle,zangle,numline,datx,daty,datz
.globl pointx,pointy
.globl pointz,xplot,yplot,xO,yO,zO,zl,linxy,sincos
.globl grhandle,global,contrl,intin,intout,ptsin,ptsout
.globl addrin,addrout
.globl apinit,openwork,clwork,aes,vdi
.globl rotate,dist,zobs
.globl matrixll,matrixl2,matrixl3
.globl matrix21,matrix22,matrix23
.globl matrix31,matrix32,matrix33
.globl xrotate,yrotate,zrotate,matinit,inkey
.globl mouse_on,mouse_off,printf
.globl clipxule,clipyule,clipxlri,clipylri
.globl filstyle,filindex,filform,filcolor,filmode,yrot
.globl lineavar,pageup,pagedown,plotpt
123
ST 3D Graphics Abacus Software
********************************************************************
* Program initialization and storage requirement calculations *
********************************************************************
.text
sstart:
trap #1
***********************************************************************
* Pass upper screen page to video controller *
trap
add. 1 #12,a7
rt s
124
Abacus Software ST 3D Graphics
***********************************************************************
* Display screen page at lower address, while all drawing *
move. w #5,-(a7)
trap Pb
add. 1 #12,a7
rts
***********************************************************************
* This subroutine calls AES functions, the user must *
* save the Registers D0-D2 and A0-A2 before the aes call, *
move.w #$c8,dO
trap
rts
dp
* call the VDI functions *
move.w #$73,dO
trap (^#2^?
rts
125
ST 3D Graphics Abacus Software
***********************************************************************
* initialize the Line-A functions, pass the address of *
* in lineavar *
***********************************************************************
.dc.w $a000
move.1 aO,lineavar
move. w #0,32(aO)
move.w #$ffff,34(aO)
rts
* announces application *
move. 1 dO,aplresv
move.1 dO,ap2resv
move.1 dO,ap3resv
move.1 dO,ap4resv
move.w #10,opcode
move.w #0,sintin
move.w #1,sintout
move.w #0,saddrout
move.w #0,saddrin
jsr aes
rts
A**********************************************************************
* Transfers desktop screen handler to caller *
***********************************************************************
move.w #0,contrl+2
move.w #5,contrl+4
move.w #0,contrl+6
move.w #0,contrl+8
126
Abacus Software ST 3D Graphics
jsr aes
move.w intout,grhandle
rts
* open a workstation *
move.w #1, dO
move.w #0,contrl+2
move.w #11,contrl+6
move.w grhandle,contrl+12
move.w dO,intin
move.w dO,intin+2
move.w dO,intin+4
move.w dO,intin+6
move.w dO,intin+8
move.w dO,intin+10
move.w dO,intin+12
move.w dO,intin+14
move.w dO,intin+16
move.w dO,intin+18
move„w #2,intin+20
jsr vdi
rts
move.w #0,contrl+2
move.w #1,contrl+6
move.w grhandle,contrl+12
jsr vdi
rts
127
ST 3D Graphics Abacus Software
* Enable mouse *
move.w grhandle,contrl+12
move.w #0,intin
jsr vdi
rts
* Disable mouse *
move.w #0,contrl+6
move.w grhandle,contrl+12
jsr vdi
rts
start 1:
128
Abacus Software ST 3D Graphics
sub. 1 #$8000,dO
rts
************************************************************************
* Plot routine x-coordinate in d2, y-coordinate in d3 *
************************************************************************
bmi stop2
bmi stop2
bhi stop2
move .w d2,ptsin
move. w d3,ptsin+2
move. w #1,intin
.dc. w $a001
stop2: rts
**********************************************************************
* draw-line routine with Cohen-Sutherland clipping. The points are *
move.w dl,codel
jsr rel_pos
move.w dl,code2
129
ST 3D Graphics Abacus Software
move.w a3, a5
move.w code2,plcode
move.w codel,p2code
130
Abacus Software ST 3D Graphics
move. w d3,lefty
clr. 1 a2
clr. 1 a3
move. w rightx,a2
move.w righty,a3
d2,38 <a0) * XI
move. w
d3,40 (aO) ★ Y1
move.w
a2,42(aO) * X2
move.w
* Y2
move.w a3,44(aO)
drawend:
**********************************************************************
* recognizes the position of a point passed in D6 and D7 relative *
neg. w dl
lsl.l #1, dl
move.w d6, dl
sub. w clipxlri,dl
neg. w dl
lsl.l #1, dl
move.w d6, dl
sub. w clipxule,dl
lsl.l #1, dl
131
ST 3D Graphics Abacus Software
swap dl
rts
**********************************************************************
* Finds the intersect point, if present, *
ext .1 d4
lsr. 1 #l,d4
lsr. 1 #l,d5
move.w d4,d6 * Store center point coord.
bne findwl
cmp.w d5,d3
cmp. w d5,a3
bne findw2
132
Abacus Software ST 3D Graphics
move. w dl,plcode
bra fndpoint
bne fotherl
cmp. w d5, a3
bne fother2
cmp. w d5,d3
* if yes, then end
beq fendit
beq fother3
fndpoint * is found
bra
******************************************************************
* sine and cosine Function, angle is passed in DO and
bpl noaddi
add.w #360,dO
133
ST 3D Graphics Abacus Software
bra sendsin
*
rt s * and back to calling program
* sine function *
t st • w dO
bpl sinl
add.w #360,dO
move.w 0(al,dO.w)
rts
************************************************************************
* Initialize the main diagnonal of the result matrix with *
move.w #0, dl
move. w d2,matrix22
move.w dl,matrix23
move.w dl,matrix31
move . w dl,matrix32
134
Abacus Software ST 3D Graphics
move.w d2,matrix33
rts
************************************************************************
* Multiplication of the rotation matrix by the rotation
* matrix for rotation about the X-axis
************************************************************************
move. w d2,cosx
move.w dl, d3
move.w d2,d4
move.w matrix31,rotx31
muls matrixl2,d2
mu Is matrixl3,dl
sub. 1 dl, d2
lsl.l #2,d2
swap d2
move. w d2,rotxl2
move. w d3, dl
move. w d4,d2
muls matrix22,d2
muls matrix23,dl
sub. 1 dl, d2
lsl.l '#2,d2
swap d2
move.w d2,rotx22
move.w d3,dl
move.w d4,d2
muls matrix32,d2
muls matrix33,dl
sub. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotx32
move.w d3, dl
135
ST 3D Graphics Abacus Software
move. w d4,d2
mu Is matrixl2,dl
mu Is matrixl3,d2
add. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotxl3
move. w d3, dl
move. w d4,d2
mu Is matrix22,dl
mu Is matrix23,d2
add. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotx23
muls matrix32,d3
mu Is matrix33,d4
add. 1 d3,d4
lsl.l #2,d4
swap d4
move.w d4,rotx33
move. 1 irotxll,al
move.1 #matrixll,a2
subq.1 #1, d7
rts
***********************************************************************
* multiply the general rotation matrix by the Y-axis *
* rotation matrix *
***********************************************************************
jsr sincos
move .w dl,siny
move.w d2,cosy
136
Abacus Software ST 3D Graphics
mu Is matrixll,d2
mu Is matrixl3,dl
add. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotxll
move.w d3, dl
move.w d4, d2
mu Is matrix21,d2
mu Is matrix23,dl
add. 1 dl,d2
lsl.l #2,d2
swap d2
move.w d2,rotx21
move.w d3,dl
move.w d4, d2
muls matrix31,d2
muls matrix33,dl
add. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotx31
neg.w d3
move .w d4,d2
move. w matrixl2,rotxl2
add. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotxl3
move.w d3,dl
move.w d4,d2
muls matrix21,dl
muls matrix23,d2
add. 1 dl,d2
lsl.l #2,d2
swap d2
move.w d2,rotx23
137
ST 3D Graphics Abacus Software
muls matrix31,d3
muls matrix33,d4
add. 1 d3,d4
lsl.l #2,d4
swap d4
move.w d4,rotx33
move.1 #8, d7
move.w zangle,dO
jsr sincos
move.w dl,sinz
move.w d2,cosz
move.w dl,d3
move.w d2, d4
muls matrixll,d2
muls matrixl2,dl
sub. 1 dl, d2
lsl.l #2,d2
swap d2
move.w d2,rotxll
move.w d3, dl
move.w d4,d2
muls matrix21,d2
muls matrix22,dl
sub. 1 dl, d2
lsl.l #2,d2
swap d2
move. w d2,rotx21
move. w d3, dl
move.w d4,d2
muls matrix31,d2
muls matrix32,dl
sub. 1 dl, d2
138
Abacus Software ST 3D Graphics
lsl.1 #2,d2
swap d2
move.w d2,rotx31
move.w d3, dl
move.w d4, d2
mu Is matrixll,dl
mu Is matrixl2,d2
add. 1 dl,d2
lsl.l #2, d2
swap d2
move.w d2,rotxl2
move.w d3, dl
move. w d4,d2
mu Is matrix21,dl
mu Is matrix22,d2
add. 1 dl, d2
lsl.l #2, d2
swap 42
move. w d2,rotx22
mu Is matrix31,d3
mu Is matrix32,d4
add. 1 d3,d4
lsl.l #2,d4
swap d4
move.w d4,rotx32
move . 1 #8,d7
move.1 trotxll,al
move.1 #matrixll, a2
rts
139
ST 3D Graphics Abacus Software
move.1 datx,al
move.1 daty,a2
move.1 datz,a3
move.1 pointx,a4
move.1 pointy,a5
move.1 pointz,a6
rotatel: move.w (al)+,dl * X-coordinate
add.w offx,dl
move.w dl, d4
move.w d3,d6
muls matrixll,dl
mu Is matrix21,d2
muls matrix31,d3
add. 1 dl, d2
add. 1 d2,d3
lsl.l #2,d3
swap d3
add.w xoffs,d3
move.w d5,d2
move.w d6,d3
muls matrixl2,dl
Abacus Software ST 3D Graphics
mu Is matrix22,d2
mu Is matrix32,d3
add. 1 dl,d2
add. 1 d2,d3
lsl.l #2,d3
swap d3
add. w yoffs,d3
mu Is matrixl3,d4
mu Is matrix23,d5
mu Is matrix33,d6
add. 1 d4,d5
add. 1 d5, d6
lsl.l #2,d6
swap d6
add. w zoffs,d6
dbra dO,rotatel
rts
************************************************************************
* Perspective, calculated from the transformed points in the arrays *
move.1 pointz,a3
ext .1 dO * as counter
subq.1 #1, dO
move.w d5,d6
141
ST 3D Graphics Abacus Software
ext. 1 d4
ext. 1 d3
bne persl
move.w dl,(a5)+
bra perendl
move.w d4,d3
move.w dl,d2
neg. w dl
move.w dl, d2
neg. w dl
muls dl, d4
add. w d4,d2
rt s ★ If yes, return
142
Abacus Software ST 3D Graphics
•dr*****************************************************************
* Draw number of lines from array from lines in linxy *
******************************************************************
ext .1 dO
subq.w #1, dl
lsl.w #1, dl
rts
***********************************************************************
* simple counting loop *
***********************************************************************
rts * down to -1
***********************************************************************
* wait for key press, for Test and Error detection *
***********************************************************************
addq.l #2,a7
rts
143
ST 3D Graphics Abacus Software
***********************************************************************
* Key sensing, ASCII code returned in lower byte word of DO *
addq.1 #4, a7
tst. w dO
bpl endkey
move.w #7,-{a7)
trap #1
addq.1 #2,a7
endkey: rts
move. w #1,contrl+6 ★ in DO
move. w grhandle,contrl+12
move. w dO,intin
jsr vdi
rts
move.w #0,contrl+2
move.w #1,contrl+6
move -w grhandle,contrl+12
move.w dO,intin
144
Abacus Software ST 3D Graphics
jsr vdi
rts
move. w #0,contrl+2
move. w #1,contrl+6
move.w grhandle,contrl+12
jsr vdi
rts
move.w #0,contrl+2
move.w #1,contrl+6
move.w dO,intin
jsr vdi
rts
move.w #1,contrl+6
move.w grhandle,contrl+12
move.w #1,intin
jsr vdi
rts
*********************************************************************
* Rotation of a number of points (nummark) in array datx etc. around*
145
ST 3D Graphics Abacus Software
move . w nummark,dO
move.w (a3)+,d2
mu Is cosy,d2
mu Is siny,dl
lsl.l #2, dl
swap dl
add. w dl,d2
swap d4
neg. w d4
mu Is cosy,d3
lsl.l #2,d3
swap d3
add. w d3,d4
rts
• even
.data * Sine table starts here
.dc. w 2563,2845,3126,3406,3686,3964,4240,4516
. dc. w 4790,5063,5334,5604,5872,6138,6402,6664
146
Abacus Software ST 3D Graphics
.dc.w 6924,7182,7438,7692,7943,8192,8438,8682
. dc. w 8923,9162,9397,9630,9860,10087,10311,10531
.dc.w 10749,10963,11174,11381,11585,11786,11982,12176
.dc.w 12365,12551,12733,12911,13085,13255,13421,13583
.dc.w 13741,13894,14044,14189,14330,14466,14598,14726
.dc.w 14849,14962,15082,15191,15296,15396,15491,15582
.dc.w 15668,15749,15826,15897,15964,16026,16083,16135
• dc.w 16182,16225,16262,16294,16322,16344,16362,16374
.dc.w 16382,16384
.dc.w 16382,16374,16362,16344,16322,16294,16262,16225
.dc.w 16182
.dc.w 16135,16083,16026,15964,15897,15826,15749,15668
.dc.w 15582,15491,15396,15296,15191,15082,14962,14849
-dc.w 14726,14598,14466,14330,14189,14044,13894,13741
• dc.w 13583,13421,13255,13085,12911,12733,12551,12365
• dc.w 12176,11982,11786,11585,11381,11174,10963,10749
.dc.w 10531,10311,10087,9860,9630,9397,9162,8923
.dc.w 8682,8438,8192,7943,7692,7438,7182,6924
.dc.w 6664,6402,6138,5872,5604,5334,5063,4790
.dc.w 4516,4240,3964,3686,3406,3126,2845,2563
.dc.w 2280,1997,1713,1428,1143,857,572,286,0
.dc.w -286,-572,-857,-1143,-1428,-1713,-1997,-2280
.dc.w -2563,-2845,-3126,-3406,-3686,-3964,-4240,-4516
.dc.w -4790,-5063,-5334,-5604,-5872,-6138,-6402,-6664
.dc.w -6924,-7182,-7438,-7692,-7943,-8192,-8438,-8682
.dc.w -8923,-9162,-9397,-9630,-9860,-10087,-10311,-10531
.dc.w -10749,-10963,-11174,-11381,-11585,-11786,-11982
.dc.w -12176
.dc.w -12365,-12551,-12733,-12911,-13085,-13255,-13421
.dc. w -13583
.dc.w -13741,-13894,-14044,-14189,-14330,-14466,-14598
.dc.w -14726
.dc.w -14849,-14962,-15082,-15191,-15296,-15396,-15491
.dc.w -15582
• dc.w -15668,-15749,-15826,-15897,-15964,-16026,-16083
.dc.w -16135
.dc.w -16182,-16225,-16262,-16294,-16322,-16344,-16362
.dc.w -16374,-16382,-16384
147
ST 3D Graphics Abacus Software
. dc. w -16225,-16182
.dc. w -15668
• dc. w -14849
.dc.w -13741
.dc.w -12365
.dc.w -10749
.dc.w -2280,-1997,-1713,-1428,-1143,-857,-572,-286,0
.even
• bss
zO: .ds. w 1
zl: .ds. w 1
pointz: • ds. 1 1
xplot .ds.l 1
yplot .ds. 1 1
datx: .ds.l 1
daty: .ds.l 1
datz: .ds.l 1
148
Abacus Software ST 3D Graphics
siny: .ds.w 1
cosx: .ds.w 1
cosz: .ds.w 1
cosy: .ds.w 1
var2: .ds.w 1
var3: .ds.w 1
zangle: .ds.w 1
sintin: .ds.w 1
sintout: .ds.w 1
saddrin: .ds.w 1
saddrout: .ds.w 1
.ds.w 6
global:
apversion: .ds.w 1
apcount: .ds.w 1
apid: .ds.w 1
apprivate: • ds. 1 1
apptree: .ds. 1 1
aplresv: .ds. 1 1
ap2resv: .ds. 1 1
ap3resv: . ds . 1 1
ap4resv: . ds. 1 1
149
ST 3D Graphics Abacus Software
grhandle: .ds. w 1
. data
leftx: .dc. w 0
lefty: .dc.w 0
rightx: .dc. w 0
righty: . dc. w 0
plcode: .dc.w 0
p2code: .dc. w 0
codel: .dc.w 0
code2: .dc.w 0
mid_code: .dc.w 0
clipyule: .dc.w 0
dist: .dc.w 0
rotxl3: .dc.w 0
rotx21: .dc.w 0
rotx23: .dc.w 0
rotx31: .dc.w 0
rotx32: .dc.w 0
.bss
150
Abacus Software ST 3D Graphics
matrixl3:
matrix21:
matrix22:
matrix23:
matrix31:
matrix32:
matrix33:
I
K PRINTERS BASIC PRG 138944 li-20-Ul
X TUTORIAL BASIC RSC 4648 11-20 i] BASIC1 S
C FKY BASIC HRK 346 11-20- GRLIHK BAT
COM TTP BASIC1 BAR 14801 11-20 BRLINK1 0
KLIB PRG 6RLINK1 S
OUTPUT PRG OPEN APPLICATION 6R0UND1 S
SPLIT TTP HIDE1 PRG
STANDARD PRT Name: BATCH .TTP HIDE1 S
TEXTPRO PRG Parameters: . HOUSE1 PRG
TUTORIAL TXT aslink grllnkl housel|__- H0USE1 S
XTTUTORI TOC HAIN1 PRG
OK I I Cancel HAIN1 S
IkJUl HAIN1C0 PRG
IJI
1 MAIN1C0 S
ST 3D Graphics Abacus Software
grlinkl.s
mouse on: Enables the mouse and its controller through the
^ — operating system.
152
Abacus Software ST 3D Graphics
153
ST 3D Graphics Abacus Software
154
Abacus Software ST 3D Graphics
**********************************************************************
* housel.s 14.1.1986 *
**********************************************************************
.globl main,xoffs,yoffs,zoffs,offx,offy,offz
.globl viewx,viewy,viewz
.globl wlinxy,setrotdp,inp_chan,pointrot
.text
main:
jsr clwork .
jsr inp chan ★ Input and change parameters' ^ *
mainlopl:
155
ST 3D Graphics Abacus Software
move. 1 physbase,logbase
********************************************************************
trap #1
addq.1 #2,a7
bra clearbuf
clearend: rts
**********************************************************************
* Change observation parameters with keyboard sensing *
bne inpwait
bne inpl
156
Abacus Software ST 3D Graphics
bra inpendl
bne inp3
bra inpendl
bne inp3a
bra inpendl
bne inp3b
subq.w #1,zwplus
bra inpendl
bne inp4
addq.w #1,zwplus
bra inpendl
bra inpendl
bne inplO
bra inpendl
157
ST 3D Graphics Abacus Software
bne inpendl
bra inpend4
bra inpend4
bge inpend5
cmp.w #-360,dl
ble inpend6
bra inpend7
bra inpend7
move. w hzangle,dl
add.w zwplus,dl
cmp. w #360,dl
bge inpend8
cmp. w #-360,dl
ble inpend9
bra inpendlO
bra inpendlO
158
Abacus Software ST 3D Graphics
rts
move. w dl,rotdpy
move.w dl,rotdpz
move. w #0,hzangle
move.w #0,hxangle
rts
move.w hzangle,zangle
move.w rotdpy,dl
move.w rotdpz,d2
move.w dl,yoffs
move.w d2,zoffs
neg. w dO
neg. w dl
neg. w d2
move.w dl, of fy
move.w d2,offz
rts
159
ST 3D Graphics Abacus Software
move.1 Ihousdaty,a2
move.1 #housdatz,a3
move.1 #worldx,a4
move.1 #worldy,a5
move.1 #worldz,a6
move.w hnummark,dO
ext .1 dO
subq.1 #1, dO
dbra dO,makewll
move . w hnumline,dO
ext. 1 dO
subq.1 U,dO
move. 1 thouslin,al
move . 1 dwlinxy,a2
dbra d0,makewl2
rts
********************************** **********************************
* Pass the world parameters to the link file variables *
********************************** **********************************
move.1 #worldz,datz
move.1 #viewx,pointx
move.1 #viewy,pointy
move.1 #viewz,pointz
move.1 #wlinxy,linxy
move.w picturex,xO
move. w picturey,yO
move.w proz,zobs
move.w rlzl,dist
move.1 #screenx,xplot
160
Abacus Software ST 3D Graphics
move.1 Iscreeny,yplot
move.w hnumline,numline
move.w hnummark,nummark
rts
*********************************************************************
* sense current display resolution and set coordinate origin of the *
trap #14
addq.1 #2,a7
cmp.w #2, dO
bne getrl
move.w #200,picturey
bra getrend
bne getr2
move.w #100,picturey
bra getrend
move.w #100,picturey
getrend: rts
**********************************************************************
* Hardcopy of the display after activating Shift d on keyboard *
**********************************************************************
trap #14
addq.l #2,a7
rts
161
ST 3D Graphics Abacus Software
*********************************************************************
* Sets the limit of the display window for the draw-line algorithm *
* The limits are freely selectable by the user, making the draw- 4
move. w picturex,dl
move.w picturey,dl
rts
.even
* *
. data
,dc. w 30,30,30,30,30,30,30,30,30,30,30,30
.dc.w 20,20,0,0,20,20,0,0
.dc.w -10,-10,-30,-30
162
Abacus Software ST 3D Graphics
.dc.w 40,10,10,40,-10,-40,-40,-10
.dc.w 0,-20,-20,0
.dc.w 15,16,16,17,17,18,18,15,19,20,20,21,21,22,22,19
.dc.w 23,24,24,25,25,26,26,23
rotdpy: .dc.w 0
rotdpz: .dc.w 0
rlzl: .dc.w 0
normz: . dc. w 1500
.bss
plusrot: . ds. 1 1
first: .ds. 1 1
second: . ds . w 1
deltal: .ds. w 1
.data
163
ST 3D Graphics Abacus Software
flag: . dc .b 1
. even
-bss
diffz: .ds.w 1
dx: .ds .w 1
dy: -ds.w 1
dz: .ds.w 1
.data
. data
loopc: .ds. 1 1
• end
164
Abacus Software ST 3D Graphics
165
ST 3D Graphics Abacus Software
166
Abacus Software ST 3D Graphics
The best thing to do is to try out the various changes possible, preferably
by changing the constants in the listing. You can, for example move the
rotation reference point on the X and Y axis, or the variable proz, which
changes the position of the projection center. The closer you move the
projection center in the direction of the house, the greater the perspective
distortion. You should also define an object yourself, and you should start
with a simple object, like a pyramid. You only have to enter the points of
the pyramid (in a pyramid with a quadratic base there are five) in place of
the house coordinates in the arrays (housdatx etc.). Furthermore, the
number of points (5) must be entered in houslin in hnummark, the
number of lines (8) in hnumline and then the information regarding
which points are connected by lines. You only have to change the storage
area and you can represent any defined object with the same program.
167
LIS projection centers
Abacus Software ST 3D Graphics
The drudgery of input can be performed by the computer for all axis-
symmetrical objects. As an example, consider the ’’chess piece’’ from
Figure 4.2.2. This figure can be created by rotating a line (the definition
line) around any axis, in this case the Y-axis. The programmer must
169
ST 3D Graphics Abacus Software
define the one line and indicate how many times it should be rotated. You
can follow the construction of the figure easily on the following
hardcopies. The rotation number must be a division of 360 for
programming reasons or a portion of the figure will be missing. From two
to four to three hundred sixty rotations are available. More than 180 just
produces a heap of points on the display (the screen resolution is too
low). Now the space requirement will become obvious. If you rotate the
12 points 360 times it results in 4,332 points not to mention the 8,291
lines created by the rotation. The number of points is calculated as
follows: nummark: =numpt* (rotations + 1). The lines include the
connecting lines of the points in the rotating definition line as well as the
horizontal connecting lines of the points in the rotation line.
The routines for the creation of the rotation body are contained in the
listing of the file rotate 1. s. The rotation body is described by a line,
i.e. a number of points (rlnumpt), whose coordinates are in rlxdat,
rlydat, r 1 zdat and the number of rotations about the Y-axis which
this line should perform. The different bodies are created by varying the
number of rotations. The maximum number of rotations in our case is
120, which is predetermined by the dimensioning of the array to 1600 etc.
and of course could be changed. The number of points of the rotation
body is contained in the variable rlnumpt. The link file remains the
same as in the first program. You only have to assemble the first file and
link it to the link file: as link grlinkl rotatel.
a*
WBSTSE23M
a*I'-H'Ji i"?u■a*iinn i:*tw
a?ttnm
170
Abacus Software ST 3D
ST 3D Graphics Abacus Software
**********************************************************************
* rotatel.s 16.1.1986 *
* Creation of rotation bodies Uwe Braun 1985 Version 2.0 *
.text
main:
jsr apinit * Announce program
jsr grafhand * Get screen handle
jsr openwork it
Display
jsr mouse_off * Turn off mouse
jsr getreso * Which monitor is connected ?
jsr setcocli * Set clip window
jsr makerotl
jsr clwork
jsr pagedown * Display logical screen page
jsr clwork
jsr inp_chan * Input and change parameters
mainlopl:
jsr pointrot * rotate around observation ref. point
jsr pagedown *
Display this logical page
jsr inp_chan *
Input and change
172
Abacus Software ST 3D Graphics
*
****************
* remove all characters from the keyboard buffer
*
*******************************************************************
trap #1
addq.1 #2,a7
bra clearbuf
clearend: rts
rt s
173
ST 3D Graphics Abacus Software
*******************it** + -k1t*-k-k**ic1t1r*1i1iii*1t1r1tl!*1cirit**ir1'1c1r1r***1i1t**i'*iiitit1i1r1rit
174
Abacus Software ST 3D Graphics
inp6 *
bne
bra inpendl
bne inplO
bra inpendl
bne inpendl
bge inpend2
bra inpend4
bra inpend4
bge inpend5
cmp. w #-360,dl
175
ST 3D Graphics Abacus Software
ble inpend6
bra inpend7
inpend5: sub. w #360,dl
bra inpend7
inpend6: add. w #360,dl
inpend7: move. w dl,hxangle
move. w hzangle,dl
add. w zwplus,dl
cmp. w #360,dl
bge inpend8
cmp. w #-360,dl
ble inpend9
bra inpendlO
inpend8: sub. w #360,dl
bra inpendlO
inpend9: add.w #360,dl
rts
******************************************************************
* Rotation of the total world system around the rotation *
* reference point *
******************************************************************
move.w hzangle,zangle
176
Abacus Software ST 3D Graphics
move.w rotdpy,dl
move . w rotdpz,d2
move . w dl,yoffs
move.w d2,zof fs
neg. w dO
neg. w dl
neg. w d2
move. w d2,offz
★ * account
move.1 #worldx,a4
move. 1 #worldy,a5
move. 1 #worldz,a6
ext .1 dO
subq. 1 #1, dO
dbra dO,makewll
move.1 #wlinxy,a2
dbra dO,makew!2
rt s
177
ST 3D Graphics Abacus Software
***********************************************************************
move.1 #viewz,pointz
move.1 #wlinxy,linxy
move.w picturex,xO
move.w picturey,yO
***********************************************************************
* Creation of rotation body in the array, the address of which *
rlset:
move. 1 rotdaty,daty
move. 1 rotdatz,datz
178
Abacus Software ST 3D Graphics
ext. 1 dO
move.1 dO,plusrot
move.w numpt,nummark
move.1 rotdatz,pointz
move.w #0,yangle
ext. 1 dO
move.1 rotydat,daty
move.1 rotzdat,datz
move. 1 dl,pointx
move. 1 pointy,dl
add. 1 plusrot,dl
move. 1 dl,pointy
move. 1 pointz,dl
add. 1 plusrot,dl
move. 1 dl,pointz
rts
179
ST 3D Graphics Abacus Software
ext. 1 d4
subq. 1 #1, d4
move.w numpt,dl
subq.w *1, dl
lsl. w #2, dl
ext. 1 dl
move.1 dl,plusrot
subq.1 #2,d5
dbra d5,rotlop2
move.1 dl,linxy
move.w numpt,dO
add.w d0,d7
dbra d4,rotlopl
move. w numpt,d7
move.w d7,deltal
lsl. w #2,d7
ext. 1 dl
move.1 d7,plusrot
move.w #l,d6
move. w numpt,dO
ext. 1 dO
subq.1 #1, dO
ext. 1 dl
subq.1 #1, dl
move.w d6,d5
180
Abacus Software ST 3D Graphics
add. w deltal,d5
move.w d5,(al)+
dbra dl,rotlop4
add. w #l,d6
dbra dO,rotlop3
move. w numro,dl
add. w #1, dl
mul s nummark,dl
muls numro,dl
move . w numpt,d2
subq.w #1, d2
muls numro,d2
add. w dl, d2
rts
move.1 #viewy,pointy
move.1 #viewz,pointz
move.1 #wlinxy,1inxy
move.w picturex,xO
move.w picturey,yO
move. w proz,temp
move.w rlzl,dist
move.1 Iscreenx,xplot
move.1 #screeny,yplot
181
ST 3D Graphics Abacus Software
rts
a**********************************************************************
trap #14
addq. 1 #2,a7
cmp. w #2, dO
bne getrl
move. w #200,picturey
bra getrend
bne getr2
move.w #100,picturey
bra getrend
move.w #100,picturey
getrend: rts
trap #14
addq. 1 #2, a7
jsr clearbuf
rts
182
Abacus Software ST 3D Graphics
*********************************************************************
* Set the limit of the window for the Cohen-Sutherland *
* The user can choose the limits freely, which makes the *
move.w #0,clipxule
move.w picturex,dl
move.w picturey,dl
move.w dl,clipylri
rts
. even
numro: .ds.w 1
numpt: .ds.w 1
worldfla: .ds.l 1
rotxdat: .ds.l 1
rotydat: .ds.l 1
rotzdat: .ds.l 1
ST 3D Graphics Abacus Software
rotdatx: .ds. 1 1
rotdaty: .ds. 1 1
rotdatz: . ds. 1 1
rlnumline: .ds .w 1
rlnummark: .ds. w 1
rlnumfla: . ds. w 1
plusagle: . ds. w 1
.data
***********************************************************************
* These are the coordinates of the definition line which *
* than 1500. *
***********************************************************************
rlnumpt: .dc.w 12
rlnumro: .dc.w 8 * Number of rotations for creation
184
Abacus Software ST 3D Graphics
.data
.dc.w 30,30,30,30,30,30,30,30,30,30,30,30
.dc.w 40,10,10,40,-10,-40,-40,-10
.dc.w 0,-20,-20,0
.dc.w 9,10,1,9,9,2,5,10,6,10,11,12,12,13,13,14
.dc.w 15,16,16,17,17,18,18,15,19,20,20,21,21,22,22,19
.dc.w 23,24,24,25,25,26,26,23
185
ST 3D Graphics Abacus Software
rotdpx: • dc.w 0
rotdpy: .dc.w 0
rotdpz: .dc.w 0
rlzl: .dc.w 0
.bss
plusrot: .ds. 1 1
first: . ds. w 1
second: .ds. w 1
deltal: .ds . w 1
.data
flag: .dc.b 1
.even
.bss
diffz: .ds. w 1
dx: .ds .w 1
dy: .ds. w 1
dz : .ds. w 1
186
Abacus Software ST 3D Graphics
• data
.data
of f z : .dc.w 0
zoffs: .dc.w 0
.bss
loopc: .ds. 1 1
.end
187
ST 3D Graphics Abacus Software
In contrast to the first program where the house was already explicitly
provided, the object to be represented must first be created. This is the
task of the subroutine makerotl, which generates the rotation body in
the array rldatx, rldaty, rldatz. This array corresponds to the
house array housdatx, housdaty, housdatz. The rotation body is
transferred to the world system and its position parameters in the main
loop are modified in a loop. You should experiment freely with this
program and change the definition line for the rotation body and the
number of rotations. The only limitation is in the maximum number of
points and lines where the total number of lines rlnumline is calculated
as follows:
188
Abacus Software ST 3D Graphics
The number of points can not exceed 1600 and the number of lines
cannot be greater than 3200.
Definition of a Ball:
You need only exchange the corresponding lines in the listing for these.
189
ST 3D Graphics Abacus Software
Shift 'D':
Hardcopy on the printer
190
Abacus Software ST 3D Graphics
If you are familiar with real time 3-D graphics on other computers, you
were probably surprised by the speed of the display of the wire frame
drawings on the Atari ST. On the other hand some game freaks may
remark that "I’ve seen the fastest 3-D games on my 8-bit C-64 and these
wire models just don’t compare.” For game programming, the main
emphasis is on the desired effect. Therefore the active figures for these 3-
D-Games are mostly space ships and landscapes which are pre-calculated
and their point coordinates are already stored in the computer. For the
display which follows on the screen, the object is simply drawn, which
naturally can be done quickly, even with 8-bit computers. A disadvantage
of this method is the enormous storage requirement, since every possible
position of the object must be available in memory, meaning that this
procedure cannot be used with complex bodies. In this case only the
rotation matrices for the rotation around three axes are calculated ahead
of time and stored in a table. Even with this method the limits of the
storage are reached quickly. An extreme example: If you want to
calculate the rotation matrices of all possible values for subsequent
rotation about three axes, with an angle increment of one degree
previously calculated, the result will be more than 46 million possibilities
(variations of three rotations around 360 possible angles). If this method
is used, the degree of freedom of the objects must be limited to one or
two possible axes, and/or the gradations of the angle values must be
raised so that the table is calculated, for example, only in ten degree
steps, or only rotations from zero to to ninety degrees are permitted.
Another common method consists of defining the objects as picture
shapes, quasi-sprites, in various positions and to switch back and forth
between the various shapes and to move the whole shape over the
display. Of course the last procedure is the fastest since nothing has to be
calculated and the only operation is moving data into the screen memory.
Now back to the Atari ST, which, because of its enormous computing
power, can not only calculate the wire frame drawing in real time, but as
you will see also offers the ability to display simple convex bodies in real
time without the hidden lines. The method used corresponds to the
surface method used in chapter 2.7. To use this method you must specify
every surface of the object precisely. For the example of our house, we
need two new variables. First the number of surfaces of the house
(hnumpla=13), and second the storage space for the description of
these surfaces (houspla). Every surface is described by the number of
191
ST 3D Graphics Abacus Software
1 1 2
2 2 3
3 3 4
4 4 1
192
Abacus Software ST 3D Graphics
ST 3D Graphics Abacus Software
Here is the surface list for the thirteen surfaces of the house from Figure
4.3.1. You can get the point indices from Figure 4.1.3.
1 4 1, 2 2, 3 3/ 4 4, 1
2 4 2, 5 5, 8 8, 3 3, 2
3 4 5, 6 6, 7 7, 8 8, 5
4 4 7, 6 6, 1 1/ 4 4, 7
5 4 4, 3 3, 8 8, 7 7, 4
6 4 2, 9 9, 10 10, 5 5, 2
7 4 10, 9 9, 1 1, 6 6,10
8 3 1/ 9 9, 2 2, 1
9 3 5, 10 10, 6 6, 5
10 4 11, 12 12,13 13, 14 14,11
11 4 15,16 16, 17 17,18 18,15
12 4 9,20 20,21 21,22 22,19
13 4 23,24 24,25 25,26 26,23
Number of surfaces: 13
196
Abacus Software ST 3D Graphics
other changes were made in the main loop. The subroutine hide it
determines which surfaces are visible from the projection center with the
help of the information in the surface arrary (wplane). The information
on the visible surfaces, which correspond to the normal surfaces in the
structure, first the number of lines followed by individual lines, is entered
into a second array (vplane) and the total number of visible surfaces is
stored in the surface counter surfcnt. All visible surfaces are
subsequently drawn on the display by the subroutine surf dr aw:
whereby many lines are drawn twice since the subroutine surf dr aw:
takes the lines to be drawn directly from the surface array (vplane).
Figure 4.3.1 and the connecting lines of points 2 and 3 show a concrete
illustration. This connecting line belongs to the visible surface 1 and the
visible surface 2. Naturally all the lines in the surface array (vplane)
could be sorted before drawing and double lines removed. My experience
shows that the time saved in drawing is lost in the additional sorting and
testing, at least for less complicated bodies. Furthermore, the surface
information is lost by the separation of the lines, which is needed in the
following program sections. Again to run this program you must first
compile and link it to grlinkl.s using the batch.ttp file and
entering: aslink grlinkl hidel
Desk
»' File
-0:\. 4I" " View Options
E: \ F:\3DW0RK.DIRS !
B butes used
BASIC1C0 S X ASStLPRO HIDEl S
S BATCH TTP X FILE-PRO H0USE1 PRG
X FORTOT H0USE1 S
BUS i iifl
X GEHDRAM
—
MAIH1
laTMt
PRG
?
W
was Ol n
a*
-■! '."il'M
a" a*.
;irna nw rrtm flCCBESXMi
197
ST 3D Graphics Abacus Software
.globl main,xoffs,yoffs,zoffs,offx,offy,offz
-globl viewx,viewy,viewz
.text
main:
jsr clwork
jsr clwork
mainlopl:
jsr hideit
jsr surfdraw
jsr clwork
jsr hideit
jsr surfdraw
198
Abacus Software ST 3D Graphics
cmp.b #'D',dO
bne inpwait
bne inpl
bra inpendl
bra inpendl
bne inp3a
bra inpendl
199
ST 3D Graphics Abacus Software
bne inp3b
subq * w #1,zwplus
bra inpendl
bne inp4
addq.w #1,zwplus
bra inpendl
bne inp6 *
bra inpendl
bne inplO
bra inpendl
bne inpendl
bge inpend2
bra inpend4
200
Abacus Software ST 3D Graphics
bra inpend4
bge inpend5
cmp. w #-360,dl
ble inpend6
bra inpend7
bra inpend7
move.w hzangle,dl
add.w zwplus,dl
cmp. w #360,dl
bge inpend8
cmp. w #-360,dl
ble inpend9
bra inpendlO
bra inpendlO
rts
move.w dl,rotdpy
move.w dl,rotdpz
201
ST 3D Graphics Abacus Software
move.w #0,hzangle
move.w #0,hxangle
rts
************************************************************************
* Rotate the total world system around one point, the rotation *
* reference point *
************************************************************************
move.w hzangle,zangle
move.w rotdpx,dO * rotation reference point
move.w rotdpy,dl
move.w rotdpz,d2
move.w dO,xoffs * add for inverse transformation
move.w dl,yoffs
move. w d2,zoffs
neg. w dO
neg. w dl
neg. w d2
move.w d2,offz
jsr matinit * Matrix initialization
jsr zrotate * first rotate about Z-axis
jsr yrotate * rotate 'matrix' about Y-axis
jsr xrotate * then about X-axis
jsr rotate * Multiply points with matrix
rts
***********************************************************************
* Generate world system from object data. All points, lines, *
move.1 #housdatz,a3
move.1 twrldx,&A
move.1 #wrldy,a5
202
Abacus Software ST 3D Graphics
move.l #wrldz,a6
move.w hnummark,dO
ext.l dO
subq.l #l,dO
move.w {a3)+,(a6) +
dbra dO,makewll
ext.l dO
subq.1 #1/dO
move.l #houslin,al
move.l #wlinxy,a2
move.l worldpla,aO
move.l #wplane,al
ext.l dO
subq.l #l,dO
subq.l #l,dl
rts
move.l #wrldz,datz
move.l ^viewx,pointx
203
ST 3D Graphics Abacus Software
move.1 #viewy,pointy
move.1 #viewz,pointz
move.1 #wlinxy,linxy
move.w picturex,xO
move.w picturey,yO
move.w proz,zobs
move.w rlz1,dist
move.1 tscreenx,xplot
move.1 tscreeny,yplot
move. w hnumline,numline
move.w hnummark,nummark
move.w hnumsurf,numsurf
rts
trap #1
addq.1 #2, a?
tst. w dO
beq clearnd
move. w #1,-(a7)
trap #1
addq.1 #2, a7
bra clearbuf
clearnd: rts
*********************************************************************
* Sense display resolution and set coordinate origin of screen *
* to screen center *
*********************************************************************
addq.1 #2,a7
cmp. w #2, dO
bne getrl
204
Abacus Software ST 3D Graphics
move.w #200,picturey
bra getrend
bne getr2
move.w #320,picturex * medium resolution (640*200)
move.w #100,picturey
bra getrend
getr2: move.w #160,picturex * low resolution (320*200)
move.w #100,picturey
getrend: rts
***********************************************************************
trap #14
addq.1 #2.a7
jsr clearbuf
rts
*********************************************************************
* Sets the limits of the display window for the Cohen-Sutherland
move . w #0,clipxule
move.w #0,clipyule
move.w picturex,dl
move.w picturey,dl
* times two minus one equal
lsl. w #1, dl
move.w dl,clipylri
rts
205
ST 3D Graphics Abacus Software
***********************************************************************
* Recognition of hidden surfaces and entry of these into the *
hideit:
subq.1 #1, dO
move.1 #viewz,a3
lsl. w #l,d2
lsl. w #1, d3
subq.w #l,d4
lsl. w #1, d4
206
Abacus Software ST 3D Graphics
doit1:
move.w (a3, d3 . w) , d5
move.w d5, kz
sub. w (a3,d2.w), d5
move.w d5, pz
move.w (a3,d4.w),d7
sub.w (a3,d2.w),d7
move.w d5,dl * qx
move. w d6,d2 * qy
move.w d7,d3 * qz
move.w d3, rx
mu Is pz,dl
mu Is px,d7
mu Is py,d5
sub. w d5,d6
move.w d6, rz
207
ST 3D Graphics Abacus Software
hideend: rts
move.l yplot,a5
208
Abacus Software ST 3D Graphics
ext. 1 dO * hideit
subq. 1 #1, dl
move . w 0(a4,d5.w),d2
swap d5 * pass.
subq.w #1, d5
lsl .w #1, d5
move.w 0(a5,d5.w),a3
* *
.data
• do. w 30,30,30,30,30,30,30,30,30,30,30,30
209
ST 3D Graphics Abacus Software
to
o
o
o
housdaty: .dc,, w 30, 30,-30,-30,30,30, -30, -30, 70, 70,- 30,
1
. dc,. w 20, 20, 0,0,20,20,0,0
housdatz: • dc., w 60, 60,60,60,-60,-60, -60, -60, 60, -60, 60, 60, 60, 60
.dc.w 4,10,9,9,1,1,6,6,10,3,1,9,9,2,2,1
.dc.w 3,5,10,10,6,6,5,4,11,12,12,13,13,14,14,11
.dc.w 4,15, 16, 16, 17, 17, 18, 18, 15,4, 19, 20,20, 21,21, 22, 22, 19
• dc.w 4,23,24,24,25,25/26,26,23
210
Abacus Software ST 3D Graphics
rotdpx: • dc. w 0
rotdpy: . dc. w 0
rotdpz: .dc. w 0
rlzl: . dc. w 0
.bss
plusrot: . ds. 1 1
first: .ds.w 1
second: .ds. w 1
deltal: .ds.w 1
.data
plag: .dc .b 1
.even
.bss
diffz: .ds.w 1
dx: .ds.w 1
dy: .ds.w 1
dz: .ds.w 1
211
ST 3D Graphics Abacus Software
surfcount: • ds. w 1
numsurf: • ds. w 1
sx: . ds. w 1
sy: .ds .w 1
sz: .ds .w 1
px: .ds. w 1
py: • ds. w 1
pz: • ds. w 1
rx: .ds. w 1
ry: .ds. w 1
rz: . ds. w 1
qx: .ds .w 1
qy: -ds. w 1
qz: .ds. w 1
kx: -ds. w 1
ky: .ds. w 1
kz: .ds. w 1
. data
212
Abacus Software ST 3D Graphics
.data
of f z: . dc. w 0
zoffs: .dc. w 0
.bss
loopc .ds. 1 1
. end
213
ST 3D Graphics Abacus Software
surf dr aw: Here the visible surfaces are displayed by drawing the
lines of the array vplane. The whole job was done
already by hideit.
214
Abacus Software ST 3D Graphics
and Y-axis can be changed with the cursor keys and the Help and Undo
keys. Of course you can also change all the parameters within the
program (projection center, rotation reference point to X and Y-axis,
etc.).
If the rotation creation routine is added to the main program and the chess
figure is created with hideit: and pladraw without hidden lines: you
can see the problem. With concave bodies such as this chess figure there
is the possibility that one of the surfaces recognized by the hideit:
algorithm as visible can be hidden by another visible surface during
viewing. In this case the hideit: algorithm fails and the problem must
be solved with another algorithm.
215
ST 3D Graphics Abacus Software
Recall the problem we‘re trying to solve: Surfaces which are seen from
an observation point have their surface normal vector pointed in another
direction from a vector from any point on the surface to the projection
center, are hidden by other surfaces which according to this criterium are
also visible. If you start from the observation point (projection center) on
the positive Z-axis, the middle Z-coordinate of a surface is a possible
description of it and its position in the world system. The middle Z-
coordinate is obtained by defining the arithmetic center of the comer
point coordinates belonging to the surface, i.e. summation of all surface
comer point Z-coordinates and division by the number of comer points
belonging to the surface. The relationship can be made clear with the
simple example with three different surfaces in Figure 4.4.1.
216
Abacus Software ST 3D Graphics
Viewing the defined world system from one point on the positive Z axis,
we can say: the surface with the largest middle Z-coordinate is visible in
its entire size and is not hidden by any other surface. Note that all
observed surfaces are on the negative Z-axis (-200 > -400). This
completely visible surface covers parts of surfaces with a smaller middle
Z coordinate. Surfaces 2 and 3 are covered by surface 1 and surface 3 is
again covered by surface 2. The surfaces are sorted by their Z-coordinates
and they are drawn starting with the smallest middle z-coordinate, surface
3, and then the surfaces with the larger Z coordinates, and we have found
a possible solution to the problem by covering hidden surfaces with other
surfaces. You must consider that it is not enough just to draw every
surface. The individual surfaces must be filled with "color" or a pattern so
that the surfaces drawn first are really covered. Figure 4.4.2 shows one
possible result
+Y
Figure 4.4.2
If we think about our rotation body from chapter 4.2, this means first of
all that when the rotation body is created its surfaces must also be
217
ST 3D Graphics Abacus Software
The shading routine is called by the subroutine paint it, which first
sorts all surfaces contained in surfaddr: according to ascending Z-
coordinates. Next you must pass the individual surfaces, i.e. their end
point coordinates, to the function "Filled Area". This begins with the
surface which has the smallest middle Z-coordinate. The function "Filled
218
Abacus Software ST 3D Graphics
If you have a color monitor, you can choose between filling with color or
patterns. If you want to try filling with color you must call the function
filstyle with the value one in the DO register when entering the
paint it routine. The subroutine filcolor: makes it possible to use
different colors. Owners of monochrome monitors don’t have to change
anything in the program. To run this program call the batch file batch.ttp
then enter: as link grlinkl paintl
F:\3DM0RK.DIR\
253882 bytes used 1 1442236 bytes used in 125 itens 333956 butes used in
Si PRINTERS 38944 H0USE1 PRG
Si TUTORIAL H0USE1 S
C FRY HAIN1 PRG
COM TTP HRIN1 S
NLlfl PRG MAIK1C0 PR6
OUTPUT PRG OPEN APPLICATION MAIN1C0 S
SPLIT TTP HENU1 PRG
STRNDARD PRT Mane: BATCH .TTP MENU1 S
TEXTPRO PRG Paraneters: MULTI1 PRG
TUTORIAL TXT aslink grlinkl paintlj—_ MULTI1 S
XTTUTORI TOC PAINT1 PRG
PAINT1 S
R0TATE1 PRG
1 R0TATE1 S
ST 3D Graphics Abacus Software
Figure 4.4.3
Here is the listing of the fourth main program for the link file
grlinkl.s. It is called paintl.s. The operating parameters again
correspond to the previous program.
220
Abacus Software ST 3D Graphics
**********************************************************************
* paint 1.s 9.2.1986 *
* Display a shaded rotation body *
* *
★*********************************************************************
.text
.globl main,xoffs,yoffs, zoffs,offx,offy,offz
.globl viewx,viewy,viewz
.globl wlinxy,mouse_off,setrotdp,inp_chan,pointrot
main:
jsr apinit * Announce program
jsr clwork
jsr inp chan
mainlopl:
jsr pointrot * rotate around observ. ref. point
jsr pers * Perspective transformation
221
ST 3D Graphics Abacus Software
move. 1 physbase,logbase
A**********************************************************************
* Creation of rotation body by passing parameters *
rts
cmp .b #'D',dO
bne inpwait
bne inpl
bra inpendl
222
Abacus Software ST 3D Graphics
bne inp3
bne inp3a
bne inp3b
bra inpendl
bra inpendl
bra inpendl
223
ST 3D Graphics Abacus Software
bne inpendl
bra inpend4
bra inpend4
bge inpend5
cmp. w #-360,dl
ble inpend6
bra inpend7
bra inpend7
move.w hzangle,dl
add. w zwplus,dl
cmp.w #360,dl
bge inpend8
cmp. w #-360,dl
ble inpend9
bra inpendlO
bra inpendlO
224
Abacus Software ST 3D Graphics
rts
move. w dl,rotdpy
move.w dl,rotdpz
move.w #0,hzangle
move.w #0,hxangle
rts
* three axes *
move.w hyangle,yangle
move.w hzangle,zangle
move.w rotdpy,dl
move. w rotdpz,d2
move.w dl,yoffs
move. w d2,zoffs
neg. w dO
neg. w dl
neg. w d2
move.w dl,offy
move.w d2,offz
rts
225
ST 3D Graphics Abacus Software
***********************************************************************
* Create world system by copying the object data into world system *
***********************************************************************
move.1 #rldaty,a2
move.1 trldatz,a3
move.1 #wrldx,a4
move. 1 #wrldy,a5
move.1 #wrldz,a6
move.w rlnummark,dO
ext. 1 dO
subq.1 #l,dO
dbra dO,makewll
move.w rlnumline,dO
ext. 1 dO
subq.1 #lf dO
move.1 #rllin,al
move.1 #wlinxy,a2
move.1 worldpla,aO
move.1 #wplane,al
move.w rlnumsurf,dO
ext. 1 dO
subq.1 #1, dO
ext. 1 dl
subq.1 #1 / dl
226
Abacus Software ST 3D Graphics
*********************************************************************
* Pass the world parameters to the variables in the *
* link files
*********************************************************************
move.1 #viewx,pointx
move.1 #viewy,pointy
move.1 #viewz,pointz
move.1 #wlinxy,linxy
move. w picturex,xO
move.w picturey,yO
move.w proz,zobs
move.w rlzl,dist
move.1 Iscreenx,xplot
move.1 #screeny,yplot
move.w hnumline,numline
move.w hnummark,nummark
move.w hnumsurf,numsurf
rts
trap #1
addq. 1 #2, a7
tst. w dO
beq clearnd
move.w #1,-{a7)
trap #1
addq.1 #2, a7
bra clearbuf
clearnd: rts
227
ST 3D Graphics Abacus Software
*********************************************************************
* Sense display resolution and set coordinate *
addq.1 #2,a7
cmp. w #2, dO
bne getrl
move.w #200,picturey
bra getrend
getrl: cmp • w #1, dO
bne getr2
move.w #320,picturex * medium resolution (640*200
move.w #100,picturey
bra getrend
getr2: move.w #160,picturex * low resolution (320*200)
move.w #100,picturey
getrend: rts
* *
trap #14
addq. 1 #2,a7
jsr clearbuf
rts
228
Abacus Software ST 3D Graphics
*********************************************************************
* Sets the limits of the display window for the
* draw-line algorithm
* The limits can be freely selected by the user which makes ‘
move . w #0,clipyule
move.w picturex,dl
★ times two
lsl. w #l,dl
move .w picturey,dl
move.w dl,clipylri
rts
hideit:
move. w numsurf, dO * Number of surfaces as
dO * counter
ext. 1
subq.1 #1, dO
move.1 #viewz,a3
229
ST 3D Graphics Abacus Software
lsl .w #l,d4
doit 1:
move. w d5, kz
sub. w (a3,d2.w),d5
move.w d5, pz
sub. w (al,d2.w),d5
move.w (a2,d4.w),d6
sub. w (a2,d2.w),d6
move.w (a3,d4.w),d7
sub. w (a3,d2.w),d7
230
Abacus Software ST 3D Graphics
move. w d5,dl * qx
move.w d6,d2 * qy
move.w d7,d3 * qz
move. w d3, rx
mu Is pz, dl
mu Is px,d7
mu Is py,d5 * in rx,ry,rz
sub - w d5,d6
move. w d6, rz
ext. 1 dl
231
ST 3D Graphics Abacus Software
*************
** Changes from the program rotl.s * it
** **
**********************************
move.1 dl,d2
232
Abacus Software ST 3D Graphics
***********************************************************************
* Create rotation body by passing parameters, *
* surface arrays *
***********************************************************************
rlset:
* Pass the
move.1 #rlxdat,rotxdat
* parameters for
move. 1 #rlydat,rotydat
move. 1 rotdatz,datz
★ Number of desired rotations
move.w rlnumro,numro
rts
ext.1 dO
move.1 rotdaty,pointy
move.1 rotdatz,pointz
move.w #0,yangle
ext.l dO
move.l rotxdat,datx
move.1 rotydat,daty
move.l rotzdat,datz
233
ST 3D Graphics Abacus Software
add. 1 plusrot,dl
move.1 dl,pointx
move.1 pointy, dl
add. 1 plusrot,dl
move. 1 dl,pointy
move. 1 pointz,dl
add. 1 plusrot,dl
move.1 dl,pointz
move.w yangle,d7
add.w plusagle,d7
move. w d7,yangle
move.1 loopc,dO
dbra dO,rloopl
move.w rlnumro,numro
move.w rlnumpt,numpt
rts
rotlin:
move.w #1, d7
ext .1 d4
subq.1 #1, d4
ext. 1 dl
move.1 dl,plusrot
move.1 linxy,al
move.w d7,d6
dbra d5,rotlop2
234
Abacus Software ST 3D Graphics
move.1 linxy,dl
add. 1 plusrot,dl
move . 1 dl,linxy
move .w numpt,dO
add. w d0,d7
dbra d4,rotlopl
move . w numpt,d7
move.w d7,deltal
lsl. w #2,d7
ext. 1 d7
move . 1 d7,plusrot
move. w #1, d6
move.w numpt,dO
ext. 1 dO
subq.1 #l,dO
ext. 1 dl
subq.1 #1, dl
move. w d6, d5
dl,rotlop4 ★ by rotation
dbra
add.w #1, d6
dbra dO,rotlop3
move.w numro,dl
add. w #1, dl
mu Is nummark, dl
move. w dl,rlnummark
move.w numpt,dl
mu Is numro,dl
move. w numpt,d2
subq.w #1, d2
mu Is numro,d2
add.w dl, d2
235
ST 3D Graphics Abacus Software
move.1 d7,plusrot
move.w d2,d5
addq.w #l,d4
addq.w #1, d5
move.w d5,(aO)+
move.w d5,(aO)+
move.w d2,(aO)+
addq.w #1, dl
addq.w #1, d2
addq.w #1, dl
addq.w #1, d2
dbra dO,rotf11
move.w numpt, dl
subq.w #1, dl
muls numro,dl
236
Abacus Software ST 3D Graphics
move.w dl,rlnumsurf
rts
move -1 #wrldy,daty
move.1 #wrldz,datz
move.1 #viewx,pointx
move.1 #viewy,pointy
move . 1 #viewz,pointz
move.1 #wlinxy,linxy
move. w picturex,xO
move. w picturey, yO
move.w proz,zobs
move.w rlzl,dist
move. 1 #screenx,xplot
move. 1 #screeny,yplot
move.w rlnumline,numline
move.w rlnummark,nummark
move.w rlnumsurf,numsurf
rts
***********************************
★
* Sort surfaces stored in pladress
***********************************
move. w surfcount,d7
subq. 1 #2, d7
subq.1 #l,d2 * j = i -1
move.1 dl, d3 * i
lsl.1 #3, d3
237
ST 3D Graphics Abacus Software
move.1 4(aO,d3.1),d6 h
Address of surface
move. 1 d5,platz * a [0] = x = a [-1] in
move.1 d6,platz+4 * this array
sortlopl: move.1 d2, d4 *
j
lsl.l #3, d4 *
j times 8 for access to array
cmp. 1 (aO,d4.1),d5 * Z-coordinate of surface
bge sortwl * while x < a[j] do
238
Abacus Software ST 3D Graphics
move. 1 #0, dl
move. 1 (aO,dl.1), d6 * first surface in array
add. w #6,d2
bpl paint2
move.w #1, d2
jsr filindex
move. 1 #ptsin,a3 * Enter points here
move. w d4,contrl+2
move. 1 (a6)+,d3 * first line of surface
swap d3
subq.w #1, d3
lsl. w #1, d3
move.w (al,d3.w),(a3)+ * transfer to ptsin array
swap d3
sub. w #l,d3
lsl. w #1, d3
move.w (al, d3 . w) , (a3) + * transmit next point
subq.w #1, d3
lsl -W #1, d3
move.w (al,d3.w),(a3)+ * X-coordinate
239
ST 3D Graphics Abacus Software
jsr vdi
movem.1 U7)+,d0-d2/a0-a2
* filling surfaces. *
move. w #2,contrl+2
move.w #1,contrl+6
move.w grhandle,contrl+12
move.w #1,intin
move. w clipxule,ptsin
move . w clipyule,ptsin+2
move. w clipxlri,ptsin+4
move.w clipylri,ptsin+6
jsr vdi
rts
. even
.bss
240
Abacus Software ST 3D Graphics
numro: .ds.w 1
numpt: .ds.w 1
rotxdat: . ds . 1 1
rotydat: .ds.l 1
rotzdat: .ds.l 1
rotdatx: .ds.l 1
rotdaty: .ds.1 1
rotdatz: .ds.l 1
rlnumline: .ds.w 1
rlnummark: .ds.w 1
rlnumsurf: .ds.w 1
plusagle: .ds.w 1
.data
rlnumpt: .dc.w 12
241
ST 3D Graphics Abacus Software
* *
* *
• data
. dc. w 20,20,0,0,20,20,0,0
.dc. w -10,-10,-30,-30
.dc.w 40,10,10,40,-10,-40,-40,-10
.dc. w 0,-20,-20,0
.dc.w 9,10,1,9,9,2,5,10,6,10,11,12,12,13,13,14
.dc.w 15,16, 16, 17,17,18; 18, 15,19,20,20,21,21,22,22, 19
.dc.w 23,24,24,25,25,26,26,23
242
Abacus Software ST 3D Graphics
rotdpx: .dc.w 0
rotdpy: .dc.w 0
rotdpz: .dc.w 0
rlzl: .dc.w 0
normz: .dc.w 1
.bss
plusrot: .ds.l 1
first: • ds .w 1
second: .ds. w 1
deltal: .ds. w 1
worldpla: .ds.l 1
.data
plag: .dc .b 1
. even
.bss
diffz: .ds. w 1
243
ST 3D Graphics Abacus Software
dx: . ds. w 1
dy: . ds. w 1
dz: . ds. w 1
platz: .ds. 1 2
pladress: • ds.l 3000 * Surface array
surfcount: .ds .w 1
numsurf: . ds. w 1
sx: -ds. w 1
sy: .ds. w 1
sz : .ds .w 1
px: -ds. w 1
py: • ds. w 1
pz: .ds. w 1
244
Abacus Software ST 3D Graphics
rx: .ds. w 1
ry: . ds. w 1
rz: . ds. w 1
qx: .ds. w 1
qy: .ds. w 1
qz: .ds.w 1
kx: . ds. w 1
ky: • ds.w 1
kz: • ds.w 1
. data
.data
.bss
loopc: .ds. 1 1
. end
245
ST 3D Graphics Abacus Software
246
Abacus Software ST 3D Graphics
In this program too, you should change various parameters to see what
they do. Up to now you had to change all the parameters in the program
text. This meant that you had to do a lot of assembling and linking just to
change a few parameters. The sort algorithm will allow you to change
parameters while the program is running. One method to change these
parameters is through a menu. See the diagram below. More about this in
the next section.
ST 3D Graphics Abacus Software
We are now ready to combine the subroutines which we have so far used
separately and to construct a little program for creating rotation bodies,
including the removal of hidden lines and shading surfaces. Furthermore,
we also want to be able to enter the creation lines for the rotation body
with the mouse so that we don’t have to reassemble the program when we
want to use a new definition line. Owners of 520ST’s may find
themselves running short of memory. The available storage space permits
the input of 25 points for a definition line of the rotation body which can
then be rotated 60 times about the Y-axis. Thus a maximum of
25*61 = 1525 points and about 3000 lines and almost 1500 surfaces will
be created. To store this many parameters as well as the program we need
about 190Kbytes of memory, about a third of which is wasted because the
object is defined twice (datx, daty, datz, wrldx, wrldy,
wrldz). This is done to make things easier, but also in consideration of
the next main program which displays several objects at the same time.
We also have to keep in mind the memory require by the two screen
pages-about 64K
248
Abacus Software ST 3D Graphics
using the ROM. If you want to generate rotation bodies with more points
without RAM enhancement, whether through ROMs or RAM chips, you
can change the program so that the rotation body is not duplicated in the
arrays rldatx, rldaty, rldatz, but generated only in the world
system wrldx, wrldy, wrldz and the definition of rldatx,
rldaty, rldatz is completely omitted. This will free about 50
Kbytes of storage which includes the savings from the line array
(rllin) and surface array (rlplane). This space can be distributed
over the world array and thus used to generate larger bodies. The product
of the number of points and the number of rotations plus one is limited.
You can for example, rotate 16 points 90 times, or 40 points 30 times, etc.
The only limits placed are those of your imagination. The number of
rotation points to be entered is determined by the variable maxpoint and
can be changed there.
The use of this program differs in a few points from the programs
presented thus far. After the program start, a menu appears where you can
determine the desired number of rotations of a rotation line already
defined in the program. After you press one of the function keys F2 to F8,
the familiar chess figure appears in the ’’wire model mode" with the
desired number of rotations. The actual rotation parameters such as
position of the rotation point and rotation angle increments can be
changed with the cursor-keys. To remove hidden lines in this rotation
body press the H key on the keyboard (H for Hide). After the visible
surfaces have been drawn, you can fill them with a pattern by pressing the
P key (P for Paint). In both cases you can obtain a hardcopy by pressing
the <Altemate> and <Help> keys at the same time since the surfaces are
drawn and in the visible screen page (physical display ). The picture
drawn on the display remains until the <Retum> key is pressed and
cannot be changed. As a further option you can fill all the surfaces in the
"wire model mode" (P key), not only the visible ones. For hardcopy of a
wire model, press Shift D. By pressing the F10 key you return to the main
menu and you can enter a new rotation line with FI and the help of the
mouse.
249
ST 3D Graphics Abacus Software
and allows you to set a new coordinate origin on the screen (left mouse
button). Here are some examples of definition lines and the rotation
bodies which result.
Abacus Software ST 3D Graphics
ST 3D Graphics Abacus Software
252
Abacus Software ST 3D Graphics
ST 3D Graphics Abacus Software
Abacus Software ST 3D Graphics
ST 3D Graphics Abacus Software
Figure 4.5.13
Don’t let the program listing frighten you. First of all, if you have entered
the previous programs, all you have to do is enter the new subroutines
and change the main loop a bit. Second, you can get a disk containing all
of the programs in the book from Abacus Software or your dealer.
253882 bytes used 1 1442236 bytes used in 123 itens. 333356 butes used in
138344 11-2 □ H0USE1 PRG
l
K PRINTERS BASIC PRG
N TUTORIAL BASIC RSC 4648 11-2 H0USE1 S
C FRY BASIC URK 346 11-2 MAINi PR6
CONV TTP BASIC1 BAR 14801 11-2 HAIN1 S
HL10 PRO HAIN1C0 PRG
OUTPUT PRG MAIN1CD S
OPEN APPLICATION
SPLIT TTP MENU1 PRG
STANDARD PRT Nane: BATCH .TTP MENU1 S
TEXTPRO PRG Parameters: . HULTI1 PRG
TUTORIAL TXT aslink grlinkl nenul|_ _ HULTI1 S
XTTUTORI TOC PAINT1 PRG
■
PAIKT1 S
R0TATE1 PRG
1 1
■
R0TATE1 S
Abacus Software ST 3D Graphics
***********************************************************************
* menul.s 2/18/1986 *
* Creation of rotation bodies Uwe Braun 1985 Version 2.2 *
* with hidden line algorithm and painting *
* *
.globl main,xoffs,yoffs,zoffs,offx,offy,offz
•globl viewx,viewy,viewz
.globl wlinxy,mouse_off,setrotdp,inp_chan,pointrot
. text
main:
jsr apinit * Announce programm
jsr grafhand * Get screen handler
jsr openwork * Display
jsr mouse off * Turn off mouse
jsr getreso * Display resolution
jsr setcocli * set Cohen Sutherland clip.
mainlopl:
jsr pointrot * rotate around observ. ref. point
jsr pers * Perspective transformation
jsr drawnl
257
ST 3D Graphics Abacus Software
jsr drawnl
move.1 physbase,logbase
move.1 #text3,aO
jsr printf
swap dO
bne menul
bra menu
bne menu 2
258
Abacus Software ST 3D Graphics
bne menu 3
move.w #8,rlnumro
bra menend
bne menu 4
move.w #12,rlnumro
bra menend
bne menu 5
bra menend
bne menu6
move. w #24,rlnumro
bra menend
bne menu7
move. w #45,rlnumro
bra menend
bne menu 8
move.w #60,rlnumro
bra menend
bne menuO
addq.1 #4,a7
bra ma inend
menend: rts
259
ST 3D Graphics Abacus Software
*****************************************************************
* Test if removal of hidden surface and shading of surfaces *
* is desired *
*****************************************************************
swap dO
★A*****************************************************************
* Call hideit routine to remove hidden Surfaces *
*******************************************************************
swap dO
beq dopain2
jsr pageup
swap dO
bne dopain3
jsr pageup
rts
260
Abacus Software ST 3D Graphics
***********************************************************************
jsr clwork
swap dO
jsr pageup
rts
rts
bne inpwait
bne inpl
261
ST 3D Graphics Abacus Software
subq.w #1,ywplus
bra inpendl
bne inp3
bra inpendl
bne inp3a
bra inpendl
bne inp3b
subq.w #1,zwplus
bra inpendl
bne inp4
addq.w #1,zwplus
bra inpendl
bra inpendl
inp6 *
bne
bra inpendl
262
Abacus Software ST 3D Graphics
bne inp8
bra inpendl
bne inplO
bra inpendl
bne inpendl
bra mainl
bge inpend2
bra inpend4
bra inpend4
cmp. w #360,dl
bge inpend5
cmp. w #-360,dl
ble inpend6
bra inpend7
bra inpend7
263
ST 3D Graphics Abacus Software
move.w hzangle,dl
add. w zwplus,dl
cmp. w #360,dl
bge inpend8
cmp. w #-360,dl
ble inpend9
bra inpendlO
bra inpendlO
rt s
fr*****************************************************************
* Set the location of the coordinate origin of the screen *
move. w y0,d3
o
a
move.w d3,y0
rts
********************************************************************
* Determine the current screen resolution *
********■*********★**********★**************"****'****•***'*■*******■****
trap #14
addq.l #2,a7
264
Abacus Software ST 3D Graphics
cmp.w #2, dO
bne getrl
move. w #200,picturey
bra getrend
bne getr2
move. w #100,picturey
bra getrend
getrend: rts
trap #14
addq.l #2,a7
jsr clearbuf
rts
move. w dl,rotdpz
move.w #0,hzangle
move.w #0,hxangle
move. w #0,ywplus
move. w #0,xwplus
move -w #0,zwplus
rts
265
ST 3D Graphics Abacus Software
* Rotation around the rot. ref. point about all three axes *
move. w hzangle,zangle
move.w d2,zoffs
neg. w dO
neg. w dl
neg.w d2
move. w d2,offz
*********************************************************************
* Set the limit of display window for the Cohen-Sutherland clip *
* The limits are freely selectable by the user which makes the *
move. w #0,clipxule
move.w #0,clipyule
move. w picturex,dl
Isl. w #1, dl * times two
subq.w #1, dl ■k
minus one equals
move. w dl,clipxlri * 639 for monochrome
move.w picturey,dl
266
Abacus Software ST 3D Graphics
move.w dl,clipylri
rt s
move. 1 trldaty,a2
move.1 #rldatz,a3
move . 1 #wrldz,a6
move. w rlnummark,dO
ext. 1 dO
subq. 1 #l,dO
move.w (a3)+,(a6)+
dbra dO,makewll
ext. 1 dO
subq.1 #1, dO
move.1 #rllin,al
move. 1 twlinxy,a2
ext. 1 dO * as counter
subq.1 #1, dO
267
ST 3D Graphics Abacus Software
268
Abacus Software ST 3D Graphics
*********************************************************************
hideit:
numsurf, dO * Number of surfaces as counter
move . w
ext. 1 dO
subq.1 #1* dO
#viewx,al * point coordinates stored here
move.1
move . 1 #viewy,a2
move.1 ffviewz, a3
move.1 #wplane,aO ★ here is information for every
lsl. w #l,d3
lsl. w #l,d4 * and finally access the current
move . w 12 (aO) , d4
subq.w #l,d4
lsl. w #1, d4
269
ST 3D Graphics Abacus Software
doit1:
move. w (a3, d3 . w) , d5
move.w d5, kz
sub. w (a3,d2.w),d5
move.w d5,pz
sub. w (a2,d2.w),d6
move. w d5, dl * qx
move.w d6,d2 * qy
move. w d7,d3 * qz
sub.w d2,d3
move.w d3, rx
muls pz, dl
mu Is px, d7
* the vector
move.w dl, ry * which is perpendicular to the
muls px, d6 * surface area stored temporarily
muls py,d5 * rx,ry,rz
sub. w d5,d6
move.w d6, rz
270
Abacus Software ST 3D Graphics
ext.1 dl
lsl.l #2,dl * Number of lines times 4 = space for lines
move.l dl,d2
lsl.l #l,dl * number of words to be transmitted
move.l a0,a4
addq.l #2,a4 * Access to first line of surface
271
ST 3D Graphics Abacus Software
hideend: rts
move.1 yplot,a5
ext. 1 dO
subq.1 #1, dl
move. w 0 (a4,d5.w),d2
272
Abacus Software ST 3D Graphics
subq. w #1, d5
lsl. w #1, d5
rlset:
move.1 #rldatx,rotdatx
move.1 #rldaty,rotdaty * rotation body
move.1 #rldatz,rotdatz
move . 1 rotdatx,datx * Array addresses of points
move.1 rotdaty,daty
move. 1 rotdatz,datz
move.w rlnumro,numro * Number of desired rotatations.
rts
************** •k
★
* and create rotation body
*
ext .1 dO
273
ST 3D Graphics Abacus Software
move. 1 rotdaty,pointy
move. 1 rotdatz,pointz
ext. 1 dO
move.1 rotxdat,datx
move.1 rotydat,daty
move.1 rotzdat,datz
add. 1 plusrot,dl
move.1 dl,pointx
move.1 pointy,dl
add. 1 plusrot,dl
move.1 dl,pointy
move. 1 pointz,dl
add. 1 plusrot,dl
move.1 dl,pointz
move. w yangle,d7
add.w plusagle,d7
move.w d7,yangle
move.1 loopc,dO
dbra dO,rloopl
move.w rlnumro,numro
move.w r1numpt,numpt
rts
rotlin:
move. w #l,d7
ext. 1 d4
subq.1 #l,d4
274
Abacus Software ST 3D Graphics
ext. 1 dl
move. 1 dl,plusrot
move.1 linxy,al
move. w d7,d6
move.w d6,(al)+
dbra d5,rotlop2
move.1 linxy,dl
add. 1 plusrot,dl
move.1 dl,linxy
move.w numpt,dO
add. w d0,d7
dbra d4,rotlopl
move. w numpt,d7
move. w d7,deltal
lsl. w #2, d7
ext. 1 d7
move. 1 d7,plusrot
move. w #1, d6
move . w numpt,dO
ext. 1 dO
subq.1 #l,dO
ext. 1 dl
subq.1 #1, dl
move.w d6,d5
dbra dl,rotlop4
275
ST 3D Graphics Abacus Software
add. w #l,d6
dbra dO,rotlop3
move.w numro,dl
add. w #l,dl
mu Is nummark,dl
move.w dl,rlnummark
move.w numpt,dl
mu Is numro,dl
move.w numpt,d2
subq.w #1, d2
mu Is numro,d2
add. w dl, d2
rts
subq.1 #l,dO
ext .1 d7 * repeat
subq.1 #2,d7
move.1 d7,plusrot
move.w #1, dl
addq.w #1, d2
276
Abacus Software ST 3D Graphics
move.w d2,d5
addq.w #l,d4
addq.w #l,d5
move.w #4, (aO> + * Number of lines / surfaces
addq.w #l,dl
addq.w #l,d2
dbra d7,rotfl2
addq.w #l,dl
addq.w #l,d2
dbra dO,rotfll
move.w numpt,dl
subq.w #1, dl
muls numro,dl
move.w dl,rlnumsurf
rts
277
ST 3D Graphics Abacus Software
************************************************************************
* Transfer the world parameters and the variables to the link file *
************************************************************************
move.1 #viewx,pointx
move.1 #viewy,pointy
move.1 Iviewz,pointz
move.1 #wlinxy,linxy
move.w picturex,xO
move.w picturey,yO
move.w proz,zobs
move.w rlzl,dist
move.1 #screeny,yplot
move.w rlnumline,numline
move.w rlnummark,nummark
move -w rlnumsurf,numsurf
rts
**********************************************************************
move.w surfcount,d7
subq.1 #l,d2 ★ j = i -1
move.1 dl, d3 * i
lsl.l #3,d3
278
Abacus Software ST 3D Graphics
bra sortlopl
addq. 1 #1/ dl * i - i + 1
sortend: rts
********************************************************************
* paintall draws all surfaces in world array wplane independent of *
paintall:
ext.l dO
move.1 #viewz,a3
move.l #wplane,aO
svisible:
ext.1 dl
subq.l #l,dl
move.l a0,a4
addq.l #2,a4
279
ST 3D Graphics Abacus Software
swap d2
subq.w #1» d2
lsl. w #1/ d2
dbra dl,ssightbl
move.w zsurf,d6
move.w numsurf,surfcount
pquit: rt s
jsr filmode
jsr filstyle
move. 1 yplot,a2
ext .1 d7 * as counter
280
Abacus Software ST 3D Graphics
lsl.l #3, dO
move.1 #0, dl
bpl paint2
move.w #1, d2
jsr filindex
move.w d4,contrl+2
swap d3
subq.w #l,d3
lsl. w #l,d3
swap d3
sub. w #1» d3
lsl. w #l»d3
move.w (al,d3.w),(a3)+ * transmit next point
subq.w #1< d3
lsl. w #l,d3
281
ST 3D Graphics Abacus Software
move. w #0,contrl+6
move.w grhandle,contrl+12
movem.1 dO-d2/aO-a2,-(a7)
jsr vdi
movem.1 (a7)+,d0-d2/a0-a2
dbra d7,paintl
rts
move.w #2,contrl+2
move.w #1,contrl+6
move.w grhandle,contrl+12
move.w #1,intin
move.w clipxule,ptsin
move.w clipyule,ptsin+2
move.w clipxlri,ptsin+4
move. w clipylri,ptsin+6
jsr vdi
rts
*******************************************************************
* this subroutine allows coordinates to entered with the Mouse
inpmous:
jsr switch
move. w #5, dO
jsr setform
282
Abacus Software ST 3D Graphics
move. 1 #0,adressx
jsr marktype
add. w #15,d2
move.w picturey,d3
sub.w #40,d3
jsr mouspos
move.w d3,newy
move.w newx,d2
move.w newy,d3
mousl: nop
move.w newx,altx
move.w newy,alty
move. w alty,d3
jsr mouspos
cmp.b #$20,dl
bne mouslop2
move.w d3,newy
283
ST 3D Graphics Abacus Software
move.w newy,d3
move.w altx,a2
move. w alty,a3
jsr drawl
move.w newx,d2
move.w newy,d3
move.1 adressx,d7
move.1 adressx,dO
rts
move.w d3,newy
move.w altx,a2
move.w alty,a3
jsr markit
jsr saveit
move. 1 adressx, dO
***********************************************************************
284
Abacus Software ST 3D Graphics
move. w grhandle,contrl+12
move. w d3,ptsin+2
jsr vdi
move . w ptsout+2,d3 * D3
rts
move.w grhandle,contrl+12
move.w dO,intin
jsr vdi
rts
move.w grhandle,contrl+12
move. w d2,ptsin
move.w d3,ptsin+2
movem.1 d0-d2/a0-a2,-(a7)
movem.1 (a7)+,dO-d2/aO-a2
rts
285
ST 3D Graphics Abacus Software
A**********************************************************************
* Set input mode
***********************************************************************
move.w #0,contrl+2
move.w #2,contrl+6
move.w grhandle,contrl+12
move.w dO,intin
jsr vdi
rts
neg.w d3
rts
Abacus Software ST 3D Graphics
**********************************************************************
* Display and describe the same screen page *
**********************************************************************
move.w #5,-(a7)
trap #14
add. 1 #12,a7
rts
move.w #1,contrl+6
move.w #0,contrl+8
move.w dO,intin
jsr aes
rts
***********************************************************************
* Drawing a coordinate system for mouse input *
***********************************************************************
move.w picturey,d3
move.w picturex,d5
lsl. w #1, d5
move.w d5,a2
287
ST 3D Graphics Abacus Software
move.w d3,a3
jsr drawl
move.w picturex,d2
move.w #0, d3
move. w d2,a2
move.w picturey,d5
lsl. w #1, d5
move.w d5,a3
jsr drawl
rts
******************************************************************
* remove all characters present in the keyboard buffer *
******************************************************************
trap #1
addq.1 #2,a7
bra clearbuf
clearnd: rts
move.w #0,contrl+2
move.w #37,contrl+6
move.w grhandle,contrl+12
move.w #8,intin
move.w #8,intin+2
288
Abacus Software ST 3D Graphics
move.w #1,intin+4
move.w #0,intin+6
move.w #1,intin+8
move.1 tintin+10,a5
move.1 (al)+,(a5)+
dbra dO,forlop
jsr vdi
rts
.even
.bss
numro: .ds. w 1
numpt: .ds. w 1
rotxdat: .ds.l 1
rotydat: .ds.l 1
rotzdat: .ds.l 1
rotdatx: .ds.l 1
rotdaty: .ds.l 1
rotdatz: .ds.l 1
rlnumline .ds. w 1
rlnummark .ds. w 1
rlnumsurf . ds. w 1
plusagle: .ds. w 1
rldatz: . ds . w 1600
289
ST 3D Graphics Abacus Software
• data
rlnumpt: .dc.w 12
rlnumro: .dc.w 8
* *
* *
************************************************************************
.data
.dc.w 40,10,10,40,-10,-40,-40,-10
.dc.w 0,-20,-20,0
290
Abacus Software ST 3D Graphics
***********************************************************************
* Here is the definition of the surfaces belonging to the house *
***********************************************************************
.dc.w 4,5,6,6,7,7,8,8,5,4,7,6,6,1,1,4,4,7
.dc.w 4,4,3,3,8,8,7,7,4,4,2,9,9,10,10,5,5,2
.dc.w 4,10,9, 9,1,1, 6,6,10,3,1, 9, 9, 2,2,1
.dc.w 3,5,10,10,6,6,5,4,11,12,12,13,13,14,14,11
.dc.w 4,15,16,16,17,17,18,18,15,4,19,20,20,21,21,22,22,19
.dc.w 4,23,24,24,25,25,26,26,23
rotdpx: .dc.w 0
rotdpy: .dc.w 0
rotdpz: .dc.w 0
291
ST 3D Graphics Abacus Software
rlzl: . dc. w 0
normz: . dc. w 1500
.bss
plusrot: . ds. 1 1
first: . ds. w 1
second: • ds. w 1
deltal: .ds. w 1
T3
•—i
worldpla: 1
w
. data
plag: • dc.b 1
.even
.bss
diffz: • ds .w 1
dx: .ds. w 1
dy: .ds. w 1
dz: • ds. w 1
292
Abacus Software ST 3D Graphics
space: .ds. 1 2
pladress: .ds. 1 3000 * Surface array
surfcount : .ds.w 1
numsurf: .ds .w 1
sx: .ds.w 1
sy: .ds.w 1
sz: .ds.w 1
px: .ds.w 1
py: .ds.w 1
pz: .ds.w 1
rx: .ds.w 1
ry: • ds.w 1
rz: • ds.w 1
qx: .ds.w 1
qy: .ds. w 1
qz: .ds.w 1
kx: .ds.w 1
ky: .ds.w 1
kz : .ds.w 1
293
ST 3D Graphics Abacus Software
Hr ************** + ********************★***
.data
• even
maxpoint: .dc. 1 25
mousx: .dc.w 0
mousy: • dc.w 0
mousbut: .dc.w 0
kybdstat: .dc.w 0
altx: .dc.w 0
alty: .dc.w 0
newx: .dc.w 0
newy: .dc.w 0
adressx: .dc. 1 1
.data
.data
294
Abacus Software ST 3D Graphics
mousforl: .dc.w
.dc.w %11111111111111U
.dc.w
• dc.w
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w %iiiiiiiimniii
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w
.dc.w %0111111111111111
• dc.w %1111111111111110
.dc.w %0000000000000000
.bss
loopc: .ds.l 1
. end
295
ST 3D Graphics Abacus Software
paint a 11: Enter all surfaces of rotation body into surf addr
array, sort and fill.
296
Abacus Software ST 3D Graphics
297
ST 3D Graphics Abacus Software
The principle of the construction of the world line array is also used
during construction of the world surface array, for example the first
surface definition of the second house within the world surface array:
4,27,28,28,29,29,30,30,27
Furthermore, the total number of all points, lines and surfaces must be
calculated and recorded.
298
Abacus Software ST 3D Graphics
Now to the object definition block, which contains all the information
describing the individual object. The idea was to extend the available
world system by one object through addition of the definition block to the
existing blocks and incrementing the "object counter." Here for
clarification is an object definition block in which N is replaced with the
index of the current object:
objectN:
objNxda: .dc.l Address of the X-coordinate
array of the obj.
objNyda: .dc.l Address of the Y-coordinate
array of the obj.
objNzda: .dc.l Address of the Z-coordinate
array of the obj.
objNlin: .dc.l Address of the object line
array
objNpla: .dc.l Address of the object surface
array
objmrk: .dc.w Number of points in this
object
objNali: .dc.w Number of lines in this
object
objpln: .dc.w Number of surfaces on this
object
objNxO: .dc.w X-position of object in world
system
objNyO: .dc.w Y-position of object in world
system
objNzO: .dc.w Z-position of object in world
system
objNxw: .dc.w Rotation angle of obj. about
X-axis
objNyw: .dc.w Rotation angle about Y-axis
objNzw: .dc.w Rotation angle aboutZ-axis
299
ST 3D Graphics Abacus Software
The angles and also the position in the world system relate to the
"rotationally neutral” point of the current object, the origin of the object
definition coordinate system. As a whole, the block consists of 38 bytes,
but can easily be extended with additional information, such as scale
factors, etc. If two identical objects are to be created, you write two
object definition blocks this is important since the creation routine finds
the next block using the distance of 38 bytes between two blocks. Since
two identical objects are to be created, the addresses for the two blocks
are the same and only the position of the objects and perhaps the rotation
angles differ. After the definition has been completed, the total number of
objects, in this case two, is placed in the variable numob j: and now the
total world system can be generated with a single subroutine call.
The main loop is easily changed. Here the total number of the desired
objects, four, is passed and the new subroutines new_wrld and
new_mark are called.
300
Abacus Software ST 3D Graphics
Beside being able to display multiple objects, this program offers another
novelty: two successive transformations of the same object. First, the four
objects are "set" into the world system with new_mark: after they have
first been rotated about three axes. After all objects have been ‘’rotated" in
the world system you can, through control with the keyboard, rotate the
entire system consisting of the four houses around a point in the world
system, or move the projection plane similar to previous programs. The
four houses of the system rotate around different axes of their
"rotationally neutral” points at various places in the world system. The
display on the screen occurs after the removal of the hidden lines with the
familiar subroutine hide it:, which is used on the complete world array
so that the four houses are not created through mirroring or something
similar, but the hidden surfaces of all four objects are calculated in real¬
time. The hide it algorithm of this program does not recognize
covering by other visible surfaces so that a house covered by other houses
will be drawn.
Control keys are again the cursor, help and undo keys, as well as the / * -
+ keys on the keypad.
301
ST 3D Graphics Abacus Software
* multil.s 22.2.1986 *
. globl main,xoffs,yoffs,zoffs,offx,offy,offz
.globl viewx,viewy,viewz
.globl wrldx,wrldy,wrldz,gnummark,gnumline,gnumpla
.globl viewx,viewy,viewz,wplane
.text
main:
jsr pageup
jsr clwork
302
Abacus Software ST 3D Graphics
mainlopl:
A**********************************************************************
4-1
4-1
move.w
0
>■
move. w #0,offz
jsr new it
move.1 #viewx,pointx
move.1 #viewy,pointy
move.1 #viewz,pointz
move . 1 #wrldx,datx
move. 1 #wrldy,daty
mo ve. 1 #wrldz,datz
move.1 #wlinxy,linxy
303
ST 3D Graphics Abacus Software
move.w gnumline,numline
move.w gnumpla,numsurf
rts
add. w #4, dO
cmp.w #360,dO
bit changwl
sub.w #360,dO
changwl:
move.w dO,objlyw
move.w dO,obj2xw
move.w dO,obj3zw
move.w dO,obj4xw
move.w dO,obj4yw
move.w dO,obj4zw
rts
***********************************************************************
* Set all world parameters for the link file variables and
* create the point, line, and surface arrays of the world system
***********************************************************************
move.w dO,offx
move.w dO,offy
move.w dO,offz
move.w proz,zobs
move.1 #screeny,yplot
move.w picturey,yO
Abacus Software ST 3D Graphics
move.1 #wrldz,datz
move. 1 #viewx,pointx
move.1 #viewy,pointy
move.1 #viewz,pointz
move.1 #wlinxy,linxy
rts
•ft**********************************************************************
ext .1 dO * as counter
move.1 d7,d6
move.1 d6,d7
add. 1 #wrldy,d7
move.1 d7,pointy
add. 1 twrldz,d6
305
ST 3D Graphics Abacus Software
move.w 36 (aO),zangle
movem.1 <a7)+,d0-d7/a0-a6
ext. 1 d7
***********************************************************************
* Pass all lines to world system, one-time call at *
ext. 1 d°
ext. 1 dl
306
Abacus Software ST 3D Graphics
ext. 1 d7
rts * back
move.1 #0,plapntr
subq.1 #l,d0
move.1 d7,a2
subq.1 #1, dl
ext. 1 d2
307
ST 3D Graphics Abacus Software
move.1 d2,d6
add. 1 d6,plapntr
move.w 24 (aO),d7
cmp.b #'D',dO
bne inpwait
bne inpl
bra inpendl
308
Abacus Software ST 3D Graphics
bne inp3a
bra inpendl
bne inp3b
subq.w #1,zwplus
bra inpendl
bne inp4
bra inpendl
bra inpendl
bne inp6 *
bra inpendl
bne inp8
bra inpendl
inp8:
309
ST 3D Graphics Abacus Software
bne inpendl
bge inpend2
bra inpend4
bra inpend4
cmp. w #360,dl
bge inpend5
cmp.w #-360,dl
ble inpend6
bra inpendl
bra inpend7
move.w hzangle,dl
add.w zwplus, dl
cmp.w #360,dl
bge inpend8
cmp.w #-360,dl
ble inpend9
bra inpendlO
bra inpendlO
310
Abacus Software ST 3D Graphics
rts
******************************************************************
* Determine the current screen resolution *
******************************************************************
. trap #14
addq.1 #2,a7
cmp. w #2, dO
bne getrl
move.w #200,picturey
bra getrend
bne getr2
move.w #100,picturey
bra getrend
move.w #100,picturey
getrend: rts
trap #14
addq.1 #2,a7
jsr clearbuf
rts
311
ST 3D Graphics Abacus Software
A**********************************************************************
move.w dl,rotdpy
move. w dl,rotdpz
move. w #0,hzangle
move.w #0,hxangle
move.w #0,ywplus
move. w #0,xwplus
move.w #0,zwplus
rts
*******************************************************************,
* Rotation around the rot. ref. point around all three axes
*******************************************************************>
move.w hyangle,yangle
move.w hzangle,zangle
move.w rotdpy,dl
move.w rotdpz,d2
move.w dl,yoffs
move.w d2,zoffs
neg .w dO
neg. w dl
neg. w d2
move.w dl,offy
move.w d2,offz
312
Abacus Software ST 3D Graphics
*********************************************************************
* Set the limits of screen window for the Cohen-Sutherland *
* The limits can be freely selected by the user, which makes the *
move.w # 0,c1ipyule
move.w picturex,dl
lsl.w #1,dl
subq.w #l,dl
move.w dl,clipxlri
move.w picturey,dl
lsl.w #1,dl
subq.w #l,dl
move.w dl,clipylri
rts
hideit:
move.w numsurf,dO * Number of surfaces as counter
ext.1 dO
subq.l #l,dO
move.1 #viewx,al * The point coordinates are stored
move.l #viewz,a3
313
ST 3D Graphics Abacus Software
subq.w #l,d4
lsl. w #l,d3
bne doitl
move.w 12(aO),d4
subq.w #l,d4
lsl. w #1, d4
doitl:
move.w (a2,d3.w),d5
move.w (a3,d3.w),d5
move.w d5, kz
sub. w (a3,d2.w),d5
move.w d5, pz
sub. w (al,d2.w),d5
sub. w (a2,d2.w),d6
move.w (a3,d4.w),d7
sub. w (a3,d2.w),d7
move. w d5,dl * qx
move . w d6,d2 * qy
move. w d7,d3 * qz
314
Abacus Software ST 3D Graphics
move.w d3, rx
mu Is pz, dl
mu Is px,d7
vector
mu Is py,d5
sub. w d5,d6
move.w d6, rz
the comparison
bmi dosight
ext.l dl
lsl.l #2,dl * Number of lines times 4 = space for Lines
move.1 dl, d2
move. 1 aO, a4
hideend: rts
*********************************************************************
* Draw surfaces entered in vplane *
**********************************************************************
move.1 yplot,a5
ext .1 dO
subq.1 #l,dl
316
Abacus Software ST 3D Graphics
subq. w #l,d5
lsl. w #l,d5
move. w 0 (a5, d5 . w) , a3
rt s * finally return.
move. w #5,-<a7)
trap #14
add. 1 #12,a7
rts
******************************************************************
trap #1
addq.1 #2,a7
bra clearbuf
clearnd: rts
. even
317
ST 3D Graphics Abacus Software
• data
318
Abacus Software ST 3D Graphics
.dc.w 4,5,6,6,7,7,8,8,5,4,7,6,6,1,1,4,4,7
.dc.w 4,4,3,3,8,8,7,7,4,4,2,9,9,10,10,5,5,2
.dc.w 4,10,9,9,1,1,6,6,10,3,1,9,9,2,2,1
.dc.w 3,5,10,10,6,6,5,4,11,12,12,13,13,14,14,11
.dc.w 4,15,16,16,17,17,18,18,15,4,19,20,20,21,21,22,22,19
.dc.w 4,23,24,24,25,25,26,26,23
rotdpx: .dc.w 0
rotdpy: .dc.w 0
rotdpz: . dc. w 0
rlzl: .dc.w 0
.bss
319
ST 3D Graphics Abacus Software
plusrot: .ds. 1 1
first: . ds. w 1
second: .ds. w 1
deltal: .ds. w 1
worldpla: .ds. 1 1
.data
plag: .dc .b 1
. even
.bss
diffz: • ds .w 1
dx: .ds .w 1
dy: .ds .w 1
dz: .ds. w 1
wrldy: • ds .w 1600
320
Abacus Software ST 3D Graphics
space: . ds. 1 2
surfcount: . ds. w 1
numsurf: . ds. w 1
zcount: . ds. 1 1 *
zsurf: . ds . w 1 *
*****************************
.data
gnumobj: .dc.w 2
gnummark: . dc. w 0
gnumline: .dc.w 0
gnumpla: .dc.w 0
mark_it: .dc. 1 0
linpntr: .dc. 1 0
plapntr: .dc. 1 0
objectl:
objlmrk: .dc.w 26
objlali: .dc.w 32
objlpln: .dc.w 13
objIzO: .dc.w 0
objlxw: .dc.w 20
objlyw: .dc.w 0
objlzw: .dc.w 0
object2:
321
ST 3D Graphics Abacus Software
obj2mrk: .dc.w 26
obj2ali: .dc.w 32
obj2pln: .dc.w 13
obj2z0: .dc.w 0
obj2xw: .dc.w 0
obj2yw: .dc.w 20
obj2zw: .dc.w 0
object3:
obj3mrk: .dc.w 26
obj3ali: .dc.w 32
obj3pln: .dc.w 13
obj3xw: .dc.w 0
obj3yw: .dc.w 20
obj3zw: .dc.w 0
object4 :
obj4mrk: .dc.w 26
obj4ali: .dc.w 32
obj4pln: .dc.w 13
obj4z0: .dc.w 0
322
Abacus Software ST 3D Graphics
obj4zw: .dc. w 0
.bss
sx: .ds.w 1
sy: .ds.w 1
sz: .ds.w 1
px: .ds.w 1
py: .ds.w 1
pz: .ds.w 1
rx: .ds.w 1
ry: .ds.w 1
rz: -ds.w 1
qx: .ds.w 1
qy: .ds.w 1
qz: .ds.w 1
kx: .ds.w 1
ky: .ds.w 1
kz: • ds.w 1
**********************
.data
• even
maxpoint: .dc. 1 25
mousx: .dc.w 0
mousy: .dc. w 0
mousbut: .dc. w 0
kybdstat: .dc.w 0
altx: .dc.w 0
alty: .dc.w 0
newx: .dc.w 0
newy: .dc.w 0
323
ST 3D Graphics Abacus Software
addrssx: .dc. 1 1
.data
• data
of f z: .dc.w 0
zoffs: .dc.w 0
.bss
loopc: .ds. 1 1
.end
10 a?
min \trrm ■n'v.-r rrrwt j-amattfil jS33HEflB33i
a? ■BSffiSMI
324
Abacus Software ST 3D Graphics
327
ST 3D Graphics Abacus Software
After the observed world is displayed, the parameters such as the position
of the airplane in the world system or the position of other objects in the
world system, such as a second airplane, can be changed. Now the
procedure described above is called again and this cycle repeated
continually.
328
Abacus Software ST 3D Graphics
329
ST 3D Graphics Abacus Software
330
Abacus Software ST 3D Graphics
(...a4a3a2aiao.a-ia-2a-3a-4.")b =
+ a4*b4 + a3*b3 + a2*b2 + ai*bl + ao*bO + a-i*b_l + ...
(3423.87)10 =
3*103 + 4*102 + 2*101 3*100 + 8*10-1 + 7*10-2 =
3000 + 400 + 20 + 3 + 0.8 + 0.07 = 3423.87
1110010010010= 1*212+1*211+1*210+1*27+1*24+1*21=
4096 + 2048 + 1024 + 128 + 16 + 2 = 7314
333
ST 3D Graphics Abacus Software
334
Abacus Software ST 3D Graphics
A line in such a system is defined by two points which belong on the line.
All points on the line can be ascertained with the following equation.
y-yi y2:yl
for (x2-xl) <> 0
x-xl x2-xl
In this two point format, the expression (y2-yl)/(x2-xl) gives the slope m
of the straight line, which simultaneously represents the tangent of the
angle between the line and the X-axis (phi).
335
ST 3D Graphics Abacus Software
y2-yi
x2-xt
With the definition of the slope m as well as the axis intersection a, the
intersection of the line with the Y-axis, we get what is called the normal
form of the straight line equation.
y = m*x + a
With this equation you can calculate all points on the line by introducing
various X values into the above equation, knowing the slope m and axis
intersection a.
For the middle-point of a straight line which connects two points (PI,
P2), we can easily calculate the coordinates of this segment:
xl+x2 yl+y2
Xm = Ym =
"T* 2
336
Abacus Software ST 3D Graphics
Figure B.2
337
ST 3D Graphics Abacus Software
With the aid of this definition we can say for the system and the screw: If
a screw is placed in such a system (in the direction of a coordinate axis)
and the screw is turned about a positive angle (see above definition), then
the screw moves in the direction of a positive coordinate axis. You can
determine the position axis of a coordinate system through the definition
of the positive angle as well as the selection of the screw, or you can
recognize the type of an existing coordinate system. As an explanation, in
a right-hand system the right-handed screw moves in the direction of a
positive coordinate axis when rotated about a positive angle. On the other
hand, a left handed screw in a left-hand system rotated about a positive
angle will also move in the direction of positive coordinate axis. Since in
our country, screws with right-handed threads are most common, we shall
follow the positive rotations of a right-handed screw in a right-hand
system.
338
Abacus Software ST 3D Graphics
339
ST 3D Graphics Abacus Software
Using a parameter u, which can assume real values between -infinity and
+infinity, all points on a line running through points Pl[xl,yl,zl]
and P2 [x2, y2, z2 ] can be determined. For individual coordinates the
values are:
x = (x2-xl) * u + xl
y = (y2-yi) * u + yl
z = (z2-zl) * u + zl
If we use only u real numbers between 0 and 1, all points on the line
between PI and P2 can be calculated. The line would not run beyond PI
and P2, but would be cut off at the two points. From the lines we get a
vector, which has a definite direction in space. In our example it points
from PI to P2.
340
Abacus Software ST 3D Graphics
341
ST 3D Graphics Abacus Software
The scalar product is the sum of the products of the individual vector
coordinates and is important to determine angles (phi) between two
vectors (A,B).
A-B = ax*bx+ay*by+az*bz = | A| *|B|*cos(phi)
A-B =V ( (ax2+ay2+az2) * (bx2+by2+bz2) ) *cos (phi)
The cross product (AxB), in contrast to the scalar product, is not a real
number but another vector (C). The resultant vector stands perpendicular
to the plane between the vectors A and B and together with them forms a
new coordinate system. The rule of the screw helps us again in the
determining the direction of the resulting vector:
Figure B.5
343
ST 3D Graphics Abacus Software
an an an ... am
a2i a22 a23 ... a2n
a3i a32 a33 ... 33n
aik,a2ic,.-amk form the kth column of the matrix. If the number of columns
is equal to the number of rows (m=n), A is called a square matrix. A few
rules can be stated for matrix calculation.
344
Abacus Software ST 3D Graphics
1 2 3 1 2 3
A= 4 5 6 B= 4 5 6
7 8 9 7 8 9
2 4 9
C = A+B = 8 10 12
14 16 18
The elements of the sum matrix result from: sik = aik + bik for i,k from 1
to 3. The limits of the variables i and k are written in mathematical form:
i,k = 1(1)3. The value in front of the parentheses is the start value, the
value in the parenthesis is the increment and the last number designates
the final value of the variables. In this example, i and k take values of one
through three with an increment of one. These are the numbers 1,2,3.
During matrix addition, one adds the elements which are in the same
place in each matrix, to obtain the elements of the sum matrix S. One
proceeds in the same manner when multiplying of matrix A with a
constant factor f ac. The elements of the product matrix P are calculated
by multiplying each element in A by the factor.
pik = fac * aik i,k= 1(1)3
345
ST 3D Graphics Abacus Software
A= 1 2 B= 5 6
3 4 7 8
19 22
43 50
The result matrix P therefore contains the same number of lines as the
multiplicand A and the same number of rows as the multiplier B. In
regard to matrix multiplication there is a neutral element, i.e. for every
matrix A there is a matrix N with which A can be multiplied without
changing the original matrix. A*N=A. N is called the unit matrix and the
elements of the diagonal are one. All others have the value zero.
Moreover, the associative and the distributive law are valid during
multiplication.
346
Abacus Software ST 3D Graphics
The commutative law does not hold for matrix multiplication. This means
A*B is not necessarily equal to B*A. The order of the multiplication is
not arbitrary, as you see, and must be observed.
347
ST 3D Graphics Abacus Software
Appendix D: Bibliography
348
Abacus Software ST 3D Graphics
INDEX
Abscissa 335
Apple Macintosh 4 D
Assembler 88, 89
Associative 346
Axis-symmetrical objects 169 Data system 117
Decimal system 333, 334
Definition block 298-300
B Definition line 169, 189
Desktop 296
Digital Research 88
BASIC1.S 92 Direction Binary number 334
Batch file 90 Display coordinate system 7
Binary system. Display of reveral objects 298
BIOS 88 Distributive law 346
Draw-line-algorithm 107
C
E
C programming language 4
CAD systems 3 Extended coordinate system 31
CAD-CAM 3 Extended-BIOS 88
Cartesian coordinate system 7, 108,
249, 335
CAT scans 3 G
Clip algorithm 122
Cohen-Sutherland clipping algorithm
122, 337 GEM functions 88
Color monitor 219 GEM-DOS 88
Column vectors 344 Global variables 152
Commodore Amiga 4 GRLINK1.S 123
349
ST 3D Graphics Abacus Software
H O
P
L
PAINT1.S 221
Left coordinate system 30, 34,47,48, Pascal 4
59, 64, 337, 338, 342 Perspective transformation 31,119,
Line array 298 122
Link file 170 Picture coordinate system 8-9
Linking programs 89 Plot-point routine 80
Point coordinate arrays 298
Point light sources 70
M-N Polygon 11
Polymarker 296
Projection 38,51
Machine language 4, 89 Projection center 50,116,167, 214
Matrices 344 Projection plane 50, 51, 56
Matrix addition 345
Matrix multiplication 119,346
MENUl.S 257 R
Metacombco Editor 107
Monochrome monitors 219
Motorola MC68000 3-4 Real time 3-D graphics 191
MULTII.S 302 Reflection coefficient 69,71
Normal vector 116 RELMOD 88
350
Abacus Software ST 3D Graphics
Taylor series 76
Transformations 31,121
Unit matrix 346
351
Optional Diskette
For your convenience, the program listings contained in this book are
available on an SF354 formatted floppy disk. You should order the diskette
if you want to use the programs, but don’t want to type them in from the
listings in the book.
All programs on the diskette have been fully tested. You can change the
programs for your particular needs. The diskette is available for $14.95 plus
$2.00 ($5.00 foreign) for postage and handling.
When ordering, please give your name and shipping address. Enclose a
check, money order or credit card information. Mail your order to:
Abacus Software
P.O. Box 7219
Grand Rapids, MI 49510
PaintPr >
Multiple J
windows
ST TextPro
For creative illustrations on the ST
ST PaintPro
r
A simple-to-use and versatile database Wordprocessor with professional A GEM™ among ST drawing programs.
manager. Features help screens; features and easy-to-use! Full-screen Very friendly, but very powerful design
lightning-fast operation; tailorable editing with mouse or keyboard and painting program, A must for
display using multiple fonts; shortcuts. High speed input, scrolling everyone's artistic or graphics needs.
user-definable edit masks; capacity up and editing; sideways printing; Use up to three windows. You can
to 64,000 records. Supports multiple multi-column output; flexible printer even cut S paste between windows.
files. RAM-disk support for 1040ST. installation; automatic index and table Free-form sketching; lines, circles,
Complete search, sort and file of contents; up to 180 chars/line; 30 ellipses, boxes, text, fill, copy, move,
subsetting. Interfaces to TextPro. Easy definable function keys; metafile zoom, spray, paint, erase, undo, help.
printer control. $49.95 output; much more. $49.95 Double-sized picture format. $49.95
AssemPro PCBoard
The complete 68000
assembler development
Designer
Create printed circuit board layouts
package for the ST
^
wuMmfimmWiiWilsmm Auto routing, component list, pinout list, net list
ST Forth/MT ST AssemPro PCBoard Designer
Powerful, multi-tasking Forth for the ST. Professional developer's package Interactive, computer aided design
A complete, 32-bit implementation includes editor, two-pass interactive package that automates layout of printed
based on Forth-83 standard. Develop¬ assembler wrth error locator, online help circuit boards. Auto-routing, 45° or
ment aids: full screen editor, monitor, including instruction address mode and 90° traces; two-sided boards; pin-to-pin,
macro assembler. 1500+ word library. GEM parameter information, pin-to-BUS or BUS-to-BUS. Rubber-
TOS/LINEA commands. Floating point monitor-debugger, disassembler and banding of components during place-
and complex arithmetic. $49.95 68020 simulator, more. $59.95 ment. Outputs pinout, component and
net list. $395.00
ST and 1040ST are trademarks ot Atari Corp.
Call now for the name of the dealer nearest you. GEM is a trademark at Digital Research Inc.
ST GRAPHICS 4SOUNO ST LOGO OUIOE ST PEEKS * POKES BASIC Training Guide BASIC to C 30 GRAPHICS
Datailad guida to graphica Taka contd of your ST by Enhance your programa with Thorough guida lor Isarning Move up from BASIC to C. If FANTASTICI Rotate, zoom,
and aound on tha ST. 20 6 learning ST LOGO—tha aaay tha aiamplaa found within ST BASIC programming. you're elreedy a BASIC and shade 3D objects. All
3D kjnctlon ptottara. Molr* to uaa. powerful languaga thla booh Explorea ualng Detaled programming funda¬ programmer, you can laarn C programa written In machine
patlarna, graphic memory Topic* Induda 61a handling, different languages BASIC. mentals, commands descilp- all that much Merer Parallel language (or high speed.
and varioua reaolutiona. recurslon-HHbert A Sierpinskl C. LOGO and machine tiona. ST graphics 8 aound. examples demoslrate tha Learn the mathematics
(ractala, recursion waveform curvaa. 2D and 30 (unction languaga. using various using GEM in BASIC, lila programing techniques and behind 3D graphica. Hidden
generation Eianpiet written plots, data atructura. error intarlacaa. memory uaaga, management, disk operation. constucts In both languages. line removal, shading With
In C, LOGO. BASIC and handling Helpful guide lor reading and saving horn and Tutorial problems give hand* Variables pointers, arrays, 3D pattern maker and
ModMe2 250pp 519 99 ST LOGO users. *19.99 todlak, more 280pp $16 95 on experience. 300pp $16 95 daU atructura 290pp*19 99 animator. $2* 96
The ATARI logo and ATARI ST era Swdamerkaof Alan Carp.
Abacusiuiiiiiiil Software
P.0. Box 7219 Dept. A9 Grand Rapids, Ml 49510 • Telex 709-101 ■ Phone (616) 241-5510
Optional diskettes are available tor all book titles at $14.95
Call now for the name of your nearest dealer. Or order directly from ABACUS with your MasterCard, VISA, or Amex card. Add
$4.00 per order for postage and handling. Foreign add $10.00 per book. Other software and books coming soon. Call or
write for your free catalog. Dealer inquiries welcome-over 1400 dealers nationwide.
M
Q> $&></■>
Vn
\ O ° <
1
D o / O
3 L> ^ 1 1
T C> / 150
j 0 / D )
l 0 1 1 0
1 o n\
j C?D O
$
I OO)
°1
\ o / -o
tp h
l J II
( 1 c
& ! ! ?£>
'X
IX 1 / of
X3
iV £ j l t V
/f f in/
FANTASTIC! Learn how to create impressive and fascinating 3D
graphics on the Atari ST. Covers introductory concepts and
background materials, graphic animation, using the assembler
and much more. Learn real-time animation with dozens of
graphic routines. 3D Graphics is an amazing book for all
programmers interested in advanced level graphics. Some of
the areas covered include:
isbn o-nibMai-bn-D