Amiga 3 D Graphic Programming in Basic
Amiga 3 D Graphic Programming in Basic
3D Graphic
Programming
in BASIC
Jennrich
Massmann
Schulz
Abacus~
First Printing, February 1989
Printed in U.S.A.
Copyright © 1987, 1988 Data Becker GmbH
MerowingerstraBe 30
4000 Dusseldorf, West Germany
This book is copyrighted. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, electronic, mechanical, photocopying,
recording or otherwise, without the prior written permission of Abacus or Data Becker
GmbH.
Every effort has been made to ensure complete and accurate information concerning the
material presented in this book. However, Abacus can neither guarantee nor be held legally
responsible for any mistakes in printing or faulty instructions contained in this book. The
authors always appreciate receiving notice of any errors or misprints.
Amiga 500, Amiga 1000, Amiga 2000 and Amiga are trademarks or registered trademarks of
Commodore-Amiga, Inc. AC/BASIC Compiler and AC/BASIC are trademarks or registered
trademarks of Absoft Corporation. Cray is a trademark or registered trademark of Cray
Incorporated. AmigaBASIC is a trademark or registered trademark of Microsoft Corporation.
ISBN 1-55755-044-1
ii
Table of Contents
1. Introduction .................................................................... 1
iii
4.1.6 The Disk Menu ...................................................... 154
4.2 Tracer Documentation .............................................. 155
4.2.1 After Starting ......................................................... 155
4.2.2 Amiga Menu .......................................................... 156
4.2.3 File Menu ............................................................. 156
4.2.3.1 Loading and Saving Objects ...................................... 156
4.2.3.2 Loading Materials ................................................... 157
4.2.3.3 Background ............................................................ 157
4.2.3.4 Saving Graphics ..................................................... 158
4.2.3.5 Printing Graphics .................................................... 158
4.2.3.6 Setting New Colors ................................................. 159
4.2.3.7 Leaving the Program ............................................... 159
4.2.4 The Editor Menu ..................................................... 159
4.2.5 The Parameter Menu ................................................ 160
4.2.6 The Draw Menu ...................................................... 161
4.2.6.1 Shadows ................................................................ 161
4.2.6.2 The Wire Model. ..................................................... 162
4.2.7 Keyboard Program Control ....................................... 163
Appendices ........................................................................... 20 1
A. Modules of the Tracer .............................................. 203
B. The Tracer Program ................................................. 207
C. The Editor Program ................................................. 302
D. The SetPoint Program ............................................. 345
E. Tracer Error Messages .............................................. 356
iv
1.
Introduction
ABACUS 1. INTRODUCTION
1. Introduction
The Amiga is a truly amazing machine, especially when it's used for
graphics. Most Amiga users, when asked why they bought their
Amiga, reply, "Great graphics." The picture on the cover of this book
was generated using the editor and tracer programs listed at the end of
this book. This shows some of the Amiga's graphic capabilities. This
book will help you explore programming 3D graphic ray tracing on
your Amiga, using the computer language that came with your Amiga
-AmigaBASIC.
You'll need basic math skills to use this book-but you won't need a
PhD in math. Many of the equations involved in computing three
dimensional figures may not make much sense to you. To help these
make sense, we've placed many explanations of the mathematical
equations alongside the sample programs and program descriptions.
The programs presented in this book, tracer and editor, are very large. A
complete listing of each of the programs can be found in the
appendices. Ray tracing requires many math calculations, which can be
very slow when done in BASIC. We recommend that the programs
presented in this book be compiled for maximum speed. The programs
should only be compiled after complete testing has been done in
BASIC. Chapter 8 describes the changes required to compile the
programs using the AC/BASIC® compiler.
The optional disk available for this book also contains the complete
program modules in ASCII format and versions compiled using
AC/BASIC®. The disk also contains two example pictures created with
the programs. The important individual routines are described through
the course of the book, but you should refer to the complete listing
when entering the programs.
3
r------ -------------- -- -- -----~
Before going on to the main part of this book, there are two terms
you'll see throughout this book-ray tracing and algorithms. These
may not sound familiar to you if you're studying 3D graphics for the
first time, so we'll define the two of them now:
Ray tracing There are a number of methods used in generating three dimensional
defined graphics on computers. Ray tracing traces the effects of light rays
which shine on an object or group of objects. Since ray tracing has its
basis in actual light and optical calculation, it reproduces the object's
surfaces and qualities (e.g., shadows, colors, reflectivity, transparency).
4
2.
The Basics of
Ray Tracing
ABACUS 2. THE BASICS OF RAY TRACING
Hidden surface Hidden surface algorithms are used when you want more realistic graph-
algorithms ics. The object is represented by many small triangles. These triangles
can be arranged so the the ones furthest away are shown first and the
closest are shown last. This gives a display with invisible surfaces. The
best presentation occurs when the triangles are a very small distance
apart. Hidden surface algorithms also can display the illusion of shad-
ows (e.g., when a bright light is shone on an object's surface).
Ray tracing Ray tracing algorithms are a step beyond hidden surface algorithms.
algorithms Ray tracing gets its name from tracing the effects of light rays shining
on an object. Unlike hidden surface and hidden line algorithms, ray
tracing allows the calculation of shadows, reflection and transparency of
objects. The result of a graphic generated from ray tracing requires more
calculation time than hidden line or hidden surface graphic<;, but the
finished graphic looks much more realistic.
The basics of ray tracing are pretty simple. You won't have to devote
your life to the study of mathematics to understand and use them.
As each light ray enters your eyes, you see a green point of light
coming from the direction of the cube. Because the sun (the light
source) sends out light rays that reflect off the cube, your eye receives
an image (graphic) of how the cube looks.
7
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
Your eye sees the visible light rays coming from the green cube. The
visible light rays reflect the cube's color, and send this information to
your eyes. You see this information because your eye is sensitive to
light rays and can receive the reflected colors.
Visual rays The computer screen uses visual rays rather than the visible light rays
available to us. The computer must calculate each visual ray and
determine whether this ray came from the surface of an object, and from
which direction the visual ray came. If the ray bounced off an object,
the computer must determine the color. The ray then appears on the
screen as a pixel, just as a retina reads light rays. Your eyes receive
light rays through lenses. The following figure shows the eye's concept
of an image, then a computer's ray tracing view of the same image:
I Light
,
rays]
Fomputer lnodeU
L1nQ of si ht
Figure 2.1
8
ABACUS 2.2 IN THE COMPUTER
perpendicular that you place a light source to a side, the brighter that
side appears.
2.2.2 Shadows
Visual rays calculate the computer model instead of actual light rays.
Therefore, we need to tackle the problem in a different manner. Imagine
that you are wearing a light source placed at the same location and
pointing in the same direction as your line of sight. Viewing the cube
with just your line of sight as the light source, you see no shadows
since they are hidden from your view, behind the object.
Now move the light source behind the cube, opposite your line of sight
(something like watching an eclipse). You are in the cube's shadow,
out of direct view of the light source.
Let's take shadowing one step further. Imagine watching the cube from
sunup to sundown. The shadows change in size, direction and intensity
as the sun moves in the sky throughout the day.
2.2.3 Reflection
An object reflects some light rays and absorbs others, depending on the
color and reflectivity of the object. The reflected rays enter your eye,
giving you a mental image of the object's shape, color and texture.
Let's try to picture this using the computer's visual rays. If the visual
rays encounter a reflecting surface, they convey the reflection's color,
brightness and degree of reflection. Then the visual rays travel onto an
object that lies in the direction of the reflection. From that the object's
color, brightness and reflection are established.
9
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPH:C PROGRAMMING
single color, brightness and reflectivity and display this data on the
screen. The programming examples shown later explain the
relationship between individual values and the final value.
2.2.4 Transparency
Transparency means that light or visual rays pass through the surface
instead of reflecting. If your visual rays strike a transparent surface,
they continue through this surface in the direction they were going
before encountering this surface (Figure 2.2). Light rays divide (reflect
and pass through) when a surface is transparent and reflective. However,
a computer's visual rays cannot pass through a surface and be reflected
at the same time, so a recursive algorithm must divide the visual rays.
£7 .L
Figure 2.2
L/
~
U
2.2.5 Limitations
Another limitation: Real light rays comprise all of the colors of the
visible spectrum, and not just a single color. An object reflects some of
this spectrum and absorbs the rest. Computer simulations require a
light source of predetermined color, not the entire spectrum.
10
ABACUS 2.3 PRESENTATION IN TilE COMPUTER
Planes The plane is the basic geometric object, described by the following
equation:
r + rl + u*r2 v*r3
r, rl, r2 and r3 arc vectors and u and v arc scalars (representing one
dimension, magnitude without direction). rl is any point that lies on a
plane. The plane passes through points r 2 and r 3. r 2 and r 3 must be
linearly (one dimensionally) independent of one another. This allows
the insertion of all possible values for u and v, supplying al\ allowable
points that lie on the plane:
r
3
/:::i rCleJ
Figure 2.3 r
The plane has one disadvantage: It is infinite. This is fine for making a
background, but you can't define a cube based on planes. Limit the
definable area for u and v (e.g., [0,1], making u ,md v greater than zero
and less than 1). This keeps the size within a specific range.
Parallelogr ams If you allow all values of the limited u and v, the points create a
parallelogram (Figure 2.4). A rectangle results if r 2 and r 3 arc
perpendicular to each other. Making r2 to r3 perpendicular and equal
in length creates a square. And joining six squares of equal size together
creates a cube:
11
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
IParallelogram I
Figure 2.4
I r = r +
123
u *r + v* r
with: O<=u<=l and O<=v<=l
)
y = -x " 1
The surface resulting from intersecting the base line and both axes
looks very similar to a triangle. If you rearrange the formula, you get x
+ y =1. But where do x and y come from?
The coordinate system's axes look like vectors at the end (see Chapter 7
for a description of vectors). Let the x axis be vector r2 and the the y
axis be vector r3. Now replace x in the formula with u, and y with v.
Because you want a triangular surface and not only an outline, replace
the equal sign with a "<=". The result:
u + v <= 1
When u and v are boLl} positive values, an infinite surface occurs. You
make these a limitation for your plane. Insert all allowed values for u
and v in the plane equation and all of the points lie inside of the trian-
gle, which has r2 and r3 as two of the sides.
ITriangle I
r = r
1
+ u*r + v*r 3
2
Figure 2.5 with: u>-O and u+v<-l
You can now display any number of rectangular objects using triangles
and parallelograms. If you create an object from many smaller triangles,
12
ABACUS 2.3 PRESENTATION IN TilE COMPUTER
you have all the basic objects that you might ever need. Some
disadvantages: Complicated .)bjects require an enormous number of
triangles, which take up a great deal of memory. Computer memory
can expand only so far, so we must make some compromises about
defining basic objccts.
Circles To describe the definition of a circle, we need to talk a bit more about
how a circle appears in a plane. Remember the general circle formula:
x2 + y2 ~ rd2
rd equals the radius. The formula is simpler for the unit circle: x2 +
y 2 = 1. This is because the unit circle has a radius of 1. The same
thing is true of our triangle: r 2 is the unit vector of the x axis, r 3 is
the unit vector of the y axis, u is x and v is y (never substitute x for
u instead). The formula now becomes:
u2 + v2 <= 1
This time you cannot assume that u and v arc positive, even though
the parallelogram equation required it. Insert all allowable values for u
and v, and you get a circular objcct:
r = r + u*r + v* r
1 2 3
wiLh:u'2 + v'2 <~ 1
Figure 2.6
r 2 and r 3 should be chosen so that they are perpendicular to each
other. If r 2 and r 3 are unequal lengths, you get an ellipse. Having
direct access to circles saves memory, since you don't have to try
generating a circular object from small triangles.
We'll want to create three dimensional circle types later, so we'll need
circular rings and circle sections (the latter can be used for pie charts).
These are both obtained from circular surfaces. Rings require the
lengths of the vectors (u,v) from the circle ring:
1 = u2 + v2
This means that 1 must lie in correct intervals between two values.
This interval value controls the thickness of the circle ring.
You must do a bit more for the circle section. For the length 1 you
must also compute the angle w that lies betwecn (u,v) and the r2 axis.
13
L THEBA~CSOFRAYTRAC~G AMIGA 3D GRAPIIIC PROGRAMMING
Isector!
Figure 2.7
Spheres Now we have enough of the basic math to create a sphere. You need to
know whether or not all possible objects can be broken down into
triangles. The answer is yes. To create a plain circle out of triangles so
small that the triangles can no longer be seen as triangles, you need
about 50 to 100 triangles. You'd need approximately 5000 to 20000
triangles to create a sphere. A true sphere always has a completely
round surface, and no comers and edges are visible. The general equation
for spheres is as follows:
(r - r:) 2 = rd2
Wait. How would you define cylinders, cones and ellipsoids? These
objects arc more difficult to create than the basic objects, but they are
created using the basic objects described above.
14
ABACUS 2.3 PRESENTATION IN THE COMPUTER
Now let's try to create a cylinder. Place the ground surface of the body
on the plane that runs through r2 and r3. Because the ground surface
of a cylinder is a circle, you can give it the limitation:
u2 + v2 = 1
u2 + v2 = 1 and O<=w<=l
ICylinder I
Figure 2.8
The bottom surface of the cone is a circle, so you already know some
of the restrictions. How do you show that the sides of a cone run
together to a point? A cone split vertically down the middle reminds us
of a triangle. The limitation for a triangle is x+y= 1. y equals w in this
case and is also the parameter of the vector that rises to the point of the
cone. x is the vector that points to a point at the base of the cone:
While you didn't need the square sign up until now (because the radius
was one and SQR(l)=l), you must take it use it here to get a result
similar to a cone. So you get:
SQR(u2 + v2) + w = 1
Here you can create a cone section as you did for the circle and cylinder
by establishing an angle interval or a truncated cone as you restrict w.
Ellipsoid The last basic object is the ellipsoid. You may wonder why you need
an ellipsoid if you already have a sphere. Unlike the sphere, the
ellipsoid can have any ellipse form, not just circular. The base surface
15
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPIDC PROGRAMMING
Make r2, r3 and r4 the same size to get a sphere. Now the second
advantage of an ellipsoid: You can add limitations to create an ellipsoid
section. This can look like an apple or melon slice. It is possible to
limit the parameters to an interval; you can think about the results of
this on your own. Cone and ellipsoid sections do not appear in the
routines developed later in this chapter-you'll have to work these out
on your own.
0: Plane, infinite
1: Triangle
2: Parallelogram
3: Circle surface
4: Circle section
5: Circle arc
10: Sphere
20: Cylinder
21: Cylinder section
22: Cone
24: Ellipsoid
As you can see, not all of the above restrictions are built into the data
structure. While K(n,D,l} is reserved for future use, K(n,D,2} contains
the index of the materials used to create the object. Instead of placing
16
ABACUS 2.3 PRESENTATION IN THE COMPUTER
all material constants into array K, the elements are placed in their own
array called Mat. The array K(n,a,2) specifies the number of elements
in Ma t, which contains the material constant for the nth object. This
means you can now assign the same material constant to multiple
objects.
The restrictions overlap with vector r 4, but that restriction does not
apply to cylinders, cones and ellipsoids. K(n,4,a) is the lower limit and
K(n,4,l) is the upper limit of the circle arc in the equation SQR(u2 +
v2). The values must be between zero and one. K(n,S,l) contains the
start angle for circle sections, circle arcs and cylinder sections. K(n,S,l)
specifies the end angle in degrees. When they are placed all together
they look like this:
K(n, 0, 0) type
K(n, 0, 1) reserved
K(n, 0,2) index for material constants
K(n, 1, .) rl
K(n, 3, .) r3
The data structure for the material constants is very easy. The field is
dimensioned with Ma t(Numbe rma t ,6). The color of the material is
established first: Mat(n,a) contains the red section, Ma t(n,l) the green
section and Ma t(n,2) the blue section. No ambient light exists in our
computer world, and this would make all shadows almost solid black.
To alleviate this, we define a shade brightness for every material which
defines the brightness of the material in the shadows. Assign this
17
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
Mat(n,4) contains the reflection factor. When this equals zero, the
surface of the material is dull. When Mat(n,4) equals one, the surface
appears as a highly polished mirror. Ma t (n,5) contains the
transparency factor, but our program doesn't use it, and Mat(n,6) is
reserved for additions to the program. The data structure for Ma t is as
follows:
Imagine that you get the value 12. Now you can specify the reflection
factor with:
This syntax is the form used by the routines presented in the program.
18
ABACUS 2.4 SIMULATING PERCEPTION
In your simulation model you sent out visual rays from every point on
the screen in the direction of the lens. We will proceed with this
method in our algorithm. We send visual rays from the projection point
P in the direction of the screen, and assign one visual ray to each screen
pixel. We must now determine the position of the screen. The main
point H performs this task. H lies in the exact center of the screen. The
vector P-H is the normal vector on your screen; it lies perpendicular
from the projection point to the middle of the screen. The distance
between P and H is called DPH.
l+-- dph .l
I<'igure 2.9
Because you must compute the picture using points (pixels), the
algorithm is simple: Provide the three dimensional coordinate for every
pixel you have to compute. Then send a visual ray from the projection
point in the direction of this pixel and determine whether you see
something. Our routi~e determines what we see and don't see,
especially the color of the point. Once the program decides, the point is
displayed on the screen. The entire procedure is in the following
subroutine taken from the tracer program listed in the appendices.
Note: The example programs that follow contain some BASIC lines that
must be entered on one line in AmigaBASIC even though they appear
on two lines in this book. Fitting some formatted program listings in
this book has caused some long BASIC lines to be split into two lines.
End of paragraph characters (~) in these program texts show the actual
19
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
Shadows:'lI
Initialization'lI
Status$ ~ ., Status: Shadows"+CHR$(O)'II
CALL SetWindowTitles&(NWBase&,SADD(Status$) ,O)'lI
'II
GOSUB DeieteMcnu'll
'll
Status$ ~ ., Status: Init"+CHR$(O)'lI
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
GOSUB InitShadows'lI
'lI
Slatus$ = " Status: InitMinMax"+CHR$(O)'lI
CALL SetWindowTitles&(~WBase&,SADD(Status$) ,O)'lI
GOSUB InitMinMax'lI
'll
Status$ ~" Status: InitMinMaxLq"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),D)'II
GOSUB InitMinmaxLq'lI
'll
CALL Sercn'll
'll
Status$ " Status: Shadows"+CHR$(O)'ll
CALL SetWindowTitles&(miBase&,SADD(Status$),O)'ll
'll
XAoff (Box\~% AND 1) *. 5'll
YAOff (BoxH% AND 1)*.5'lI
'lI
, Offsets to guarantee correct point size'll
IF XAOff ~ .5 THEN'll
XBOff .S'lI
ELSE'll
XBOff l'll
EN;) If'j[
IF YAOff ~ .5 THEN'll
YEOff .5'lI
ELSE'll
YEOff 1'll
END IF'll
'll
Eody%~O'lI
'lI
FOR yb%=YStart%+EoxH%/2 TO Yend%+BoxH%/2 STEP BoxH%'Il
FOR xb%~XStart%+BoxW%/2 TO XEnd%+BoxW%/2 STEP BoxW%'ll
CALL ReProjection(Rx,Ry,Rz,O!,FN Xresc(xb%),FN
Yresc(yb%))'ll
'll
Rx Rx-Px'll
Ry Ry-Py'll
Rz Rz-Pz'll
'II
StackPtr% ~-i'll
'll
Pxl ~ Px'll
Pyi ~ Py'l[
Pzi ~ Pz'll
'll
Original! = True'll
GOSUB Computepoint'll
20
ABACUS 2.4 SIMULATING PERCEPTION
'll
Px = Pxl'll
Py = Pyl'll
pz = PzI'l[
'II
IF
Stack(O,O»=O THEN 'If no Intersect point ,> -l'll
Bright.r=Stack(O,O)*Qh.r'll
Bright.g=Stack(O,I)*Qh.g'll
Bright.b=Stack(O,2)*Qh.b'll
CALL OSSetPoint&(CLNG(xb%-BoxW%/2+XAOff),
CLNG(yb%-BoxH%/2+YAOff) ,
CLNG(xb%+BoxW%/2-XBOff),
CLNG(yb%+BoxH%/2-YBOff),
CLNG(I024*Bright.r),
CLNG (I024*BricJht .eJ),
CLNG(I024*Bright.b))'ll
END IF'll
NEXT xb%'ll
'll
IF INKEY$ <> "" THEN'll
IF yb% < Yend%+BoxH%/2 THEN'll
'll
CALL Scroff'll
a$="Next line:"+STR$(yb%+BoxH%)'II
CALL PrintIt (a$, l30,Fal,.",) 'II
CALL DialogBox ("Continue", 0, True, xIa%, yla%, x,)" %,
y2a%,False)'II
CALL DialogBox("Stop",2,False,xlb%,ylb%,x2b%,
y2b%,!.'alse)'II
'll
CALL DoDialog (n%, 0, xIa%, yla%, x2a%, y2a%, -I, -1, --1,--
1,xIb%,yIb%,x2b%,y2b%)'ll
'II
CLS'll
'II
IF n% = °THEN'll
CALL Scron'll
ELSE'll
GOTO ShadowEnde'll
END IF'll
END IF 'll
END It"'ll
NEXT yb%'ll
'll
ShadowEnde:'ll
'll
CALL Scroff'll
CLS'II
GOSUB MakeMenu 'll
RETURN'll
21
2. TilE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
After a line is computed, the routine checks to see if the user has
pressed the spacebar. If so, the program asks if the user wants to stop
the calculation. The Scron/Scroff calls only bring the graphic
screen to the foreground or place it in the background (the DialogBox
function is listed later in this book).
r, rl, and r2 are vectors and 1 is a scalar (see Figure 2.3). The point
rl that runs through the line, is the equivalent of your projection
point. r2 specifies the direction of the line which is equivalent to your
vector R (Rx,Ry,Rz) calculated above. To provide an intersection with
the plane, you set the line and plane equations equal to each other so
that you can figure out parameters I, u and v. You can obtain the
intersection point by inserting 1 in the equation and calculating this.
The following SUB program contains the intersection point calculation:
SUB IntersectpointPlane(n%,Px,Py,Pz,Rx,Ry,RZ,l) STATIC~
SHARED Help(),K() ~
I ~> 1 = exact pararneter~
D~Ry*Help(n%,4)-Rx*Help(n%,3)-Rz*Help(n%,5)~
22
ABACUS 2.4 SIMULATING PERCEPTION
IF D<>O THEN'll
1=«Px-K(n%,1,0»*He1p(n%,3)-(Py-K(n%,1,1»*He1p(n%,4)+(pz-
K(n%,1,2»*Help(n%,S»/D'll
ELSE'I[
1=-1'1[
END IF'I[
END SUB'll
You assign the end point of the line (Px,Py,Pz) and the direction
vector (Rx,Ry,Rz). In addition, n% establishes which plane should be
used to calculate the intersection point. The line parameter 1 is returned
from the subroutine. When no intersection point exists, 1 = -1 is
returned. 1 can be negative. This places the intersection point behind
you (i.e., you can't see the intersection point). You should only be
interested for now in the things that you can see.
You can read how to solve the equation system in the mathematical
basics chapter (Chapter 7). You must first calculate the denominator
determinant. This looks like the following:
D = I Rx (K(n,2,O) K(n,3,O)1
Ry (K(n,2,1) K(n,3,1) Naming determinant
DL = I
Rz (K ( n, 2, 2 ) K ( n, 3 , 2 )
K(n,l,O)-Px K(n,2,O) K(n,3,O)
K(n,l,l)-Py K(n,2,1) K(n, 3, 1)
K(n,1,2)-Pz K(n,2,2) K(n,3,2)
I
Rx K(n,l,O)-Px K(n,3,O)
Du=1 Ry
Rz
K(n,l,l)-Py
K(n,1,2)-Pz I
K(n,3,1)
K(n,3,2)
Dv=1 ~
K(n,2,O)-Px K(n,l,O)-Px
Figure 2.10
K(n,2,1)-Py K(n,l,l)-Py
K(n,2,2)-Pz K(n,1,2)-Pz I
Only one line is unknown in this determinant-the direction of the
line. You must solve the determinant for this line. The 2x2 sub-
determinant contains all of the values that do not change. Here you
calculate these values and store them in the array Help(). It looks like
this:
Help(n%,3) K(n%,2,1)*K(n%,3,2)-K(n%,3,1)*K(n%,2,2)
Help (n%, 4) K(n%,2,0)*K(n%,3,2)-K(n%,3,O)*K(n%,2,2)
Help(n%,S) K(n%,2,0)*K(n%,3,1)-K(n%,3,0)*K(n%,2,1)
Before you calculate the intersection point for other basic objects, a few
words about general procedure: For every object in your computer
world, test for the intersection point with the visual ray. This way we
23
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
find how many objects are next to it; we also search for an object with
a minimall. When we find this, we also get the number of objects
that can be seen in the current screen.
CircleSurface (IntersectpointCircle:
IF a*a+b*b>l THEN
1 = -1
END IF
CircleSection (IntersectpointCircleSector):
IF a*a+b*b< = 1 THEN
CALL Angellnterval(l,n%,a,b)
ELSE
1 = -1
END IF
Circlearc (IntersectpointCircleRing):
d = SQR (a*a+b*b)
IF (d> = K(n%,4,O)) AND (d< = K(n%,4,1)) THEN
CALL AngleInterval(l,n%,a,b)
ELSE
1 = -1
24
ABACUS 2.4 SIMULATING PERCEPTION
END IF
pi is the circle value 3.141592, Prn2 = 2*pi and Pd2 = Pi /2. Here
we see in detail how you can calculate the angle.
For the sphere, insert the line equation in the sphere equation and
calculate this. We get a quadratic equation system that can be solved
using the standard procedure. A problem: We can only compute a
maximum of two intersection points. We must compute the parameter
1 for both. Then we choose where the next one lies.
SUB IntersectpointSphere(n%,Px,Py,Pz,Rx,Ry,Rz,l) STATIC~
SHARED Help() ,K(),Threshold~
, ~> 1 ~ exact parameter~
D~Rx*Rx+Ry*Ry+Rz*Rz~
p;(Rx*(Px-K(n%,1,0))+Ry*(Py-K(n%,1,1))+Rz*(Pz-K(n%,1,2) ))/D~
q; ( (Px-K (n%, 1, 0)) A2+ (Py-K(n%, 1, 1) ) A2+ (pz-K (n%, 1, 2)) A2_
K(n%, 2, 0) *K(n%, 2, 0)) ID~
D;p*p-q~
IF D>~O THEN~
l~-p+SQR(D)~
Ll~-p-SQR(D)~
IF (Ll<l) AND (Ll>Threshold) THEN~
SWAP 1,L1~
END IF~
ELSE~
1~-1~
END IF~
END SUB~
2S
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPIDC PROGRAMMING
Until now the routine to calculate the intersection point was straight-
forward, to a certain extent. Now we come to the cylinder and its uses.
There are three unknowns in the cylinder equation and one in the line
equation, so setting them equal will not solve anything. To solve this
we would have to solve a 4x4 determinant. Let's try something else.
(u, v, w) should be the intersection point with the line. The line
equation, split into three coordinate equations, reads:
u = Pxt + l*xt
v = Pyt + l*yt
w = Pzt + l*zt
Now there is only one unknown and this can be calculated after some
rearranging:
26
ABACUS 2.4 SIMULATI;\,G PERCEPTION
SWAP c, c'lI
END IF'lI
Here, like the sphere, two solutions are possible, and they both must
be calculated. From these the intersection point is chosen. c and d
satisfy both solutions for w and must be between zero and one. When
an intersection point exists, a and b (the solutions for u and v) are
computed.
27
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
The equations must now be solved and the parameters u, v and w must
be computed. Since the denominator determinant is one, this time we
don't have to do extra calculating. When computing the determinant we
can use the fact that only one column is unknown while the two others
are constant. We can calculate these beforehand and store them in
Help.
With this, the intersection point of a line with a cylinder can be calcu-
lated. We must create a check of the anglc interval of parameters a and
b for a cylinder section:
(InterscctpointCylinderSegm)
1= -p+SQR(D)
Ll = -p-SQR (D)
c Pzt+l*Zt
c
Cl ,~ PzL+L1*ZL
CALL AngleInterva1(11,n%,Pxt+L1*Xt,Pyt+l1'yt)
ELSE
L1 = -1
END IF
28
ABACUS 2.4 SIMULATING PERCEPTION
a ; Pxt+l*Xt
b ; Pyt+l*Yt
The subprograms for cones and ellipsoids don't have any special differ-
ences from the one for the cylinder. The procedure is identical. The
equations look a little different because the restrictions have a different
form:
Cone (IntersectpointCone):
d ; Xt*Xt+Yt*Yt-Zt*Zt
IF d<>O THEN
P ; (Pxt*Xt+Pyt*Yt+Zt*(l-Pzt))/d
q ; (Pxt*Pxt+Pyt*Pyt-(1-Pzt)A2)/d
d ; p*p-q
END IF
Ellipsoid (IntersectpointEllipsoid):
d ; Xt*Xt+Yt*Yt+Zt*Zt
IF doO THEN
p; (Pxt*Xt+Pyt*Yt+Pzt*Zt)/d
q ; (Pxt*Pxt+Pyt*Pyt+Pzt*Pzt-l)/d
d ; p*p-q
END IF
These two program sections are found in the SUB programs following
the Bas i s T ran s call in the complete tracer program (see the
appendices for the listing).
29
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
END IF'I[
IF K(n%,O,O)=l THEN'll
CALL IntersectpointTriangle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'I[
GOTO Wkok'l[
END IF'll
IF K(n%,O,O)=2 THEN'I[
CALL IntersectpointRectangle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'I[
GOTO Wkok'l[
END IF'll
IF K(n%,O,O)=3 THEN 'I[
CALL IntersectpointCircle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'I[
GOTO Wkok'l[
END IF'I[
IF K(n%,O,O)=4 THEN'I[
CALL Intersect.pointCircleSector(n%,Px,Py,Pz,Rx,Ry,Rz,l
,a,b) 'I[
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=5 THEN'I[
CALL IntersectpointCircleRing(n%,Px,Py,Pz,Rx,Ry,Rz,l,
a,b)'ll
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=10 THEN'll
CALL IntersectpointSphere(n%,Px,Py,Pz,Rx,Ry,Rz,l)'ll
GO TO Wkok'l[
END IF'I[
IF K(n%,O,O)=20 THEN'I[
CALL IntersectpointCylinder(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,
Original! ) 'I[
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=21 THEN'll
CALL IntersectpointCylinderSegrn(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,
b,c, Original')'ll
GO TO wkok'II
END T1"'lI
IF K(n%,O,O)=22 THEN'I[
CALL IntersectpointCone(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,
Original')'ll
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=24 THEN'll
CALL IntersectpointEllipsoid(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,
Original! ) 'I[
END IF'I[
Wkok:'lI
, Work OK''ll
'lI
IF (l>Threshold) AND (la<=O OR l<la) AND (n%<>Kp% OR
K(n%,O,O»=lO) THEN'lI
la=l'l[
Body%=n%'ll
IF K(n%,O,O»=20 AND Kp%=O THEN'll
Ac=,,'1[
Bc=b'l[
Cc=c'll
END :F'I[
END IF'll
Nxtk:'ll
, Next body'll
NEXT n%'I[
30
ABACliS 2.4 SIMULATING PERCEPTION
'I!
?~GV% 1 A~D ~8%=C :HEN~
Sx-=-Px-r d*Rx~
Sy=Py4 a*Ryq[
SZ--P?J- a*R7S
END -;-?
The endpoint of the (visual ray) line is assigned in (Px,Py,P z) and the
direction vector in (;x,Ry,Rz). As a result you get the number of the
body where (Px,F ,Pz) lies next in Body%. Kp% is needed for the
shadow and is expb:;;c;d in that routine.
It's not enough simply to bring the color of the body to the screen.
That would give us the outline of the body and nothing else. We need
to see the brightness of the body's surface.
We already know that a surface shines brighter when light rays strike
perpendicular to the ,urL.!,'e. All we have to do is test for the angle that
lies between the normal vector on the intersection point and the line
from the intersection point to the light source. The brightness is at a
maximum when this angle is zero, and when this angle is greater than
90 degrees, the point is dark because the light shines on it from
"below."
Liqht source Q
Surface
+
I Not 11 L um~ na::?TI
Normal vector n
?ro~~cticn
+ point P
Figure 2.11
31
2. TilE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
the cosine for perpendicular light rays (0 degrees) is one and for
extremely Oat light rays (90 degrees) is zero. We just have to multiply
these by the three color intensities of the surface (red, green, blue) to
get the correct color tone. The cosine for angles over 90 degrees is
negative, so a simple test for a negative leading character sees if the
point lies in the path of the light source.
It is more difficult for cylinders, cones, and ellipsoids. It's not enough
to compute the normal vector in (r2,r3,r4) and then change it back.
There are other options.
Solution for y:
y b * SQR(1-(x"2 I a"2))
y b/a * SQR(a"2 - x"2)
We split these into an equation for nx and for ny so that ny/nx does
not change:
ny = (a*b)*SQR(a"2 - x"2)
32
ABACUS 2.4 SIMULATING PERCEPTIO;'I;
nx ~ (b'2)*x
This seems rather arbitrary, but it solves the equation to our advantage.
Now we insert the original ellipse equation in the formula for ny to
solve the base, and for n y we get:
Now we have two equations for nx and ny. But the disadvantage is that
in our cylinder equation we don't have a, b, x, or y. We must now
determine which parameters each represents. a is the main axis of the
ellipse which corresponds to the length of vector r2, or Ir21. b is the
other axis and corresponds to the length of r 3, or Ir 31. x and yare
coordinates of a point which we call u * r 2 and v * r 3, where u and v
are intersection point parameters. Because our parameter vectors have
different directions, we can add the equation for nx and ny. The result
is the normal vector for the cylinder:
Things look very similar for the cone, except that the normal vector
arcs in the direction of the cone point. We first create the normal vector
from the base ellipse. Then we change the length of the normal vector
so it is exactly athe length of u * r 2 + v * r 3. Now we retain the length
from r4 to the length of the normal vector, which is exactly the slope
of the cone surface when we consider a longitudinal section of the cone.
We get the calculation of the perpendicular from the normal vector on
this point of the cone surface. n2 is the normal vector on the base
surface as it was already written above for the cylinder. So:
The derivation of the normal vector for the ellipsoid will not be
discussed here because of page limitations. However, we can supply the
equation which provides the solution:
Now we can test for the brightness of every point of the basic object
surfaces, once we establish the location of the light source. It would be
best if we could see the reflection of light on the surface of our object.
33
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PnOGRAMMING
We calculate the reflected light rays; the angle between them and the
visual rays; and the vector from intersection point to projection point.
When this angle is zero, we are looking directly into the light source,
and the reflected light is very dark. The larger the angle, the greater the
retlc-ction of light.
To obtain the reflected light rays we first compute the dIstance of light
somce Q from the plane that runs t.angential to the surface through
intersection point s. Now mullipiy the normal vector D by a factor that
makes the length the same as the distance from Q to the tangent plane.
After that test the refleaed vector $P is as foJlow~:
SP = (:)--Q) + 7*"
.
.;',.
,
,
f
..... -------- .. _----
.'
.'. '
~",. .'~
f .'
j
,
j
. "
"
:
j .'
..........
. ........•...
SP ~ w"'""1: ......... .
~................................... '.......................... a
Figure 2.12
I
Instead of t.he angle, we usc the cosine and slore it in the variable
Mi r ro r. So the reflected light level stays low, we increase the result
by a relatively high power so that the value of Mirror is dose to zero
for small angles.
Now we can finally put all of the calculations together to get the
brightness of a point on a surface. We've put them into a SUB program
named Set Brightness. The brightness is stored in the variable
Bright and the reflection of the light source is stored in Mirror.
This SUB program has nothing to do will] the color of the body. This
comes later.
34
ABACUS 2.4 SIMULATING PERCEPTION
IF Original!<>True THEN~
IF FN CosinAngle(Nx,Ny,Nz,Px-Sx,Py-Sy,Pz-Sz)<0 THEN~
'Normal vector must point to projection point!~
Nx~-Nx~
Ny~-Ny~
Nz~-Nz~
END IF~
END IF~
Dqe=Nx*(Qx-Sx)+Ny*(Qy-Sy)+Nz*(Qz-Sz)~
~
Spx=Sx-Qx+2*Dqe*Nx~
Spy~Sy-Qy+2*Dqe*Ny~
Spz=Sz-Qz+2*Dqe*Nz~
~
Mirror=FN CosinAngle(Spx,Spy,Spz,Px-Sx,Py-Sy,Pz-Sz)~
~
IF Mirror<O THEN~
Mirror=O~
END IF~
~
Bright~FN CosinAngle(Nx,Ny,Nz,Qx-Sx,Qy-Sy,Qz-Sz)~
ELSE~
I Determine mirror vector SP~
IF K(n%,O,O)=lO THEN~
Nx=Sx-K(n%,l,O)~
Ny=Sy-K(n%,l,l)~
Nz~Sz-K(n%,1,2)~
END IF~
35
2. TilE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
IF FN CosinAngle(Nx,Ny,Nz,Px-Sx,Py-Sy,Pz-Sz)<0 THEN~
I => Normal vector points to projection point~
Nx=-Nx~
Ny=-Ny~
Nz=-Nz~
END IF'll
Nl=SQR(Nx*Nx+Ny*Ny+Nz*Nz)~
Nx = Nx/Nl~
Ny = Ny/Nl~
Nz = Nz/Nn
~
Dqe=Nx'(Qx-Sx)+Ny*(Qy-Sy)+Nz*(Qz-Sz)~
~
Spx=Sx-Qx+2*Dqe*Nx'll
Spy=Sy-Qy+2*Dqe*Ny~
Spz=Sz-Qz+2*Dqe*Nz~
~
Mirror=FN CosinAngle(Spx,Spy,Spz,Px-Sx,Py-Sy,Pz-Sz)'lI
'lI
IF Mirror<O THEN'
Mirror=O~
END IF~
~
Bright=FN CosinAngle(Nx,Ny,Nz,Qx-Sx,Qy-Sy,Qz-Sz)~
END IF'lI
~
IF Mat (K(n%,O,2),4»O THEN'lI
Mirror=1.5*Mirror (30*Mat(K(n%,O,2) ,4))'lI
A
END IF'lI
END SUB'J;
The variables Ae, Be, and Ce contain the intersection point parameters
for u, v, and w in case it is an object like a cylinder, cone, or ellipsoid.
The normal vector is regulated and has a length of one. This is
important for later calculations. Dqe represents the distance from the
iighi source to the tangent plane. Tne formuia for calcuiating Mirror,
located at the end of the SUB program, has been arbitrarily defined and
can be experimented with. When we have defined a dull surface, and
Mat(n,4) is relatively small, the reflected light from the light source is
equally small.
36
ABACUS 2.4 SIMULATING PERC EPTION
Now that we have defined the formulas to our satisfaction, we can get
to other things. We have the intersection point S of the visual ray with
an object and the position of the light source Q. All we have to do is
check whether the line from S to Q intersects with any objcct, and if
this intersection point lies between S and Q.
Figure 2.13 s
The line Q-S acts as the direction vector. Because of the inaccuracy of
the operation using real numbers, we check the intersection point
calculation to see if parameter 1 of the line is greater than a threshold,
which is dependent on the numerical presentation of the inaccuracy (we
talked about this earlier). Because we didn't pay attention to this, the
same object that lies on the intersection point is calculated as the object
throwing the shadow only, because the calculation of the inequality
came out 0.00005 instead of O.
Because there is no stray light in our computer world, the shadows are
naturally solid black. Since this is undesirable, we assign every object a
shadow brightness number between zero and one.
37
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
RestLght(StackPtr%)=Mat(K(Body%,O,2),4)~
~
IF Bright<=O THEN~
'unlit: ~
Bright.r=Mat(K(Body%,O,2),O)*Mat(K(Body%,O,2),3)~
Bright.g=Mat(K(Body%,O,2),1)*Mat(K(Body%,O,2),3)~
Bright.b=Mat(K(Body%,O,2),2)*Mat(K(Body%,O,2),3)~
ELSE~
Kp%=Bodyn
'Shaduw ?~
CALL WhichBody(Kp%,Sx,Sy,Sz,Qx-Sx,Qy-Sy,Qz-Sz,False,True)~
SWAP Body%, Kp%~
Bright.r=Bright*Mat(K(Body%,O,2),O)+Mirror*
RestLght(StackPtr%)~
Bright.g=Bright*Mat(K(Body%,O,2),1)+Mirror*
RestLght(StackPtr%)'l!
Bright.b=Rright*Mat(K(Body%,O,2),2)+Mirror*
RestLght(StackPtr%)~
END IF~
END IF'll
Now we must color in the point on the screen with the equivalent of
the value from Bright.r (red), Bright.g (green), and Bright.b
(blue). But we want to go a step further. We hope that you are not tired
from all of these steps, because now it gets really interesting.
2.4.4 Reflection
The duller a surface is, the harder it is to see the reflection of this
object. In nature, reflections also lose some intensity, constantly
changing the original color information.
38
ABACLS 2.4 SIMULATING PERCEPTJOI'
CA:,L 1j·n:; ,-=":JBody (:; ?x, I Py,~)!; Rx, Ry, 1-(Z, Origi:lal ~ , False'} 91
END ";."
:;tack(StackPtr%,C)=Brlgrt.r'il
S~ack(StackPtr%f1)~Brig~lt.g~
,C;La;"'K (StasK:)L r%, 2) :::;d~- -j qht. b'l!
Px Sx9!
Py S;9l
pz ,;z'il
39
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
Bright.g=-l'll
Bright.b=-l'll
ELSE'II
Bright.r=O'II
Bright.g=O'lI
Bright.b=O'II
END IF'll
END 1F'II
Stack(StackPtr%,O)=Bright.r'lI
Stack (StackPtr%,l)=Bright.g'lI
Stack (StacKPtr%,2)=Bright.b'lI
RestLght(StackPtr%)=O'lI
StackPtr% = StackPtr%-l'll
RETURN'll
This routine also contains the program section that was mentioned in
the section describing shadows. The variables used were already
discussed, so here we'll just introduce S t a c k P t r %. In the main
program, from which the calculated point is called, Stackptr% is set
to -1. This increments by 1 for every reflection until there are no more
reflections, or until the maximum stack depth (20) is reached.
The results of our calculations up until now have been three values that
stand for the red, green, and blue hues of the color. Now we must
somehow bring these colors onto the screen. Because we don't have
many colors to insert, we must now figure out how to combine these
colors until we get desired color.
You may be thinking, "Hold it. HAM mode gives us 4096 colors to
use, and that's more than enough." That's correct, but anyone pixel
can only take on one of 64 colors: 16 basic colors plus 16 colors by
changing the red intensity, 16 colors by changing the green intensity,
and 16 colors by changing the blue intensity. This gives us a total of
64 colors.
40
ASACCS 2.4 SIMljLA TING PERCEPTION
Now we have another problem that we cannot ignore: which two colors
do we combine to get the desired color combination? It's not easy.
When you want to display a picture in monochrome (gray scales), all
you need are two shades of gmy.
Problems occur when you switch to color display. Put the color in
three dimensions: A red axis, a green axis, and a blue axis. The result is
a cube that has one comer on the origin. To make the problem easier to
visualize, here is an example:
Red Yellow
~ Combined yeclow
and red (green)
Black Green
Figure 2.14
black awi red i'lreen)
When the yellow intensity is less than 0.5, the color black seems to
work best. The second best color is either red or green, because these
colors are closer to yellow than black is to yellow. This provides an
intermediate color between black and yellow. When the yellow
intensity is greater than 0.5, yellow works best. Red or green are the
next best colors. When red or green is chosen, in which case they are
equal, both colors are the same distance from the desired color. The
result can only be changed by increasing the number of the color.
41
2. THE BAStes OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
Here's an alternative: Try the two colors whose hues are similar to the
one you are searching for. The direction of the color vector must be
tested for as well as its polar coordinates. Disadvantage: The calculation
of the desired color in polar coordinates takes time. In addition, the
result does not completely solve the problem. For example, to get a
gray tone, you'd combine white and black instead of two shades of
gray. Here a lot depends on the pattern itself, namely, the ratio in
which the colors are mixed.
We must admit that we haven't found the ideal algonthm. We've used
the first (combining the two closest colors). When the basic colors are
well distributed you get good results, especiaily in HAM mode.
The assumption for the 0 S S po i n t routme is that the red, green, and
blue values of the basic colors are stored in the array 0 S Co lor. This
field is found directly behind the assembler routine and the values must
be poked. Each element contains four values (16 bits): Number of the
corresponding color registcr, red intcnsity* 1024, green intensity* 1024,
and blue intensity*1024. The number of the basic color must be in
OSMaxColors. OSRastPort contains a pointer for the RastPort
of the window or screen, OSMode contains the presentation mode, for
example, $800 for HAM mode. OSRasterl'l and OSRasterH
42
ABACUS 2.4 SIMULATING PERCEPTION
To get a good color palette, you should put in the optimal color palette
for each picture. Allow the picture to go through a long calculation and
note how the colors come out. Then alter the color palette so that for
each color there is the widest range of color shades. It would be best to
use the HAM (Hold and Modify) mode.
43
2. BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
2.5 Optimization
Next we draw a minimal rectangle for each object, so that the object
lies completely within it. In our SUB program WhichBody we check
if the actual visual ray passes through this rectangle. If it does, we
calculate the intersection point. This check for the current point within
the rectangle goes much faster than the intersection point calculation,
it must execute more determinate calculations (cylinder, cone,
ellipsoid).
The rectangles for our above graphic can look like this example:
44
ABACLS 2.5 OPTIMIZATIOI\
Figure 2.16
The rectangles for the individual objects are narrow and the rectangle for
the screen section is wide. Notice that the cube is assembled from six
parallelograms (sides), but only the visible three are shown here,
because otherwise it would make the diagram hard to follow.
This optimization only helps us when we send out visible rays for
testing. It doesn't help for reflected visual rays or shadow calculation.
We can't take any optics for the reflected visual rays because neither the
starting point of the reflected visual ray nor iL~ direction is confirmed.
But what about the shadows? The light source stays in the same posi-
tion. The surface that lies in the shadows can be above everything, but
it also cannot be confined to a plane, like the projection surface. When
we calculate all objects relative to the light source instead of the
rectangles, and establish minimums and maximums for both angles, we
are dealing with shadows. T rue is tested to see if the polar coordinates
of the intersection point lie inside the intervals set for each object.
45
2. BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING
the object the angle a lies between Amin and Amax. The same thing
can be done for b by setting a Bmin and Bmax.
We can also limit the minimum distance of an object from the light
source. We can then test if the distance of the object from the light
source is greater than the distance of the point from the light source.
This would also mean that we can skip the intersection point calcula-
tions.
The problem comes from the angles location, which can usually lie
between -pi and +Pi. When an object lies on the boundary between
+ pi and - pi, you get an incorrect angle interval. In this case we must
add an angle interval so that the angle lies between 0 and 2 * P i. This
increment must be kept for every object and must be considered during
the test. The field that contains all of these values is called
MinMaxLq, and its elements have the following meaning:
46
ABACUS 2.5 OPTIMIZATION
END IF'll
IF minmax%(n%,l»yb% THEN~
GOTO Nxtk~
END IF~
IF minmax%(n%,2) <xb% THEN~
GOTO Nxtk'll
END IF'll
IF minmax%(n%,3)<yb% T~EN'll
GOTO Nxtk'lI
END IF'll
END IF'll
'lI
IF Shadown' ~ True THEN'll
CALL NormalAngle (Wa, Anglea+minmaxlq (;;%, 0) ) '!I
CALL NormalAngle(Wb,Angleb+minmaxlq(n%,3))'ll
IF Wa<minmaxlq(n%,l) THEN'll
GOTO Nxtk~
END IF'll
IF Wa>minmaxlq(n%,2) THEN~
GOTO Nxtk'll
END IF~
IF Wb<minmaxlq(n%,4) THEN~
GOTO Nxtk'll
END IF'll
IF Wb>minmaxlq(n%,5) THEN'll
GO TO Nxtk~
END IF'll
IF Dist<min~1xIq(n%,6) THEN~
GOTO Nxtk'll
END IF'll
END TF~
'll
IF K(n%,O,O)~O THEN'll
CALL IntersectpointPlane (n%,Px,Py,Pz,Rx,Ry,Rz, l)'ll
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=l 7HEN'll
CALL Inters('ctpointTriangle(n%,Px,t'y,Pz,Rx,Ry,Rz, I,a,o)'ll
GOTO Wkok<:
END IF'll
IF K(n%,O,O)=2 THEN'll
CALL IntersectpointRectangle(n%,Px,Py,Pz,Rx,Ey,Rz,l,a,b)'ll
GO TO Wkok'll
END IF'll
IF K(n%,O,O)=3 THEN'll
CALL IntecsectpointCircle(n%,Px,Py,?z,Rx,Ey,Ez,:,a,b)'ll
GOTO Wkok'
END IF'll
IF K(n%,O,O)=4 THEN~
CALL IntersectpointCircleSector(n%,Px,Py,Pz,Rx,Ry,Rz,
I,a,b) 'll
GOTO Wkok~
END IF~
IF K(n%,O,O)-5 ~HENS
CALL IntersectpointCi.,rcleRing (n%, Px, ~)y, Pz, Rx, Ry I ~z, 1/.:1, b) 'li
GOTO Wkok'll
END IFII
IF K(n%,O,G)=lO THEN'll
CALL IntersectpointSphere(n%,Px,Py,Pz,Rx,hy,hz,I)'ll
GOTO Wkok~
F:ND IF'll
IF K(n%,O,O)=20 THEN'
47
2. BASICS OF RAY TRACING AMIGA 3D GRAPIIIC PROGRAMMING
We leave you with a few words about calculation time. A super com-
puter like a Cray needs a good twenty minutes to compute a picture.
The tracer program is written in BASIC mainly because BASIC is an
easy language to understand. BASIC is also a slow language. Picture
calculation requires lots of time. Luckily the Amiga multitasks so that
you aren't inhibited during calculation.
We recommend that you compile the tracer program or the one you
create for this routine (see Chapter 8 for compiling instructions). That
lowers the computation time for a 320x200 picture to under a day.
When you have defined only a few unreOected objects, the computation
time goes under a few hours. Rewriting this routine in assembly
language will speed things up considerably.
48
3.
The Tracer
Program
------------------------------------------------------------------------.---
ABACUS 3. THE TRACER PROGRAM
Now that you've learned some of the theory of how ray tracing works,
this section explains how to make three dimensional wire models.
3.1.1 From 3D to 2D
This wire model is used to display the objects on the screen before
calculating the shadows. This saves a good deal of time and allows the
objccts to be placed on the screen in the best manner.
Where do we see the scene from? With only a point in the room we
cannot locate the direction of vision. We place a second point that is
51
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
also appropriate for the vision direction. We call this point the Ma i n
point, whose coordinates are Hx, Hy, and Hz.
The main point does more than determine the vision direction. This
point is also a point of our projection plane-the plane on which our
points are projected. Before the points are given on the screen, the
projection plane must first be constructed.
But the projection point is not totally passive. The line through the
projection point and the main point is perpendicular to the projection
plane:
Projection point
Projection plane
Figure 3.1 y
We first place the main point at the origin. We do this because the
coordinates of all the points are taken from the coordinates of the main
point.
52
ABACUS 3.1 Wnu:;\1 ODELS
~------------------~P
y
Figure 3.2
Hy Py
As you can see, the relationships for the angle Alpha (Z axis) and the
angle Beta (Y axis) are:
Sin (alpha) (Px-Hy)/Dl
Cos (alpha) (Px-Hx)/Dl
Angle = ATN(Sin/Cos)
The angle from the X axis must be set very close to O. As the diagram
shows, when the projection plane lies in the YZ plane or the projection
points lies on the X axis, the rotation angle does not need to he
calculated any more.
The InitialP routine calculates the position of the main point and
the projection point of the required rotation angle, as well as the
distance from the main point to the projection point.
InitialP:'11
D1=SQH «Px-Hx) A2+ (Py-Hy) A2) 'II
DPH~SQR«px-Hx)A2+(Py-Hy)A2+(Pz-Hz)A2)'11
IF 01=0 THEN'll
Sina=O'II
Cosa=l'II
ELSE'll
Sina=(Py-Hy)/Dl'II
Cosa=(Px-Hx)/Dl'II
END IF'II
'II
IF DPH=O THEN'll
Sinb=O'II
Cosb=l'II
S3
3. TIlE TRACER PROGRAM AMIGA 3D GRAPIIlC PROGRAMMING
ELSE'll
Sinb=(Pz-Hz) /DPH'll
Cosb=Dl/DPH'll
END IF'll
'll
Sinc=O , Z-Axis angle not'll
Cosc=l , solely determined here'll
IF Cosa=O THEN'lI
Alpha=Pd2'!I
ELSE'll
Alpha=ATN(Sina/Cosa) , compute cosinem and Sine'll
END IF , angle'll
IF Cosa<O THEN'll
Alpha Alpha+Pi'll
END IF'll
=F Cosb=O THEN'll
Beta=Pd2'll
ELSE'll
Beta=ATN(Sinb/Cosb)'ll
END IF'll
'll
IF Cosb<O THEN'll
Beta = Beta + Pi'll
END IF'll
Gamma=O'll
RETURN'll
When we calculate the rotation angle, we need to make sure that the
point rotates around the coordinate axes. We must subject every point
to the same rotation as the projection plane so that they lie on the Y Z
plane.
y Q'y
'. .
...
•
\ , Qy
,,
,,
,,,
,
(.;
Figure 3.3 Q'x Qx x
The point Q rotates around the angle alpha. Q I is the point rotated
around the angle alpha. It is described by the following relationships:
S4
A HACl:S 3.1 WIRE MODELS
Insert this in the addition theorem and you get the formula for the
rotation of a point around Lhe angle alpha.
Now we need to rotate the points around all three coordinate axes
according Lo the above formula. For example, we rotate a point around
tile Z axis, and the Z coordinate does not change. It is the same when
rotating around the other two axes.
y
z
........... y
,tc... __ ........
,
Figure 31 ~ (x7,y2,z2)
y
You should remember that for rotation around the Y axis the previously
computed coordinates for the rotation around the Z axis are used. The
resulL>; of the Y rotation are used for the rotation around the X axis.
55
3. THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
P
-x
Now we look at the intersection points of the line with the plane. Each
of these intersection points places a displayed point there. The
coordinates of the individual intersection points can also be used for our
screen output.
x Qx (Px-Qx)
y -- Qy t ,.. (Py-Qy)
z Qz (pz-Qz)
x Qx (DPH-Qx)
y ~
Qy + t * (O-Qy)
z Qz (O-Qz)
x Qx + t * (DPH-Qx) 0
t -Qx/(DPH-Qx)
By inserting from t and converting the remaining e{jualions you get the
Y and Z coordinates of the intersection points (Q' is already rotated
around all 3 axes):
56
AUACUS 3.1 WIRE MODELS
y Q'y*DPH/(DPH-Qx)
Z Q' z*DPH/ (DPH-Qx)
The following routine does the entire 3D/2D conversion, the rotating of
the coordinate axes, and the perspective transformation. The points
returned then must be displayed on the screen.
SUB Projection(Px%,Py%,x,y,z) STATIC~
SHARED Sina,Sinb,Sinc,Cosa,Cosb,Cosc,DPH,Hx,Hy,Hz'l[
, 3D coordinates (x,y,z) to 20 (Px%,Py%) = Screen!
IF DPH<>x3 THEN'lI
Px%=FN Xsca~e((y3*DPH)/(DPH-x2)) -4 ' Intersecting point
with projection point 'lI
Py%=FN Yscale((z3*DPH)/(DPH-x2)) <7 ' scaliny'1l
ELSE!
Px% = FN Xscale(C) -4 , Subtraction 0' 4 and 2 cased on
drawing'lI
Py% = F~ Yscale(O) -2 1 in a GH-1~J~~ZEROZEFC-~"Jindow {B~.SlC--
Wcndow)'lI
END IF'll
END SUB !
When examining this routine you will notice the following functions:
They make sure that the intersection points with the YZ plane are
shown with the correct enlargement. To understand what this user
function does, we must first clarify the meaning of the variable:;;
57
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Figure 3.6
o Screen Screen
The larger Picturex and PictureY, the larger the area of points
that must be presented on the screen. pic t ureX and pic t u re Y are
calculated as follows:
XScale and YScale ensure that the origin of the coordinate system
(= transformed main point) transforms to the midpoint of the screen.
You can change the main point in the following routine, give a new
projection point, change the rotation angle in degrees (not radians), and
increase or decrease the distance DPH. A very small DPH distorl<; the
three dimensional presentation on the screen, while a large DPH loses
the central perspective effect (the picture is in parallel perspective).
58
ABACI]S 3.1 WIRE MOI)ELS
InputH:'li
Status$ = II S':aLus: t<a':"n pointll"<-CHRS (8) cr
CALL SetWindow';': L:"5& (NWBase&, SA;)] (SL1~;lS$), u) 'li
GOSUB DeleteMen,l'lI
LOCATE 10,1'li
PRINT " Main point: "qr
LOCATE 13,1'll
PRINT " Hy = "; 'll
CALL Formlnput (Hy,30!,-lE+14,1E+14)'ll
'll
LOCATE 14,1'lI
PRINT" Hz = ";<ll
CALL FormInput (flz,lO!,-1E+14,1E T 14)'lI
GOSUB Initial'li
Newone! = True'll
CLS'll
GOSUB MakeMenu'll
RET lJRN 'li
"It
InputP:<]l
Status$ = 11 States: Projection pc~nt"+CHRS(O)<f[
CALL SetWindowTi tles& (NWBase&, SAD~; (Sl at \1s$) ,0) 'li
GOSUB DeleteMenu'll
LOCATE 10,191
PRINT " Projection point: 11'
LOCATE 12,1'li
PRINT II ?x = 1I;1l
CALL FormInpu'~ (Px,lC',-1E+14,1E+H)'li
LOCATE 14,1'lI
PRINT II pz = 11;1
CALL Formlnput (?z,30:,-1E+14,1E,']4)S
'li
GOSUB Initia;P'll
Newonc' = True'll
CLS'll
GOSUB EakeMenu '!I
RE7URN'll
Tr,;:JutDPH:'ll
Status$ = " Stalus: Spacing"+CHRS(C)~
CALL SetWindowTit1es&(~~3ase&,SADD(Status$),O)~
'!I
GOSUB DelcleMenu'll
'!I
LOCATE lO,I'll
PRINT " ";'li
59
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
GOSlJB =nitial'll
Newonc' = True'll
CLS'll
COSlJB MakeMeou'l!
RE':'URN'll
'~nd of Draw-Input.asc'l!
When changing the main point, the distance DPH or the rotation angle,
you should be careful because the position of the projection point is
also changed. The main point is shown as the basis point now.
* Input-Houtine * 'II
****~*~*~********~***~**~
"1
10i tia 1: 'II
WHEE Alpha<O'll
Alpha = Alpha + Pm2'll
WEND'lI
WHILE Bela<O'll
Beta - Beta + Pm2'll
WEND'll
60
ABACUS 3.1 WIRE MODELS
WHILE Garmna<O'll
Gamma = Gamma + Pm2'll
WEND'll
WHILE Alpha>Pm2'll
Alpha = Alpha - Pm2'll
WEND 'II
WHILE Beta>Pm2'll
Beta = Beta - Pm2'll
WEND'll
WHILE Gamma>Pm2'll
Gamma = Gamma - Pm2'll
WEND'II
Sina=SIN (Alpha) 'll
Cosa=COS (Alpha) 'II
Sinb=SIN(Beta)'II
Cosb=COS(Beta)'II
Sinc=SIN(Gamma)'II
Cosc=COS (Gamma) 'II
'll
Px=Hx+DPH*Cosa*Cosb , Projection point basedon the 'll
Py=Hy+DPH*Sina*Cosb , main point and the spacings'll
Pz=Hz+DPH*Sinb , DPH and Alpha, Beta and Gamma'll
RETURN 'II
''II
We can also move around the main point with the projection point,
which gives our stationary point.
Now that we can display points from the space onto the screen, we
want to present these points as objects and surfaces.
The principle here is very simple. From given information about the
objects and surfaces you calculate specific pixels and project these
pixels on the screen. To complete the particular object, the program
draws lines from one pixel to the next ("connecting the dots" using
these lines).
We get this information about the individual bodies and surfaces from
the array KO which was dimensioned with Dim K(NumberK,5,2). The
following diagrams show you how the individual array elements must
look or which values they must contain to present a certain body or
surface:
61
3. TIlE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
"
Figure 3.7
Triangle: K (n%, 0, 0) =
a K (n%, l, .)
b K (nl, 2, .)
Z c K (n%, 3, .)
Figure 3.8 y
Rectangle: K)n%,O,O)
a K (n\, 1, .1
b K (n', 2, .1
c ~
K (n%, 3, .1
Z
Figure 3.9
62
ABACUS 3.1 WIRE MODELS
,,,
,
Figure 3.10
7
,/'
~------------------~--~------,~
y
,,
,,,
Figure 3.11
,"
,/'
l
~------------------\--~------~
y
63
3. THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMIl'IG
Sphere: K(n%,O,O) 10
0= K(n't, 1, .• )
r = K(n%, 2, 0)
Figure 3.12
Figure 3.13
64
ABACUS 3.1 WIRE MODELS
Cylinder: K(n%,O,O) 20
0 K (n%, 1, ·)
a = K (" %, 2, ·)
b K (n%, 3, ·)
h K (n %, 3, ·)
Z
Figure 3.14
x
,, ,
------ --
.
. .... .....~
65
3. Tm: TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMIl"C
Cone: K(n%,O,O) 22
K (n%, 1, .)
°=
a K(n%, 2, .)
b K (n'll, 3, .)
Figure 3.16
Ellipsoid: K(n%,O,O) 24
o K(n'll, 1, ·)
a K(n'll, 2, ·)
b K(n%, 3, ·)
c = K(n%, ~, ·)
z
r
Figure 3.17
DrawPlane:'11
CALL
:> ra jectian (Xp%, Yp%, K (n%, 2, 0) +K (n%, l, 0) , K (n%, 2, 1) + K (n%, 1, 1) , " (n %,
2,2)+K(n%,1,2))'11
CALL Move&(RastPort&,Xp%,Yp%)'11
CALL Prajection(Xp%,Yp%,K(n%,1,O),K(n%,1,1),K(n%,},2))'11
66
ABACUS 3.1 WIRE MODELS
CALL Draw&(RastPoct&,Xp%,Yp%)~
CALL
Projection(Xp%,Yp%,K(n%,3,O)+K(n%,1,O),K(n%,3,1)+K(n%,1,1) ,K(n%,
3,2)+K(n%,1,2))~
CALL Draw&(RastPort&,Xp%,Yp%)~
RETURN~
'~
DrawTriangle: ~
CALL Projection(xl%,yl%,K(n%,1,01,K(n%,1,1),K(n%,1,211']!
CALL Move&(RastPort&,x1%,y1%1~
CALL
Projecti on (Xp%, Yp%, K (n%, 2,01 +K (n%, 1,0) , K (n%, 2, 1) t K (n%, 1,11 ,K (n %,
2,2)+K(n%,1,21)~
CALL Draw&(RastPort&,Xp%,Yp%l~
CALL
Pro jection (Xp%, Yp%, K (n%, 3,01 +K (n%, 1, 01 , K (n%, 3,11 +K (n %, 1, 1) ,K (n%,
3,2) tK(n%,1,2))~
CALL Draw&(RastPort&,Xp%,Yp%)~
CALL Draw&(RastPort&,x1%,y1%)~
RETURN~
'~
DrawRectangle:~
CALL Projection(x1%,yl%,K(n%,1,0),K(n%,1,11 ,K(n%,1,21)~
CALL Move&(RastPort&,x1%,y1%)~
CALL
Pro jection (Xp%, 'o'p%, K (n%, 2,0) +K (n%, 1, 01 , K (n%, 2,11 +K (n %, 1, 1 ) ,K (n%,
2,21+K(n%,1,21)~
CALL Draw&(RastPort&,Xp%,Yp%l~
Dx=K(n%,2,0)+K(n%,3,O)+K(n%,1,0)'J!
Dy=K(n%,2,11+K(n%,3,1)+K(n%,1,1)'J!
Dz=K(n%,2,21+K(n%,3,2)+K(n%,1,2)'J!
CALL Projection (Xp%,Yp%,Dx, Dy,Dz)'J!
CALL Draw&(RastPort&,Xp%,Yp%l~
CALL
Pro jection (Xp%, Yp%, K (n%, 3,0) +K (n%, 1 , 01 , K (n%, 3,11 +K (n %, 1, 11 ,K (n %,
3,2)+K(n%,1,2))~
CALL Draw&(RastPort&,Xp%,Yp%l~
CALL Draw&(RastPort&,xl%,y1%)'J!
RETURN,]!
''J!
DrawCircle:~
CALL
Projection (Xp%, 'o'p%, K (n%, 1,0) +K (n %, 2, 01 , K (n%, 1 , 1) +K (co %, 2, ~) ,:~ in %,
1,21*K(n%,2,2)1']!
, SIN(OI = 0 and COSIO) = 1 goto K(n%,3, .. 1, and K(~%,2, .. )
takes over~
CALL Move&(RastPort&,Xp%,Yp%)'J!
w=Pm2/NumberSegments'J!
D=w~
Repeatl:~
Dx=K(n%,1,0)+K(n%,2,0)*COS(w)+K(n%,3,01*SIN(w)~
Dy=K(n%,1,1)+K(n%,2,1)*COS(wl+K(n%,3,11*SIN(wl~
Dz=K(n%,1,21+K(n%,2,2)*COS(w)+K(n%,3,21*SIN(wl~
CALL Projecti on (Xp%, Yp%, Dx, Dy, D70I ~
CALL Draw&(RastPort&,Xp%,Yp%)'J!
w = w+D~
IF (w<=Pm2+D/2) THEN GO,O Repeatl:'J!
RETURN~
'~
DrawCircleSector:~
C[,LL Projection(x1%,yl%,K(n%,1,01,K(n%,1,1),K(n%,1,21)'ll
w=K(n%,5,0)~
67
3. TIlE TRACER PROGRAM AMIGA 3D GRAPIlIC PROGRA!\oIMIl\'G
Dx~K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,xl%,yl%)~
CALL Draw&(RastPort&,Xp%,yp%)~
[)~Pm2 /NumberScgments~
WHILE w<K(n%,5, l)~
w ~ w+D~
IF w>K(n%,~,l) THEN~
w~K(n%,~,l)~
END IFS
Dx-K(n%,1,D)+K(n%,2,D)*COS(w)+K(n%,3,O)*SIN(w)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)~
CALL Projcction(Xp%,Yp%,Dx,Dy,Dz)~
CALL Draw&(RastPort&,Xp%,Yp%)~
WEND~
CALL Draw&(RastPort&,xl%,yl%)~
RETURN~
'~
DrawCircleRing:~
w~K(n%,~,O)~
Dx~K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w) )*K(n%,4,O)S
Dy~K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w) )*K(n%,~,O)~
Dz~K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w) )*K(n%,4,O)~
CALL Projection(Xua%,Yua%,Dx,Dy,D7.)~
Dx~K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,C)*SIN(w) )*K(n%,",l)~
Dy~K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w) )*K(n%,4,1)~
Dz~K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w) )*K(n%,4,1)S
CALL Projection(Xoa%,Yoa%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)~
CALL Draw&(RastPort&,Xoa%,Yoa%)~
D=Pm2/NumberSegments~
WHILE w<K(n%,~,l)~
w ~ w+D~
IF w>K(rl%,5,1) THEN~
w~K(n%,~,l)~
END IF~
Dx~K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w))*K(n%,4,O)S
Dy~K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w))*K(n%,4,O)~
Dz~K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w))*K(n%,4,O)~
CALL Projection(Xu%,Yu%,Dx,Dy,Dz)~
Dx~K(n%,1,C)+(K(n%,2,O)*COS(w) +K(n%,3,O)*SIN(w) )*K(n%, 4,1)~
Dy~K (n%, 1, 1 ) + (K (n%, 2,1) *COS (w) +K (n %, 3, 1) *SIN (w) ) *K (n %, 4,1) ~
Dz~K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w))*K(n%,4,1)'
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)'
CALL Move& (RastPort&,Xua%,Yua%) ,
CALL Draw&(RastPort&,Xu%,Yu%)'
CALL Move& (RastPort&, Xp%, Yp%)'
CALL Draw&(RastPort&,Xoa%,Yoa%)'
Xua%~Xu%'
Yua%~Yu%'
Xoa%~Xp%'
Yoa%~Yp"
WEND'
CALL Move&(RastPort&,Xua%,Yua%)'
CALL Draw&(RastPort&,Xoa%,Yoa%)'_
RETURN'
ul!
DrawSphere:'
D~Pm2/NumberSegments'
68
ABACUS 3.1 WIRE MODELS
69
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Dx~K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)~
CALL Projection(Xua%,Yua%,Dx,Dy,Dz)~
Dx~K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)+K(n%,4,O)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)+K(n%,4,1)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)+K(n%,4,2)~
CALL Projection(Xoa%,Yoa%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)~
CALL Draw&(RastPort&,Xoa%,Yoa%)~
D~Pm2/NumberSegments~
WHILE w<K(n%,S,1)~
w ~ w+[)~
IF w>K(n%,S,1) THEN~
w~K(n%,5,1)~
END IF~
Dx~K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIK(w)~
CALL Pro jection (Xu%, Yu%, Dx, Dy, Dz) If
Dx~K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)+K(n%,4,O)~
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)+K(n%,4,1)~
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K{n%,3,2)*SIN(w)+K(n%,4,2)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)'li
CALL Draw&(RastPort&,Xu%,Yu%)~
CALL Draw&(RastPort&,Xp%,Yp%)~
CALL Draw&(RastPort&,Xoa%,Yoa%)~
Xua%~Xu%~
Yua%~Yu%~
Xoa%~Xp%~
Yoa%~Yp%~
WEND~
RETURN~
'~
DrawCone:9'
'~
DrawEllipsoid:~
D~Prc.2 /NumberSegment s~
FOR w1~-Pd2+D TO Pd2-D/2 STEP D~
Dx~K(n%,1,O)+K(n%,2,O)*COS(wl)+K(n%,4,O)*SIN(w1)~
Dy~K{n%,1,1)+K(n%,2,1)*COS(w1)+K(n%,4,1)*SIN(wl)~
Dz~K{n%,1,2)+K(n%,2,2)*COS(w1)+K{n%,4,2)*SIN{w1)~
CALL Projection(Xp%,Yp%,[)x,Dy,Dz)~
70
ABACUS 3.1 WIRE MODELS
CALL Move&(RastPort&,Xp%,Yp%)~
FOR w2~D TO Pm2+D/2 STEP D~
Dx~K(n%,1,O)+K(n%,2,O)*COS(wl)*COS(w2)+K(n%,3,O)*COS(w1)*SIN(w2)
+K(n%,4,O)*SIN(wl)~
Dy=K(n%,1,1)+K(n%,2,1)*COs(wl)*COS(w2)+K(n%,3,1)*COS(w1)*SIN(w2)
+K(n%,4,1)*SIN(wl)~
Dz=K(n%,1,2)+K(n%,2,2)*COS(wl)*COS(w2)+K(n%,3,2)*COS(w1)*SIN(w2)
+K(n%,4,2)*SIN(wl)~
CALL Proiection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Draw&(RastPort&,Xp%,Yp%)~
NEXT w2'l1
NEXT wl~
"OR wl=-Pd2+D TO Pd2-D/2 STEP D~
Dx=K(n%,1,O)+K(n%,2,O)*COS(wl)+K(n%,3,O)*SIN(wl)~
Dy=K(n%,1,1)+K(n%,2,1)*COS(wl)+K(n%,3,1)*SIN(wl)~
Dz=K(n%,l,2)+K(n%,2,2)*COS(wl)+K(n%,3,2)*SIN(wl)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xp%,Yp%)~
FOR w2=D TO Pm2+D/2 STEP D~
Dx=K(n%,1,O)+K(n%,2,O)*COS(wl)*COS(w2)+K(n%,4,O)*COS(w1)*SIN(w2)
+K(n%,3,O)*SIN(wl)~
Dy=K(n%,l,l)+K(n%,2,l)*COS(wl)*COS(w2)+K(n%,4,1)*COS(w1)*SIN(w2)
+K(n%,3,1)*SIN(wl)~
Dz=K(n%,1,2)+K(n%,2,2)*COS(wl)*COS(w2)+K(n%,4,2)*COS(w1)*SIN(w2)
+K(n%,3,2)*SIN(wl)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Draw&(RastPort&,Xp%,Yp%)~
NEXT w2'l1
NEXT wl~
RETURN~
'~
.~
Now for a word about circle presentation. The routines dealing with
circles (almost everything except DrawPlane, DrawRectangle,
and DrawTriangle) calculate the circle points in the same way: The
segment points of the circle periphery are calculated depending on an
angle. The more segment points, the rounder the circle.
The rounder the circle, the longer the computation time involved. We
have limited the number of segment points of a circle to save time.
When the shadow routines are called we will get completely round
circles. The variable NumberSegrnents corresponds to the roundness
of a circle:
71
3. THE TRACER PROGRAM AMIGA 3D GRAPIDC PROGRAMMING
Number of segments
4 8 >30
Figure 3.18
Back to object and surface presentation: The abovementioned Draw ...
routines are individul subroutines. What calls the individual routines?
The following routine jumps to the corresponding Draw ... routine
with the help of KCn%,O,O):
DrawAll :'lI
, Draw routiCle for calliClg each figure'll
FOR n%~l TO l\umber,,'ll
IF K(n%,O,C)~O THE~'lI
GOSUB DrawPlane'll
END IF'lI
IF K(n%,O,O)=l THEN'll
GOSUB DrawTriangle'l[
END IF'll
IF K(n%,O,O)~2 THEN'll
GOSUB r;rawRectangle'll
END IF),
1F K(n%,O,O)~3 THEN'll
GOSUB DrawC i I"cle'll
END IF'll
IF K(n%,OjO)=4 THEN~
C;OSUB DrawCircleSector'll
END IF'll
IF K(n%,O,O)~5 THEN'll
GOSUB DrawCircleRing'll
END IF'll
IF K(n%,O,O)~lO THEN'll
GOSUB DrawSphere'll
END l?'ll
IF K(r"%,O,O)~20 THEN'll
GOSUB DrawCy2inder'll
SND IF'll
IF K(n%,O,D)~21 THEN'll
GOSUB DrilwCylinderScgm'lI
END IF'lI
IF "(n%,O,O)~22 THEN'lI
GOSL13 DrawCone'lI
END IF'i[
IF K(n%,O,O)=24 THEN'lI
GCSUB DrawEllipsoid~
El\D IF'll
NEXT n%'il
RETURN'll
''lI
72
ABACUS 3.1 WIRE MODELS
The DrawNew routine ensures that the screen is cleared before any
objects arc displayed, and takes all of the necessary steps before the call
(activates the screcn, waits for a key and returns to the user screen).
DrawNew:'IT
IF (Hg = False) AND (Newone' True) THEN I no Background'll
CALL SetRast&(RastPort&,O) I but new drawing'lf
END IF I => clear screen'll
'IT
CALL Scron 'll
'If
IF (Ncwone! True) OR (Hg True) THEN I Background and
New drawing'lf
GOSUB DeleteMenu'll
RetRast& = RastPort& I reserve RastPort 'll
RastPort& = WINDOW(8) I In Window-RastPort
(GIMMEZERO Windowl)'Jl
CALL SetAPen&(RastPort&,l) I the new Screens~
GOSUB DrawAll , draw (because of Clipping)'ll
RastPort& = RetRast&~
BEEP'll
END IF'll
'Jl
IF WaitFlg! = True THEN I wait for mouse or key
press'll
GOSUB Pause 'll
CALL Scroff'll
END IF'lf
73
3. TilE TRACER PROGRAM AMIGA 3D GRAI'IJIC PROGRAMMING
Our goal is to design a program that calculates any picture that is made
up of simple objects and display it in 3D. The previous section
described which objects and which data are needed to do this. It is also
known that this data is stored in the arrays K! and MAT! . Now, how do
we insert the data for our picture into this array? Many different
methods are available.
One solution would be to manually calculate all of the data and enter it
as program lines, then read the data with a corresponding routine. This
is the easiest to implement, but the hardest to test. The advantage: you
save a lot of time in program development. The disadvantage: the user
must have the finished picture in mind and enter it by hand, and then he
has no control over whether the data complies with his image.
It would be better to enter the values into the computer and display
these values graphically. This is done using a simple menu driven
program which displays the data input as three pictures, and lets you
make corrections. The next section shows how to do this in BASIC.
74
ABACUS 3.2 THE EDITOR
The method that shows the user input fastest and easiest is the
projection of bodies from the three main views. The object appears in
front, side, and top views, like a standard technical drawing. The front
view is equivalent to the xz plane, the side view of the projection is
equivalent to the y z plane, and the top view is equivalent to the
projection of the xy plane. The illustration below shows perspective
(1), top (2), side (3) and front (4) views of a simple 3D house:
(1) (2)
Figure 3.19
(3)
(4 )
75
3. TIlE TRACER PROGRAM AMIGA 3D GRAPJIlC PROGRAMMING
These three views are displayed in three windows at the same time.
Because the screen doesn't divide very well into three sections, we
divide it into quarters and have one section for data entry and text
output. The windows are very small, but the user can enlarge and move
them. It must also be possible to move and enlarge the section where
the individual window is displayed so that large objects can be entered
and that details can be recognized. The following example should make
this clear.
Figure 3.20
...
x
The rectangle surrounding the lower house represents the window; the
lower house is visible, the house above remains hidden. By moving the
border in the Y direction, the second house becomes visible:
Y l
Figure 3.21 ..
x
76
ABACUS 3.2 THE EDITOR
The section is made clear by examining the position of the upper left
hand comer. In the first case this comer is (0,28,0) and in the second
case it is (0,42,0).
Data input A program should be designed so that the inexperienced user can easily
and output use it, recognize incorrect input, and correct data already entered. The
interface between the user and the program provides the use of menus
on the Amiga.
Direct input of data is also required. In our editor program you can, for
example, enter data at the following text:
Body : 1 Sphere
visible Material
M :
This input could achieved using the INPUT sUltemenl. We don't advise
this because you have no control over the entered characters. Writing
your own routine that gives you control of the entered characters is a
better solution. Besides correcting data, manipulating the entered data in
our program would be very helpful. By manipulation we mean rotating,
moving, enlarging and copying an object. Naturally old data sets must
be either redisplayed or deleted. Adding the mouse as an input device
eases the use of the editor. The mouse makes it possible to simply
click on the necessary coordinates. You don't have to manually
compute them and enter them in the computer through the keyboard.
One final point: The editor must make it easy to change a graphic made
of many objects. If the user has a graphic made of 253 different objects,
and object 253 is incorrect, should the user re-enter all 253 objects? No.
We added a function that lets the user view each object, change it, and
save it for later recall.
The optional disk for this book contains the sample editor program that
is listed in the appendices. Section 4.1 of this book contains a brief
usage guide for this editor. We recommend that you look at this
program to get a feel of what is in store in the next pages. Before you
put the book aside to get to work on your Amiga, we should offer you
77
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
the following tip in case you have difficulties with the abovementioned
projects. The optional disk has a data file named H ous e. You must
execute the following procedure to view this file from the optional
disk:
1. Load AmigaBASIC
2. enter CLEAR,120000
3. enter LOAD "editor.bas"
4. start the program (with RUN)
S. wait a few seconds-be patient
6. select "Load List" from the "Disk" menu
type house ana press RETURN
8. press CTRL-R
9. wait some more
10. look around (e.g., section)
The following sections describe each module, refine them, and show
them in BASIC program form. Then the long-range goals and
associated problems are presented, and the simplest procedures solved.
For example, the input module includes a procedure for reading the
keyboard. This procedure comes from a normal string input routine,
from which the input procedure for a real number is supported which is
finally called from the procedure to read a vector. This principle of
development allows the creation of more complex algorithms in the
rest of the chapter.
To read a character string there must be a routine that sets the cursor on
the screen, waits for a keypress, then erases the cursor. To display the
78
ABACUS 3.2 TilE EDITOR
cursor at a certain point on the screen, the character width and height
must be known. This is dependent on the chosen character set. The
important information for this is in the Ra s t Port data structure. To
explain what this has to do with the Ra s t Port data structure and how
it is constructed would be outside the realm of this book. It is
important for our purposes that the character height and width can be
found as follows:
Now to display the cursor so that the characters under the cursor remain
readable, the screen section must be inverted. This is done simply with
SETDRMD, a function that is found in the graphics .library and
linked to our program with (our disk name is Tracer and the bmap files
are located in the libs directory):
LIBRARY "Tracer:/graphics.library"
SUB getstring(oldS,aS,z$,z,s,inplcn)STATIC'
79
3. Tm: TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
'TASK :Reads two strings which can be edited from the input'll
line using cursor left/right,backspace and delete. 'II
In addition the string scrolls when the input'll
extends past the screen hne 'II
'PARAMETER:=>old$ old value of string to be read'll
a$ key pressed 'II
z$ valid characters'll
z line'll
s column'll
inplen Lenght of inout window'll
<=old$ specified string~
IF inplen =1 THEN 'if only one char entered? => no Return'll
old$=a$'lI
WHILE INSTR(z$,oldS)=O'll
CALL getkey(old$,z,s)'lI
WEND~
LOCATE z,s'll
PRINT old$'ll
ELSE'll
i=1 'points to current string position'll
position=l 'points to current screen posiliorl~
WHILE ASC (a$) ><1 3'II
IF' INSTR(z$,a$»<O THEN 'valid character?'ll
old$=LEFT$ (old$, i-I) +a$+RIGHT$ (old$, LEN (old$) -i+l) '!I
lei tl '!I
position=position+l'!1
IF position>inplen THEN'll
position=inplen 'II
END IF '!I
ELSE '!I
IF ASC(a$)=30 AND i<=LEN(old$) THEN 'Cursor right?'ll
i~i+l'!1
posi tion=posi t ion+ 1 ~
IF position>inplen THEN~
position=inplen 'II
END IF ~
ELSE'll
IF ASC(a$)=31 AND i>1 THEN 'Cursor left?'ll
i=i-l'll
position~position-l'll
IF position=O THEN'll
posit ion=l '!I
END IF 'II
ELSE'll
IF ASC(a$)=l27 AND i<=LEN (old$) THEN 'delete '?'ll
01d$=LEFT$(01d$,i-1)+RIGHTS(01d$,LEN(01d$)-i)'11
ELSE'll
IF ASC(aS)=8 AND i>1 THEN 'Backspace?'lI
i=i-1'll
position=position-l'll
IF position=O THEN'll
posilion=l'll
END IF'll
old$=LEFTS(old$,i-l)+RIGIITS(oldS,I,E:\(ctd$)-i)'ll
END IF'll
END IF'll
END IF'll
FI\D IF'll
FND IF'll
LOU,TE z, s'll
PRINT MID$(old$+" ",i-posi~ionTl,inplen 'String
output'll
so
ABACLS 3.2 TilE E DITO R
2.) <Cursor right>, then i and posi t ion are increased by olle
4.) <Delete>, here the ith chamcters arc removed [rom old$
The entire valid area of the string is displayed and the routine waits for
the next key. When the user presses <Return>, the length of the
characters is given. The putstring routine (described later in this
section) is used.
The following routine simplifies the input of integers and real values:
SUB getreal(l!,a$,z,s,inpIcn ,,"r,t',ob') STATIC'iI
'TASK : Read in real va l ue'lI
'PARAMETER:=>i' old value'll
as
pressed key'll
z line'll
s column'll
inplen lenqth of input line'jl
~nt' upper limit'll
ab! lowe~ limit~
<=i! specified valueq{
CALL conreal.str (", j$) G[
loopl: 'll
i$=jS'll
CALL getstr-lng(i$, as, U12]~56,]89~-. I I , Z: Sf irplr:fl )S
j$=iSCjf
CALL constrreal(i$,l')'ll
IF is='''' OR i!<llnt! OR i !>ob! T~i~NT
as=-1! liS!
Goro looplSI
i':ND IF'll
END S:;R'll
'll
81
3. TIlE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Notice that real values in both procedures have only three places after
the decimal point, and the values whose sums lie between zero and one
have a preceding zero. When the input does not satisfy these
requirements, the co nst r re al routine makes the empty character
string the output value for i $, as the resulL of incorrect input. The
restriction to three places after the decimal point is necessary because
exact input values change minutely when calculating the graphic later.
Besides character strings, integer and real numbers in our program need
vectors as input. It is practical to write individual input procedures for
these objccts. A vector is presented by three real numbers separated by
commas. We use the conversion routines (c 0 n 3 rea 1 s t r anel
constr3real) in the input procedure, and for the first time the
82
ABACUS 3.2 TilE EDITOR
The single addition to this routine is the second IF check where the
array k! emerges for the first time. First the program checks for an
allowable mouse input. If so, the modus index selects from the mouse
vector, or from the difference vector between the mouse vector and the
reference vector of the object.
83
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
A requirement for our menu was that a correction to entered data could
be made at any time. This should be done with the <Cursor up> and
<Cursor down> keys. <Cursor up> moves you to the previous cursor
84
ABACUS 3.2 TilE EDITOR
position and <Cursor down> moves you to the next position. So that
the procedure knows which input follows, a number variable (nr) is
used, which is in a certain range (0 <= n r <= number of input
positions). Besides the object data, additional information is needed
concerning whether the objects in the projection window should be
visible or not. This boolean value is stored in k ! (pt r,5 ,2) where pt r
points to the given objcct and the type is entered in k ! (p t r , 0 ,0).
SUB getcrarc(ptr) STATIC~
SHARED k~ (),tabs(),min!,max',grad',rad"il
tabs(0,0)=2~
tabs(1,O)=2~
tabs(2,O)=3~
tabs(3,O)=4~
tabs(4,O)=5~
tabs(S,0)=6'lI
tabs (6,0)=6'lI
tabs(7,0)=7'lI
tabs (8,0) =7'lI
tabs(0,1)=10'll
t;,bs(1,1)=22'lI
tabs (2, 1) =4'll
tabs(1,1)=4'lI
tabs (4,1)=4'll
tabs(5,1)~4'll
tabs(6,1)=,6'll
tabs (7,1) =4'll
tabs (8, 1) =16'll
nr=O~
WHILE nr<=8~
CALL getkey(a$,tabs(nr,O),tabs(nr,l))'lI
IF ASC(a$)=28 THEN'll
IF nr>O THEN'll
nr=nr-l'll
END IF 'II
ELSE ~
IF ASC(a$)=29 THEN'll
nr=nr+l'll
ELSE'll
IF nr=O THEN'll
CALL gctstring(b$,a$,"yn",tabs(nr,o), (nr r 1 ) r ~ ) q[
IF b$="y"THEN'll
k' (ptr,5,2)=1'll
ELSE 'II
k! (ptr,5,2)=0'll
END IF'll
END IF'll
IF nr=l THEN'll
CALL
getint (k! (ptr, 0,2) ,as, tabs(nr, 0), tabs (nc, 1),5,1' ,max') q:
END IF 'II
If nr=2 THEN'll
CALL
get3real(k' (ptr,l,O),k~ (ptr,l,l) ,k' (pLr,1,2),aS,tabs ',0) ,t.aos!
n r, 1) , 26, mi n ! ,max' , -1) 'II
END IF'll
IF nr=3 ',HEN'll
CALL
get3real(k! (ptr,2,O),k' (ptr,2,1),k! (ptr,2,2),aS,taos(nr,O),lar;';(
nr,1),26,min',max',ptr)~
8S
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END IF'll
IF nr=4 THEN'll
CALL
get3real (k! (ptr, 3, 0), k! (ptr, 3, 1), k! (ptr, 3, 2), as, tabs (nr, 0) , tabs (
nr,l) ,26,minO! ,max! ,ptr)'ll
END IF'll
IF nr=5 THEN'll
k!=grad!*k! (ptr,5,0)'ll
CALL getreal(k!,a$,tabs(nr,O) ,tabs(nr,l) ,8,min!,max!)'ll
k! (ptr,5,0)=rad!*k!'ll
END IF 'll
IF nr=6 THEN'll
k!=grad!*k! (ptr,5,1)'ll
CALL getreal(k!,a$,tabs(nr,0),tabs(nr,1),8,min!,max!)'ll
k! (ptr,5,1)=rad!*k!'ll
END IF 'll
IF nr=7 THEN'll
CALL
getreal(k! (ptr,4,0),a$,tabs(nr,0),tabs(nr,1),8,0!,1!)'ll
END IF 'll
IF nr=8 THEN'll
CALL
getreal(k! (ptr,4,1),a$,tabs(nr,0),tabs(nr,1),8,O!,1!)'ll
END IF 'll
nr=nr+l'll
END IF'll
END IF'll
WEND'll
END SUB 'll
'll
'll
86
ABACCS 3.2 THE EDITOR
As with the input procedures, the operations for real values and vectors
can be simplified with this put string routine. First the values must
be converted into strings using the conversion functions, and then
displayed with the putstring routine:
SUE fXl~.:ea:
(i!, Z, s, inplen I STATIC'lI
f'.L'AS~-< ::)isplay real value of predetermined lE?nqthqr
'PAI<At/;ET;::'·I.:~>i' the real value'll
z~ine'll
s colurnr;S
inplen Le~c;'--h of output window<:II
CALL conreal st r (i ' , s$ I'll
CALL putstring(s$,z,s,inplen I'll
ENG SUB'll
'lI
SUB putJreal(il',i2',iJ',z,s,inplen I STATIC'll
'TASK :display 3 Real values of certain length'll
!FAi'jl,i-.IF,TE?,: >il!,i2!,iJ! the real valuesqr
'~ line91
s columnq[
inplen Length of the output winciuw'q]
CALL con3realstr(il!,i2!,i3!,i$)qr
CAL: '·'.lL st dng (i$, z, s, inplen ) 'll
END SUBcIT
'1!
Now all we need is the display procedure for object data. Unlike an
input, where a separate routine must be constructed for each object, it
can all be done in one output procedure:
SUB showelem(ptr) STATIC'll
'TASK :dilLa out.put of eleC'.ent ptr'll
'PARAI1ETER:=>per pointer to tice specified element'll
:;ii!',h(r:U k: (), typ$ () ,empty$,grad', reid' 'il
LCJC'l\'l'E :. ( ] q[
::;'CT\ ~ -~ ~ 7q[
c ,'::1pty$'ll
NEXT LS
LOCATE i, 1 SI
PFTNT "Body :"'lI
CA~~ p~treal(ptr*1',1,8,5)'lI
lyp~INT(k! (ptr,O,O))'ll
IF pt.r><O Ti-lENSI
LOCATE 1,14'll
PRINT typ$(typ)'ll
LOCATE 2,;",
PRINT "visible :o;<Jl
IF k' (ptr, .),)) C TH:cN~
PRINT "n"'ll
ELSE 'll
PRINT "y"'ll
'C;::; ;: 'll
) , 131[
PFI~/r 1I:~aterLal: "'ll
Cl\LL pL:.real (k! (ptr,O,2) ,2,22,S)S[
:: tYP"lO THEN'll
~<X:l-\ TE 3, 19t
"M :"'ll
PP.INT "r :"<[
CALL puUreal(k'(ptr,1,O),k'(ptr,1,1),k!(ptr,1,2),3,t;,26)'ll
87
3. TIlE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
SUH91
':-,yp.:;' :4:'
= ItCircle segmentll<j{
typS (5) =lfi\rcllg:
88
ABACUS 3.2 TilE EDITOR
typ$(lO)="Sphere"'ll
typ$ (20) ="Cylinder"'ll
typ$ (21) ="Cylinder segment"'ll
typS(22)="Cone"'ll
typ$(24)="Spheroid" 'll
The graphic commands used in this program should consider that each
object must be displayed in three different windows. To complicate the
implementation of this routine, you must add the enlargement factor
and the chosen section. This isn't easy, because pixel width is less than
pixel height on the Amiga. This can be evened out by making a
correction factor for the X coordinates. You may have seen this
phenomenon for yourself, but if not, try to display a square with an
edge length of 100. When you use the following command, you may
see a rectangle on the screen instead of a square:
LINE (O,O)-(lOO,lOO)"b
To calculate the correction factor you must measure the height of the
rectangle and divide it by its length. This value should change in the
program to correspond to your screen (the variable is called
xcoorfac! and is in the ini t SUB program).
The simplest graphic objects are points and lines. We use room
coordinates in our program instead of screen coordinates. This means
we must create our own procedures for these graphic objects. You'll
nced the coordinates of the point or line, the character color (colour),
the statement of the section and the enlargemen t factor (f act 0 r ! ) .
The WINDOW function receives the data about the window display.
SUB setpoint (x', y!) STATIC'll
'TASK : set point in current outFJt ·.-lindow'll
'PARAMETER:=>x!,y' Poine coordinate'll
SHARED mx!,my!,mz~,factor!,xcorrfac!,colour~
swindow=WINDOW(l) 'll
IF swindow=l THEN'll
LINE ((x! -mx!) *xcorrfac I *factor', (my! -y!) *factor!) - ( (x ,_
mx!) *xcorrfac' * factor! , (my! -y! ) *factor' ) ,colour'll
ELSE'll
IF swindow=2 THEN'll
LINE ((x'-rnx!) *xcorrfac! *factor', (mz! -y! ) *factor!) - ((x'-
mx' ) *xcorrfac! * factor! , (m2! -y! ) *factor! ) ,colour'll
ELSE'll
IF swindow=3 THEN'll
LINE ((my! -x' ) *xcorrf ac' * factor! , (mz' -y! ) * factor' ) -
((my!-x!) *xcorrfac! *factor', (mz'-y!) *factor') ,colour'll
END IF'!'
"ND IF'll
89
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END IF'll
END SUB'll
'iI
SUB drawlinelx~,y )STATIC'll
'TASK :draw 1 ne from last point to specified point'll
'PARAMETER:=>x!,y Point coordinates'll
SPARED mx!,my!,mz!,factor!,xcorrfac!,colour'll
swindow=WINDOW(l) 'II
IF swindow=l THEN'll
LINE - ( (x' -mx! ) *xcorrfac! *factor' , (my' -y! ) *factor! ) ,colour'll
ELSE'll
IF swindow=2 THEN'II
LINE - I lx' -mx I ) *xcorrfac I * facto, I , (mz!-
y!)*factor!),colour'll
ELSE'll
IF swindow=3 THEN'll
LINE - ( (my! -x' ) *xoorrfac! *factor! , (mz!-
y!)*factor!),colour'll
END IF'li
END IF'll
END IF'll
F:ND SUB'll
'II
Now comes the drawing routine for an ellipse. Let's think about how
an ellipse can be constructed.
We have used a method that uses the midpoint of the ellipse and two
more vectors which span the ellipse, clearly establishing the ellipse.
The ellipse begins by rotating the two vectors around the midpoint.
When a full rotation is executed, all of the points of the ellipse are set.
90
ABACUS 3.2 TilE E DITO R
y!=ay!*COS(alpha!)+by:*SIN(alpta!)+my!~
CALL drawline(x!,y') 'draw line from old point to new'll
NEXT i'll
END SUB'll
91
3. THE TRACER PROGRA:\1 AMIGA 3D GRAPHIC PROGRAM:\1ING
We are still missing the display routine for the other 10 objects, which
are fairly easy to develop. You can explore these yourself. Check the
complete editor listing in the appendices if you run into trouble.
Now you're familar with some of the tools that make up an editor, but
there are still more. Suppose you entered some objects and want to
work with the first object; or you want to recreate an object and you
don't remember the data; or you notice that your last input makes no
sense and you want to delete the object.
Figure 3.22
92
ABACUS 3.2 THE EDITOR
Now to request these as free memory, we add one procedure that marks
the entire array k! as free at the start of the program and adds it to the
free list:
SUB newelem(ptr) STATIC~
'TASK :get address of free place in list~
'PARAMETER:<~ptr points to this area~
SHARED kfree,k! (),knum~
IF kfree<knum THEN~
ptr=kfree~
kfree~k! (ptr,O,l)~
k! (ptr,O,O)=O~
k' (ptr,O,l)=O~
k' (ptr,0,2)~1~
END IF ~
END SUB~
~
These are our own memory management routines, which work on the
same principle as the Amiga's equivalent operating system procedures.
93
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END SUB'I!
'I!
We need a procedure that can move objects around in the list. We want
to move objects to the left in the list so the pointer can be lowered to
element one, and we want to move objects to the right in the list so we
can increase it past one. We must assume that until now the pointer
was never negative, contained too large a value, or didn't point to an
erased element:
SUB lefts(ptr) STATIC'I!
'TASK : gee. element to left of current elememt'l!
'PARAMETER:=>ptr poinLs to current body'l!
SHARED k' () 'I!
IF ptr><O THEN 'I!
ptr=ptr-l'll
END IF'll
WHILE k' (ptr,O,O)=-H
ptr=ptr-l'l!
WEND'I!
CALL showelem(ptr)'!!
END SUB 'I!
'I!
Slill rights (ptr) STATIC'll
'TASK :get element to right of current element'!!
'PARAMETER:~>ptr pointer to current body'll
SHARED k! () , knum'll
old=ptr'll
IF ptr<knum THEN'll
ptr=ptr+l'll
END IF'I!
WHILE k' (ptr,O,O)=-l AND ptr<knum'l!
pt r=ptr+ 1 'I!
WEND'll
IF k! (ptr,O,O)=-l THENq[
ptr=old 'I!
ELSE'll
CALL showelem(ptr)~
END IF'I!
END SUB'I!
'I!
To move our shape we must move its reference point. The new
reference point can be entered either with the keyboard or the mouse.
94
ABACUS 3.2 THE EDITOR
a-x*coslgamma)-y*sin(gamma)
b=x*sin(qamma)+y*cos(gamma)
c=a*sin(beta)-z*cos(beta)
from
X=a*cos(beta)+z*sj~(beta)
Y~c*sin(alpha)+b*cos(beta)
Z=b*sin(alpha)-c*cos(alpha)
This formula must be taken for granted because the proof would fill a
page. An object should be copied and then rotated, instead of just
rotating it. It would help the user to be freed of this copy operation.
Our rotation can can be defined by the following BASIC procedure:
SUB rotation(ptr) S~ATIC'
'TASK :rotate body by three angles'll
'PARAMETER:=>ptr points to the body'll
SHARED k! (),grad!,rad!,min!,max!'J[
IF pt r><O THEN'
WIN:::OW 5,"Rotation", (O,129)-(314,170),4,1'll
vx!:- gra.d! *vx! t]l
vy! =grad' *vy"
vz!=grad!*vz~<!I
LOCATE 2,1'll
PRI NT "'J : '''ll
PR_\T"q<ni t, d<.:;, c<cpy&do :"91
CALL put3real (vx!, vy', vz', 2,4(26)'
CALL get3real (vx!, vy ~, vz! f" 11,2,4,26, min! max! , 0)I Cj[
CALL getstring(a$," ","qcd",3,21(1)'
vx!=--=r2d:*vx!'1I
vy! ::- ad! *vy ! ~
vz' =rad' *vz''ll
WINDOW CLOSE S'
l'iINDOW OUTPUT
IF a$><"q" THEN'll
4'
1:;-·" a$_:::lIc l i THENlI
CALL copy(ptr)'lI
EiIiD IF'
IF k! (ptr,O,O»=20 THEN'll
til=s,!!
ELS[q
Lil-3'll
ENS iF'!!
FOR i=2 TO til'll
a =k! (pcr,i,O)*COS(vz!)-k! (ptr,i,l)*SIN(vz!)'lI
b =1:' (pcr,i,O)*SIN(vz')+k' (ptr,i,l)*COS(vz!)91
c ~a!*SIN(vy')-k' (ptr,i,2)*COS(vy:) '!!
k (ptr,i,O)~il'*COS(vy!)fk' (ptr,i,2)*SJN(vy')'
k (ptr,i,l)cc!*SIN(vx!)+b!*COS(vx!)'lI
95
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
k' (ptr,i,2)=b!*SIN(vx!)-c'*COS(vx'l~
NEXT i ~
CALL showelem(ptrl ~
IF k' (ptr,5,2)=1 THEN~
CALL drawelem(ptr)~
END IF 'II
ELSE ~
WINDOW CLOSE 5'II
END IF~
END IF'll
END SUB~
'll
3.) The instruction for the enlargement is set in the FOR loop:
k' (ptr,i,OI~vx!*(ptr,i,O)
k ' (pt r , i, 1) =vy , * (pt r , i, 1 )
k ' (pt r , i , 2) =v z ' * k ' (pt r , i, 2 )
Now two more routines editor are ready for adding to the editor.
These operations are basically very simple. The contents of the array
k! 0 are written to the disk, element by element. It should be possible
to save only certain sections of the data, specified by the top and
bottom limits of the indices. Before choosing this option in the
progam, the elements that should be deleted should be marked so they
are not written to the disk. The editor adds a file extension of .list to
the filename to distinguish the file from any other file types on disk.
SUB savelist STATIC~
'TASK :See save routine for material list 'II
SHARED k! () ,knum, legchar$, Fi le$'II
WINDOW 5,"Save List", (O,129)-(314,170),O,1'll
PRINT "Name:"'!!
PRINT "from: 1 "'ll
PRINT "to :"'ll
mfrom! ,=1 'lI
mto!=knum'll
96
ABACUS 3.2 TilE EDITOR
CALL putreal(mto!,3,6,'-0)
CA=~~ getstring(FileS," 11/ cqcharS,l,6,lQ)1I
CJ<~J getint(mf:rom!,II ",2, ,10,1~rk~':'~~:\'<'Ir=-;)'ll
getint(mto!," 11,3,6, 8/mfrc)m~ ,~n~m*}_!)'
-::F ~~i le$><"11 THEN'll
OPEN File$+".LIS':''' FOR AS lS
quantity~O'll
FOR i~mfrom' TO mto! 'delermine :lUrrJJer of elements to be
sdvcd~
IF kI (i, 0, 0) ><-1 THEN'll
quantity q'leJrltity+l'll
END IF'll
NEXT i'll
PRINT 81,quarltity I
FOR ptr~mfrom' TO mta!I
IF k! (ptr, 0, 0) ><-l THEN 'forget blank elementsS
~OR 1-::-0 TO S'IT
PRINT #l,~! (ptr,i,O);",";k! (ptr,i,l);",lI;k! (ptr,i,7)'1r
NEXT i'll
END IF'll
hEXT ptrl
c~nSE I I
:<ILL File$+". LIST. int""1
END IFI
v;UJi)OW CLOSE 51
WINDOW OUTPUT 4,
L:.ND SUB
'll
The procedure does not test for the existence of the file on disk. If the
llser enters a nonexistent name, the following error message appears:
The program stops and the line with the OPEN instruction is displayed.
You may wish to add error handling.
97
3. TilE TRACER PROGRA;'\I AMIGA 3D GRAPIIIC PROGRAMMI:"G
1l
click:1l
durrunyccMOUSE (G) 'fi
x!=MOUSE(3)/{factor!*'xcorrfac!) 'Get nCL~SC pos.i: ic-~r: ()~d
compute'll
y' ='MOlJSE (4) / factor ''ll
n::::.WU,,ljJOW (8)
'window clicked'IT
oldwind0wo=~\lINDOW(1) 'output windc)w91
CALL acci vatc,;indow& (W:NDOW (1) ) 'll
IF n<4 THEN 'was projestioll windoiw icked?'I!
WINDOW CJUTPUT n9i
LINE U-'i()lISF~ (1) -I ,_ MUU:;l~ f4}} - (MOUSE (J) +~, (I;) ) f 3 ':::)rdV;
ci role'll
LINC (MOl)SE(3),MOUSE(1)-1)-(MOUSE(3) , (~)+1),3'11
11_;-- :-'.·1 THE.N 'corrpute spatial coord~;;c3.u::sSl
[f,DX! ~-rnx: +x! en
;r,QY ~ -==rny! -y ! <IT
ELSS'!i
IF n=2 Tf-lENq[
mox ! -;::rnx ! -+- x ~ en
moz I ~m2 ' -y I 91
ELSE'll
IF w3 THEN'll
may I -my I -x : 'll
rna z ! ==mz ! -y ! 11
END IF'll
END :F'!i
END IFS
,,:ox I ~F:X (max: •. 5) 'ro~nd'll
moy' "FIX (:noy' + . .s) 'Il
moz I c-f-lX (:r,oz: -+. ) 'Il
WINCUir~l OCT?U'I' 411
:no$=-STR$ (rn:]x:) -i-", n+S'I'RS (may:) -+ n, "+3 (~:',OL:) S
LOCATE lG,8 'delete o~d :;:c-,;se vaLles and
o:;es91
PRINT SPACES(26)'
LOCt'1':T: llJ,8qr
98
ABACUS 3.2 THE EDITOR
PRINT MID$(mo$,1,26) ~
WINDOW OUTPUT oldwindow~
ELSE~
CALL checkgadget 'was a gadget clicked?~
END IF~
RETURN ~
~
The ini tgadget routine lets you establish where on the screen a
certain gadget of a specific height and width should appear. All of this
information goes into a special global array. When the user presses the
left mouse button, the checkgadget routine is called. It checks for
whether the mouse pointer lies inside of the gadget. If so, the following
two possibilities exist:
1.) When the gadget is a slider, the old slider must be deleted and
drawn at the new position. The position of the orginal slider is
saved in the gadget% array in the fourth position.
2.) When the gadget is an icon, this icon whose picture information
is in the array gadget s % is either inverted or is given a
completely new icon graphic. This screen information is loaded
at the start of the program with GET and is accessed by PUT.
The additional gadget is stored temporarily in gadget %( 4).
Another routine ensures that the gadgets which are no longer necessary
are deleted from the screen:
SUB checkgadget STATIC~
'TASK :test whether a gadget has been clicked ~
SHARED gadget%(),gadgets%{) ~
dummy=MOUSE (0) ~
ax=MOUSE(3) 'Mouse position~
ay=MOUSE (4) ~
i=O~
WHILE i<=lO 'search entire array~
x%=gadget%{i,O) 'get values from array ~
y%=gadget%{i,l)~
h%=gadget%(i,2)~
1%=gadget%(i,3)~
valu%=gadget%(i,4)~
wind%=gadget%(i,5)~
yes%=gadget%{i,6)~
none %=gadget %(i,7) 'Mouse over gadget ?~
IF x%<ax AND x%+l%>ax AND y%<ay AND y%+h%>ay AND x%>=O AND
WINDOW{O)=wind% THEN~
old=WINDOW{l) 'reserve output window~
WINDOW OUTPUT wind% 'delete old slider draw new one~
IF yes%=-l THEN~
LINE {valu%+x%+l,y%+l)-{valu%+x%+l,y%+h%-l),O~
99
3. TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMIN(;
valu%=ax-x%-l'l[
LINE (valu%+x%+1,y%+1)-(valu%+x%+1,y%+h%-1),3'l[
gadget%(i,4)=valu% 'get new value'l[
ELSE'l[
IF none%=-l THEN'l[
IF valu%=l THEN 'first time, invert it'l[
gadget%(i,4)=O'l[
LINE (x%,y%)-(x%+I%,y%+h%),O,bf'l[
PUT (x%,y%),gadgets%(yes%),?RESET'l[
ELSE 'l[
gadget%(i,4)=1 'else return 'l[
LINE (x%,y%)-(x%+l%,y%+h%),O,bf~
PUT (x%, y%) ,gadgets%.(yes%) 'll
END IF'll
ELSE 'll
IF valu%c1 THEN 'first time, display no output'l:
gadget% (i,4)=O'l[
LINE (x%,y%)-(x%+I%,y%+h%),O,bf'l[
PUT (x%,y%),gadgets%(none%)'ll
ELSE 'l[
gadget%(i,4)=1 'else yes output'l[
LINE (x%,y%)-(x%+l%,y%+h%),O,bf'll
PUT (x%,Y%),gadgets%(yes%)'l[
END IF'l[
END IF'll
END IF'll
WINDOW OUTPUT old 'old output window active'll
i=10 'II
END IF'l[
i=i+1'11
WEND'l[
END SUB 'l[
'II
'II
SUB initgadget (x%,y%,h%,l%,valu%,wind%,nr%,yes%,none%)STATIC'l[
'TASK :place a new gadget in thp garlget array (Jadr.;::et% () en
I P.tI~F...l'...."1ETER: ->X%I Y% Posi tion of UpfJET
, h%,l% border height and lenght'l[
valu% Start value'll
wind% Output window'll
yes%,none% if yes%=-l,then slider'll
if none%=-l,gadgets inverts when clicked'll
else disp10y another gadget'll
yes% and none% s~~pply the indices [-or
graphic information'll
of the array gadgets 'l[
<=nr% Position of the gadgets i" array'll
SHARED gadget% () ,gadgets% () 'll
IF x%>=O AND y%>=O AND h%>=2 AND 1%>=3 AND valu%>=O AND
valu%<l% AND wind%>O THEN'l[
MOUSE OFF'l[
old=WINDOW (1) 'II
WINDOW OUTPUT wind%'l[
IF yes%=-l THEN'r
LINE (x%,y%)-(x%,y%+h%)'l[
LINE -(x%+l%,y%+h%)'l[
LINE -(x%+l%,y%)'l[
LINE -(x%,y%)'l[
LINE (valu%+x%+l,y%+l)-(valu%+x%+l,y%+h%-l) ,3'l[
ELSE'l[
IF valu%=l THEN'
PUT (x%,y%),gadgets%(yes%)'ll
100
ABACUS 3.2 TilE EDITOR
ELSE'll
PUT (x%,y%),gadge~s%(none%)'ll
END IF'll
END IF'll
nr%~O'll
WHILE gadget%(nr%,O»<-" AND nr%<~9 'll
nr%~nr%+l'j]
WEND'll
IF gadget %(nr%, 0) ~-1 T'"EN 'll
gadget%(nr%,O)~x%'lI
gadqet%(nr%,l)~y%'lI
qadgeL%(n,,%,2)~h%'lI
qadqet% (nr%, 3)-1%'lI
qadqct% ('1r%, 4) -valu%'lI
gadqet%(nr%,5)~wind%'lI
qadqet%(nr%,6)~yes%'lI
gadget%(nr%, 7)~none%'lI
END IF 'lI
MOUSE ON'lI
\;/INDOW OUTPUT old'll
END IF'lI
END SUB'll
'iI
SUB deleteqadget(i) STATIC'lI
'TASK :delete a gadget91
'PAPAMETEP:~>i Index of gadqe~s in array 'I[
SHARED qadget %() 'lI
IF i>~O AND i<=lO THEN'lI
qadqet%(i,O)=-l'll
END IF'!!
END SUB 'jj
'lI
'I[
101
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
PRINT 'II
PRINT "Shadow:"'
PRINT'll
PRINT "~irroring :"~
wl%=mat~ (matptr, 01 *101'11
w2%=mat' (matptr, 11 *101 'II
w3%=mat! (matptr,21*101'll
w4%=mat! (matptr,3) *101'11
w5%=mat! (matptr,4)*101 'll
CALL initgadget(110,8,10,102,w1%,5,nrl%,-1,-1)'ll
CALL inilgadget(110,24,10,102,w2%,5,nr2%,-1,-1)'lI
CALL inilgadget(llO,40,10,102,w3%,5,nr3%,-1,-1)'ll
CALL initgadget (110,56,10,102, w4%, S, nr4 %, -1, -1) 'll
CALL initgadget(1l0,72,10,102,w5%,5,nr5%,-1,-1) 'II
CALL initgadget(110,88,15,30,1,5,nr6%,0,-1IS
END IF'IT
ZND SUB'll
'lI
The zero in the last ini tgadget call is the address of the OK gadget
which must be clicked to end data inpul.
The routine to read the material data is just as easy as the above
procedure. It is called after showmat:
SUB getmat (matptr) STA':'IC'IT
'TASK osee corresponding routine for the body list 'lI
SHARED mat! (),gadget%(),nr1%,nr2%,nr3%,nr4%,nr5%,nr6%'ll
CALL showmat(matptr)'II
WH~LE gadget%(nr6%,4»<O'll
PALETTE ), gadget %(nrl %, 4) /l00, gadget% (nr7%, 4 I /l 00,
gadget%(nr3%,4)/100'll
vlEND 'IT
mat' (matptr, 01 cgadget% (nri%, 41 /l 0 I'll
redl' (matptr, ;)~q"dget%(n,2%,4)/lOl'll
This was the la'>t important routine for creating our ray tracer editor.
102
An,\CLS 3.2 THE EDITOR
Next all of the global variables must be initialized and the global arrays
dimensioned. A screen and four windows for the display and the text
input and output be open.:d. The arrays k! ,md rna t! should be linked
at the beginning, declare all the elements as free, and put them in the
free list.
Use the routines and ideas presented to create your own editor or see the
complete listing in the appendices. The real fun of programming is in
creating your own programs.
103
3. TilE TRACER PROGRAM AMIGA 3D GRAPIlIC PROGRAMMIi'\G
You probably noticed that we're aiming toward a specific goal. All of
the routines listed up until now can be combined to make a complete
program. The object editor is a self-sufficient module called from the
main program. The tracer program has also been built using modules
that can be combined to make a complete program or can be
incorporated into your own programs.
104
ABACLS 3.3 TilE MAIN PROGRAM
NWBase& ~ WINDOW(7)~
NRastPoLt& ~ WINDOW(8)S
~~Screen& ~ PEEKL(NWBase&+46)~
, Base address of Window-Structure~
, from which the screen structure is taken~
, RastPort belongs with the WINDOW () funct ion~
~
Status$ ~ " Status: Select resolution"+CHR$ (0) 'Status
line output~
dummy ~ SetWindowTitles(~~ase&,SADD(Status$),O)~
105
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
'II
IF x(y) < a THEN x(y) Modulo (y)-l'II
IF a$ = CHR$(28) THEN'll
Colours(y) = 2'II
y = y-1'11
END IF'll
, CRSR up'll
'II
IF a$ = CHR$(29) THEN'll
Colours(y) = 2 'II
y = (y+l) MOD 4'II
END IF'll
, CRSR Down'll
'II
IF y<O THEN y=3'II
'II
Colours(y) = I'll
'II
IF (x(O) > 0) AND (y=O) THEN'll
x(1) = 0 ' Select HAM or Halfbrite 'II
x(3) = 5 ' 5+1 BitPlanes'II
Modulo(3) 6'11
END IF'll
'II
IF x(O»O THEN x(3) 5 ' Number of BitP lanes unchanged by 'II
, HAM or Halfbrite mode'll
'II
IF (x(O) = 0) AND (x(1)<>1) THEN ~
Modulo(3) = 5'II
IF x(3) > 4 THEN x(3) = 4 'Maximum 4+1 Bitplanes'll
END IF ' in Normal Mode'll
'II
IF (x(1) = 1) AND (y = 1) THEN'll
x(O) = 0 ' HIRES and Normal'll
IF x (3) >3 THEN x (3) = 3 ' Maximum 3+1 BitPlanes 'II
Modulo (3) = 4'11
END IF'll
'II
IF a$<> CHR$(13) THEN GOTO Outg'II
'II
COLOR 1'II
'II
RasterW%=(x(1)+1)*J20'II
RasterH%=(x(2)+1)*200 'PAL-resolution = 256'11
'II
IF x (0) 1 THEN Modus% &H800 'HAM'll
IF x (0) 2 THEN Modus% &HBO ' Hal fBd te'll
IF x (l) THEN Modus% &H8000 'HIRES'II
, (HAM, Hal fbri tel and HIRES close the Siime way 'lI
'II
IF x(2) 1 THEN Modus% = Modus% OR 4 'LACE'll
'II
CLS'II
RasterT% = x(3) f1'11
'II
IF RasterT% = 6 THEN RasterT% = 5'11
, I f HAM, open a normal screen 'I!
, (max. 5 Bi::Planes)'II
'II
IF FRE(-I) < (RasterW%/8*RasterH%*RasterT%)+SOOO THEN'll
CLS'II
106
ABACUS 3.3 THE MAIN PROGRAM
IF RasterT% = 6 THEN'll
Groesse& = Raster:W%*(RasterH%\8)'ll
F1ags& = 65536&+2 • t-SMF CHIP MEMF CLEAR'll
Mem& ~ Al 1 ocMem& (Ccocsse&,Flags&) 'II
IF Mem&0 0 THEN'll
CALL SCLOff'll
CALL PrintIt ("Not enough memory for sixth BitPlane
!!! ", lOO,False) 'll
CALL DialogBox("Sorry
''',1,True,xla%,y1a%,x2a%,y2a%,Falsc)'11
'II
CALL DoDialog(n%,l,-1,-l,-l,-1,xla%,yla%,x2a%,y2a%,-1,-1,-
1,-1)'ll
107
3. THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
GOSUB CloseIt'll
RUN'!!
END IF'!!
'!!
POKE Depth&,6'll
, New depth'll
POKEL BitPla~e6&,Mem&'!!
BitPlanes&(5)=Mem&'!!
, Poke address of the sixth BitPlane'll
'!I
POKEW Viewport&+32,:-1odus%'l[
, Poke for display mode POKEN'l[
'l[
duwmy = RemakeDisplay(dummy&)'lI
, compute new display'll
END IF 'lI
'!I
Status$ "Status: Initializing"+CHR$ (0) 'I!
CALL SetWindowTi tles& (t-"tlBase&, SADD (Status$) ,0) '!I
'll
CALL Scroff'll
CALL SetDrMd&(RastPort&,l)'ll
'll
RasterW1% lZasterW%-l , 319/639'll
RasterHl% RasterH%-l , 199/399'll
RasterW2% - RasterW%/2 'Screen middle'll
RasterH2% RasterH%/2'll
'!I
FactorX (x(l)+1)/2'll
FactorY (x(2)+l)/2'll
'!I
POKEW OSModus&,v'odus%'ll
POKEL OSRastPort&,RdSLPort&'ll
POKEW OSRasterW1&,RasterWl%'ll
POKEI'J OSRasterHl &, RasterHl %'ll
MaxColour% = 2 lZasterT%'ll
A
IF (RastcrT% = 6) THEN'll
IF (Modus% AND &H800) &H800 THEN 'I!
MaxColour% 16 'HAM~1
ELSE'!!
MaxColour% 64 'Halfbrite'll
END IF'!!
END IF'll
'll
POKEW OSMaxColour&,2 RastcrT%
A
'If HAM: 64 Colo~r!'lI
DIM Colour(MaxColour%,3)'ll
'l[
FOR m%~O TO 3'll
Colour(l,m%)=O 'Black'll
Colour(2,m%)=1 'White'll
NEXT m%'lI
'!!
IF (Modus% AND &H80) &H80 THEN 'Half Brite'!!
MF%=MaxColour%/2'!!
'll
Colour(MF%+l,O)=MF%'lI
Colour(MF%+2,O)=MF%+1'll
FOR m%=l TO 3'll
Colour (MF%+l,m%) = '!I
Colour(MF%+2,m%)=.5'lI
°
108
ABACUS 3.3 TilE MAl)'; PROGRAM
NEXT m%'lI
RESTORE OptimaleHBColour'll
ELSE'll
MF%~MaxColour%'ll
RESTORE OptimaleColourS
END IF'll
FOR n% 3 TO MF%'lI
READ r%,g%,b%'ll
'll
Colour (n%. O)=n%-l'll
Colour(n%,1)~r%/15'll
Colour(n%,2)~g%/15'll
Colour(n%,3)~b%/15'll
CALL SetRGB4&(Viewport&,n%-1,r%,g%,b%)'ll
'11
IF (Modus% AND &H80)<>0 THEN 'Half Brite'll
Colour(n%+MF%,O)~n%+MF%'ll
FOR m%~l TO 3'll
Colour(n%+MF%,m%)~(INT(Colour(n%,m%)*15)\2)/15'll
NEXT m%'ll
END IF'll
'11
NEXT n%'ll
, ~> Colour (n, 0) color index, '11
Colour(n,1 .. 3) RGB brightness'll
'll
, Poke colors into assembler routines array:'ll
'll
FOR n%~O TO MaxColour%-l'll
POKEW OSColour&+n%*8,Colour(n%+1,0)'ll
FOR m%~l TO 3'll
POKEW OSColour&+n%*8+m%*2,Colour(n%+1,m%)*1024'll
NEXT m%'ll
NEXT n%'ll
CLS'll
RETURN'll
The Ra s t e r I nit routine also sets the colors for the user screen. If
you are not happy with the default colors these may also be changed:
ColorPalette:'ll
Status$ ~ " Status: Color change"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$) ,OJ'll
'11
GOSUB DeleteMenu'll
'll
CALL SetRast&(RastPort&,O)'ll
CALL Scron'll
CALL PrintIt("Which color to change ?",lOO,True)'ll
'll
NumCol ~ MaxColour%'ll
IF NumCol ~ 64 THEN NumCol ~ 32 ' Halfbritc ?'ll
Widthe ~ (RasterW%-40)/NumCol'll
LINE ((20+l) ,1)-(20+Widthe-l,RasterH%/lO-1) ,1,b 'll
FOR i~l TO NumCol-l'll
LINE ((20+i*Widthe+l),1)-((20+(i+l)*Widthe)-1,RastcrH%/lO-
l),i,BF'll
IF MaxColour% ~ 64 THEN 'Halfbrite Colour output'll
LINE ((20+i*Widthe+l),RasterH%/10)-((20+(i+l)*Widthe)-
1,RasterH%/5-1) ,i+32,BF'![
109
3. TIlE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END IF'll
NEXT'll
'II
LoopA:'ll
CALL EmptyBuffers'll
lIO
ABACUS 3.3 THE MAIN PROGRAM
The colors of the user screen can, if you want, be changed in the
RasterIni t routine by using the PALETTE statement.
We have provided for file access between computer and disk. You can
build object definitions with the editor and then load existing
definitions from disk into the tracer program. Or you can merge
different object definitions and save all of the objects together on disk:
********************************~
* 'SERVICE' - Module *'lI
********************************~
''I[
Saver: 'lI
, Save array K() to disk'l[
GOSUB Directory'lI
CLS'll
IF dn$<>· ..• THEN'lI
dn$ = dn$ + ".LIST"'l[
OPEN "O",#1,dn$,1024'll
PRINT #l,NumberK'l[
FOR n%=l TO NumberK'lI
FOR p%=Q TO 5'lI
PRINT #1,K(n%,p%,O),K(n%,p%,1),K(n%,p%,2)'lI
NEXT p%'lI
NEXT n%'lI
CLOSE #l'll
'The following will delete icons when included:'ll
dn$ = dn$+".info"'lI
KILL dn$'I:
END IF'll
CLS'll
GOSUB MakeMenu'lI
RETURN'll
''ll
111
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Loader: 'II
I Load array K() from disk'll
GOSUE Directory'll
'II
Status$ = " Status: Object Loader"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$) ,OJ'll
'II
LOCATE 3,1'll
j'RINT" Which object do you wish to load?"'ll
PRINT 'II
PRINT" Filename : "; 'II
dn$ = IIUqr
CALL FormInputString (dn$,30!)'II
CLS'll
IF 00$ <> "" THEN'll
dn$ = OO$+".LIST"'ll
OPEN "I",#1,OO$,1024'l!
INPUT #l,NumberK'l!
LOCATE 10, 1 'II°
PRINT "Total ";NumberK;" Object ("+dn$+"). "'II
PRINT'll
PRINT " Maximum number of objects? ";'l!
MaxNumber NumberK'l!
CALL FormInputInt (MaxNumber,301,1',NurcberK)~1
'II
IF NumberK > MaxNumber THEN NumberK = MaxNumber'II
'II
ERASE K'l!
DIM K(MaxNumber,5,2)'l!
'II
FOE n%=l TO NumberK'l!
FOR p%=Q TO 5'll
INPUT #l,K(n%,p%,O),K(n%,p%,l) ,K(n%,p%,2)'l!
NEXT p%'l!
NEXT n%'lI
CLOSE #1 'II
Newor.e! = True'll
Start% = I'll
END IF'll
CI~S'!l
GOSUB MakeMenu'II
Fti:TURNg[
Merger:'ll
• Elements appended to available array K()'ll
IF (MaxNumber-NumberK) <= 0 THEN'll
Status$ = " Status: Object Merger"+CHRS(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
1:
a$ = "lnsufficent memory for more objects!! I "'ll
CALL PrintIt (a$,lOO,False)'ll
as = "please select New to create a cleared array K () I "'II
CALL PrintIt (a$,130,False)'ll
CALL DialogBox("OK",1,True,xla%,yla%,x2a%,y2a%,False)'II
'II
CALL DoDi.alog(n%,l,-1,-1,-1,-l,xla%,yla%,x2a%,y2a%,-1,-l,-
l,-l)'ll
ELSE 'll
GOSUE Directory'll
'II
Status$ = " Status: Object Merger"+CHR$(O)'ll
112
AUACCS 3.3 TilE MAIN PROGRA\I
LOCATE 3,1'i:
PRINT" Which ob'~ecL would yO'-.J :i ke to ~.e~q«;]1
PRINT'll
dnS = 1111 ~:
CLS'Ii
IF dnS <> "" THEN'll
enS dn$ + ".LIST"q:
:c-=
OPEN l'I",#1,dnS,1824~
INPUT #l, x'll
LOC1\TE 6, 1 'Ii
PR::::~T II TClta~ ";x;" Objects ("tdn$-t") ."'ll
?[{INT'll
PRINT .. Suff~C(::-it me~ory for II; MaxNl1mber-NumberK; "
Object.s. "'ll
PRINT'll
PRINT .. How IT,,}ny merges? n;q{
num = x'll
CALL Formlnp'i-.:tlnt (rlum, 30: ,1 !, lOGe; ~) q]
1 13
3. TIlE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMIl'iG
CLS'II
GOSUB Ma%eMenu'II
RETURN'll
''ll
IS
'"8adMat: 'll
C;OSUB 1:~,ectDry'll
'll
Statl1s$= II Status: Material constants loader"+CHRS (O)~
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'lI
'I!
LOCATE J, 1 'll
?RINT" I'lhich mate~ial would you like to lodCl:''''ll
PRI:-IT li
PRINT " Filename: ";11
'll
dn$ :::: 111Iq;
C:I'l.LL Forml r~~)utStrir:q (on:), 3D!) ~[
IF dn$<>llll THEN ~
dnS--=dn$+".MAT"qr
O~!EN !Ii !t, #l,dn$11
irlCltptr C-~ 'lq;
INPUT 1:', ~l1mberMatS
ERlISi:: Mat'll
DIM Mat (NurrDerMat, 6) 'I!
WHI!.I~ NOT (EOF (1 ) ) 'll
FOR ~O ['0 6'll
I~PUT II,Mat (macp~r,i)'ll
M.'X;' I'll
ITatpt r = mdLpt L+ 1'lI
WD:O'll
CLOS~: #J'lI
r:ND IF91
CLS'll
GOSUB MakeMenu'lI
RETUR,,'ll
We have added a routine for you that makes it possible to save the
screens created by the tracer program as an IFF (I nterchange File
Format) file. A picture saved in this format can be used with any
program that supports IFF (e.g., DeluxePaint®):
:-~~·reenSavf":::-: qI
GOSUB C, reet ory'll
'II
114
ABACCS 3.3 TilE MAI:"J PROGRAM
LOCATE 3,1'll
PRINT" Under what name would you like the se,een saved?"'ll
PRINT 'lI
PRINT II Filename: ";<JI
IFFFile$ ""'lI
CALL FormInputString (IFFFile$,30 ' )'lI
'lI
IF IFFFile$ <> THEN'lI
'lI
Handle& = 0 , File Handle'll
Buffer& = 0 , Buffer memory'lI
, reserve buffer'lI
Flags& = 65537& 'MEMF PUBLIC I MEMF_CLEAR'lI
BufferSize& = 360'lI
Buffer& = AllocMem&(BufferSize&,Flags&)'ll
IF 8uffer& = 0 THEN'll
DialogS c "No more memory! I ! "'ll
GOTO EndSave'll
END IF'll
'll
ColorBuffer& Buffer&'lI
S
Null& = O'll
PadByte% O'll
'lI
IF RasterW% 320 THEN'll
IF RasterH% = 200 THEN'll
Aspect% &HAOB'll
ELSE'!!
Aspect% &H140B'll
END IF'll
ELSE'll
IF Raste,H% = 200 THEN'll
Aspect% &H50B'll
ELSE'll
Aspect% &HAOB'll
END IF'lI
END IF'll
CJ
"' IFFFile$ = IFFFile$ + CHR$(O)'ll
Handle& = xOpen& (SADD(IFFFi leS) ,1006)'ll
IF Ha"dle& = 0 THEN'll
Dialog$ = "Can't open the file you wanted'! ''''ll
GOTO EndSave'll
END IF'll
'll
'll
, How many bytes contain IFF-Chunks ?S
BMHDSizc& 20'll
CMAPSize& .~ MaxColour%*3 + ((M,"xColour%*3) AN8 1) G
C1\MGSize& 4'll
.0
115
3. TIlE TRACER PROGRAM AMIGA 3D GRAPlIIC PROGRAMMING
Length& ~ xWrite&(Handle&,V&~?TR(FORMSize&),4)~
• + 1LBM for BitMap-File~
ChunkS = "ILBM"'II
Length& = xWrite&(Eandle&,SAOO(ChunkS) ,4)'II
~
E' Length& <= 0 THEN'lf
DialogS ~- "Write error on iCO;(M-Header I: '''\1
GOTO EndSave<jI
END IF 'II
'II
• BMHD-Cnunk ~
ChunkS = "BMHO"'II
Length& xWrite& (Handle&,SADO (Chunk$) ,4)'11
Length& xWrite&(Handle&,VARPTR(BMHOSize&),4)~
Length& xWrite&(Handle&,VARPTR(RasterW%),2)~
Length& = xWrite& (Handle&, VAI\PTR (RasterH%), 2) '11
Length& xWrite&(Handle&,VAR?TR(Null&),4)'II
Temp% ~ (256 * RasterT%) , No MASK1NG~
Length& " xWrlte&(Handle&,VAR?TR(Temp%),2)'I1
Temp% = 0 ' No Packing'll
Length& xWri te& (Handle&, VARPTR (Temp%) ,2) 'If
Temp% = O'lf
Length& xWrite& (Handle&,VARPTR(Temp%) ,2)'11
Lengt.h& xWri te& (Handle&, VARPTR (Aspect: %) ,2) '11
Length& xWri. te& (Handle&, VAI\PTR (RasterW%) ,2) 'II
Length& "c xWrite& (Handle&, VAP?TF (FasterH%), 2) 'il
'If
IF Length& <= 0 THEN'll
Oialog$ = "Write error on BMHD-Chunk !! !'"
GOTO EndSave'll
END IF 'II
'II
, CMAP-Chunk 'II
ChunkS "CrvrAP"9!
Length& xWrite&(Handle&,SADD(ChunkS),4)~
Length& xWr l te& (Handle&. VA'''''!'R (CMAPSi 7P!.) , 4) ,
, CAMG-Chunk ~
ChunkS = "CAMG"qr
Length& = xWrite&(Handle&,SADD(ChunkS) ,4)'ll
Length& = xWrite& (Handle&,VARPTR(CAMGSize&) ,4)'11
Modes& ~ PEEKW(Viewport& + 32)'II
Length& = xWrite&(Handle&,VARPTR(Modes&),!')'II
116
ABACUS 3.3 THE MAIN PROGR.r,,\\
Files created [rom this routine are not created in compressed form. More
memory is required for saving an IFF file to disk, but IFF file~; save to
disk 75% [aster than normal files.
117
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
sigBit% = AllocSignal%{-l)~
Flags& = 65537& ' MEMF PUBLIC MEMF CLEAR~
MsgPort& = AllocMem&{40,Flags&)~
IF MsgPort& = 0 THEN~
Dialog$ = "No 'MsgPort' !! !"~
GOTO EndPrinter4~
END IF~
~
POKE(MsgPort& + 8), 4 ~
POKE(MsgPort& + 9), 0 ~
Nam$ = "PrtPort"+CHR${O)~
POKEL(MsgPort& + 10), SADD(Nam$)~
POKE{MsgPort& + 14), 0 ~
POKE{MsgPort& + 15), sigBit%~
SigTask& = FindTask&(O)~
POKEL(MsgPort& + 16), SigTask&~
~
CALL AddPort{MsgPort&) 'lsit Port~
~
ioRequest& = AllocMem&(64,Flags&)~
IF ioRequest& = 0 THEN~
Dialog$ = "No ioRequest !! '''~
GOTO EndPrinter3~
END IF~
~
POKE{ioRequest& + 8),5 ~
POKE{ioRequest& + 9),0 ~
POKEL(ioRequest& + 14), MsgPort&~
~
~
Nam$ = "printer.device"+CHR${O)~
PrinterError& = OpenDevice&{SADD{Nam$) ,0,ioRequest&,0)~
IF PrinterError& <> 0 THEN~
Dialog$ = "No Printer ?!?"~
GOTO EndPrinter2~
END IF~
~
POKEW(ioRequest& + 28), 11 , DumpRastport to
Printer~
POKEL(ioRequest& + 32) , RastPort& , Print entire screen 'll
POKEL{ioRequest& + 36) , ColorMap&~
POKEL(ioRequest& + 40) , ModesH
POKEW (ioRequest& + 44), O~
POKEW(ioRequest& + 46), O~
POKEW{ioRequest& + 48) , RasterW%~
POKEW{ioRequest& + 50) , RasterH%'ll
POKEL(ioRequest& + 52) , O&~
POKEL (ioRequest& + 56), O&~
POKEW(ioRequest& + 60) , &H84~
'll
CALL
DialogBox ("Printing ... ",1, False, xla%, yla%, x2a%, y2a%, False) ~
~
PrinterError& = DoIO&{ioRequest&)~
IF PrinterError& <> a THEN~
Dialog$ "DumpRPort Error ="+STR${PrinterError&)+" '! !"'ll
GOTO EndPrinter~
END IF~
~
CLS~
Dialog$ "Hardcopy done"~
~
118
ABACCS 3.3 TilE MAIN PRO(;RA:\l
EndPrinte,,: 'I!
CIIL: CloseDevice (ioRequest&) 'll
;:ndPrintcr2:'il
P~~"V (:oRRCJuest& + 8), &HFF'll
f'~;:0:~(ioReq'lest& + 20), -I'll
PCKE~(ioRequest& + 24), -I'll
CII~L FreeMern& (ioRequest&, 64) 'll
'll
EndPrinter3:91
CALL RemPort (tl,sqPort&) 'll
POKE(MsgPort:& + 8), &HFF 'll
POKEL(MsgP"rt& + ;;>0), -l'll
CALL FreeSignaJ(sigBit%)S
CALL FreeMern&(MsgPort&,'O)'lI
'lI
EndPrinter4:91
CALL D.ii'dog8ox (Dia"og$, 1, True,x1b%,ylb%,x2b%,y2b%, F.llsc) 'li
CAL:. DoDialog(n%,1,-1,-1,-1,-1,x:~%,yl~%,x2b%,y2b%, -l,-l,-
1, -1) 9
END iF'li
C1,:;11
GOSl]f~ Makc~enu ~
Bac.:kgro~jr.d: q
, Bae k(] cC'clnd Determine9I
Stat.usS II Status: Background selcctionll+Cllf\';; (0) ~
CALL Set:l1JindowTitles&(r..TWBase&,SADU(Stalt.:s$), )1[
GOSU13 DcletcMenu'l1
'lI
CALL Dialog13ox ("Pat tern", 0, True, xla%, yla%, x2a%, y2a%, False) '::'
CALL Dialoqflox("Load
sc~een",2,False,xlb%,ylb%,x2b%,y2b%,False)'lI
CALL DoDialog(n%,O.xla%,yla.%,x/<"l%,y2a%,-1,-1,-1/-
1,xlb%,y1b%,x2b%,y2b%)'ll
CLS 'll
\1
~~2SUB Lep.nLoacierTt
:lg- ';'rc,("'li
E:SE'll
C.l\LL Dic:.logBox ("Pattern ", 0, T r1].e ( x 1 a %, Y _~:J %( x'=:' a i, ( ,C'alse)~
ct~ LL Ji alogI3ox (I1Sky", 1, Fa 1 se, xl£;%, y 1 r;'%, X)::-;Qi( y,/b%, F al c e} g
('-" ; T
~_t\LJ
Gi.alog8ox (IiFloa.t i ngll 12, False, X~C%, yJ.c%, x2c%:, y2c%, Fal se) q~
qj
119
3. Till: TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMII'G
CALL
DoDialog(~%,O,xla%,yla%,x2a%,y2a%,x:b%,ylb%,x2b%. (xlc%, ylc%,
x~'c%, y2-::_'%) <II
CLS'll
IF n% = 0 THEN •
'lI
LOCATE 10, I'll
PRINT " Numrx,r of the patt.ern (0 .. 34) ";91
a = 091
CALL Forml"Vll:nt (Hx,30!,O!,34!)'ll
Xpattern% = a'll
Xpallcc~.'i,),l\Pen%.8Pen%) 91
[Fen
fif) Truc9I
i·:ND
"
iF n% = 1 THf'NSI
LOCATE J ,1 ~
PRINT Sky type: "'II
II
120
ABAClJS 3.3 TilE MAIN PROGRA;\I
CLS'll
CALL Sky (Art%,HColr%,num%)'ll
Hg = True'll
END IF'll
'll
IF n% = 2 THEN'll
CLS'll
'll
CALL PrintIt("Floating Background",40,False)'ll
'll
LOCATE 10, I'll
PRINT" from color: ";qI
Fl = O'll
CALL Formlnput (Fl,30!,0!,CSNG(MaxColour%-1))'II
Coloursl%=Fl'II
LOCATE l2,1'll
PRINT" to color: n;'ll
F2 = I'll
CALL FormInput (F2,30!,0!,CSNG(MaxColour%-1))'II
Colours2%=F2'll
CALL Fhg(Coloursl%,Colours2%)'ll
Hg = True'll
END IF'll
END IF'll
CLS 'll
GOSUB MakeMenu'll
RETURN'll
121
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
CALL
OSSetPoint&(0,y%,RasterW1%,y%,CLNG(1024*red),CLNG(1024*green),CL
NG (1024*blue)) 'll
NEXT y%'ll
POKEW OSMaxColour&,64'll
ELSE'll
FOR y%~O TO RasterH1%'ll
red=red.s+ (y%/RasterH1%) * (red.e-red.s)'ll
green~green.s+(y%/RasterH1%)*(green.e-green.s)'ll
blue~blue.s+(y%/RasterH1%)*(blue.e-blue.s)'ll
CALL SetPoint(O,y%,RasterWl%,y%,red,green,blue)'ll
CALL
OSSetPoi.nt& (0, y%, RasterWl%, y%, CLNG (1024 *red) , CLNG (1024 *green) ,CL
NG (1024*blue)) 'll
NEXT y%'ll
END IF'll
CALL Scroff'll
END SUB'll
"II
SUB Sky(a%,Col%,num%) STATIC'll
SHARED WScreen&,NWBase&,RasterW%,RasterH%,RasterW1%'ll
SHARED RasterH1%,RasterW2%,RasterH2%,RastPort&'ll
CALL Scron'll
'll
CALL SetAPen&(RastPort&,Col%)'ll
CALL SetRast& (RastPort&,O)'ll
'll
FOR n%=l TO num%'ll
RANDOMIZE TIMER'll
IF a%<4 THEN'll
IF a% AND 1 THEN'll
x%=RasterW2%+RasterW2%*RND*RND*SGN(RND-.5)'ll
y%~RasterH2%+RasterH2%*RND*RND*SGN(RND-.5)'ll
ELSE'll
x%=RND*RasterW1%~
y%=RND*RasterHl%'ll
END IF~
'll
IF a% AND 2 THEN'll
IF x%=RasterW2% AND y%=RasterH2% THEN'll
dummy = WritePixel(RastPort&,x%,y%)'ll
ELSE'll
xl%=(x%-RasterW2%)*.1+x%'ll
y1%=(y%-RasterH2%)*.1+y%'ll
IF x1%>=O AND x1%<RasterW% AND y1%>~O AND y1%<RasterH%
THEN'll
CALL Move&(RastPort&,x%,Y%)'ll
CALL Draw&(RastPort&,x1%,y1%)'ll
END IF'll
END IF'll
ELSE'll
'll
IF RND<.9 THEN'll
CALL WritePixel&(RastPort&,x%,y%)'ll
ELSE'll
CALL Move&(RastPort&,x%-l,y%)'ll
CALL Draw&(RastPort&,x%+l,y%)'ll
CALL Draw&(RastPort&,x%,y%-l)'ll
CALL Draw&(RastPort&,x%,y%+l)'ll
END IF'll
END IF'll
122
ABACUS 3.3 Tm: MAIN PROGRA;\I
ELSE'll
'll
x%=RND*RasterWl%'ll
y%=RND*RasterHl%'ll
CALL Move&(RastPort&,RasterW2%,Raster!l2%)'ll
CALL Draw&(RastPort&,x%,y%)'lI
END IF'll
NEXT n%'ll
'll
CALL SetAPen&(RastPort&,l)'ll
'll
CALL Scroff 'll
END SUB'll
''ll
'lI
ScreenLoader:'ll
GOSUB Directory'll
'll
Status$ = n Status: Screen Loader"+CER$(O)'ll
CALL SetWindowTitles&(~~Base&,SADD(Status$) ,OJ'll
'll
LOCATE 3,1'll
PRINT" Which IFF-File would you like to load?"'lI
PRINT 'lI
PRINT" Filename: n;'ll
IFFFile$ n"'ll
CALL FormInputString (IFFFile$,30!)'ll
'll
IF IFFFile$ <> "" THEN'll
'll
BMHD False'll
CMAP False'll
CAMG False'll
Body False'll
'll
Handle& O'll
Buffer& O'll
'll
, reserve buffer'll
Flags& = 65537& ' MEMF PUS:.IC M..:MF CLEAR'll
BufferSize& = 360'll
Buffer& = AllocMem&(BufferSize&,Flags&)'ll
IF Buffer& = 0 THEN'll
Dialog$ = "No more memory!! ! n'll
GOTO EndLoad'll
END IF'll
'll
InputBuffer& = Buffer&'ll
ColorBuffer& Buffer& + 120'll
'll
'll
IFFFile$ = IFFFile$ + CflR$(O)'ll
Handle& = xOpen&(SADD(IFFFile$) ,l005)'lI
°
IF Handle& = THEN'lI
Dialog$ = "IFF-File can not be opened!! ''''ll
GOTO EndLoad'll
END IF'll
'll
'll
Length& = xRead&(Handle&,InputBuffer&,12)~
ChunkS ""'ll
FOR n% = 8 TO ll'll
123
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
ReadLoop:'ll
Length& = xRead&(Handle&,InputBuffer&,S)'ll
Chunkwinlen& = PEEKL(InputBuffer& + 4)'ll
ChunkS = .... 'll
FOR n% = 0 TO 3'll
ChunkS = ChunkS + CHR$(PEEK(InputBuffer&+n%))'ll
NEXT 'll
'll
IF ChunkS = "BMHD" THEN • BitMap-Header 'll
BMHD = True'll
Length& = xRead&(Handle&,InputBuffer&,Chunkwinlen&)'ll
RDepth% PEEK(InputBuffer& + S) 'll
Compression% PEEK(InputBuffer& + lO)'ll
RWidth% PEEKW(InputBuffer& + 16)'ll
RHeight% PEEKW(InputBuffer& + lS)'ll
BytesPerRow% RWidth%/S'll
RMaxColors% 2~(RDepth%)'ll
124
ABACUS 3.3 TilE MAIN PROGRAM
'll
ELSEIF Compression% = 1 THEN 'CmpByteRunl compression'll
FOR yl = 0 TO RHeight% -I'll
FOR b= 0 TO RDepth% -l'Jl
IF b<RasterT% T:IEN'll
Adress& BitPlanes& (b)+(yl*BytesPerRow%)'ll
ELSE'll
Adress& Buffer&'ll
END IF'll
NumBytes% O'll
'll
WHILE (NumBytes% < BytesPerRow%)'ll
Length&= xRead& (Handle&, InputBuffer&, 1) 'll
Code% = PEEK(InputBuffer&)'ll
IF Code% < 128 THEN ' Code%-Bytes take over'll
Length& = xFead& (Handle&,Adress& + NumBytes%,
Code%+l)'ll
NumBytes% = NumBytes% + Code% + I'll
ELSE IF Code% > 128 THEN ' Byte replicates'll
Length& = xRead& (Handle&, InputBuffer&, 1) 'll
Byte% = PEEK (InputBuffer&)'ll
FOR n% = NumBytes% TO NumBytes% + 257 - Code%'ll
POKE(Adress&+n%),Byte%'ll
NEXT 'll
NumBytes% = NucnBytes% + 257 - Code%'ll
END IF'll
WPC;[)1[
NEXT'll
NEXT'll
'll
ELSE'll
Dialog$ = "Unknown comprc5sjen procedure!! ~1I<jI
GOTO End Load'll
END IF'll
CALL Scroff'll
ELSE 'll
, "Unknown" Chunk-Typ'll
FOR n ~ 1 TO Chunkwinlen&'ll
Length& = xRead&(Handle&,InputBuffer&,l)'ll
NEXT'll
, Chunks have even numnber of bytes'll
IF (Chunkwinlen& AND 1) = 1 THEN'll
Length& = xRead&(Hand1e&, TnputBuffer&,l)'ll
END IF'll
END IF'll
'll
, All Chunks read?'
IF (BMHD True) AND (CVJ\P TriJc) AND IEccy True) THEN'll
GOTO LcadOK'll
END IF'il
'll
, Read ok, get next Chunk'll
IF Lenglh& > 0 THEN GOTO ReadLoop'll
'll
IF Length& < 0 THEN 'll
DialogS = I'Read error!! !II~
GOTO EndLoad'll
END IF 'lI
'll
IF (BMi':J~Fillse) 0;, (CMAP=False) OR (Body<) THEN'll
Dialog$ = "Not all necessary HEM-Chunks four.d~!! "'ll
GOTO EndLoad'll
125
3. THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
END IF'll
'lI
LoadOK:'ll
Dialog$ "Loading OK"'ll
'lI
EndLoad:'ll
IF Handle& <> 0 THEN CALL xClose&(Handle&)'ll
IF Buffer& <> °
THEN CALL FreeMem&(Buffer&,BufferSize&)'ll
CALL DialogBox(Dialog$,1,True,xlb%,ylb%,x2b%,y2b%,False)'lI
CALL DoDialog(n%,1,-1,-1,-1,-1,xlb%,ylb%,x2b%,y2b%,-1,-1,-
1, -1) 'll
END IF'll
CLS'lI
GOSUB MakeMenu'lI
RETURN'll
"J[
The next routine (1 n f 0) tells you how many free and used elements
(object definitions) there are in array KO. The routine named Help
displays information on how to control the program from the keyboard.
The menus include information about which keyboard shortcut can be
used for which command:
Info:'ll
, Information about free elements of K()'ll
Status$ ~ .. Status: Info"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'lI
'll
GOSUB DeleteMenu'll
126
AIIA CUS 3.3 TilE MAI N PR O GRA:'>l
Nexl is the routine used for enlargemenl or magn ification of the screen
image:
'li
CALL
Di_ alogBox( '1 P~oportiorl a l ' · , O , T r ue , x l a %, yla% , x 2a% , y2a%,False}~
CALL D j.al c g B ox( I' Dj 5 t o~ t, " , 2 / False r xlb %,y l b% , x2b% , y2 b % , Fa lS8 )~
CALL GO Dia log (n% , O, xla% , yl a% , x2a%, y 2a% , x l b% , ylb% ,x 2b%, y2b% ,-
1. I J J. , - 1) 11
· - 1 --
CL.s<n
127
3. TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
Pictureheight~RasterH%/Heighte% * FactorY~
Picturex~(RasterW2%-Sx%) /FOlctorXS
Picturey~(RasterH2%-Sy%)/FactorY ~
END IF~
Newone! True~
WaitFlg! ~ True~
GOSUB DrawNew~
RETURN~
MENU 5,O,Start%,"Draw u q[
MENU 5,l,Start%," Shadows FlO"'ll
MENU 5,2,Start%," InilLalizeltion F9 "'ll
MENU 5,3,0, 1I _____________________ 1I<JI
MENU 5,4, Start%," Wire model < >"'11
MENU 5,5, Start%, II Clear screen \.~ II err
'lI
GOSUB NOOP~
CALL Empty8uffers~
RETURN'll
128
ABACUS 3.3 TilE MAl:" PROGRAM
''l[
MessageEvent:'l[
Mri~le MENU (0) 'l[
MPo~nt = MENU (l) 'l[
<;T
IF MTitle = 1 THEN'l[
IF MPoint 1 THEN COSUS IC1fo"I
GOTO MessageEnde'l[
END IF'l[
'l[
IF MIitle 2 THEN'l[
IF MPoin~ ~ 1 THEN GOSUB Loader'l[
IF MPoint 2 THEN GOSUB Saver'l[
IF MPoint 3 THEN GOSUB Merger'l[
IF MPoint THEN GOSUB ArrayInit'l[
'Mpoint 5: "---------"<J[
IF MPoint ~ 6 THE:N GOS~B LoacL'12l'l[
I MPoint = 7 : "--------- "91
IF MPoint 8 THEN GOSUB Bdckgroundo/,
IF MPoint -= 9 THEN GCSUR ScreenSav(-~r91
IF MPoint = 10 THEN GOSUB llardCopyo/,
, MPoint = 11 : "~~-------"o/,
IF MPoint = 12 THEN GOSUE ColorPaletteo/,
, MPoint = 13 : "---------"S
IF MPoint 14 THEN GOSUB Quit'l[
GOTO MessageEndeo/,
END IFo/,
'l[
IF MTitle = 3 THENo/,
IF MPoint = 1 THEN GOSUB LoadEditoro/,
Goro MessageEndeo/,
END IFS
0/,
IF MTi tle THEN 0/,
IF MPoint - 1 THEN COSUS InpuLP'li
IF MPoint 2 THEN ~OSUIl InputH'l[
IF MPoint 3 THEN GOSUB InplltAngle'l[
IF MPoint 4 THEN GOSUB
~-
InputQP;:i!
I MPoint =5: n ___________ lIqr
IF MPoint = 6 THEN GOSUB Enlarqcment'l[
IF MPoint = 7 THEN GOS~B HowManyCorners'l[
GOTO MessageEnde'l[
END lEo/,
'l[
IF MIi tle 5 THEN'll
IF MPoint 1 THEN GOSUB Shadows'l[
IF MPoint 2 THEN GOSUB InitParameters'll
IF MPoint = 1 THEN GOSUB DrawNew'l[
IF MPO} nt ~ THEN GOSUB ClearScreen'l[
END IF'll
END IF'll
McssageEnde: 'll
RF,TURN'l[
''ll
When you select a menu item, all other menu items should be
deactivated, to avoid accidentally choosing another menu item at the
same time. The menu items are listed internally and deacitivated one
129
3. Tm: TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRA\IMI:,\C
after anothcr-no item is skipped. When we turn the menus off, the
program ignores any accidental menu item selections:
Delete:.1enu:<n
M!::N~: =., Or 0, "Amiqa"'fl
iVJ:~NLJ ?,O,J,"FiJcll'jf
MFNU J,C,O, ",,:ditor'''f:
MENU 4,OfO,lIP.J.:a~~erl!s.
t'J<:NC 5,0,0, "[)rdw'''j]
'\ETUFN~
''II
When we want to go back to the main loop where the meDII itcms
appear, we must reactivate the menus (call MakeMenu).
KcoyEvenL: 'II
Key$-fNKEYS<TI
rE·' KeyS <.> 1111 TllFN<JI
toeA 1'2 1, _: q[
'l:
IF Sta rt% 1 THF:N'II
T~~ KeyS THEN C;OSUB DrawNelo.'II
;[' Key S "d" THe,N GOSUB ; npu~ CPH'II
'l'Ci EN 'II
,~ K€y $ !It-" THEN [) ~
10 'i1
VC'y.s ~
" " 'rHEN D
~,
c-~O'II
-;~: 1ey$ T"E~ D ] C2qr
){,'y$ " /il rl-IE:,\' D c'~ l [) Ll'll
-- "0." '-;-'~P,r\
~~ .;l'T
[l" Kt-"'/$
IF K"y$ lib" THEN COSU}) Scn:~cr--:.3averSI
1F '<C'iS :;;- CHRS (137) THEN ~~CSt}T) ~_r,~_tPn.~'_'!lt:('l (-~r
~F
KeyS CHR.$ (138) THEN C;OG~B Shddo;,,;s'j
130
ABACUS 3.3 THE MAIN PROGRAM
131
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
132
ABACUS 3.3 TilE MAIN PROGRAM
SUB DoDialog(n%,Ret%,xla%,yla%,x2a%,y2a%,xlb%,ylb%,x2b%,
y2b%,xlc%,ylc%,x2c%,y2c%) STATIC~
I Dialog boxen read~
I n%: which gadget clicked ?~
I Ret%: which gadget specified by pressing <Return>?~
I xl.,yl.,x2.,y2. coordinates of the box~
CALL EmptyBuffers~
n% = -U
WHILE (n% = -l)~
IF MOUSE (0) <> 0 THEN~
x = MOUSE(l)'ll
y = MOUSE (2)'ll
'll
IF (xla%<x) AND (x2a%>x) AND (yla%<y) AND (y2a%>y) THEN n%
= O'll
IF (xlb%<x) AND (x2b%>x) AND (ylb%<y) AND (y2b%>y) THEN n%
= 1 'll
IF (xlc%<x) AND (x2c%>x) AND (ylc%<y) AND (y2c%>y) THEN n%
= 2'll
END IF'll
IF INKEY$ CHRS(13) THEN n% Ret%'ll
WEND'll
END SUB'll
''ll
The text is centered on the screen. This is especially useful for the
information lines that appear inside requesters.
The Box routine draws a box around requesters, while the RubberBox
routine keeps mouse movement within this requester:
SUB Box(RastPort&,xl%,yl%,x2%,y2%) STATIC'll
I rectangle in Display-Screen'll
I RastPort&: draw in which RastPort 'll
I xl,yl,x2,y2 coordinaten of the rectangle'll
CALL Move&(RastPort&,xl%,yl%)'ll
CALL Draw&(RastPort&,x2%,yl%)'ll
CALL Draw&(RastPort&,x2%,y2%)'ll
133
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
CALL Draw&(RastPort&,xl%,y2%)~
CALL Draw&{RastPort&,xl%,yl%+l)~
END SUB~
'~
SUB Rubberbox( x%, y%, w%, h%, Back!) STATIC~
SHARED RasterWl%,RasterHl%,WScreen&,NRastPort&,RastPort&,
NWScreen&,NWBase&,h~ase&,Length&,True,False~
, Make rectangle with mouse~
, x%,y%: upper left corner~
, w%,h%: Width, Height~
, Back!: Return touser window ?~
CALL Scrot1~
CALL SetDrMd&(RastPort&,2) 'COMPLEMENT ~
~
CALL SetAPen&(RastPort&,l)~
~
Repitition:~
Oldx% H
OldY% :'lI
Flag' O~
~
CALL EmptyBuffers~
~
mousel: ~
x% PEF.KW(WScreen&+18)~
y% = PEEKW(WScreen&+16)~
CALL Move&(RastPort&,x%,O)~
CALL Draw& (RastPort&,x%,Rasterfll%) ~
CALL Move&(RastPort&,O,y%)~
CALL Draw&(RastPort&,RasterWl%,y%)~
Oldx% x%~
OldY% y%~
END IF 'll
134
ABACUS 3.3 Tm: MAIN PROGRA:I1
CALL Empt.yBuLfers'!I
'll
a$ ;::; ""en
WHILE (MOUSE (0) 0) AND (a$ <> C~q$(13)) 'II
a.) = INKEY$'!I
WEND1f
Mx% PEEKW(WScreen&+18)'ll
My% PEE~l~ (WScreen&+ 16) '!I
'll
TryAgain ~" True'll
IF (Mx%>xIa%) AND (Mx%<x2a%) AND (My%>yIa%) AND (MY%<l2a%)
THEN TryAgain = False'll
IF a$ ~ CHR$(13) THEN TryAgain False'll 00
'II
CALL Pr:'ntIt ("Section Ok ?", :.30, True) '!I
CALL Dia]ogBox("OK",l,True,xla%,yla%,x2a%,y2a%,:rue)'!I
'lI
IF Tryl\gain = True THEN GOTO Repitition '!I
'II
wi - wl-x%'ll
h% hl-y% '!I
We have used our own Box routine instead of the LINE statement.
This allows us to display requesters in both the display screen and the
user screen. We can't use LINE in this ca,e because we are accessing
135
3. TilE TRACFR PROGRAM AMIGA 3D GRAPIliC PROGRAMMING
The Pause routine waits for the user to press either a mouse button or
a key.
We must make sure that the mouse and keyboard buffers are empty. So
all the keypresses before the check are ignored and it can react to the
new keypresses:
Pause: 'll
I Wait for (Mouse-I key press'
CALL EmplyBuffers I clear buffer q[
WHILE (INKEYS ~ ""I AND (MOUSE (01 oI'll
WEND'll
RETURN'
"!!
136
ABACUS 3.3 TilE MAIN PROGRAM
z = CSRLIN'll
CALL PutStri~g (s$,z,s,winlen)'l[
CJllL GetString
(s $, a$, "abcde fghi jk Imnopqrstuvwxyzdv I ABCDEFCHIJKLMNOPQRSTUVWXYZ
DV\1234567890.- :/",z,s,winlen)'l[
END SUB'll
''ll
These routines waits for the input of a real number, an integer value or
a character string. The input routines of the editor are used for this.
All disk operations can either use the current subdirectory or change to
a new one. The Directory routine makes this possible:
Directory:'lI
f Directo:y read, or change drive~
Statlls$ = " Status: Directory"+CllR$(O)'ll
CALL SetWindowTi tles& (Nv.13ase&, SADD (Slatus$) ,0) 'lI
'lI
GOSUB De~eteMenu'll
a$ = "Aclive Directory: n+ActClrive$'lI
CALL PrintTt(a$,50,False)'l[
CHDIR ActDrive$'lI
'lI
RepcatD:'lI
CALL DialogBox ("j'-i ~es", 0, Fa~se, xla%, yea%, x2a%, y2a %, False) 'l[
CALL QialogBox ("Lo",d", 1, True, xlb%, ylb%, x2b%, y2b%, False) 'lI
CALL Dia~ogRox("Chdir",2,False,xlc%,ylc%,x2c%,y2c%,False)'ll
CALL
DoDialog(~%, 1,xla%,y:",%,x2a%,y?a%,xlb%,ylb%,x?b%,y2b%,xlc%,ylc%,
x2c%,y2c%) 'lI
'l[
CLS'll
TF n% = 0 THEN'll
FILES'll
GOSUB Pause'll
C~Sqr
COTO r:epeiltD'll
END IF'll
IF n% = 2 THEN'll
as ~ "Active D; rectory: "+Ac~Drive$'ll
CALL Printlt (a.$, 'lO,False) 'll
'II
LOCATE 10, I'll
PRINT II New Directory: II;~
CALL FormInputString (ActDrive$,JO')'ll
CHIlI? ActDrive$'lI
'lI
CLS'lI
GOT a RepeatD'lI
END IF 'lI
CLS'lI
HETURN'll
137
3. TilE TR,\CfR PROGRAM
When you want to leave the progrmn, Qui t is calkd. This routine
asks you if you want to quit the program and gives you a chance to
respond. If you exit the program, it releases all the memory it has
occupied and closes all of the libraries and the newly opened display
screen:
CloseIt.:'i1
t Close a}} and Eree mernory~[
GOSUB ClosC'G7x<j!
WINDO\~CLOSE 2'1l
SCEEEN CLOSE I d',Jtomatic release c: allocated 6t~h bitmap<JI
, 'lI
138
AOACl,;S 3.3 TilE MAIN PROGRAM
RETURN'll
"1I
This routine allows you to restart the program instead of ending the
program.
The Scron and Scroff routines switch between the new display
screen and the user screen. To erase the display screen (e.g., before
redrawing a wire model) ScreenErase is called:
Clearscreen:'lI
StatusS = " Status: Clear" screen"+CHR$ (0) 'll
CALL SetWindowTitles&(NWBase&,SACD(Status$) ,OJ'll
'll
CALL SetRast&(RastPort&,O)'ll
Hg = True'll
'll
GOSUB NOOP'll
RETURN'll
'Sf
You have the option of calling the object editor with LoadEdi tor:
LoadEditor:'ll
Status$ = " Status: Editor 10ading"+CHRS (O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$) ,OJ'll
'lI
GOSUB DeleteMenu'll
139
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END'll
ErrorHandling: 'II
NumErr ~ ERR'll
'II
StatusS = " Status: Next Big Error!' '''+CHRS (0) 'll
CALL SetWindowTitles& (r--'WBase&, SADD (StatusS), 0) 'II
'II
GOSUB DeleteMenu'll
'll
DialogS = ""'ll
IF NumErr 64 TllEN I Bad File Mode'll
DialogS = "Bad file r",me !!! '''lJ
END IF'll
'II
IF NumErr 57 ,HEN I Device I/O Error'll
Dialog$ "Device I/O Error !!! HCft
END IF'll
'II
TF NumErr 68 THEN I Device unable'll
Dialog$ "Device not found"'ll
END IF'll
'II
IF NumErr 61 THEN I Di sk Full'll
DialogS "Diskette is full !!!" <]I
END IF'll
'II
IF NumErr 53 THEN , File not found'll
Dialog$ "Fi Ie not found'!! "'II
END IF'll
'II
IF NumErr - 10 TflEN , Permission denied'll
DialogS IIPermission denied! ! ! 11<JI
END IF'll
'II
IF Dialog$ - "" THEN'll
Dialoq$ = "Error Numb"r ="+STRS(NumErr)'11
END IF'll
'II
CAL!, Dialoqllox (Di al og S, 1, True, x1a %, y la %, x2a%, y 2a %, Fa 1 se) 'II
'II
CALL DoDialog(n%,1,-1,-1,-1,-1,x1a%,y1a%,x2a%,y2a%,-1,-1,-1 ,-
1)'11
'II
CLS'll
GOSUB MakeMenu'll
RESUME ok 'II
RETURN'iI
''II
140
ABACUS 3.3 THE MAIN PROGRAM
This explains all of the routines used in our tracer program. These
routines are completely listed in the appendices and are contained on the
optional disk in seven separate modules. This makes merging and
adapting them to your own programs much easier.
Note: If you type in these modules yourself, here arc a few ground rules
which you must follow to complete the tracer program:
Name the disk to which you are saving the files tracer: and
create a directory called modules.
save "tracer:modules/init.asc",a
Now that you've seen all of the routines used in the tracer, we must
combine the program modules (which arc saved as ASCII files) into
one program on disk.
clear ,140000
chdir "tracer:modules"
141
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Note: If you're using a backup copy of the optional disk, or you're using a
disk that you named yourself, rename your disk to t race r.
merge "Jnit.asc"
merge "Syster:l.asc"
merge "Wiremodel-draw.asc"
merqe "Wiremodel-Lnput.asc"
merge IIShadow-init.asc"
merge "ShadoVv'Lng.asc
ll
merge "Service.asc"
save "Lracer:tcacer"
You can save this program to the optional disk or to your own disk.
Note: Your own disk must have the name t racer for the tracer program to
work correctly.
The tracer program, the editor program, and the machine language
routine SetPoint.B must be available in the main directory of the
disk. The SetPoint.B routine is described in Appendix D, which
includes the source code and a BASIC loader.
You must ensure that the .bmap files are also on the disk, since the
program uses dos.bmap, exec.bmap, graphics.bmap, and
intuition.bmap libraries. These fiies are iocated in the libs
directory of the optional disk. If you're using your own disk, you may
have to create these libraries using the FDConvert program on your
Extras disk.
The easiest procedure is to copy the entire disk with the Diskcopy
command. After merging the individual modules you can erase these
from the modules directory to get more room on the disk. Do this
with the copy of the disk only, and not with the original disk! After
saving the complete t race r the entire program is on the disk. You're
ready to go into 3D mode.
142
4.
Using the Program
ABACLS 4. USING TilE PROGRAM
All input occurs in the windows. Input can be edited with the cursor
keys, <Delete> and <Backspace> keys when input mode is active inside
of the editor's main window. When input extends past the window, the
window scrolls to the left and the characters at the beginning of the line
scroll of[ the screen. The <Cursor left> and <Cursor right> keys let the
visible section be accessible. It is important to note that only certain
keys arc accepted for certain prompts:
e) single characters:
for visible input: y,n
for enlargement, rotation, movement: q,c,d
for the Show function: d,m,f
145
~. lJSl:'\G TilE PROGRAM
The last point is easy: All the predefined objects can be found under the
Body menu item. When you want to enter a certain object from this
list, you only need to choose it from the list. A new data set appears in
the editor window and the cursor moves to the firq position. The input
can then begin. The object data is checked to see if the given object
should be visible on the screen. and which material shou Id be assigned
to it. The materials can differ in color, shade intensity. and reflection
facto!", which are represented by numbers. The material belonging to
this number is entered with the material editor. which is described in
the next section. The following pictures show the simpler types of
objecL~ that can be entered.
146
ABACUS 4.1 EDITOR DOCUMENTATIOl"
Plane
M 0, 0, 10
A 10, 0, 0
B 0, 10, 0
Triangle
y
M 10, 10, o
A 10, 0, o
B 10, 10, o
x
Figure 4.1
147
4. Usr:"G TilE PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
y Parallelogram
M 10, 10, 0
A 10, 0, 0
B 10, 10, 0
Circle
y
M 10, 10, 0
A 10, 0, 0
B 0, 10, 0
Figure 4.2
148
ABACUS 4.1 EDITOR DOClJ:\tE~TATIO;-';
Circular segment
M 10, 10,
A
B
10, 0,
0, 10,
°°°
SW 90°
EW 180 0
y
Arc
M
A 1O,
1O,
0,
1O,
°0
B
SW
0, 1O,
90° °
EW 180 0
ri 0.6
ra 1
y
Figure 4.3
149
4. liSING TIlE PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Sphere
z M 10, 10, o
r 10
Cylinder
M 10, 10, 0
A 10, 0, 0
tz
I
B
C
0, 10,
v,
()
0
v, 10
()
Figure 4A
150
A B,\C(;S
Cylinder segment
M 1O, la, a sw () 0
A 10, 0, 0 ew 90'
0, 1O,
Z
B
C 0, 1 0, ° 0
Cone
M 10, 10,
1'. 1 0, 0, °
0
B 0, 10, 0
iz c 0, 10, (;
Spheroid
11la, 10, 0
Z A 10, 0, 0
D 0, 10, 0
C 0, 0, S
Figure ·LS
15 I
4. USING THE PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
The Ma t . edi tor item enters the material editor section of the
program (see Section 4.1.4 below for details). You have more control
over the speed of the graphics with the Lines item. This procedure
can test for the number of lines used in drawing a circle, and this value
must be between 1 and 50. The Show item displays a certain body,
either as data or in graphic form. Graphic display can appear either in
the middle of each window or in red. You must enter which mode and
which body are to be used. Pressing <d> displays the data; pressing
<c> displays the graphic body in red. When you enter <m>, the body
section moves to the center of the window in case you want to execute
Ref resh. The Qui t item lets you end the program.
When you have entered the entire object list, which contains the daw of
the picture to be calculated, you have to assign each object a matc:riai
number as well as the necessary coordinates. Each of these numbers
represents a specific material for which you have set a certain color,
shade intensity, and reflection factor. The material input is done in the
152
ABACUS 4.1 EDITOR DOCUMENTATION
The color can be adjusted with the first threc sliders, which stand for
red, green, and blue. Here you can judge the color in the rectangle that
is found in the upper right comer. You can specify the brightness of a
body with the shade intensity. A value near zero is a dark shade ancl a
value near 1 is a light shade. Which value should be inserted cannot be
determined because personal taste is important here. When you want a
high, hard contrast, the value must be set at 0.1. This has the
disadvantage that objects in the shadows arc barely visible. You can
experiment with this factor as well as the reflection factor.
Light that shines on the body should be reflectecl. When the body
appears dull, the reflection factor should be increased. When it is placed
at one, all of the light is reflected, and the body does not have its own
color any more. When you also want to enter a material, select the
Ma t e ria 1 item from the Mat. Editor menu, or just press the <m>
key. After that input can begin. When all values arc correctly entered,
click on the OK gadget. You can move in the material list as usual
using the Left and Right items. Should you want to crase a
material, select the Delete menu item. To correct a material, select
Correction. This reactivates the controller ancl the input of the
desired material appears as usual. When all of the materials arc entered,
select Qui t to return to the main program The material editor asks if
you really want to exit. Click on the Yes or No gadget.
There are more possibilties here to change the entered object d:lia. The
simplest example is editing data. Delete deletes the object data set,
while Copy copies the data. The following commands Iet you choose
the current parameters of a certain mode. This mode is tested by
pressing a key. When you press <q>, the program exits this section
without doing anything else. Pressing <d> exccutes the operation on
the current body, and <c> copies the body, then executes the
transformation on this copy. The transitions arc: rotation, enlargement,
and translation.
153
4. USIl\G THE PROGRAM AMIGA 3D GRAPHIC PROGRAMI\U\cG
The three angles of rotation must be given when the rotation is chosen.
The midpoint remains unchanged throughout this. The new midpoint of
the object must be entered with the translation, either through the
keyboard or the mouse. The enlargement is just as easy. Three
enlargement factors must be entered for the three main directions. The
body is extended the same distance in all directions if these values slay
the same. Otherwise the proportions of the body are distorted.
To save and reload the entered data of the object and the material list
four items exist in the Disk menu: Load list, Save list, Load
mat, and Save mat. When the user selects the Load list item
from the Disk menu, the program asks for the names of the file to be
read. The user just has to enter the filename in the string gadget and
press the <Return> key. The program automatically adds the file
extension . 1 i st.
Note: The program does not check to see if the given file is on the disk. If the
user enters a filename that the program cannot find, the program
displays an error message.
After the file loads correctly, the desired data set is found in memory
and lisL, the la5t body entered.
Load mat and Save mat handle the loading and saving of the
materials lists from and to disk.
154
ABACUS 4.2 TRACER DOCUMENTATION
You can edit and shade some objects if you have put all of the modules
together and c:onstructed a running program.
Editing and entering objects is made easier by the object editor. This
section is limited to the tracer program (the main program).
When you start the program and all the libraries open, you can specify
the resolution and the appearance of the display screen. The display
screen is the screen where the shaded picture and the wire model appear.
The user screen is the screen used by AmigaBASIC. This is where all
user input occurs.
The first screen that appears gives you the option of selecting
resolution. The <Cursor up> and <Cursor down> keys let you scroll
through the choices. You can view alternatives with <Cursor left> and
<Cursor right>. So, for example, in the first line you can establish the
display mode (normal, hold and modify, extra halfbrite), X resolution in
the second line (normal and HIRES), and Y resolution in the third line
(normal and interlace).
The last line in this screen specifics the number of bit planes. The
program confirms that HAM and extra halfbrite run with 6 bit planes in
the normal X resolution, and that the number of bit planes corresponds
to the amount of memory available.
Having established the display mode and the resolution, you can press
<Return> and go back to the main loop of the program. Not all of the
menu items can be used at the beginning of the program. For example,
it makes no sense to draw a wire model when there arc no objects in the
object memory. You can access all of the menu items when the first
object definition is loaded or merged.
ISS
4. USING THE PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
The File menu contains items for controlling printer and disk access.
Selecting the Load item lets you load object definitions into the
computer. The current disk directory can be displayed using requesters
before the object file is loaded. A requester displays three gadgets:
Files, Continue and Chdir.
When you want to select another subdirectory from which the ohject
[iie shouid be loaded, click on the Chdir gadget. Enter a new
subdirectory or a new disk name. When using the optional disk for this
book, click on the Chdir gadget. Move the cursor past the word
tracer:. Enterthe word objects and press <Return>.
Click the Continue gadget or press <Return> to tell the program that
you want to enter a filename for loading. Enter the filename without a
file extension ( . 1 i s t for object definition lists and . rna t for material
lists). and press <Return>. The program automatically appends the
. list file extension.
When the given file opens, the program asks how many objects should
be loaded from this file. You can enter the number of objects currently
in the file, a larger number or a smaller number. The default number is
the number of objects currently in the file. In other words, this number
is the number of elements in array K () actually containing objects.
You should provide a large enough number here in case you want to
load more objects later.
156
ABACUS 4.2 TRACER DOCUMENTATION
Then by selecting the Me rge item you can add more objects to the
ones that already exist. Here you should select the correct subdirectory
as with all disk operations.
After you open the file, you are asked how many objects should be
ioaded. Please note that if you want to load more objects than are found
in the object memory, memory fills up and the excess objects
disappear.
You can avoid this by creating a large enough object memory using the
New menu item. Objects are placed in the desired memory location.
Memory set with New should be loaded with Merge. The object
memory is reset when using Load.
You can also write objects from memory to disk. Only memory that
contains objects is written to disk. Unused object memory (array
elements of array K ( ) ) are not saved. If the user presses <Return>
without entering a filename, the disk operation aborts and the program
returns to the main loop.
You can load materials that you created with the editor into the
computer. You can also change the current subdirectory of the diskette.
You only need enter the name of the new material's file. These are used
instead of the default materials that are used for shadows. Do not
include the file extension (. rna t for material lists). The program
automatically appends the . rna t file extension to the file.
4.2.3.3 Background
157
4. USING TilE PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Now back to the background. When you decide on a paltern for the
background, you can choose from three alternatives:
Pattern Click on the Pattern gadget to fill the display screen with a fill
pattern. Enter the first number of the desired pattern, which must be
between 0 and 35. This gives you a set of 36 different fill patterns
(standard and extended). Then you need only select the foreground and
background pen colors. The display screen fills with the pattern in the
given color.
Sky Let's produce a starry sky. We won't go into forming individual stars
here because the alternatives are automatically shown from the
program.
After entering the star color and you enter the number of stars to be
drawn, this background appears on the screen.
Floating Here you can display the changes from one color to another. Simply
background specify the number of the color register between whose colors the color
path should be calculated.
For example, if you want the color bright green in color register 1 and
the color dark green in color register 3, you simply enter 1 and 3 for a
color cycle from light green to dark green.
Generally you should only create a background when you are sure that
the next step will be shadowing. For example, if you are not sure if the
position of an object is correct, you should try to determine this first.
Loading a similar IFF file can be an easy test.
You can save graphics in IFF format on disk for later recall. Besides
storing the picture, this lets you edit the picture later with a drawing
program. Select the Save Screen item from the menu and enter the
name of the file that should be written to disk.
You can also print your graphics on paper using the tracer program.
Ha rdcopy creates a hard copy on the printer selected from Preferences.
You will also need Preferences 1.3 if you want the picture printed
sideways or in gray scales.
158
~---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -.......
Select the Ha rdc 0PY item from the File menu. A requester asks
whether a printer is connected. Click on the Printer OK gadget if so.
Clicking the No Printer gadget returns you to the main menu.
Note: Selecting Color palette deletes the current graphic from the
display screen, replacing the graphic with the palette screen. Save
graphics often.
When you want to leave the program select the Program end item.
You will be asked if you really want to leave. Click on the Yes gadget
to leave the program. Click on the No gadget to return to the main
loop of the program.
By clicking on the New start gadget the entire program starts over as
if you had just begun working. This option deletes any work that was
in memory, so use with caution.
This item invokes the editor. Before the editor is called, confirm your
choice. You can save a picture that was not previously saved by
clicking on the Cancel gadget and saving the graphic.
159
4. USI:-;G THE PROGRAM AMIGA 3D GRAPIDC PROGRAMMING
This menu contains routines which change the parameters for the three
dimensional display.
You can reset the coordinates of the projection point with the
Projection point item. The Main point item lets you
control the coordinates of the main point. The rotation angle around the
coordinate axes can be changed in a, ~,X. The distance from the
projection to the main point can be reset from the Distance item.
Proportional Here you enter an enlargement factor. The picture is then enlarged in
the X and Y directions by the same measurements.
Distorted A section of the screen must be selected with the mouse for a distorted
enlargement. Press the left mouse button so the pointer position
detennines the upper left comer of the rectangle. Move the mouse while
holding down the button and you can see how the mouse movement
reduces and enlarges the rubberbanded rectangle.
When you have set the correct rectangle, release the left mouse button.
You are then asked \vhether t..l-te chosen section is OK. Click on t'1e OK
gadget if it is. If you would prefer to enlarge another section, click
anywhere outside of the OK gadget.
When the section is OK, the contents of the specified rectangle are
enlarged.
160
ABACUS 4.2 TRACER DOCUMENTATION
This menu lists items for controlling the shadowing as well as drawing
wire models.
4.2.6.1 Shadows
You must first determine the parameters used by the shadowing process
first (Shadow window, etc.).
You can decide the end first and then the start positions of the stripe.
The sequence is the same. The program ensures that the sizes of the Y
coordinate of the end and the smaller Y coordinate of the start position
are correct
We now come to more parameters for the shading. You must enter the
coordinates of the light source. Simply enter the X, Y, and Z
coordinates of the light source in Qx, Qy, and Qz. Be aware that the
light source rotates around the coordinate axes.
You can also set the color of the light source. Enter the red, blue, and
green components of the light source in values between 0 and 1. Three
ones give a white light source.
For values between 0 and 1, be sure that you include a zero preceding
the decimal point. For example, the program accepts the notation 0.5
in these cases, but will ignore an input of .5-remember the zero
before the decimal point.
161
4. USING THE PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Choosing a pixel width and pixel height larger than 1 makes every
second, third, fourth, etc., point available for color calculation. Thc
picture is also shaded in a point width * point height grid.
The midpoint of such a grid rectangle is the color of the entire
rectangle.
After all of these parameters are entered, you can then choose the
Shadows menu item to start the shadow calculation process.
You can control the default values for shading by changing the values
in the program. The picture on the cover of this book was produced by
shading the entire screen with the light source is set at the coordinate
(0,0,50) with the color (1,1,1,) = white. Pixel width and Pixel
height are both 1. The projection point was 270,10,255 and the
main point was 0,0,25. The object and material were loaded from the
optional disk from the Spheres .list and Spheres. mat files.
The enlargcment factor was 4.
You shouldn't try to use the keyboard during shading. When you press
any key during the shading operation, after the current line is shaded,
the program asks if the shading should be continued or stopped.
You can, for example, let the computer shade overnight and save the
picture in the morning. Naturaily you could object that the Amiga is a
multitasking machine. Therefore AmigaBASIC could be started from
the CLI to allow other work in the AmigaDOS window. This is not
recommended since too many interruptions of the shading task can
cause a Guru Meditation.
When you select the Wire Model item, the wire model of the object
is redrawn on the display screen, or if it has already been drawn, the
display screen is rcdisplayed.
162
ABACUS 4.2 TRACER DOCUMENTATION
After choosing a background for the display screen the new drawing is
not erased. The wire model is drawn over the background. When the
wire model finishes drawing, the screen flashes briefly. The wire model
stays on the screen until you press a key. Then the program returns to
the main loop.
The menu items that can be addressed from the keyboard show the key
to the right of the item name. There are also functions that can be
called using the keyboard instead of the menu.
You know, for example, that the rotation angle can be increased and
decreased using the cursor keys, the <R> key and <Ctrl><R>. The
distance to the projection surface (DPH) can be changed using + - * /.
That's it for keyboard and menu control of the program. Going deeper
into this subject is unnecessary, because you can only be a tracer expert
through practice.
163
5.
Program
Enhancements
ABACUS ~ PROGRAM ENHANCEMENTS
5. Program Enhancements
The algorithms and routines in this book are not as complete as they
could be. Improvements of all kinds could be made here and there
throughout the program. We'll look in this chapter at some of the
improvements that can be made to the programs you've read about so
far. Perhaps you've already thought of your own enhancements to the
tracer and editor programs, or perhaps this chapter will help you think
of some improvements.
Extended Let's start with the basic objects. We can give the objects more
objects restrictions than already exist in the tracer and editor. For example, with
a little reprogramming we could add cone segments, truncated cones,
ellipsoid segments, etc., to our list of basic objects. Because these
restrictions are not that different from the complete objects, they can be
created from the existing subroutines and added to the editor's menu set
as needed.
It's even possible to create new basic objects which have little basis in
the original object routines. For example, imagine what might happen
if you change the restrictions of an ellipsoid to u" lO+v" lO+w" 10= l.
What would you get? A cube with rounded corners? Change the
restrictions of the other basic objects, perhaps by calculating a cube
instead of a square, or something similar.
Triangles and Another option for creating new forms consists of assembling multiple
extended triangles. You can make almost any figure if you have enough triangles
objects available for creating it. Unfortunately, it's rather time consuming to
enter each individual triangle.
B-splines Try both methods of creating a surface that has separate passages, but
no corners or edges. This is done with B-splines that run through the
points of the surface. The problem with this is that a surface must be
divided into many triangles so that they function very smoothly.
The big advantage to B-splines lies in that you can get wonderful
shapes with little programming hassle. You can define a wine glass for
the computer to calculate with a few dozen points. By using Bezier or
B-splines a few thousand triangles are created which then create a nearly
perfect illusion.
Smooth In addition to Bezier or B-spline, you can use smooth shading. Smooth
shading shading erases the edges from surfaces by calculating the normal vectors
of the two surfaces in such a way that they are continually changing.
You must define which surface is being pushed against for each edge of
the surface you are working with.
167
5. PROGRAM ENHANCEMENTS AMIGA 3D GRAPHIC PROGRAMMING
The calculation of these surfaces is fairly easy. You must find the
normal vectors of the other surfaces and join them together
independently of the distance of the intersection point from the shifted
edge. When the intersection point is very far from the shifted edge, take
the original normal vector, which is directly on the intersection point,
and add the normal vectors of both surfaces in the ratio of 50 to 50.
You don't need to work out as many triangles with smooth shading
because the borders are smooth. The program coding involved requires
more memory, and the computation time increases as well. The
disadvantage of smooth shading is that only the normal vectors are
smoothed. The outline of the surface remains unchanged. If you change
the surface of a cube into that of a circle, the border will keep the
appearance of a cube.
As Y0U see, the basic objects have room for improvement. You can
have more options for creating shapes by changing the surface structure
of the objects.
Until now all of the objects have been the same in that they were
smooth. We can define different material constants which affect only
the color and reflection coefficient of the surface. Wouldn't it be nice if
we could define any relief for a surface? Calculation solves this
problem. In relationship to a function, which tests for the method of
the relief, the normal vectors are bent. This happens in relationship to
the position and is repeated periodically, and produces a very ordinary
relief. A small disadvantage of the relief is that it is only related to the
normal vectors; the surface itself remains smooth. You should always
use small reliefs because they do not draw attention to themselves.
168
ABACUS 5. PROGRAM ENHANCEMENTS
1: Chessboard
2: Dotted
3: Lined
4: ...
IFF So far we've learned how to project a graphic on a surface and how to
improve the data structure. Now we must build the ability to load an
IFF graphic into the program. We must specify where the graphic
should be on the surface and if it should lie next to it, like our pattern.
Instead of the color that is defined in the Ma t array for the surface, we
take the color that is used in the graphic. The X and Y coordinates of
the graphic are calculated in the approved method from the
parameters/polar coordinates. The other material attributes, like
reflection, etc., can stay the same. Put a bottle, which was defined with
Bezier, smoothed with smooth shading, and distorted with some good
taste, into a BASIC program. We are operating our Amiga to the limits
of its capabilities, both in computing time and in resolution and color.
Transparency Now we want to turn to other things to make our graphic more
realistic, such as transparency. We have already described how to
simulate transparency. It's not enough to construct a
CalculatePoint call in the respective subroutine. We must also
consider that a transparent object allows light to pass through, so there
is light beneath the object instead of a shadow, but light whose color is
not quite the same as the original color.
We can build transparency for the place we have already prepared in our
material data structure. We have constructed another call for this routine
in Cal c u 1 ate Poi nt, before the recursive call from
CalculatePoint for the reflection. The direction vector of the
visual ray (rx, ry, rz) is unchanged. We must be careful that all
variables that are needed for the Cal c u 1 ate Poi n t call are not
changed. The object is searched first, the shadows thrown from the
point in question, and the light source is next. Then the color of the
light rays change according to the material structure of the object. After
169
5. PROGRAM ENHANCEMENTS AMIGA 3D GRAPHIC PROGRAMMING
that the object must be searched, then the light source, and so on, until
all of the objects that throw shadows on the point in question are
known. The calculation of Bright. r, Bright. g, and Bright. b
for the color must be considered. The consideration of the color of the
light source must then be preferred and may not be executed twice in
the case of shadows.
Maybe you like more optimizations, if only for more light sources. Or
you have an idea for more shapes. This chapter only shows a starting
point, which should give you an idea of the possibilities that arc
possible in ray tracing. These possibilities are left up to you to use and
find. Computer graphics are a fascinating subject; make the best of it.
170
6.
3D Tricks and Tips
ABACUS 6. 3D TRICKS AND TIPS
Graphic First the design. One of the most difficult problems is thinking about
planning the scenery that the computer should calculate. At first, try it with just
a few simple objects. Too many objects clutter the picture and confuse
the viewer. Don't go into too much detail-limit yourself to the
important items. This book lists some examples. Or load some objects
from the optional disk if you don't want to type them in yourself.
When you have some idea of the body you want drawn, sit down and
sketch it out on graph paper. Graph paper allows for easier
measurement. Draw three views of your object, the way the editor will
draw the object. You should also layout the material constants for each
object material and include these in the working sketch, where each
material is assigned a number.
Handy tools One of the best items you can have available for keeping track of your
3D parameters is a small notebook and pencil. Keep these next to the
computer when using the tracer program. Write down original
coordinates of graphics, experimental coordinates. colors, etc. (you may
also want to write down whether these experiments worked or not),
Colors When choosing color, try to keep the graphic from appearing too bold
or too dull. Select colors that complement each other well, instead of
using every color available. Assign these colors to individual objects
where they will look best.
Shading and The shade brightness should be set at roughly the same value for all
reflection objects (0 to 0.25). The reflection value can be somewhat higher. Add
reflective properties to single objects, instead of the entire scene. Have
the appearances of the objects set in your mind to help add these
properties to the actual graphic.
When the mental picture meets your satisfaction, start the editor and
enter the individual objects. Later, when you have given more thought
to the scene, you can divide it up into sections and enter the data
directly into the editor.
173
6. 3D TRICKS AND TIPS AMIGA 3D GRAPHIC PROGRAMMING
Keeping it To keep your graphic from becoming too complicated, you should set
simple visible to y (yes) for all objects in the editor, so you can see
exactly what you have entered. After entering each object and editing it
to your satisfaction, save the object. Load the materials editor and add
the material constants. Save the entire collection of data, then start the
tracer.
Resolution Now you must decide in which resolution you want the picture
calculated. The HAM mode offers the most colors, but a HAM screen
consumes quite a bit of memory. When you have enough memory, you
can choose a HAM screen at the start because the color palette doesn't
need to be selected so carefully.
Point of view After you have loaded your objects and materials, you must consider at
which angle the scene should be observed. Examine your sketch and
consider the point of view from which you want to the scene to appear.
Experiment with changing the main point first (the default when
loading objects for the first time is usually 0,0,0). Try some negative
and positive settings.
Next experiment with your distance between the projection point and
the main point (DPH-see Section 2.4). Be careful not to make this
figure LOO small, since this can greatly distort perspective of the
graphic.
Projection Now enter your projection point. Enter the coordinates (-1000,-
point 1000,1000) if you have no other position specifically in mind. Press
<Space> to see the wire model. It is probably relatively small on the
screen. Press <v> to enlarge the picture and select either the
Proportional Of Distort gadget. The object should almost fill the
screen, without going past the edges. When you define reflecting
objects, select a larger section so the reflections appear on the screen.
Experiment with each point until the display pleases you. Write down
all of the values that you have entered, including the main point,
enlargement factor, and either the projection point or angle and distance.
This will help if you want to reproduce these conditions later.
Light source Now specify the position of the light source. A recommended value is a
position "to one side" of the observer, so the shadows are most distinct.
Try the projection point at (-lOOO,-1000,1O00), and the light source at
(-1000,1000,1000) if you want the shadows to fall to the right. If you
want short shadows, increase the Z coordinate of the light source's
position. Decrease the Z value for longer shadows.
Write down the position of the light source in the notebook. Press
<F9> to initialize shadowing parameters. Select the entire screen or a
section, and enter the position of the light source. Enter (1,1,1) for the
light source color, which provides a white light.
174
ABACUS 6. 3D TRICKS AND TIPS
Big pixels for For the pixel height and width, enter 16 and 10 (1/20 of the screen
draft height and width). This computes the shadowing in a blurred fonn.
calculation These pudgy pixels are enough for a draft display, since calculation
time is 1/400 the time normally needed.
Press <FlO> to calculate the picture. Clock the time between the
setting of the first and last pixels. After the picture is complete, you
can approximate the amount of time the computer needs to calculate the
picture with normal single pixels. Use the following equation:
If you're nearsighted, take your glasses off and back away from the
screen until the draft graphic looks close to a normal close-up view
(people with normal vision can just back away). This gives you an idea
of what the finished product will look like.
Colors Now you can see if the colors came out as you had thought. It is very
important that you :et the color palette at the optimal setting, even for
HAM pictures. Set the color palette so that many different shades of
brightness are available for each color. The more colors you have to
use, the more degrees of brightness you can set.
Set the color palette for HAM mode so each sudden transition from one
color to another requires no more than two colors in the palette.
Transitions from black to red, black to green, or black to blue are no
problem, while a transition from black to gray cannot be done directly
because this gray tone is not in the palette.
Once you have set the colors properly, the picture can be calculated. If
you select a smaller pixel size (e.g., height and width of 2), you can
recognize more features. When you arc satisfied with the result, you can
consider whether you want to stay with this display mode, or change
modes. If you want to change, you should write down the color palette
configuration for later reference.
Before you calculate the picture in nonnal pixel size, you should figure
out how long the computer will take to compute the graphic (see
calculation described above). It's not a bad idea to plan to let the Amiga
calculate overnight.
175
7.
Mathematical
Basics
ABACUS 7. MATHI:MATICAL BASICS
7. Mathematical Basics
Some people suffer from math anxiety. This book: was designed for the
non-math person in mind, but ... c should list a few of the equations
involved. We would like to show you some of the basics of three
dimensional math in this chapter.
7.1 Vectors
Figure 7.1
ill geometry there arc two ways to differentiate vectors:
179
7. MATHEMATICAL BASICS AMIGA 3D GRAPHIC PROGRAMMING
Direc ion
Figure 7.2 vecto
-I
Figure 7.3
180
ABACUS 7.1 VECTORS
y
Figure 7.4 +
You can add or subtract the vector components (vectors have X,Y,Z
components; points have X,Y:Z coordinates):
(ax) (ox) (ax±ox)
a±6 (ay) ± (oy) (ay±oy) Q
(az) (oz) (az±oz)
ax (t*ax)
t * a t * ay (t*ay) Q
az (t*az)
ax (t *ax)
t * 1l - t • ay - (t*ay) - 0
az (t*az)
A
l*a
·;I ............ ""X-----------1.. ........... jf........................111.
~
Figure 7.5
181
7. MATHEMATICAL BASICS AMIGA 3D GRAPHIC PIWGRAMMING
You can describe all sorts of three dimensional bodies and surfaces with
vectors; these are the connection between math and geometry-and
computer graphics.
Lines are also represented by using veclOrs. You take a position vector
that fixes a point Oft a line, and a direction vector that lies on a position
veclOr. The following equation can describe a line:
X ox rx
y oy + 1 * ry
Z OZ rz
Direction vector
POSiti~
~
Figure 7.6
x
TIle direction vector extends like a telescope arm to the length stated in
1 and encompasses all of the points of the line.
Planes Planes are presented in a similar way. Two linearly independent vectors
are needed here. Linearly independent means that one vec~or is not a
factor of the other. The plane equation looks like this:
x ox rlx r2x
y oy + a*rly + b* r2y
z oz rlz r2z
Spheres The equation used to prepare spheres may be a little more intimidating.
The equation itself appears below:
(x Mx) ~2
(y - My) ~2
(z Mz)~2
182
ABACUS 7.2 USING VECTORS
Figure 7.7
y
..
In the sphere equation notice that a point on the surface of the sphere is
created from other vectors, instead of being based directly on the point
of origin of the sphere. And the vector squaring is new. The difference
of these two vectors (point on the sphere-midpoint) is the radius, in
which case the point lies on the surface of the sphere.
When this number is equal to the square of the radius, you know:
x
The point (position vector) y lies on the sphere
Z
This is also true for the basic objects and surfaces that can be created
with vectors.
183
,
7. MATHEMATICAL BASICS AMIGA 3D GRAPHIC PROGRAMMING
You can also test for the angle enclosed by two vectors. Let's move
outside of the space in the plane and look at two perpendicular vectors:
Figure 7.8 x
ax = -o'y ay = o'x
Because 6' is a factor of vector 0, you can write k * 6 for <5 ':
ax = -k*oy ay = k*ox
ax*ox+ay*oy = 0
This is also a form of the scalar product placed between two vectors.
184
ABACUS 7.3 ANGLES BETWEEN Two VECTORS
Oy
Figure 7.9
A
ax
A
Ox x
Now look at the equation for this (note: the a character represents the
Greek letter alpha; the ~ character represents the Greek letter beta):
The expression with the many sine and cosine functions can be simpli-
fied by using the addition theorem of cosines:
(Cos (~-a) = Cos (Ct.) *Cos (~) +Sin (Ct.) *Sin (~))
ax*ox+ay*oy
Cos(~-a)
Ia 1 * 16 i
185
7. MATHEMATICAL BASICS AMIGA 3D GRAPIDC PROGRAMMING
y2
y2-yl dy
yl
x
Figure 7.10 xl x2
x2-xl ~ dx
Insert the value of the vector in the formula for the cosine and examine
the two vectors in the space, and you get two vectors for the formula of
the cosine of the enclosed angle:
ax*ox+ay*oy+az*oz
186
ABACUS 7.4 INTERSECTING LINES AND PLANES
Now we'll examine the intersection points of lines and planes, and
lines and spheres. These intersection points are especially important in
shading three dimensional bodies. You must test for the point of a
surface on which a visual ray (light), represented by a line, falls.
We use a line equation for the visual ray, as well as a body equation for
the body.
For the sphere you need to insert the line equation for the point on the
surface of the sphere and view the individual components to understand
the intersection point:
(ox rx Mx)2
(oy + l*ry +My)2
(oz rz Mz) 2
(l*rx + (ox+Mx))2 = r2
The 1, for which the line and the sphere have an intersection point, can
be tested with the help of the binomial formula and by solving the
quadratic equation. The 1 is the telescope Jactor with which the
direction vector of the line must be multiplied to meet on the sphere
surface. When the quadratic equation is unsolvable, no intersection
point exists.
ox rx ax rlx r2x
oy + l*ry ay + a*rly + b*r2y
oz rz az rlz r2z
Then you must create the equation for each component and ensure that
all variable elements are on the left side of the equation, and constants
are on the right side:
187
7. MATHEMATICAL BASICS AMIGA 3D GRAPHIC PROGRAMMING
Now we have an equation system with three variables (1, a and b) and
three equations. This 3x3 equation system can be solved using a deter-
minant.
You must build a matrix from the equations. Take all of the coeffi-
cients of the variables and wri te these in a matrix:
rx -rlx -r2x ax-ox
ry -rly -r2y ay-oy
rz -rlz -r2z dZ-OZ
The coefficients for the same variable must be beneath each other. The
matrix also has the following form, where a stands for the coefficients
and b stands for the constants:
all a12 a13 bl
a21 a22 a23 b2
a31 a32 a33 b3
I all bl a131
02 det A2 I a2l b2 a231
la3l b3 a331
188
ABACUS 7.4 INTERSECTING LINES AND PLANES
a=D2/D
b=D3/D
189
8.
The Optional Disk
ABAClJS 8. THE OPTIONAL DISK
You can see the sample graphics by booting the optional disk. Turn off
your Amiga and eject any disks in the drives. Turn on your Amiga.
When the Workbench disk hand icon appears, place the optional disk in
drive dID:. A graphic appears on the screen. To end a graphic display
click on the upper left comer of the screen. The next graphic then
appears. Click the upper left corner to end the display and get to the
eLI prompt (1)).
Now we come to the last directory on the disk. Many object definitions
are found in the Objects directory. The results of three of these
objects are found in the screens directory. The picture On the cover
of this book was generated using the tracer program and the
S phe re s . 1 is t and Sphe re s . ma t files. The point of projection
was 270,10,25, the main point was 0,0,10 and the enlargement value
was 4. Shadow initilization was ALL, light source was 0,0,50, light
colour was 1,1,1 amd pixel width and height was 1,l. The picture took
about two weeks to generate completely on the uncompiled tracer.
The optional disk also contains compiled versions of the editor and
tracer programs, named edi tor. run and trace r. run. They were
193
8. THE OPTIONAL DISK AMIGA 3D GRAPHIC PROGRAMMING
The fun of ray tracing wears thin very quickly once you find how much
time the calculations require. The computations become even slower
when the ray tracing program is written in a slow language. We decided
to compile our programs to get the most speed out of them.
Please remember that the optional disk for this book already contains
compiled versions of the editor and tracer. Do not try to compile these
two pre-compiled programs. However, it may be worthwhile for you to
try compiling the uncompiled versions of the programs after you read
through this chapter.
Note: Never use an original disk for compiling. Always use a copy!
CLEAR ,140000
LOAD "Editor.bas"
194
ABACUS 8.1 CO~IPILING THE PROGRAMS
Once the editor finishes loading, save it as an ASCII file using the
following:
SAVE "Editor.cmp",a
The " , a suffix saves the program in ASCII format. The compiler can
only handle ASCII files-it can't compile straight AmigaBASIC
programs. The . cmp extension saves the ASCII file without
overwriting the original BASIC program. Quit AmigaBASIC.
Now load the editor source text into an editor (e.g., ED). You must do
some adapting of commands, since the compiler cannot handle a few of
the commands which appear in the source text. You could have made
these changes using the AmigaBASIC editor, but since it has no search
and replace facility, it will L:'lke longer. We recommend that you use a
text editor or word processor.
That's almost all you have to do to the source. Now for exiting the
program. The compiler will not accept the qui t variable. You could
press <Ctri><C> to exit, but that isn't very elegant. Look at the menu
reading routine toward the beginning of the program for our key line:
IF chose~l: THEN
CALL finish(quit)
END IF
GOTO E:nde
Save the editor code and exit your text editor. Copy your editor source
code to the RAM disk.
Make a backup copy of your AC/BASIC compiler disk. Discard all the
unnecessary files from this backup to make room (e.g., drawers named
Chapter, bspread and examples). All you should be able to sec
in this backup disk's window are the files ac-basic and sortsubs.
Copy your editor source text from the RAM disk to the backup
compiler disk.
195
8. THE OPTIONAL DISK AMIGA 3D GRAPHIC PROGRAMMING
Once sort subs ends, double-click the compiler icon. Select the
following compiler options:
N: This ensures that the editor uses ON MENU GOSUB and ON MOUSE
GOSUB
Be sure enough memory exists on the disk (the cditor requires 120K).
Delete some graphics from the screens directory. The compiler
overwrites any existing compiled versions of the program, so make
sure you didn't have a copy of the original compiled version on the disk
you're using for compiling. Start the compiler and wait a few minutes.
If no errors occur, you're over the first hurdle. Rename the finished
editor editor. run.
We'll now walk you through the steps of compiling the tracer using the
AC/BASIC Compiler. First make a backup of the disk containing the
tracer modules (you may want to add AmigaBASIC to this disk
temporarily). Name this backup disk tracer using the Workbench
menu's Rename item.
elear,140000
ehdir "modules"
merge "Init.asc"
merge "System.ase"
merge "Wiremodel-draw.ase"
merge "Wiremodel-input.ase"
merge "Shadow-init.ase"
merge "Shadowing.ase"
196
ABACUS 8.1 COMPILING THE PROGRAMS
merge ffService.asc"
Save the merged program to the main directory (NOT to the modules
directory) using the command:
save "tracer:tracer.cmp",a
Notice the addition of the . cmp extension. This keeps you from
accidentally overwriting the original code. Exit AmigaBASIC and start
the C L I. Delete the modules from the backup disk's mo d u 1 e s
directory, and the backup's modules directory itself. Load the tracer
source code into a text editor or word processor which has text search
capabilities, since we have to change a few things in the code to get the
tracer to compile properly.
Note: Some of the following changes require deleting lines of source code.
We found that pressing the apostrophe «'» key to make lines into
remarks is faster than deleting a line of text. So we recommend using
the <'> key to mark the unnecessary lines as remarks.
CHAIN "tracer:editor.run"
Next find the three occurrences of the RUN command and replace each
occurrence with the following two lines:
CLEAR
GOTO StartUp
Bypassing You'll need to make lines in some of the source text's routines inactive.
routines You have two ways of doing this: Either by making the problem lines
comments by starting them with apostrophes, or by deleting the lines
altogether. Search for the SetPoint SUB program, which isn't needed
by the compiled program. It looks like this:
SUB SetPoint(xl%,y:%,x2%,y2%,Bright.r,Bright.g,Bright.b) STATIC
SHARED MaxColour%, Colour (), RastorHl %, Raste rWl %, RastPort&
SHARED Numbe rPatternX%, PatternX&, Pat ternHX ()
IF x2%>RasterWl% THEN x2%~RasterWl%
' ... more oode follows ...
197
8. THE OPTIONAL DISK AMIGA 3D GRAPIIIC PROGRAMMING
Use your text editor's search function to find the label, then either delete
the text between the label and RETURN or END SUB, or add an
apostrophe to the beginning of each line after the label and before the
RETURN or END SUB:
Hardcopy
initPattprnS
InitPatternX
Standard,,'j 11
t:xtended,,' 111
Note: Users compiling with AC/BASIC Version 1.2 should remove the
Screen Loader subroutine as well as the routines listed above.
The program will now access the subroutine or SUB program label,
ignore the deleted/commented text and return to the main program.
Some of these routines can be replaced by others. For example, if you
want to print a graphic, use a separate program available for printing
IFF files. The Ini tPat ternS, Ini tPa t ternX, ExtendedFill
and StandardFill only come into play with patterned
backgrounds. The speed increase from the compiled program is well
worth the loss of a patterned background.
You will also need to change the Background routine, since the
compiled version of the program deletes any background you might
generate. Find the label-the code looks something like this:
Background:
, Backgro~~d Determine
more code tetween here and RETURN ...
RETURN
198
ABACUS 8.1 COMPILING THE PROGRAMS
Comment out (or delete) the rest of the lines up to the RETURN. Add
the two lines stated below so the routine looks something like this:
Background:
PRINT "Not implemented in compiled version"
fOR X=l to 3000: NEXT X
CLS
, Background Determine
more code between here and RETURN ...
RETURN
About The compiled tracer may not add any background to any objects you
backgrounds create and calculate. The ray tracing calculates properly (i.e., shading
and colors), but without any background, the "leftovers" of the wire
model may jut out from the edges of the finished graphic. You have a
number of options for curing this problem:
Save the graphic as an IFF file and load it into a program that
will handle the number of bitplanes you used in computing the
graphic. Then edit out the jagged edges left from the wire model.
For Version 1.2 of the AC/BASIC compiler need the following changes. A
AC/BASIC bug occurs because of the Intuition function called TextLength,
1.2 users which crashes the 1.2-compiled version from time to time. Replace this
TextLength function with the following if you are using
AC/BASIC 1.2:
PEEKW(rp&+60)*LEN(.S)
Now we come to the most irritating error within AC/BASIC 1.2. The
WINDOW n commands in Scron and Scroff don't work properly,
and cause a Guru Meditation number 81000008. Search for the Scron
and Scroff SUB programs. Delete liHNDOliJ n from these routines.
One last problem with the 1.2 compiler. The program occasionally
crashes when you exit it. Check the RAM disk for any data. This
concludes the changes for AC/BASIC 1.2 users.
For all users Save the tracer to the RAM disk and exit the editor to the Workbench.
Make a backup copy of your AC/BASIC compiler disk. Discard all the
unnecessary files from this backup to make room (e.g., drawers named
Chapter, bspread and examples). All you should be able to see
199
8. THE OPTIONAL DISK AMIGA 3D GRAPHIC PROGRAMMING
in this backup disk's window are the files ac-basic and sortsubs.
Copy your tracer source text from the RAM disk to the backup
compiler disk. Make sure this disk has at least 230K available (click on
the disk icon and select the Info item from the Workbench menu).
T: Keep temporary files on the RAM disk (you can do this only if you
have enough RAM-approximately 1 megabyte)
The tracer requires at least 50K of extra RAM to compile. Set your
WORK AREA slider gadget (we chose 54K).
Click the Compile gadget. You shouldn't get any error messages.
Exit the compiler and rename the compiled tracer tracer. run. Copy
the compiled tracer to your copy of the optional disk.
The compiler manual offers some tips for speeding up your programs.
For example, if you avoid ON ... GOSUBs at all costs, this will speed
things up considerably. Menu reading should be rewritten and ON
ERRORS avoided. Furthennore, if you define all arrays as STATIC, this
increases array access by a factor of 6. To do this, you must determine
the sizes of all arrays, and not change them in the program. Also, all
arrays must be defined in the main program. If you want to use this,
you must delete all ERASE commands and put all array definitions in
the program. For example, set a maximum size of 250 for K () (which
is enough for all demo objects) and 50 for Ma t ( ) . Define all other
arrays according to definition using numbers, or else the compiler will
display errors. If you convert the tracer to use S TA TIC arrays, select
the U option in the compiler. These methods can increase speed up to
70%.
200
Appendices
ABACUS ApPENDIX A - MODULES OF TilE TRACER
DECLARE FUNCTIONs
InitMat
InitPatternS
InitPatternX
InitSetPoint
Rasterlnit
CloseIt
PrintIt
EmptyBuffers
Pause
Box
DialogBox
DODialog
Rubberbox
NOOP
MakeMenu
DeleteMenu
MessageEvent
KeyEvent
ColorPalette
ErrorHandling
Quit
Scron
Scroff
GetString
GetReal
GetInit
Get Key
SetCursor see Editor
Put String
PutReal
conrealstr
constrreal
FormInput
FormInputInit
FormInputString
Directory
203
ApPENDIX A - MODULES OF THE TRACER AMIGA 3D GRAPHIC PROGRAMMING
Projection
DrawPlane
DrawTriangle
DrawRectangle
DrawCircle
DrawCircleSector
DrawCircleRing
DrawSphere
DrawCylinder
DrawCylinderSegm
DrawCone
DrawEllipsoid
DrawAll
DrawNew
HowManyCorners
Enlargment
Initial
InitialP
InputP
InputH
InputDPH
InputAngle
InitParameters
Tranform
InitShadow
TransforrnMM
MinMaxtest
InitMinMax
NormAngle
DeltaSum3
DeltaSum4
Getxyzlq
Getxyzlqk
DistTest
ArcTan
204
ABACUS ApPENDIX A - MODULES OF THE TRACER
Calcablq
MMlq3Test
MMlq4Test
MMlqKTest
MMlqkSphere
MMlqCylinder
MMlqCone
MMlqEllipsoid
InitMinMaxlq
IntersectionPointPlane
IntersectionPointTriangle
IntersectionPointRectangle
IntersectionPointCircle
AngleIntervall
IntersectionPointCircleSector
IntersectionPointCircleRing
IntersectionPointSphere
BasisTrans
IntersectionPointCylinder
IntersectionPointCylinderSegm
IntersectionPointCone
IntersectionPointEllipsoid
WhichBody
Set Brightness
StandardFill
ExtendedFill
SetPoint
Reprojection
ComputePoint
Shadows
Saver
Loader
Merger
ArrayInit
LoadMat
ScreenSaver
205
ApPENDIX A - MODULES OF TilE TRACER AMIGA 3D GRAPHIC PROGRAMMING
ScreenLoader
Hardcopy
LoadEditor
ClearScreen
Info
Help
Sky
Fhg
Background
206
ABACUS ApPE:,\DIX B - TilE TRACER PROGRAM
When you're ready to merge the modules, see the merging instructions
in Section 3.3.2 (page 141). Any changes you must make to the
modules before compiling should be done from a text editor or word
processor (see Chapter 8 for compiling suggestions).
The following pages contain the listings of the seven modules used to
make the completed tracer program.
207
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMIl"G
'Init.asc start~
, 3-D Graphics~
'~
, Peter Schulz, 1986~
, AMIGA-Version Bruno Jennrich, 1987~
'~
, Mainpoint H (hx,hy,hz)~
, Distance to projection point : DPH~
, alpha, beta, gamma : three angle for all three axis~
, => P(px,PY,pz) : Projection point'll
'~
, k(n,O,O)=Typ: O=Plane, 1=Triangle, 2=Parallelogramm,~
3=Circle, 4=Circle segment, 5=Circle arc'll
10=Sphere, 20=Cylinder, 22~'Cone, 24=Ellipsoid~
21=Cylinder segment~
, k(n,O,1)=Reserved~
, k(n,2,0)=Radius of the Sphere~
, k(n,0,2)=Material number~
, k(n,1,x)=Calculation point'll
, k(n,2,x)=Intersect vector (:,2) or distance vector (3)~
, k(n,3,x)=Intersect vector (1,2) or distance vector (3)'Il
, If Typ>=20: (k(n,2,x),k(n,3,x),k(n,4,x)) = Base'll
, If Circle segment/arc or cyiinder segment:'I1
k(n.5,0)~St~rt angle, k(n,5,ll=End angle'll
, If Circle arc: k(n,4,0)=inner Radius [0 .. 1J, ~(n,4,1)=outer Radius [0 .. 11'11
'~
'demo: '11
'DATA 4'l!
'DATA 10,0,8,O,0,O,50,0,O,O,O,0,0,O,0,O,O,0'lI
'DATA 2,O,8,80,-30,30,0,60,0,-:0,0,-60,O,0,O,0,0,0~
'DATA 20,0,8,-30,-30,5,25,0,0,0,25,0,0,0,75,0,0,0'11
'DATA 10,0,5,30,-30,30,25,0,0,0,0,0,0,0,0,0,0,0'11
''I!
**************************************~
* Initial Routine and DATAs *'11
**************************************~
''l!
Material: '11
DATA 20'11
DATA 0,.9,0,0,0'11
DATA . 6, . 6, . 6, 0, . 5'11
DATA .9, .9, .9,0, .8'1l
DATA 1,1, 1, .1, .9'l!
DATA .7,0, .7, .2,0'l!
DATA 1,1,1,0,.9'l!
DATA 0,0,.5,0,0~
DATA .8,0,0, .2,0~
DATA 1,1,1,.2,.2'1l
DATA 1,1,1,.2,.1~
DATA .7,.7,0,0,0~
DATA 1,1,1,0,1'11
DATA 0,.4, .4, .2, O~
DATA 1,1,1,.2,.5~
208
ABACUS ApPENDIX B- THE TRACER PROGRAM
DATA &HFFFF'lI
DATA &flFFFF 'lI
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HFFFF'lI
DATA &HHTF'll
DATA &HFFFF'lI
DATA &fiFFFF'll
DA TA &HFFFF'll
DATA &HFFFF'll
DATA &HFFFF'll
DA TA & rlFFFF'll
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HFFFF'!!
''ll
DATA O.0234375'll
DATA &'!I'FFF'll
DATA &Hl:EFE'll
DATA &HFFFF'll
DATA &HFFFF'll
DATA &EFFFF'll
DATA &!'LlFB'll
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HEFEF,!!
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HFFFF'll
DATA &HBFBF'lI
DATA &HFFFF'!!
DATA &HFFFF'll
''ll
DATA O.12S'lI
DATA &H555,)'lI
DATA &HFFFF'll
DATA &HAA1I.A'lI
DATA &HFFFF'll
DATA &H5555'l1
DATA &HFFFF'lI
DATA &HAAAA'lI
DATA &HFFFF'lI
DATA &H5555'l1
DATA &HFFFF'll
DATA &HAAAA'lI
DATA &HFFFF'll
209
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DATA &H5555'J[
DATA &HFFFF'J[
DATA &HAAAA'lI
DATA &HFFFF'J[
"1I
DATA 0.2S'J[
DATA &HFFFF'J[
DATA &H5555'1!
DATA &HFFFF'J[
DATA &HS555'1!
DATA &HFFFF'll
DATA &HS555'1!
DATA &HFFFF'll
DATA &H5555'll
DATA &HFFFF'Il
DATA &H5555'1l
DATA &HFFFF'J[
DATA &H5:155'l[
DATA &HFFFF'Il
DATA &H555591
DATA &HFFFF'I!
DATA &!l5555'1!
'91
DATA 0.37591
DATA &H555591
DATA &HBRBB'I!
DATA &H555591
DATA &HBBBB9I
DATA &H555591
DATA &HBBBB'I!
DATA &H5555'l[
DATA &HBBBB9I
DATl\ &H555591
DATA &HBBBB'll
DAT,ll, & H55 5S<JI
DATA &HBBBB9I
DATA &H555591
DATA &i'BBBB'I!
DATA &H555591
DATA &HBBBB'J[
''ll
DATA O.5'll
DATA &H555591
DATA &HAAAA9I
DATA &H555591
DATA &HAAM'll
nATA &H555591
DATA &hAAAA91
Dl\TA &H5555'll
DATA &HAAAA'll
'lATA &1l5S55'll
DATA &IIl~'ll
DATA &H5555'll
DATA &HAAAA'J[
DATA & H55 55'1!
DATA &flAAAA9I
DATA &H5555'll
DATA &HAAAA'll
''J[
DATA D.625'll
210
ABACUS ApPENDIX B- THE TRACER PROGRAM
DATA &Hllll'l!
DATA &HAA.AA'l!
DATA &H4444'l!
DATA &HAA.AA'l!
DATA &Hllll'l!
DATA &HAAAA'l!
DATA &H4444'l!
DATA &HAAAA'l!
DATA &Hllll'II
DATA &HAAAA'lI
DATA &H4444'lI
DATA &HAA.AA'lI
DATA &Hllll'lI
DATA &HAAM'lI
DATA &H4444'lI
DATA &HAAAA'l!
''II
DATA O.75'lI
DATA &HAA.AA'lI
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO'll
DATA &HAAM'lI
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO'll
DATA &HAAAA'lI
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO'll
DATA &HAAAA'lI
DATA &HOOOO'll
''lI
DATA O.875'lI
DATA &HAAM'lI
DATA &HOOOO 'II
DATA &H5555'II
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO 'II
DATA &H5555'II
DATA &HOOOO'll
DATA &HAA.AA'II
DATA &HOOOO 'II
DATA &H5555'II
DATA &HOOOO'll
DATA &HAAAA'lI
DATA &HOOOO 'II
DATA &H5555'II
DATA &HOOOO'll
''lI
DATA O.9765625'll
DATA &HOOOO'II
DATA &HOI01'll
DATA &HOOOO'II
DATA &HOOOO'II
DATA &HOOOO'll
DATA &H0404'll
211
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HI0I0'll
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &H4040'll
DATA &HOOOO'l[
DATA &HOOOO'l[
''ll
DATA 1'1[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'l[
''I[
PatternX:'ll
, Number Fill patterns - I'll
DATA 12'11
''ll
DATA 0'11
DATA &HOOOO'll
DATA &HOOOO'll
D. liiT
. .Zl. ... &HOOOOcn
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
''I[
DATA 0.00390625'lI
DATA &H8000'lI
DATA &HOOOO'l[
DATA &HOOOO'll
DATA &HOOOO'lI
DATA &HOOOO'lI
DATA &HOOOO'lI
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'l[
DATA &HOOOO'l[
212
ABACUS ApPENDIX B- THE TRACER PROGRAM
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
''l[
DATA O.0078125'll
DATA &H8000'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &H0080'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
"1I
DATA O.015625'll
DATA &H8080'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &H8080'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
''ll
DATA O.O3125'l[
DATA &HBOBO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'll
DATA &H0808'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HB080'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &H0808'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
DATA &HOOOO'l[
213
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
''lI
DATA O.0625'lI
DATA &H8888'lI
DATA &HOOOO'lI
DATA &HOOOO'lI
DATA &HOOOO'lI
DATA &H8888'lI
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &H8888'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &H88 88'll
DATA &HOOOO'll
DATA &HOOOO'll
DATA &HOOOO'll
'll
DATA O.12S'll
DATA &H8888'll
DATA &HOOOO'll
DATA &H2222'll
DATA &HOOOO'lI
DATA &H8888'll
DATA &HOOOO'll
DATA &H2222'll
DATA &HOOOO'll
DATA &H8888'll
DATA &HOOOO'll
DATA &H2222'll
DATA &HOOOO'll
DATA &H8888'll
DATA &HOOOO'll
DATA &H2222'll
DATA &HOOOO'll
''ll
DATA O.1875'lI
DATA &H8888'll
DATA &H2222'll
DATA &H8888'll
DATA &HOOOO'lI
DATA &H2222'll
DATA &H8888'll
DATA &H2222'll
DATA &IIOOOO'll
DATA &H8888'll
DATA &H2222'll
DATA &H8888'll
DATA &HOOOO'll
DATA &H2222'll
DATA &H8888'll
DATA &H2222'll
DATA &HOOOO'll
''ll
DATA O.25'll
DATA &HAAAA'll
DATA &HOOOO'll
DATA &HMAA'll
DATA &HOOOO'll
214
ABACUS ApPENDIX B - TilE TRACER PROGRAM
DATA &HAAAA'J[
DATA &HOOOO'J[
DATA &HAAAA'J[
DATA &HOOOO'lI
DATA &HAAAA'lI
DATA &HOOOO'J[
DATA &HAAAA'lI
DATA &HOOOO'J[
DATA &HAAAA'J[
DATA &HOOOO'lI
DATA &HAAAA'J[
DATA &HOOOO'J[
''J[
DATA O.3125'lI
DATA &HAAAA'J[
DATA &Hllll'lI
DATA &H4444'lI
DATA &Hllll'lI
DATA &HAAAA'lI
DATA &i-lll11'lI
DATA &H4444'lI
DATA &Hll11 'lI
DATA &HAAAA'J[
DATA &Hll11'lI
DATA &H4444'J[
DATA &Hllll'lI
DATA &HAAAA'lI
DATA &Hll11'lI
DATA &H4444'lI
DATA &Hll11'lI
''lI
DATA 0.375'J[
DATA &hAAAA'lI
DATA &Hllll'J[
DATA &HAAAA'lI
DATA &H4444'J[
DATA &HAAAA'J[
DATA &Hll11'J[
DATA &HAAAA'J[
DATA &H4444'J[
DATA &HAAAA'lI
DATA &Hllll'lI
DATA &HAAAA'lI
DATA &H4444'lI
DATA &HAAAA'lI
DATA &Hl111 'J[
DATA &HAAAA'J[
DATA &H4444'J[
''II
DATA 0.43751[
DATA &HAAAA'lI
DATA &H5555'lI
DATA &HAAAA'lI
DATA &H44441[
DATA &HAAAA'J[
DATA &H55551[
DATA &HAAAA'lI
DATA &H44441[
DATA &HAAAA'lI
DATA &H5555'II
215
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
DATA &HAAAA'll
DATA &H4444'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H4444'll
''ll
DATA O.5'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
DATA &HAAAA'll
DATA &H5555'll
''ll
StartUp:'ll
CHDIR "Tracer:libs"'ll
'll
DECLARE FUNCTION SetRast() LIBRARY'll
DECLARE FUNCTION SetRGB4() LIBRARY'll
DECLARE FUNCTION GetRGB4%() LIBRARY'lI
DECLARE FUNCTION SetDrMd () LIBRARY'll
DECLARE FUNCTION SetAPen() LIBRARY'll
DECLARE FUNCTION SetBPen() LIBRARY'll
DECLARE FUNCTION Move() LTBRARY'll
DECLARE FUNCTION Draw() LIBRARY'll
DECLARE FUNCTION Wri teP ixcl () LIBRARY'lI
DECLARE FUNCTION RectFill () LIBRARY'll
DECLARE FUNCTION Text () LIBRARY'lI
DECLARE FUNCTION TexlLength&() LIBRARY'll
LIBRARY "graphics. library"'!!
'll
DECLARE FUNCTION SetWinaowTitles() LIBRARY'll
DECLARE FUNCTION ScreenToFront() LIBRARY'll
DECLARE FUNCTION ScreenToBack() LIBRARY'lI
DECLARE FUNCTION ActivateWindow() LIBRARY'll
DECLARE FUNCTION RemakeDlsplay() LIBRP~RY'll
LIBRARY "intuition.library"'ll
'll
DECLARE FUNCTION AllocMem&() LIBRARY'lI
DECLARE FUNCTION FreeMem() LIBRARY'll
DECLARE FUNCTION AllocSignal% () LIBRARY'll
DECLARE FUNCTION FindTask& () LIBRARY'll
DECLARE FUNCTION DoIO&() LIBRARY'll
DECLARE FUNCTION OpenDevice& LIBRARY'll
LIBRARY "exec.library"'ll
'll
DECLARE FUNCTI ON xOpen& ;,IBRARY'll
DECLARE FUNCTION xRead& ;,IBRARY'll
DECLARE FUNCTION xWrite& LIBRARY'll
216
AIlACIJS ApPENDIX B- Tm: TRACER PROGRAM
LIBRARY n(hs_library"'!!
'!!
DEF FN Xscale(x)~(x+P;cturcx)*Pictllrewidth'!!
DEI" FN Yscale(y)=(P;cturey-y)*Pictureheight'!l
lli-',I-' FN Xresc(x) x/ricturewidth-Pic:turex,!!
DEF FN Yresc(y) Picturey-y/Picturehelght,!!
,
DEl" FN Deg(a)=a*IBO/P;'
, Dpgree to Radiant:,!!
, DEF FN Rad(a)=a*Pi/lBO'
True
~alse
= l'
= NOT(True)'!!
'!!
, Search depth for calculation point'!!
,
MaxStack% - :9 '!!
Pi = 3_141592654#'
Pd2 Pi/7'!!
Pm2 = 2*1' i '!!
'!!
Threshold _0001'!!
Hx
Hy
'!!
0'
0,
,Hz 0 '!I
Px 500'
Py O'll
Pz ~ 0,
'!!
, Picture drawn after first call of new drawing'll
Newone! = True'll
'll
, Wait in New Drawing mode for key or mouse'll
WaitFIgl = True'll
'll
, All Men'] points active?'!!
Stilrt% = O'll
'll
DIM Stack(MaxStack%,2)'ll
DIM RestLght (MaxS:.ack%) 'll
'll
I Arrays for ERASE added to system'll
DIM Help(O)'!!
DIM minmax%(O)'ll
DIM minmaxlq(O)'
DIM K(O)'ll
'!I
217
ApPE','DlX B - TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRA:I1MING
'li
Qx~l
Oy ~(;:
Qie-l
'f
, Fill patlern = Standard'l[
, Only need in case of SetPoint. OSSetPoint has its own pattern''iI
PalternAt-t%~O'IT
1 VCli
t'\c :COY-: liS
;(
caSUB Cpcn~Ex~
COSlJn ;;;'ast.e:-Ir:i ~:l
'., =-F::lc_torX
p :,ic:-to:-yqr
Picturewidtr,fl
s~c. / Picturehe:q}1t~
'IT
c
GCSUB Ma~e~e:l.u'TI
RE~< r"er:love a ft.cr test :~g s
218
ABACUS ApPENDIX B - THE TRACER PROGRAM
DIM PatternHS(NumberPatternS%)'lI
PatternS& = AllocMem& ((NumberPatternS%+l) *2*16, 65536&+2) ~
IF PatternS& = 0 T~EN~
CLS'II
CALL DialogBox("No free Chip-Memory!' ''',1,True,x1a%,yla%,x2a%,y2a%,False)'II
CALL DoDialog(n%,1,-1,-1,-1,-1,x1a%,yla%,x2a%,y2a%,-1,-1,-1,-1)~
GOSlJB CloseIt ~
END~
END IF,!!
'II
FOR i%=D TO NumberPatternS%,!!
READ PatternHS(i%)~
FOR j%=D TO 15~
READ TempPattern%'lI
POKEW (PatternS&+i%*32+j%*2),TempPattern%'lI
NEXT j%'lI
NEXT i%~
RETlJRN~
"II
TnitPatternX:~
, Initialize fill p~ttern (Extended)'!!
RESTORE PatternX~
READ NumberPatternX%'lI
~
DIM PatternHX(NumberPatternX%*2)~
PatternX& = AllocMcm&((NumberPacternX%*2+1)*2'16,65536&+2)~
IF PatternX& ~ 0 THEN~
219
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
CLS'I
CALL DialogBox ("No free Chip-Memory! ! !", 1, True, xla%, yla%, x2a%, y2a%, False) 'll
CALL DoDialog(n%,1,-1,-1,-1,-1,xla%,yla%,x2a%,y2a%,-1,-1,-1,-l)'ll
GOSUB CloseIt'll
END'll
END IF'll
FOR i%=O TO NumberPatternX%'ll
READ PatternHX(i%)'lI
PatternHX(NumberPatternX%*2-i%)= 1 - PatternHX(i%)'ll
FOR j%=O TO is'll
READ TempPattern%'ll
POKEW (PatternX&+i%*32+j%*2),TempPattern%'ll
POKEW (PatternX&+NumberPatternX%*2*32-i%*32+j%*2) ,NOT (TempPatte rn%) 'll
NEXT j%'l!
NEXT i%'ll
RETURN'll
''ll
InitSetPoint: 'll
, Read assembler routine for Point-drawing:'ll
220
ABACVS ApPENDIX B- TilE TRACER PROGRA:\1
CALL OSCloseGfx&'ll
RETURN'll
''ll
RasterIni t: 'll
I Select resolution and display !T;l)cie 91
WINDOW CLeSE 2 1 delet.e any wi~6cv;::: ,Jrd'T:
SCREEN CLCSE: : ' s::,eens 'll
'll
WINDOW 1,"11, (0, C) - {632, 1.8~), (; I i~e',.,; ",i:1GUW Y·ilth ~;tatus-lirje'1I
'll
'PALETTE 0,0,0,0
'PALETTE 1.1,1,] 'll
'PALETTE 2,.4, .4,1'll
'II
~~ase& ~ WINDOW(7)'lI
NRastPort& cc WINDOW (8) ~[
NWScreen& ~ PEEKL(NWBase&+46)'ll
I Base addr-ess of Window-Structllre91
1 from which the screen struct.ure is takE'n~
, RastPort belongs wi th the WINDOW () funct ion'll
'II
Statl1s$ = " Stat\1~:;: SE~lcc:t. !':esojut,icrll'~CHR$ (O) I Status 1 inc output91
durnrr'.y :::.. Set Wi ndowT L~_] E-: S (t\~,o,JI.~,1 se;;', St\[';~ (SL at,-, L~;$) f C) en
'll
x(D) ~ O:x(1) O:x (2) Cox (:3) c 41!
'll
y cc 0'11
I topmost lJne = S~drt lineS
'II
Modulo (0) 3'11
Modulo(}) 2'11
t1odulo(2) )'11
Modulo (3) 6'll c
221
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
222
ABACUS ApPENDIX B- TilE TRACER PROGRAM
223
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
IF RasterT% = 6 THGN~
RSize& = RasterW%*(RasterH%\8)~
Flags& = 65536&+2 1 MEMF CHIP MEt"IF CLEAR'll
Mem& = Alloc~em& (Rsize&,Flags&)~
IF Mem& = 0 TflEN~
CALL SC1:'off<rr
CALL l'rintIt ("Not enodgh memory for sixLh Biti'lane ! 1I",102,rdlse)'ll
CALL OialogBox("Sorry !",l,True,xla%,yla%.x2a%.y2a%,False)~
~
CALL OoOialog(n%, 1,-I.-I.-I.-1,xla%,yla%,x2a%.y2a%,-l,-1.-1.-1)~
GOSUB CloseIt ~
RUN~
ENO IF'll
~
POKE Dcpth&,6'll
1 New depth'll
91
POKEL Bi tP 1 ane 6&. Me:-c& 91
BitPlanes&(5)=Mem&'ll
, Poke address of the sixth BitP~ane'lI
'lI
POKEW Viewpo,t&+32,Moduc;%91
f Poke !or display mcde 2()KEN~
91
dummy hcmakeOisplay (d'~mrny&) 91
1 compute new display 91
END IF ~
~
Statlls$ " Status: Initializing"+CHR$(O)'ll
CALL SetWindowTitles& (N~13asc&,SADD(Stc1tuS$),O)~
CALL Scrof:'ll
CALL SecDrMd&(RastPort&.l)'lI
91
RasterWJ% RasterW%-l '319/63991
RasterHl% RasterH%-1 '199/399~
RasterW2% RastcrW%/2 'Screen middle'll
RasterH2% RasteriH17'll
91
FactorX (x (1) -1) /291
FactorY Ix (2) +1) /291
'll
POKEW OSMoG,]s&. Modus%~
POKEL OSRastPort &, F<ast,Port&~
POKEW OSRasterWI &, Raste r\'Jl%~
POKEW OSRasterHl&.RasterHl%~
~
MaxColour% ~ 'ARasterT%~
IF IRasterT% = 6) THEN~
IF (ModllS% AND &H800) &,i800 THEN 91
MaxC810ur% 16 'HAM'll
ELSE~
MaxColour% 'Halfbrite'll
END IF'll
END IF~
224
ABACUS ApPENDIX B- THE TRACER PROGRAM
'll
FOR m%=O TO 3'll
Colour(l,m%)=O 'Black'll
Colour (2, m%) =1 'White'll
NEXT m'l;'ll
'll
IF (Modus% AND &H80) &H80 THEN 'Half Brite'll
MF%=MaxColour%/2'll
'll
Colour (MF%+I,O) =MF%'ll
Colour (MF%+2,0) =MF%+I'll
FOR m%=l TO 3'll
Colour(MF'I;+l,m%)=O'll
Colour (MF%+2,m%) .S'll
NEXT m%'ll
RESTORE OptimaleHBColour'l!
ELSE'll
MF%=MaxColour%'ll
RESTORE OptimaleColour'll
END IF'll
'll
FOR n% 3 TO MF%'ll
READ r%, g%, b%'ll
'll
Colour(n%,O)=n%-I'll
Colour(n%,I)=r%/IS'll
Colour(n%,2)=g%/IS'l!
Colour(n%,3)=b%/IS'll
CALL SetRGB4&(Viewport&,n%-I,r%,g%,b%)'l!
'll
IF (Modus% AND &H80) <>0 THEN 'Hal fBri te'll
Colour(n%+MF%,O)=n%+MF%'lI
FOR m%=l TO 3'll
Colour(n%+MF%,m%)=(INT(Colour(n%,m%)*IS)\2)/lS'll
NEXT m%'ll
END IF'll
'll
NEXT n%'ll
, => Colour(n,O) color index, 'l!
Colour (n, 1. .3) RGB brightness'lI
'l!
, Poke colors into assembler routines array:'l!
'll
FOR n%=O TO MaxColour%-l'l!
POKEW OSColour&+n%*8,Colour(n%+1,0)'l!
FOR m%=l TO 3'll
POKEW OSColour&+n%*8+m%*2,Colour(n%+1,m%)*1024'lI
NEXT m%'lI
NEXT n%'ll
CLS'll
RETURN'lI
'lI
OptimaleHBColour: 'Hal fBri te'll
DATA 10,0,0'll
DATA 0,10,0'll
DATA 0,0,10'll
Dl,TA 10,10, O'll
DATA 10,0,10'll
DATA 0,10,10'lI
DATA 10,10,lO'lI
225
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DATA lS,10,0'J[
DATA 15,O,10'J[
DATA 15,10,10'J[
DATA 10,15,0'J[
DATA 0,15,10'J[
DATA 10,15,10'J[
DATA 0,10,lS'll
DATA 10,0,lS'll
DATA 10,10,lS'll
DATA 15,15,10'll
DATA 15,10,15'll
DATA 10,15,15'll
DATA 13,13,13'll
DATA 8,8,8'll
DATA 8,0,0'll
DATA D,8,0'll
DATA D,0,8'll
'll
, and the next six Colours'll
'll
OptimaleColour:'ll
DATA lS,O,O'll
DATA 0,15,O'll
DATA O,O,lS'll
DATA 15,15,O'll
DATA 15,O,15'll
DATA 0,15,lS'll
DATA 7,O,0'll
DATA 0,7,O'll
DATA 0,0,7'll
DATA 7,1,0'll
DATA 7,0,7'll
DATA 0,7,7'll
DATA 7,7,7'!i
Dil Til 15,7,D'll
DATA lS,0,7S
DATA lS,7,7'll
DATA 7,15,O'll
DATA 0,15,7'll
DATA 7,15,7'll
DATA 0,7,15'll
DATA 7,0,lS'll
DATA 7,7,lS'll
DATA 15,15,7'll
Di\TA lS,7,1~'ll
DATA 7,15,15'll
DATA 3,3,3'![
DATA ID,10,10'll
DATA 10,D,0'll
DATA 0,10,O'll
DATA D,0,10'll
''ll
'end of INIT.ASC'll
"f
226
ABACUS ApPENDIX B- TilE TRACER PROGRAM
'SYSTEM.ASC start ~
***************************************~***~
* Trace-System-Koutines *'ll
*******************************************~
"II
CloseIt:'ll
, Close all and free memory~
GOSUB CloseGfx'll
WINDOW CLOSE 2~
SCREEN CLOSE , automatic release of allocated 6th bit~ap~
MENU RESET , ~
~
IF SetPointAdr& <> 0 THEN CALL FreeMem&(SetPointAdr&,SctPointNum&l~
IF PatternS& <> 0 THEN CALL FreeMem& (PatterC'S&, (NumberPattecnS%+l I *2*161 ~
IF PatternX& <> 0 THEN CALL FreeMem& (Patter:oX&, (NumberPattecnX%*2+11 *2*161 'iI
'Save pattecn and release ASSEM-Routine~
LIBRARY CLOSES:
RETURN~
~
SUB PrintIt(Out$,y%,Scrl STATIC'lI
SHARED RastPort&,NRastPort&,RasterW2%,:rue,Length&~
, Centered text output on one of the two screens ~
, OutS: Printed string~
, y%: verticle Position ?~
, Scr: User or Display Screen?~
IF Scr = True THEN'lI
rp& = RastPort&'lI
Middle& = RasterW2%'ll
, write to new (Displayl Screen'lI
ELSE'll
rp& = NRastPort&'lI
Middle& = 320 ' User-Screen (NO OP Windowl'lI
END IF']
Length & Text Leocjth& (rp&, SADD (Out$ I , LEN (OLt$ I I '"
Middle& Middle& - Length&/2'lI
CALL Move& (rp&,Middle&,CLKG(y%II'lI
CALL Text& (rp&,SADD(Out$I,LEN(Out$1 I~
END SUB'lI
'~
SUB EmptyBuffers STATIC'll
, clear mouse and keyboard buffer 'ii
WHILE MOUSE(OI <> 0'lI
WEND'lI
WHILE (INKEY$<>nnl'l:
WEND'll
END SUB'll
'~
Pause: 'll
, Wait for (Mouse-I key press'll
CALL EmptyBLffers
WHILE (INKEY$ = nnl AND (MOUSE (01 Ol~
WEND'll
RETURN'll
227
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
"II
SUB Box (Ra.stPort&, xU, yl%, x2%, y2%) STATIC'll
, rectangle in Display-Screen'll
, RastPort&: draw in which RastPort 'II
, xl,yl,x2,y2 coordinates of the rectangle'll
CALL Move& (RastPort&,xl%,yl%)'II
CALL Draw& (RastPort&,x2%,yl%)'11
CALL Draw& (RastPort&,x2%,y2%)'II
CALL Draw& (RastPort&,xl%,y2%)'II
CALL Draw&(RastPort&,xl%,yl%+l)'11
END SUB'll
''II
SUB DialogBox(DialogS,Position%,Ret,x1%,yl%,x2%,y2%,Scr) STATIC'll
SHARED RastPort&, NRastPort&, True, RasterW1%, RasterW2%'11
, Create your own requester'll
, DialogS ~ Text in Dialog Box'll
, Position% 'II
o right'll
1 center'll
2 left'll
'Ret% can you press <Return>?'ll
True ~ Yes'll
False ~ No'll
, xl%,yl%,x2%,yl% ~ Size of 'click'-Field (word returned)'ll
Scr - In which screen output ?'11
True ~ Display-Screen'll
False ~ User-Screen'll
228
ABACUS ApPENDIX B- THE TRACER PROGRAM
mousel: 'IT
x% PEEKW(WScreen&~18)'lI
y% = PEEKW(WScrecn&~16)'IT
229
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMI:'\G
IF Flag! = 1 THEN ,
CALL Move &(RastPort&,Oldx%,O)'
CALL Draw&(RastPort&,Oldx%,Ras~erHl%)'
CALL Move&(RastPort&,O,OldY%)'
CALL Draw&(RastPort&,RasterWI%,OldY%)'ll
END IF'
, Flag' = I'll
, OldY% = h%'ll
230
ABACUS ApPENDIX B- TilE TRACER PROGRA\I
'll
CALL EmptyBuffers'll
'll
a$ = "II~
WHILE (MOUSE (0) ~ 0) AND (a$ <> CHR$(13)) 'll
a$ = INKEY$'ll
I'v'END'll
'll
Mx% PEEKW(WScreen&+18)'ll
My% PEEKW(WScreen&+l6)'ll
'll
TryAgain = True'll
IF (Mx%>xla%) AND (Mx%<x2a%) AND (My%>yla%) AND (My%<y2a%) THEN TryACjain
False'll
IF a$ = CHR$(13) THEN TryAgain = False'll
'll
CALL Printlt ("Section Ok ?",130,True) 'll
'll
CALL DialogBox("OK",1,True,xla%,yla%,x2a%,y2a%,True)'ll
'll
IF TryAgain = True THEN GOTO Repitition 'll
'll
w% ~ w%-x%'ll
h% h%-y% 'll
'll
CALL SetDrMd& (RastPort&, 1) 'JAM2'll
CALL SetDrMd&(NRastPort&,l)'ll
'll
IF Back' = True THEN CALL Scroff'll
END SliBO:
''ll
NOOP: 'll
Status$ = " Status: NOP"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
RETURN'll
''ll
MakeMenu:'ll
Status$ ~ " Status: Building menu"+CHR$ (0) 'Il
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
'll
MENU 1,0,1, " Amiga"'ll
MENU 1,1,1," 3D-Cad-Info I"'ll
'll
MENU 2,O,1,"File"'ll
~ENU 2,1,1, " Load L"'II
MENU 2,2,Start%, " Save S"'ll
MENU 2,3,1, " Merge M"'ll
MENU 2,4,1, "11 _New N"'ll
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1I<.![
MENU 2,5, 0,
MENU 2,6,1, " Load material "'ll
MENU 2,7, a, 11 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ll<J[
231
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMIl\G
MENU 4,O,Start%,"Parameter"<JI
MENU 4,1, SLart%, II Projec~ion POlot P"~
MENU 4,2, Start%, " ::-1ai~ point H"'l!
MENU 4,3,Start%, "a, , c A"'l/
MENU 4,4,SLart%, 0"'11
"'I ____________________
Distance II!
MENU 4,'0,0,
MENU 4,6, Starr.%, " Enlarge V"'lI
MENU 4,7,Start%, "Nu::,ber cc;rner E"<J:
'11
!veNU S,O,Start%,"C.::-aw"q[
MENU 5,l,Start%," Shadows FlouT
MENU 5,2,Start%," Initialization F9 "'11
MENU 5,3,0; lI ____________________ IIqr
MENU 5,4,Start%," Wire model < >"'11
MENU 5,5,Start%," Clear screen C "'11
GOSUB NOOP'l/
CALL EmptyBuffers9!
RETURN'lI
'91
Dc 1eteMer,u: 'ii
!'-CENU l,O,O,"Amiga ll
<J1
MENU 2,O,O,"File ll q[
MENU 3,0,0, "Editor"9!
MENU 4,0,0,"Paramcter"'ll
MENU 5,0,0, "Dra'l'Ii'"q[
RETURN'll
"II
MessageEv~nt.:~
reTitle MENU (0) 'll
MPoint MENU(l)'lI
'lI
IF' MTitlc <> 0 TlICN<.IT
'l!
IF MIitie ~ 1 THEN'll
IF MPoint ~ 1 THEN COSUl, Info'll
GOTO MessageEnde'll
END IF'll
'lI
IF MTit 1.e 2 THEN'i!
IF MPoint C;OSUtl Loader'll
1 THEr.:
IF MPoint GOSUB Savert}[
2 THEN
~
IF MPoint :1 THEN
GOSUB Merger'll
IF MPoin':. C;OSUB ArrayInit'li
THEN
I Mpoint = 5 : " _________ "qr
IF MPoint = 6 THEN GOSUB LoadMat'i!
, MPoint = 7 : u---------IICJI
IF MPoint 8 THEN GOSUB Background~
IF MPoint = 9 THEN COSUB ScrecnSaver'll
IF MPoint ~ 10 THEN GaSUB H3rdCopy'll
, MPoint 0- 11 : "---------II~
IF MPoint ~ 12 THE~ GOSUB ColorPalette~
1 MPoint = 13 : "---------"<JI
IF MPoint ~ 14 ':'HEN GOSUB Quit<i[
GOTO MessageEnde'll
END IF'lI
q[
3 THEN'll
232
ABACUS ApPE:-iDIX B- TilE TRACER PROGRA:l-1
IF Key$ 11*11
OR Key$ ~
"/" OF Key$ ~ n+n OR Key$ "_II THEN'lI
IF Key$ 11+11
THEN D = 10 'lI
IF Key$ THEN D ~-10'lI
IF Key$ "*,, THEN D = lOJ'l!
IF KeyS "j" THEN D =-100'1
IF Key$ ~
"5 11 TIlEN COSUB Saver'lI
IF KeyS lib" TE:::N ~:OSUB ScreenSaver'lI
IF Key$ C:-iR$ (137) THEN COSUB In: tP ar ,-j~e:: cr sq;
233
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMIl"G
234
ABACUS ApPDIDIX B - THE TRACER PROGRA~1
235
ApPENDIX B- THE TRACER PROGRAM
END IF'll
'll
CALL SetRGB4& (Viewport &, Cel r%, CI'\T (ced) ,C~,T (greee) ,C=:H (lc ~"l) ) 'II
ErrorHandling:'ll
Nurr.F: r r ERR '11
'll
Status$ "Statu~;: Next '] Errc~ !:! ",t'C;;~~:I (0) ql
CALL SeLWi QoowT i c 1..;; s& (NIIIIBa: c&, Sl\D;~ (S:.a tu:>$) I 0) 91
'll
GOS:jB lJelelc)!er:u'1l
'll
Dialog$ ~ u"'ll
IF Nurrl-:rr = 61 THEN ' i\ad Fi l" Vccdc'il
Dialog$ "::: !!~3ad fi ~e ;--:amc ! ~: tlqr
END IF'll
'll
IF Nl1rnErr S7 THEN Err()~qj
END 1F'[
'IT
Ii:' NumErr
Dialog$
END IF'll
'll
1 F NumErr 70 THEN I Pe LIT : .s ,'3 i on oc,' ~ (~d 91
236
ABACL'S ApPENDIX B - THE TRACER PROGRc\:\1
CLS'I[
GOSUB MakeMenu'l[
RESUME ok 'I[
RETURN'I[
''I[
Quit: 'I[
CALL Scroff'l[
Status$ = " Program end ?"+CHR$(O)'I[
CALL SetWindowTitles& (NWBase&,SADD(Status$) ,0)'1[
'I[
GOSUB DelcteMenu'l[
'I[
CALL Printlt("Do you really wLsh to exit the prograr?",lOJ,False)'I[
'I[
CALL DialogBox(IINo ,O,True,xla%,yla%,x2a%,y2a%,Falsc)q]
lI
'll
CALL DoDialog(n%,O,xla%,yla%,x2a%,y2a%,xlb%,y16%,x2b%,y2b%,xlc%,yle%,x2e%,y2c%)
'I[
'I[
CLS'I[
IF n% > 0 THEN'I[
GOSUB CloseIt'll
IF n% 1 THEN'I[
RUN 'I[
ELSE'll
END'I[
END 1F'I[
END IF'I[
GOSUB MakeMenu'l[
RETURN'I[
''I[
SUB Seroff STATIC,![
SHARED NWBase&,~wScreen&'I[
, Display Screen off, User Screen on1
CALL ScreenToFront&(NWScreen&)'I[
WINDOW OUTPUT 1'1[
WINDOW 1'1[
CALL ActivateWindow&(NWBase&)'I[
END SUB'll
''I[
SUB Scron STATIC'll
SHARED WScreen&,WBase&'ll
, Display Screen on, User Screen off'lI
CALL ScreenToFront&(WScreen&)'I[
WINDOW OUTPUT 2'1[
WINDOW 2'1[
CALL ActivateWindow&(WBase&)'ll
END SUB'I[
''I[
SUB GetString(oldS,a$,z$,z,s,winlen)STATIC!
'TASK :Read a string while allowing thc,]s'?e ,.,) ,,,iit. . :~L, r-~nc:ql
i.e. :cursor left/right, backspace: acci dC:CLC ~1
In addition the string should b~ seeol j~b,~ a
if the input is longer than the " in,,"
'PARAMETER:=>old$ old value of string to be read'l[
a$ key pressed'll
z$ legal characters'l[
237
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
z line'll
s column'll
winlen Length of input windpow'll
<=old$ of specified string'll
IF winlen=l THEN 'if only 1 character entered? => no <Return> needed'll
old$=a$'ll
WHILE INSTR(z$,old$)=O'll
CALL GetKey(old$,z,s)'II
WEND'll
LOCATE z, s'll
PRINT old$'ll
ELSE'll
i=l 'display current string position'll
Position=l 'display the actual screen position 'II
WHILE a$><CHR$(13)'ll
IF INSTR(z$,aS»<O THEN 'legal character?'ll
old$=LEFT$ (old$,i-l)+a$+RIGHTS (oldS,LEN(old$)-i+l) 'll
i=i+l'IT
Position=Position+l'll
IF Position>winlen THEN'll
Position=winlen'll
END IF 'II
ELSE 'II
IF a$ = CHRS(30) AND i<=LEN(oldS) THEN 'Cursor rignt?'ll
i=i+l'll
Position=Position+l'll
IF Position>winlen THEN'll
Position=winlen'll
END IF 'II
ELSE'll
IF as = CHR$(31) AND i>l THEN 'Cursor left?'ll
i=i-l'll
Position=Position-l'II
IF Position-O THEN'll
Position=l'll
END IF 'II
ELSE'll
IF a$ = CHR$(127) AND i<=LEN(old$) THEN 'delete?'ll
old$=LEFT$(old$,i-l)+RIGHT$(oldS,LEN(old$)-i)'ll
ELSE'll
IF a$=CHR$(8) AND i>l THEN 'Backspace?'ll
i=i-l'll
Position=Position-l'll
IF Position=O THEN'll
Position=l'll
END IF'll
old$=LEFT$(old$,i-l)+RIGHT$(old$,LEN(old$)-i)'II
END IF'll
END IF'll
END IF'll
END IF'll
END IF'll
LOCATE z,s'll
PRINT MID$(oldS+" ",i-Position+l,winlen) 'String output'll
CALL GetKey(a$,z,s+Position-l) 'get next key 'II
WEND'll
END IF'll
IF i><Position THEN'll
CALL PutString(old$,z,s,winlen)'11
END IF 'II
238
ABACUS ApPENDIX B- TilE TRACER PROGRAM
END SUB'!!
'!!
SUB GetReal(i!,a$,z,s,winlen,unt',ob!) STATIC'!!
'~ASK :Read a real value,!!
'PARAMETER:;>i! old value,!!
a$ pressed key'!!
z line'll
s column'!!
winlen length of input line'll
unt! lower limit'll
ob! upper limit'll
<~i' given value'll
CALL conrealstr(i!,j$)'ll
loopl: 'II
i$;jS'!!
CALL GetString(i$,a$,"1234567890-.",z,s,winlen)'ll
j$;i$'!!
CALL constrreal (i$,i')'!!
IF i$~"" OR i'<unt! OR i!>ob! THEN'll
a$;" "'II
BEEP'll
GOTO loopl'll
E~,;) IF'!!
END SUB'Il
''Il
SUB GetInt(i!,a$,z,s,winlen,unt!,ob') STATIC'!!
'TASK :Read a Integer value'll
'PARAMETER:~>i! old value'll
a$ key pressed'!!
z line,!!
s column'!!
winlen Length of input line'll
unt' upper limit'll
ob! lower limit'!!
<=i! given value,!!
CALL conrealstr(i!,j$)'!!
loop3: '!!
i$;j$'ll
CALL GetString(i$,a$,"1234567890-",z,s,winlen)'ll
j$=i$'!!
CALL constrreaL (i$,i')'!!
IF i$~"" OR i'<unt! OR i!>ob! THEN'!!
a$=11 n<II.
BSEP,!!
GOTO loop3'1l
END IF'!!
END SUB'll
''!!
SU~ GetKey(a$,z,s)STATIC~
'TASK :Fead a Character '!!
'PARAMETER:=>z line'll
s co~umntjl
<;a$ Key pressed'll
CALL SetCursor(z,s) '!!
a$~"'''lI
WHILE as;'''',!!
a$=INK,':YS'jT
WEND'!!
CA~L Se~Cursar(z,s)'ll
END S'lB'll
239
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
''l[
SUB SctCursor(z,s) STATIC'l[
'TASK :set the cursor to the given position'l[
'PA~METER:=>z line'lI
s column'lI
rp&=WINDOW(8)'lI
Cw%=PEEKW(rp&+60)'l[
Ch%~PEEKW(rp&+58)'l[
CALL SetDrMd&(rp&,2)'l[
LINE (s*Cw%-Cw%,z*Ch%-Ch%)-(s*Cw%,z*Ch%),3,BF'l[
CALL SetDrMd&(rp&,l)T
END SUB 'l[
"1I
SUB PutString(s$,z,s,winlen)STATIC'l[
'TASK : Output a string of the speci fied lensth'IT
'PARAMETER:=>s$ the string'lf
z line5
s column'lI
winlen lenghtof the output string'IT
LOCATE z, s 'delete given range'll
PEINT SPACE$(win]en)'lI
LOCATE Z,s 'output the slriny'lI
PRINT MID$(s$,l,winlen)'IT
END s':"T
'l[
SUB PutReal (i ~ ,Z, s, winlen) ST/ITIC'II
'TASK :Output a real value of the specified length'll
'PARAMETER: =>i! the real value'll
7 line'l[
s column'lI
winlen length of the output windo'w'IT
CALL conrealstr(i',sS)'11
CALL PutString(s$,z,s,winlen)~
E:-JD SUB'll
'IT
SUB conrealstr (i', is) STATIC'j[
'TASK :convert one real value to a string~
rounding off value to three decimal places'IT
'PARAMETER:=>i! t.he Real value'lI
<=i$ the string'l[
i$-STR$ (i') 'lI
j'=tTX(lOOO'*i'+.5*SGN(i'))/lOOO' 'roGnd'll
i$=STRS (j , ) 'll
IF ABS(j!»O AND ABS(j!)<l THEN 'Insert 0 i f O<j!<1 'll
i$=MIDS(i$,1,1)+"O"+MID$(iS,2,LEN(i$) ) 'IT
END IF'll
IF j'>=O THEN 'falls O<=j' truncate first place'lI
is=RIGHT$(i$,LEN(i$)-l)'il
END IF'IT
END SUB'l[
''ll
SeB constrreal (is,i!) STATIC'
'TASK :convert strir:g to real vdl~e~
'PARAMETER:=>i$ the string'll
<=i! the real value'll
is If conversion error is='''''IT
i'=VAL(i$)'ll
IF i ~>=O THEN'li
IF i!>O fu~D i!<l THEN'll
i$~" "+RIGHTS(i$,LEN(i$)-l) 'Insert space and remove O'll
240
ABACUS ApPENDIX B - THE TRACER PROGRAM
ELSE 'll
i$=" lI+i$ 1 insert space'll
END IF'll
END IF'll
j' ~i! -FIX (i' *1000') !l000! 'round 'II
IF i$><STR$(i') OR j!><O THEN 'error ?'11
L$="II<I{
LND IF 'll
END SUB'll
''ll
SUB Formlnput (i,winlen,unt',ob!) STATIC'll
'Enter indivlldal real values'll
'1 => number variables to be real (old value displayed)'lI
'winlen,unt!,ob! => see above~~
z~CSRLIN'lI
s=POS(O)'ll
a$ = "'llII
241
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMML\'G
CLS'II
IF n% ~ 0 THEN'll
FILES'll
GOSUB Pause'll
CLS'II
GOTO RepeatD'll
END IF'll
IF' n% = 2 THEN'll
a$ = "Active Directory: "tActDri ve$'Il
CALL PrintIt(a$,50,False)'ll
'll
LOCATE lC,l'II
FRINT " New DirecLory: "; 'II
CALI. FormInputString (ActDrive$,30!)'II
'II
CHDIR ACLDrive$'Il
'Il
CLS'iI
GO TO RepeatD'll
END IF 'II
CLS'II
RETURN 'II
'End of SYSTEM.ASC'II
''Il
242
ABACUS ApPE;I;DIX B- TilE TRACER PROGRA\I
'WIREMODEL-Draw.ASC~
''lI
''lI
**************************~
* Wire model *'ll
**************************~
''ll
''ll
SUB Projection(Px%,Py%,x,y,z) STATIC'll
SHARED Sina,S:nb,Sinc,Cosa,Cosb,Cosc,DPH,Hx,Hy,Hz~
• 3D coordina:es (x,y,z) to 20 (Px%,Py%) ~ Screen~
'll
xl~(x-Hx) ~Cosa< (y-fly) *S:na • Z-Axis rotation'll
yl=(y-Hy)*Cosa-(x-Hx)*Sina'll
x2~xl*Cosbt (z-Hz) *Si"b ' Y-Axis rotation'll
z2~(z-Hz)'Cosb-x]*Sinb~
y3~yl*Cosc+z2*Sin~ • X-Axis rotation~
z3~z2*Cosc-yl*Sinc~
~
IF DPH<>x3 THEN'll
Px%~FN Xscale «y3*DPH) / (DPH-x2)) -4 • Intersecting point with projection poi ,,:
'll
Py%=FN Yscale«z3*DPH)/(DPH-x2)) -2 • scaling'll
ELSE'll
Px% = FN Xscale(O) -4 • Subtraction of 4 and 2 based on drawing'll
Py% = FN Yscale(O) -2 • in a GIMMEZEEOZERO-Window (BASIC-Window)'ll
END IF'lI
END SUB ~
''ll
''lI
DrawPlane:~
CALL
Pro ject ion (Xp', Yp%, K (n %, 2, C) +K (n%, 1,0) , K(n%, 2,1) +K (n %, 1 , 1 ) , ": (:1 %, ;;, ;;) t K (n'o, . , 2) ) 'II
CALL Move& (Ras:Port&,Xp%,Yp%)~
CALL Projection(Xp%,Yp%,K(n%,l,O),K(n%,l, 1),K(n%,1,2))~
CALL Draw& (RastPort&,Xp%,Yp%)~
CALL
Projection(Xp%,Yp%,K(n%,3,O)+K(n%,:,O),K(n%,3,1)-K(n%,1,1) ,K(n%,3,2)tK(n%,i,2))'11
CALL Draw&(RastPort&,Xp%,Yp%)'11
RETURN'll
1':[
:)rawTriangle: 'll
CALL Projection(xl%,yl%,K(n%,1,O),K(n%,1,1),K(n%,1,2))'11
CALL Move&(Rast~orL&,x:%,yl%)~
CALL
Pro ject ion (Xp%, Yp%, K (n %, 2, 0) tK (n%, 1,0) , K(n%, 2, 1) ! K (n %, : , 1) , / (:: %, / , ' ) f K ( ,·,2) ) Sl
CALL Draw& (RastPort&,Xp%,Yp%)S
CALL
Projection(Xp%,Yp%,K(n%,J,C)+":(n%,1,O),K(n%,3,1)+K(n%, " ') ,r ).K(~%,~,2))<l!
CALL Draw& (RastPorl&,Xp%,Vp%)~
CALL DC1W& (i(astPort &, xl%, y1 %) 'II
RETURN'lI
'~
243
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DrawRectangle:'l[
CALL Projecticm (xl %, y1 %, K(n%, 1, 0) ,K (n%, 1, 1), K (n%, 1, 2) ) ~[
CALL Move& (RastPort&,xl%,y1%)'ll
CALL
Projection(Xp%,Yp%,K(n%,2,O)+K(n%,1,0),K(n%,2,1)+K(n%,1,1),K(n%,2,2)+K(n%,1,2))'ll
CALL Draw&(RastPort&,Xp%,Yp%)'ll
Dx=K(n%,2,O)+K(n%,3,O)+K(n%,1,O)'ll
Dy=K(n%,2,1)+K(n%,3,1)+K(n%,1,1)'ll
Dz=K(n%,2,2)+K(n%,3,2)+K(n%,1,2)'ll
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)'ll
CALL Draw&(RastPort&,Xp%,Yp%)'ll
Cr,]'L
Projection(Xp%,Yp%,K(n%,3,O)+K(n%,1,0),K(n%,3,1)+K(n%,1,1),K(n%,3,2)+K(n%,1,2))'ll
CALL Draw& (RastPort&,Xp%,Yp%)'ll
CALL Draw&(RastPort&,x1%,y1%)'ll
PETURN'll
''ll
DrawCircle:'ll
CALL
Pro jecti on (Xp,", Yp%, K (n %, 1, O)t K (n%, 2, 0) , K (n%, 1,1) +K (n%, 2, 1) , K (n %, 1,2) +K (n%, 2,2) ) 'll
'SIN(C) 0 and COSIO) ~ 1 goto K(n%,3, .. ), and K(n%,2, .. ) takes over'll
CALL Move& (PasLPort&,Xp%,Yp%)'ll
w=Pm2 /NuC',be rSegment s'll
D=w'll
Pcpeatl :'ll
Dx=K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)'ll
Dy"K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)'ll
Dz~K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)'ll
CALL Projection (Xp%,Yp%,Dx,DY,Dz) 'll
CALL Draw&(RastPort&,Xp%,Yp%)'ll
w = w+D'll
IF (w<=Pm2+D/2) THEN GOTO Repeatl:'ll
RETUPN'll
''ll
DrawCircleScctor:~
CALL Projection(xl%,yl%,K(n%,1,O),K(n%,1,1),K(n%,1,2))'ll
w=K(n%,S,O)'ll
Dx=K(n%,1,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)'ll
Dy=K(n%,1,1)+K(n%,2,1)*Ccs(w)+K(n%,3,1)*SIN(w)'ll
Dz=K(n%,1,2)+K(n%,2,2)*CCS(w)+K(n%,3,2)*SIN(w)'ll
CALL ProJcction(Xp%,Yp%,Dx,Dy,Dz)'ll
CALL Move&(RastPort&,x1%,yl%)'ll
CALL Draw&(PastPort&,Xp%,Yp%)'ll
D=Pm2/NumberSegments'll
WHI IE w<K (n%, 5, 1 ) 'll
w w+D'll
IF w>K(n%,5,1) THEN'll
w=K(n%,5,1)'ll
E"J IF'll
Dx=K(n%,1,O)+K(n%,2,O)*COS(w) tK(n%,3,O)*SIN(w)'ll
Dy=K(n%,1,1)+K(n%,2,1)*CCS(w)+K(n%,3,1)*SIN(w)'ll
Dz=K(n%,1,2)+K(n%,2,2)*COs(w)+K(n%,3,2)*SIN(w)'ll
CALL ProjecLion(Xp%,Yp%,Dx,Dy,Dz)'ll
CALL Draw& (RastPort&,Xp%,Yp%)'ll
WEND'll
CALL Draw& (RastPort&,xl%,yl%)'ll
PETUPN'll
''ll
DrawCircleRing:'ll
w~K(n%,5,O)'ll
244
ABACUS ApPENDIX B - TIlE TRACER PROGRAM
Dx=K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w»*K(n%,4,O)~
Dy=K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w»*K(n%,4,O)~
Dz=K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w»*K(n%,4,O)~
CALL Projection(Xua%,Yua%,Dx,Dy,Dz)~
Dx=K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w»*K(n%,4(1)~
Dy=K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w»*K(n%,4(1)~
Dz=K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w»*K(n%,4(1)~
CALL Projection(Xoa%,Yoa%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)~
CALL Draw&(RastPort&,Xoa%,Yoa%)~
D=Pm2/NumberSegments~
WHILE w<K(n%,5,1)~
w = w+D~
IF w>K(n%,5,1) THEN~
w=K(n%,5,1)~
END IF~
Dx=K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w»*K(n%,4,O)~
Dy=K(n%,1,1)+(K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w»*K(n%,4,O)~
Dz=K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w»*K(n%,4,O)~
CALL Projection(Xu%,Yu%,Dx,Dy,Dz)~
Dx=K(n%,1,O)+(K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w) )*K(n%,4,1)'
Dy=K(n%,1,1)+(K(n%,2,1)*Cos(w)+K(n%,3,1)*SIN(w) )*K(n%,4,1)~
Dz=K(n%,1,2)+(K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w»*K(n%,4(1)'
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)'
CALL Draw&(RastPort&,Xu%,Yu%)'
CALL Move&(RastPort&,Xp%,Yp%)'
CALL Draw&(RastPort&,Xoa%,Yoa%)'
Xua%=Xu%'II
Yua%=Yu%~
Xoa%=Xp"
Yoa%=Yp%~
WEND'II
CALL Move&(RastPort&,Xua%,Yua%)'I[
CALL Draw&(RastPort&,Xoa%,Yoa%)'I[
RETURN~
'~
DrawSphere:'
D=Pm2/NumberSegments~
FOR w1=-Pd2+D TO pd2-D/2 STEP D~
Dx=K(n%,l,O)~
Dy=K(n%,1,1)+K(n%,2,O)*COS(wl)'II
DZ=K(n%,l,2)+K(n%,2,O)*SIN(w1)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xp%,yp%)~
FOR w2=D TO Pm2+D/2 STEP D~
Dx=K(n%,l,O)+K(n%,2,O)*SIN(w2)*COS(wl)'II
Dy=K(n%,1,1)+K(n%,2,O)*COS(w2)*COS(wl)'II
Dz=K(n%,l,2)+K(n%,2,O)*SIN(wl)'
CALL Projection (Xp%,Yp%,Dx,Dy,Dz)'II
CALL Draw&(RastPort&,Xp%,Yp%)'II
NEXT w2'II
NEXT wl'II
FOR wl=-Pd2+D TO Pd2-D/2 STEP D'
Dy=K(n%,l,l)~
Dz=K(n%,1,2)+K(n%,2,O)*COS(wl)~
Dx=K(n%,1,O)+K(n%,2,O)*SIN(wl)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move& (RastPort&,Xp%,yp%)~
FOR w2=D TO Pm2+D/2 STEP D~
245
ApPENDIX B - THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
Dy~K(n%,1,1)+K(n%,2,O)*SI~(w2)*COS(wl)~
Dz~K(n%,1,2)+K(n%,2,O)*COS(w2)*COS(wl)q
Cx=K(n%,1,O)+K(n%,2,O)*SIN(wl)~
CALL Projection(Xp%,Yp%,Dx,Dy, Dz)'l!
CALL Draw&(RastPort&,Xp%,Yp%)~
NEXT w2'l!
Nc:XT wI 'II
RETUEi'J'l!
~rawCylinder:~
Dx=K(n%,~,O) +;<;(n%,2,0)91
Dy=K (n %, 1, 1) I K (n %, ? , l) 91
Dz~K (n %, 1 ,2) +K (n %, ;7, 2) 'l!
CALL Project_lon (X1la%, ':'~~a%,Dx,DYfDz)~
Dx=K (n%, 1, O)i K (r: %,2,0) +K (n %, 4, 0) 'l!
Dy =K (n %,I, : ) +K (n %, ) , 1 ) +K (n %, 4, 1 ) 'l!
Dz=K (n%, 1 ,2) +K (n %, ;; , 2) • K (n %, 4,2) 'll
CALL Prejection(XD3%,YD~%,Dx,Dy,Dz)'ll
D--:::Pm2/Numbc r Scc;mC"nt sq!
FOR w~D TO rm2+D/2 STEP D'l!
Dx=K(n%,1,O)+K(n%,2,0)*COS(w)+K(n%,J,O)*SIN(w)'l!
Dy-K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)'l!
Dz=K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,J,2)*SIN(w)'ll
CALL Projection(Xu%,Yu%,Dx,Dy,Dz)'l!
Dx=K(n%,1,0'+K(n%,2,0)*COS(w)+K(n%,J,0)*SIN(w)+K(n%,4,O)'ll
Dy=K(n%,I,I)+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(w)+K(n%,4,I)'ll
Dz=K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)+K(n%,4,2)'ll
ClILL Project ion (Xp%, Yp%, Dx, Dy, Dz) 'll
CALL Move&(RastPort&,Xua%,Yua%)'l'
CALL DCl';;'& 0<,,;[ Port&, Xu%, Yu%) 'll
CALI. fJrdW& (iiastPort&, Xp%, Yp%) 'II
Cl'l,LL U;-':~'.·n; U':;astPnrL&, Xca%, Yoa%) Tt
Xua% Xu%l1
Y1Jr1%~Y\l%q:
XOd%=Xp-:;'~;
Yoa%-Y~)%ll
NEXT w91
iZr:TUFN'II
'91
DCClwCylinderSegm:'ll
w=K(n%,S,O)'1
Dx=K(n%,1,O)+K(n%,2,0)*C0S~) +K(n%,3,O)*SINlw)'1
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,3,;)*SIN(w)'
')zc K (n%, I , 2) + K (n%, 2,2) *COS (w) +K (,,%,3,2) * SJ N(w) •
CI\LL Projection(Xua%,Yua%,Dx,Cy,Cz)'II
Dx Kln%,1,O)+K(n%,2,O) 'COS(w)+K(n%,3,O)*SIN(w)+K(n%,4,O)'1
c
Dy-K(n%,1,1)+K(n%,2,1)*COS~)iK(n%,3,1)*SIN(w)+K(n%,4,1)t
Cz~K(n%,1,2)+K(n%,2,2)*COS~)+K(n%,3,2)*SIN(w)+K(n%,4,2)'ll
CALL Projcccion (Xoa%, YCH%,[]x,Dy,Dz)'
CALL Move& (RastPort&,Xua%,Yua%)'1
CALL DrJ''';; (?astPort&, Xea%, '{oal)'
D=Pm2/Ncrr:c;e rSegme:lL 591
WHILE w<K(n%,~, :)'1
w = wiDS
IF w>K(n _,5, 1) THEN'll
w=K(r%,~,:)'11
END;!''ll
Dx~K(n%,1,O)TK(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)'ll
Dy~K(n%,1,1)+K(n%,2,1)*COS(w)+K(n%,J,1)*SIN(w)'
Dz=K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,J,2)*SIN(w)'l!
246
ABACUS ApPEC'lDIX B - TilE TRACER PROGRA;\I
CALL Projection(Xu%,Yu%,Dx,Dy,Dz)~
Dx=K(n%,l,O)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)+K(n%,4,O)~
Dy=K(n%,l,l)+K(n%,2,l)*COS(w)+K(n%,3,l)*SIN(w)+K(n%,4,l)~
Dz=K(n%,l,2)+K(~%,2,2)*COS(w)+K(n%,3,2)*SIN(w)+K(n%,4,2)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move&(RastPort&,Xua%,Yua%)~
CALL Draw&(RastPort&,Xu%,Yu%)~
CALL Draw&(RastPort&,Xp%,Yp%)~
CALL Draw&(RastPort&,Xoa%,Yoa%)~
Xua%=Xu%~
Yua%=Yu%~
Xoa%=Xp%~
Yoa%=Yp%~
WEND~
RETURN~
'~
DrawCone:~
CALL
Projection(x1%,yl%,K(n%,l,O)+K(n%,4,O),K(n%,l,l)+K(n%,4,1) ,K(n%,l,2)+K(n%,4,)))'
CALL
Projection(Xp%,Yp%,K(n%,l,O)+K(n%,2,C),K(n%,l,1)TK(n%,2,1) ,K(n%,l,2)+K(n%,2,2))~
CALL Move&(RastPort&,Xp%,Yp%)~
D=Pm2/NumberSegments~
FOR w=D TO Pm2+D/2 STEP D~
Dx=K(n%,l,O)+K(n%,2,O)*COS(w)+K(n%,J,O)*SIN(w)'
Dy=K(n%,l,l)+K(n%,2,1)*COS(w)+K(n%,3,l)*SIN(w)~
Dz=K(n%,l,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)~
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)'
CALL Draw&(RastPort&,Xp%,Yp%)~
CALL Move& (RastPort&, xl %, y1 %) ~
CALL Draw&(RastPort&,Xp%,Yp%)~
NEXT w~
RETURN~
'~
DrawEllipsoid:~
D=Pm2/NumberSegments'
FOR w1=-pd2+D TO Pd2-D/2 STEP D'
Dx=K(n%,l,O)+K(n%,2,O)*COS(wl)+K(n%,4,O)*SIN(w1)'
Dy=K(n%,1,l)+K(n%,2,l)*COS(wl)+K(n%,4,l)*SIN(wl)~
Dz=K(n%,l,2)+K(n%,2,2)*COS(w1)+K(n%,4,2)*SIN(wl)~
CALL Projection (Xp%,Yp%,Dx,DY,Dz)'
CALL Move&(RastPort&,Xp%,Yp%)'
FOR w2~D TO Pm2+D/2 SrEP D~
Dx=K(n%,l,O)+K(n%,2,O)*COS(wl)*CCS(w2)+K(n%,3,O)*COS(w1)*SIN(w2)+K(n%,4,O)*SIN(wl)~
Dy=K(n%,l,l)+K(n%,2,l)*COS(wl)*COS(w2)+K(n%,3,l)*COS(w1)*SIN{w2)+K{n%,4,l)*SIN(wl)'
Oz=K(n%,1,2)+K(n%,2,2)*CCS(w1)*COS(w2)+K(n%,3,2)*COS(w1)*SIN(w2)+K{n%,4,2)*SIN(wl)'
CALL Projection(Xp%,Yp%,Dx,Oy,Dz)~
CALL Oraw& (RastPort&,Xp%,Yp%)~
NEXT w2~
NEXT wi'll
FOR w1=-Pd2+0 TO Pd2-0/2 STEP 0'
Ox=K(n%,l,O)+K(n%,2,O)*COS(wl)+K(n%,3,O)*SIN(w1)~
Dy=K (n%, 1, 1) tK (n %,2, 1) "COS (w1) +K (n%, 3,1) *SIN (wl) •
Dz-K(n%,l,2)+K(n%,2,2)*COS(wl)+K(n%,3,2'*SIN(wl)'
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Move& (RastPort&,Xp%,Yp%)~
247
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMI;\(;
Dx=K(n%,1,O)+K(n%,2,O)*COS(wl)*COS(w2)+K(n%,4,O)*COS(w1)*SIN(w2)+K(n%,3,O)*SIN(wl)'lI
Dy=K(n%,1,1)+K(n%,2,1)*COS(wI)*COS(w2)+K(n%,4,1)*COS(w1)*SIN(w2)+K(n%,3, l)*SIN(wI)'lI
Dz=K(n%,1,2)+K(n%,2,2)*COS(wI)*COS(w2)+K(n%,4,2)*COS(w1)*SIN(w2)+K(n%,3,2)*SIN(wI)'lI
CALL Projection (Xp%,Yp%,Dx,Dy,Dz)'lI
CALL Draw&(RastPort&,Xp%,Yp%)'lI
NEXT w2'lI
NEXT wI'll
RETURN'lI
''lI
''lI
DrawAll :'lI
, Draw routine for calling each figure'lI
FOR n%=l TO NumberK'lI
IF K(n%,O,O)=O THEN'lI
GOSUB DrawPlane'll
END IF'lI
IF K(n%,O,O)=l THEN'lI
GOSUB DrawTriangle'lI
END IF'll
IF K(n%,O,O)=2 THEN'lI
GOSUB DrawRectangle'lI
END IF'lI
IF K(n%,O,O)=3 THEN'lI
GOSUB DrawCircle'lI
END IF'lI
IF K(n%,O,O)=4 THEN'lI
CaSUB DrawCircleSector'lI
END IF'lI
IF K(n%,O,O)~5 THEN'lI
GaSUS DrawCircleRing'lI
END IF'lI
IF K(n%,O,O)=lO THEN'lI
GaSUB DrawSphere'lI
END IF'll
IF K(n%,O,O)=20 THEN'lI
GOSUB DrawCylinder'lI
END IF'll
IF K(n%,O,O)=21 THEN'lI
GOSUB DrawCylinderSegm'lI
END IF'll
IF K(n%,O,O)=22 THEN'll
GaSUB DrawCone'll
END IF'll
IF K(n%,O,O)=24 THEN'lI
GaSUB DrawEllipsoid'lI
END IF'lI
NEXT n%'lI
RETURN'lI
''ll
DrawNew:'lI
IF (Hg False) AND (Newone! True) THEN 'no BacKground'lI
CALL SetRast&(RastPort&,O) , b'.]t. new dra,;ing'lI
END IF I => clear screen~
'll
CALL Scron 'll
248
ABACUS ApPE:-iD!X B- TilE TRACER PROGRAM
CALL DialogBox("Proportional",O,True,xla%,yla%,x2a%,y2a%,False)'ll
CALL DialogBox("Distort",2,Falsc,xlb%,ylb%,x2b%,y2b%,False)'ll
r;;
249
ApPENDIX B - TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
ELSE'II
WaitFlg! = False'II
GOSUB DrawNew'II
CALL Rubberbox {Sx%,Sy%,Widthe%,Heighte%,False)'II
Picturewidth=RasterW%/Widthe% * FactorX'II
Pictureheight=RasterH%/Heighte% * FactorY'II
Picturex={RasterW2%-Sx%)/FactorX'II
Picturey={RasterH2%-Sy%)/FactorY'II
END IF'II
Newone! = True'!I
WaitFlg! = True'!I
GOSUB DrawNew'!I
RETURN'II
'END of Wire-model.asc'!I
''!I
250
ABACUS ApPENDIX B- Tm: TRACER PROGRAM
'WIREMODEL-INPUT.ASC
************************~
* Input-Routine *~
************************~
"1I
Initial:~
WHILE Alpha<O~
Alpha - Alpha + Pm2~
WEND~
WHILE Beta<O~
Beta = Beta + Pm2~
WEND~
WHILE Gamma<O~
Gamma = Gamma + Pm2~
WEND~
WHILE Alpha>Pm2~
Alpha = Alpha - Pm2~
WEND~
WHILE Beta>Pm2~
Beta = Beta - Pm2~
WEND~
WHILE Gamma>Pm2~
Gamrna = Gamma - Pm2~
WEND~
Sina=SIN(Alpha)~
Cosa=COS(Alpha)~
Sinb=SIN (Beta) ~
Cosb=COS(Beta)~
Sinc=SIN(Gamma)~
Cosc=COS(Gamma)~
251
AI'PEJ'DlX B- TilE TRACER PROGRAM AMIGA 3D GRAI'I1IC PROGRAMMING
Cosb-:<)l /~'?E'TI
ENJ lFS
'II
Sjnc=O , Z-l~is angle not'll
Cosc=J I solely determined hereS
IF C02,a.
Alpha ·';2qT
ELSZ'iI
Alpha=ATN(Sina/Cosa) , compute cosinemand sine'll
END IF I dr.gle<JI
~F C:osa<O H1EN'll
j\lpr.a All)ha+Pi'll
foND IF'll
E.ND IFS
~[
BeLa
END IF'll
Gamrr!<1 ·O<JI
RETURN'll
Iq;
IcPtJt~): 91
Status$ = II Status: ProjccLioJ; point"+CHRS (O) <JI
C~LL SetWindowTitles& (NWBase&, SADD (Status$) ,0)9
rJ!
PRINT 11
'II
LOCATEL:, 1 'ii
PRINT " U;S
CALL FOIT:'llr:pu:-, (L"x,JC:,- tJ4,lE+14)'ll
:OCATE l~,l'll
?i~INT ., pz = ";<JI
Cl\LL Forrnlnpu!:: (Pz,JO! ,-1£+1-1, lEi 14)S
'll
GOSCB T~"'j_tL:i~pqr
~Jewor..e ~ = T ;_-I1C'(:~
CLS'lI
GOSUB Max("':-<cr~L: c::
!~
InFutH:~
Status:) ~ " St,:j:"us: tvla:n T)()_~nt"+CHR$(O)9I
CALL SetW'.ndowTitles&(NWBase&,SADD(Status$),O)'lI
252
ABACUS ApPENDIX B - THE TRACER PROGRAM
'II
COSUB DeleteMenu'II
'II
LOCATE lO,l'll
PRINT " Main point: "'II
'II
LOCATE 12,1'II
PRINT" Hx - ";'Il
CALL FormInput (Hx,30!,-lE+14,lE+l4)'iI
'II
LOCATE 13,1'II
PRINT" Hy - ";'ll
CALL ForcnInpul (fly,JO',-lE+l4,lE+l4)'II
'II
LOCATE 11,1'"
PRINT" Hz - ";'11
CALL Form~nput (Hz,38',-1E+14,lE+14)'11
'II
GOSUB Initial'JI
Newonc' - True'JI
CLS'II
COSUB MakeMenu'll
RETURN'll
''II
InputDPH:'II
Status$ - " Status: Spacing"+CHR$ (0) 'II
CALI. SetWindowTitles&(NWBase&,SADD(StaLus$),O)'ll
'II
GOSUB DeleteMenu'II
'II
LOCAcE :C,:'ll
PRINT II SPdC:; ng oL pro jection surface - "; qr
CALL Fon",np1;~ (!;I)H,10',-1E+14,lE+14)'ll
'II
GOSUB IniLial'll
Newonc~ = TrueS
CLS'II
GOSUB t1,,:<eMc:lu'JI
RETURN'i!
''II
InputAngle:'II
Slatus$ - " Status: Ent~r angl~ of rotation"+CHR$(O)'II
CAc,L SetWindowTi tles& (NWf3ase&, SADfJ iSta tus$) ,0) 'll
'JI
GOSUB De1eteMenu'll
'll
a-:eN Deg (Alpha).'ll
b-E'N Deg(Beta)'II
c=E'N Ceq i: ;lrmna) <IT
'II
LOCATE 10, '.'11
PRINT II ~~glc ~~ ~otation (a, ,e): 11'
'II
LOCAIE :2, lS
PRINT " A~pha (Z-Axis) = ";'ll
CALL FonnlccpClt (2,30',0!,360!)'II
'll
LOCATE 13,1'll
PRINT " Beta (Y-Axis) = "; 'II
C.2\YL Formlnput (b,30!,O!,360')'lI
253
ApPENDIX B - THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
LOCATE 14,1'll
PRINT" Gamma (X-Axis) = ";'ll
CALL FormInput (c, 30',O',360!) 'll
'll
Alpha=FN Rad(a)'ll
Beta=FN Rad(b)'ll
Gamma=FN Rad(c)'ll
'll
GOSUB Initial'll
Newone' = True'll
CLS'll
GOSUB MakeMenu'll
RETURN'll
'End of wiremodGl-Input.asc'll
''ll
254
ABACUS ApPENDIX n- THE TRACER PROGRAM
'SHADOW-:NIT • ASC'll
*******************~****k*************~
* Shadows initL,lizaticn * '!I
*********~**************~*******~***K*~
''ll
InitParameters:'.li
Status$ ~ " StdClOS: Parameter initia;ization"+CHR$(8)'ll
CALL SetWindowT~~ies&(NWBase&,SACD(Status$),O)'lI
'lI
GOSUB CeleteMenu'll
F n% = 2 THEN~
Ci\,"L Sc:ron~[
'll
CA~L Set-DrMd& (RAstPort&, 2) <]I
XStart% = O'll
XEnd%
'll
CALL Er.1pr..yBu '?rs1t
OldY% ~ -I'll
Fla'] O'JI
'll
\\iO;),,, (MOU:c::: (0) = [)) 'll
'/% PEEKll (NWScreen&+16) g
IF y% <> OldY% :HEN'JI
CALL Move& (HastPort&,O,y%)'
CALL Draw& (R2stPort&,RasterWl%,y%lS
IF Flag <> 0 THEN'JI
255
ApPEI\DIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMI:,>r;
CALL Move&(RastPort&,O,OldY%)~
CALL Draw&(RastPort&,RasterWl%,OldY%)~
END I?~
Flag ~ l~
OldY% = y%'lI
END IF~
WEND'lI
'lI
YStart% = y%'lI
UldY% = -1'lI
Flag = 0'lI
'lI
WHILE (MOUSE (0) <> OJ'll
y% = PEr':KW(NWScroen&+l6)'lI
IF y% <> OldY% THEN'lI
CALL Move& (RastPort&,O,y%)'[
CALL Draw& (RastPort&,RasterWl%,y%),
IF F!ag <> a THEN'
CALL Movce&(RastPort&,O,OldY%)'ll
CALL D!aw&(RastPort&,RastcerWl%,OldY%)'ll
END IF~
Flag = l '
OldY% = yl'll
END
WEND'lI
IF'
'lI
,
Yend% ~ y%'lI
, CALL Draw&(RastPorl&,RaslerW1%,YStart%)'lI
LOCATE 6, l'lI
PRINT" Position of light source :"'ll
S
LOCATE 8,191
PRI~':'II Qx ~ ";91
CALL Formlnpu: (Qx,30I,-lE+14,1~114)~
91
LOCATE 9, ,'ll
PRINT" Qy ~ ";~
CALL F'ormInpul (Qy,30!,-lE+14,lE+c~)91
LOCATE 10,:'lI
PRINT n Qz = II;CfI
CALL Formlnput (Q2,30!,-lE+14,-,E+14)'lI
256
ABACUS ApPEl'iDIX B- TilE TRACER PROGRA:\!
'll
LOCATE 13, ''ll
PRINT " Color of .liqht source"cn
'll
LOCATE 15,l'l:
PRINT " ~eti-intenslty (C .. 1) ";'ll
CALL Forr,Ir.p.Jt (Qh.r,3C:,~',:')'fi
LOCATE 16,1,:(
PRINT" green-intensity (0 .. 1) ";'iI
CALL Formlnput (Qh.g,30!,O',1')'ft
LOCATE 17,1'll
PRINT" blue-intensity (0 .. 1) ";'ll
CALL Formlnput (Qh. b, 3D!, 0 ',1') 'll
'll
LOCATE 19,1'll
PIUNT " Pixel width : ";'ll
a = BoxW%'ll
CALL FormlnputInL (a,30',1',CSNG(RasterWl%))'ll
BoxW% = a'll
'll
LOCATE 20, I'll
PRINT" pixel heiqhL : ";'ll
a = Boxt'%'ll
CALL FormInpltlnt (a,3D',1',CSNG(RasterHl%))'ll
BoxH% ~ a'll
'll
, CALL PrintIt("Which pattern?",130,False)'ll
, CALL DialogBox("Standard",0,True,xla%,yla%,x2a%,y2a%,False)'ll
, CALL DialogBox("Extended",2,False,xlb%,ylb%,x2b%,y2b%,False)'ll
''ll
, CALL EmptyBuffers'll
CALL DoDialog(PatternArt%,O,xla%,yla%,x2a%,y2a%,-J,-1,-1,-
, PatternArt% = PatternArt% AND ~'ll
'll
CLS'll
GOSUB ~1akeMenu'll
RETURN'll
''ll
''ll
SUB Transform(Xt,Yt,Zt,x,y,z,n%) STATIC'll
SHARED K(),~e~p()'ll
, => (xt,yL,zt) - transforration vector base k(n%)'ll
Xt=FN Det (x-K (n%, 1,0) ,K (n%, 3, 0) ,K (n%, 4,0) ,y-K (n%, 1,1) ,K (n%, 3, 1) ,K (n%, 4,1) , z-
K(n%,1,2),K(n%,3,2),K(n%,4,2))/Help(n%,O)'ll
Yt=FN Det(K(n%,2,0),x-K(n%,1,0),K(n%,4,0),K(n%,2,1) ,y-
K (n %, 1, 1 ) , K (n %, 4 , 1) , K ( n %, 2, 2) , z - K (n %, 1 , 2) , K (n %, 4 , 2) ) / He 1p (n %, 0) 'll
Zt=FN Det(K(n%,2,O),K(n%,3,0),x-K(n%,I,O) ,K(n%,2,1) ,K(n%,3,1),y-
K (n %, } , 1) ,K (n%, 2, 2) ,K (n%, 3,2) , z-K (n%, } ,2) ) /Help (n%, 0) 'll
END SUB'll
''ll
InitShadows:'ll
, Write as ruch as was computed previously into the help array'll
ERASE Help'1l
DIM Help (NumbcrK, 21) 'll
'll
FOR n%=1 TO ~umbecK'll
IF K(n%,O,O)<c9 THENS
I Triangle, Rectangle or Circle => Help(n,O .. 2) normal \/cctor Oil surface~:
I Help(n,3 .. 5) = 2*2-Determinante for x,y,z~
257
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
Nx=K(n%,2,1)*K(n%,3,2)-K(n%,2,2)*K(n%,3,1)~
Ny=K(n%,2,2)*K(n%,3,O)-K(n%,2,O)*K(n%,3,2)~
Nz=K(n%,2,O)*K(n%,3,1)-K(n%,2,1)*K(n%,3,0)~
IF FN CosinAngle(Nx,Ny,Nz,Px-K(n%,l,O),Py-K(n%,l,l),Pz-K(n%,l,2))<0 THEN~
I => Normal vector points to Projection point~
Nx=-Nx~
Ny=-Ny~
Nz=-Nz~
END IF~
Nl=SQR(Nx*Nx+Ny*Ny+Nz*Nz)~
Nx Nx/Nl~
Ny NylNl~
Nz Nz/Nl~
258
ABACUS ApPENDIX B - TilE TRACER PROGRAM
CALL Transform(Xt,Yt,Zt,Px,Py,Pz,n%)~
Help(n%,lO)=Xt'l[
Help(n%,ll)=Yt'l[
Help(n%,12)=Zt'll
Help (n%, 13) = (K (n %,3,1) *K (n%, ~,2) -K (n%, 4,1) *K (n%, 3,2) ) /He lp (n%, 0) ~
Help(n%,14)=(K(n%,3,O)*K(n%,4,2)-K(n%,4,O)*K(n%,3,2) )/Help(~%,O)~
Help(n%,15)=(K(n%,3,0)~K(n%,~,1)-K(n%,4,0)*K(n%,3,1)/Help(n%,C)~
Help(n%,16)=(-K(n%,2,1)*K(n%,~,2)+K(n%,4,1)*K(n%,2,2) )/Help(n%,O)~
Help (n%, 17) = (-K (n%, 2, 0) *K (n%, 4,2) +K (n%, 4, 0) *K (n%, 7, 2» /Help (n%, 0) s:
Help(n%,18)=(-K(n%,2,0)*K(n%,4,1)+K(~%,4,0)*K(n%,2,1) )/Help(n%,O)~
Help (n%, 19) = (K (n%, 2,1) *K (n%, ], ;;) -K (n%, 3,1) *K (n%, 2,2) ) / He Ip (~%, ) 'll
Help (n%, 20) = (K (n %,2,0) *K (n%, 3,2) -K (~%, 3,0) *K (n %, 2,2) ) / He lp (n%, C) ~
Help (n%, 21 ) = (K (n %, 2, 0) *K (n%, 3,1) -K (n%, 3,0) *K (n %,2, 1) ) / lIe~p (n%, 0) 'lI
END IF~
NEXT nt'll
RETURN'll
''ll
''ll
SUB Transformmm(x,y,2) STATIC~
SHARED Sina, Sinb, Sine, Cosa, Cosb, Case, i,asterW1%, RasterH1 %~
SHARED DPH,Hx,Hy,Hz,Xt,Yt,Zt~
, => xt,yt,zt for minmax'll
~
x1=(x-Hx)*Cosa+(y-Hy)*Sina 'Rotation Z-Axis'll
y1=(y-Hy)*Cosa-(x-Hx)*Sina'll
Xt~x1*Cosb+(z-Hz)*Sinb ' Rotation Y-Axis'll
z2=(z-Hz)*Cosb-x1*Sinb~
y3=yl*Cosc+z2*Sine ' Rotation X-Axis~
z3=z2*Cosc-yl*Sine~
'II
IF DPH<>Zt THEN~
Yt =FN Xscale ( (y3*DPH) / (DPH-Xt) ) ) division point with projection plane~
Zt ~FN Yscale ((z3*DPH) / (DPH-Xt) ) , scaled'll
ELSE~
Yt = FN Xseale (0) 'll
Zt = FN Yseale(O) 'll
END IF'll
IF Yt<O THEN'll
Yt= 0 'II
END IF'll
IF Yt>RasterWl% THEN'll
Yt=RasterWl%'ll
END IF'll
IF Zt <0 THEN'll
Zt~O'll
END IF'll
IF Zt>RasterHl% THEN'll
Zt=RasterH1%'ll
END IF'll
END SUB~
''II
SUB MinMaxtest(n%,x,y,z) STATIC'll
SHAFED DPH,minmax%(),RasterWl%,RasterHl%,Xt,Yt,Zt,XMin%'::
SHARED YMin%,XMax%,YMax%'ll
, if point preceding projection point => minmax%(n%,O)=-l ~> no screen : mit'll
IF minmax%(n%,O»=O THEN'll
CALL Transformrrm(x,y,z)'ll
IF Xt>=DPH THEN'll
minmax%(n%,O)=-l'll
259
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
rninmax%(n%,l)=-l'll
rninmax%(n%,2)=RasterWl%'lI
rninmax%(n%,3)=RasterHl%~
XMin%=O'lI
Y~ax%=RasterW1%'lI
YMin%=O'lI
YMax%=RasterHl%'ll
ELSE'lI
IF Yt<minmax%(n%,O) THEN'll
minmax%(n%,O)=Yt'lI
END IF'll
IF Yt>minmax%(n%,2) THEN'lI
minmax%(n%,2)=Yt'll
END IF'lI
IF Zt<minmax% (n%,1) THEN'll
minmax%(n%,l)=Zt'lI
END IF'lI
IF Zt>minmax% (n%,3) THEN'lI
minmax%(n%,3)=Zt'll
END IF'll
IF Yt<XMin% THEN'll
XMin%=Yt'lI
END IF'll
IF Yt>XMax% THEN'll
XMax%<'~~
END IF'll
IF Zt<YMin% THEN'll
YMin%=Zt'll
END IF'll
IF Zt>YMax% THEN'll
YMax%=Zl'll
END IF'll
END IF'll
END IF'll
END SUB'll
"II
InitMinMax:'ll
, Compute screen section allocated tor indivudal objecls'll
'll
ERASE minmax%'lI
DIM minmax%(NumDcrK,3)'ll
'll
XMin%=RasterWl%'ll
XMax%=O'lI
YMin%=RasterHl%'lI
YM;)x%-cO'lI
'll
FOR n%=1 TO NumbcrK'lI
minmax%(n%,O)=RasterW1%'lI
minmax%(n%,1)=RasterHl%'lI
minmax%(n%,2)=O'lI
minmax%(n%,3)=O'lI
'll
IF K(n%,O,O)~O THEN'll
minmax%(n%,O)=O'll
minmax%(n%,1)=O'll
minmax% (n%, 2) ='RasterWl%'ll
minmax%(n%,3)=RasterHl%'ll
XMin%=O'll
XMax%~RasterW1%'ll
260
ABACUS ApPENDIX B- THE TRACER PROGRAM
YMin%~O'II
YMax%~RasterH1 %'II
END IF'II
'II
IF K(n%,O,O)~l THEN'II
CALL MinMaxtest(n%,K(n%,1,0),K(n%,1,1),K(n%,1,2))'II
CALL
MinMaxtest (n%, K (n%, I , 0) +K (n%, 2, 0) ,K (n%, 1 ,1) +K (n%, 2, I ) , K (n%, 1, 2) +K (n%, 2, :7) ) 'li
CALL
MinMaxtest (n%, K (n%, 1,0) +K (n%, 3, 0), K (n%, l, 1) +K (n%, J, 1) ,K (n%, 1, 2) tK (n%, 3, 2) ) 'li
END IF'II
'II
IF K(n%,0,0)~2 THEN'II
CALL MinMaxtest (n%,K (n%, 1,0) ,K(n%, 1, 1) ,K(n%, 1, 2)) 'II
CALL
MinMaxtest (n%, K(n%, 1,0) +K (n%, 2, 0), K (n%, 1, 1) +K (n%, 2, 1) ,K (n%, 1,2) +K (n%, 2, 2) ) 'II
CALL
MinMaxtest(n%,K(n%,1,0)+K(n%,3,0),K(n%,1,1)+K(n%,3,1),K(n%,1,2)+K(n%,3,2))'II
CALL
MinMaxtest (n%, K (n%, 1, 0) +K (n %,2, 0) +K (n%, 3, 0) ,K (n%, 1, I ) tK (n%, 7, 1 ) + K (n%, 3, I ) , K (n%, 1,7)
+K(n%,2,2)+K(n%,3,2))'II
END IF'II
'II
IF K(n%,0,0»~3 AND K(n%,O,0)<~5 THEN'II
CALL MinMaxtest(n%,K(n%, 1,0)-K(n%,:7,0)-K(n%,J,0),K(n%, 1,1 )-K(n%,7,1)-
K (n %, 3,1) ,K (n%, 1,2) --K (n%, 2, 2) -K (n%, 3,2) ) 'II
CALL MinMaxtest(n%,K(n%,1,O)+K(n%,2,0)-K(n%,3,0),K(n%,1,1)+K(n%,2,1)-
K(n%,3,1),K(n%,1,2)+K(n%,2,2)-K(n%,3,2))'II
CALL MinMaxtest (n%,K(n%,1,0)-K(n%,2,0)+K(n%,3,0),K(n%,1,1)-
K (n %,2, 1) +K (n%, 3,1 ) , K (n%, 1,2) -K (n%, 2,2) +K (n%, 3, 2) ) 'II
CALL
MinMaxtest (n%, K (n%, 1, 0) +K (n%, 2, 0) +K (n%, 3, 0) ,K (n%, 1,1) +K (n%, 2,1) +K (n%, 3,1) ,K (n%, 1,2)
+K (n%, 2, 2) +K (n%, 3, 2) ) 'II
END IF'II
'II
IF K(n%,O,O)=10 THEN'll
CALL MinMaxtest(n%,K(n%,1,0)-K(n%,2,0),K(n%,1,1)-K(n%,2,0),K(n%,1,2)-
K(n%,2,0) ) 'II
CALL MinMaxtest (n%, K (n%, 1, O)tK (n%, 2, 0), K (n%, 1,1) -K (n%, 2, 0), K (n%, 1,2)-
K(n%,2,0))'II
CALL MinMaxtest (n%, K (n%, : , 0) -K (n%, 7, 0) ,K (n%, I , : ) + K (n%, 7, 0) , K (n%, ; , :7) -
K(n%,2,O))'II
CALL MinMaxtest(n%,K(n%,1,0)+K(n%,2,0),K(n%,1,1)+K(n%,2,O),K(n%,1,2)-
K(n%,2,0) ) 'II
CALL MinMaxtest(n%,K(n%,1,0)-K(n%,2,0),K(n%,1,1)-
K (n %, 2, 0) ,K (n%, : , 2) +K (n%, 2, 0) ) 'II
CALL MinMaxtest(n%,K(n%,:,0)+K(n%,2,O),K(n%,1,1)-
K (n%, 2, 0) ,K (n%, 1, 2) +K (n%, 2, 0)) 'II
CALL MinMaxtest(n%,K(n%,l,O)-
K (n %,2,0) ,K (n%, 1,1) +K (n%, 2, 0) , K (n%, 1,2) +K (n%, 2, 0) ) 'II
CALL
MinMaxtest (n%, K (n%, 1, 0) +K (n%, 2,0) ,K (n%, 1 , 1) +K (n%, 2, 0) ,K (n %, 1, 2) +K (n%, 2, 0) ) 'II
END IF'II
'II
IF (K(n%,0,O)~20) OR (K(n%,O,0)~21) OR (K(n%,O,O)=21) THEN'II
IF K(n%,OhO)~20 THEN'II
Xh%=K(n%,1,O)'II
Yh%=K (0%,1,1) 'II
Zh%~K(o%,1,2)'II
ELSE'll
261
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
Xh%=K(n%,1,0)-K(n%,4,O)~
Yh%=K(n%,1,1)-K(n%,4,1)~
Zh%=K(n%,1,2)-K(n%,4,2)~
END IF~
CALL MinMaxtest(n%,Xh%-K(n%,2,0)-K(n%,3,0) ,Yh%-K(n%,2,1)-K(n%,3,1) ,Zh%-
K(n%,2,2)-K(n%,3,2) )~
CALL MinMaxtest (n%, Xh%+ K (n%, 2, 0) -K (n%, 3, 0), Yh%+K (n%, 2,1)-
K(n%,3,1) ,Zh%+K(n%,2,2)-K(n%,3,2))!
CALL MinMaxtest(n%,Xh%-K(n%,2,0)+K(n%,3,0) ,Yh%-K(n%,2,1)+K(n%,3,1) ,Zh%-
K(n%,2,2)+K(n%,3,2))!
CALL
MinMaxtest(n%,Xh%+K(n%,2,0)+K(n%,3,0),Yh%+K(n%,2,1)+K(n%,3,1),Zh%+K(n%,2,2)+K(n%,3,
2) ) 'll
Xh%=K (n%, 1,0) +K (n%, 4,0) 'll
Yh%=K(n%,1,1)+K(n%,4,1)~
Zh%=K(n%,1,2)+K(n%,4,2)'ll
CALL MinMaxtest(n%,Xh%-K(n%,2,0)-K(n%,3,0),Yh%-K(n%,2,1)-K(n%,3,1),Zh%-
K (n%, 2, 2) -K(n%, 3, 2)) ~
CALL MinMaxtest(n%,Xh%+K(n%,2,0)-K(n%,3,O),Yh%+K(n%,2,1)-
K (n%, 3,1) ,Zh%+K (n%, 2, 2) -K (n%, 3,2) ) 'll
CALL MinMaxtest(n%,Xh%-K(n%,2,O)+K(n%,3,0),Yh%-K(n%,2,1)+K(n%,3,1) ,Zh%-
K(n%, 2, 2) +K(n%, 3,2)) 'll
CALL
MinMaxtest (n%,Xh%+K(n%,2,O)+K(n%,3,O),Yh%+K(n%,2,1)+K(n%,3,1),Zh%+K(n%,2,2)+K(n%,3
,2) ) 'll
END IF!
IF K(n%,O,O)=22 THEN~
CALL MinMaxtest(n%,K(n%,1,C)-K(n%,2,O)-K(n%,3,O),K(n%,1,1)-K(n%,2,1)-
K(n%,3,1),K(n%,1,2)-K(n%,2,2)-K(n%,3,2))~
CALL MinMaxtest(n%,K(n%,I,O)+K(n%,2,O)-K(n%,3,0),K(n%,1,1)+K(n%,2,1)-
K (n%, 3,1) , K (n%, 1,2) +K (n%, 2, 2) -K (n%, 3,2) ) 'll
CALL MinMaxtest(n%,K(n%,I,O)-K(n%,2,O)+K(n%,3,O) ,K(n%,l,l)-
K (n%, 2, 1) +K (n%, 3,1) ,K (n%, 1,2) -K (n%, 2, 2) +K (n%, 3,2) ) 'll
CALL
MinMaxtest(n%,K(n%,1,O)+K(n%,2,O)+K(n%,3,O),K(n%,1,1)+K(n%,2,1)+K(n%,3,1),K(n%,1,2)
+K(n%,2,2)+K(n%,3,2))'lI
CALL
MinMaxtest(n%,K(n%,I,O)+K(n%,4,O),K(n%,1,1)+K(n%,4,1),K(n%,1,2)+K(n%,4,2))'ll
END IF'lI
NEXT n%'ll
'll
IF XMin%>XStart% THEN'll
XStart %=XMin%'ll
END IF'll
IF XMax%<XEnd% THEN'lI
XEnd%~XMax%'lI
END IF'll
IF YMin%>YStart% THEN'll
YStart%=YMin%'ll
END IF'll
IF YMax%<Yend% THEN'll
Yend%=YMax%'ll
END IF'll
RETURN'll
''ll
''ll
SUB NormalAngle(Pw,Wi) STATIC'll
SHARED Pi, Pm2'll
I => Picture Wi from [ -PI , +PI J 'll
262
ABACUS ApPENDIX B- TilE TRACER PROGRAM
WHILE Wi>Pi'lI
Wi~Wi-Pm2'lI
WEND'lI
WHILE Wi<~-Pi'lI
Wi~Wi+Pm2'lI
WEND'lI
Pw=Wi'lI
END SUB'lI
''lI
SUB Deltasum3(Pw,wl,w2,w3) STATIC'lI
I => if light source in triangle: w=2*?i, else w=D'lI
CALL NormalAngle(Dl,w2-wl)'lI
CALL NormalAngle(D2,w3-w2)'lI
CALL NormalAngle(D3,wl-w3)'lI
Pw=Dl+D2+D3'lI
END SUB'lI
''lI
SUB Deltasum4(Pw,wl,w2,w3,w4) STATIC~
I ~> if light source in triangle: w=2*pi, else w=D'lI
CALL NormalAngle(Dl,w2-wl)'lI
CALL NormalAngle(D2,w3-w2)'lI
CALL NormalAngle(D3,w4-w3)'lI
CALL NormalAngle(D4,wl-w4)'lI
Pw=Dl+D2+D3+D4'lI
END SUB'lI
''lI
SUB GETxyzlq(Px,Py,Pz,n%,a%,b%,c%) STATIC'lI
SHARED K() 'lI
I ~> Compute XYZ-coordinates from factors a,b,c'lI
Px=K(n%,1,D)+a%*K(n%,2,O)+b%*K(n%,3,D)+c%*K(n%,4,D)'lI
Py=K(n%,1,1)+a%*K(n%,2,1)+b%*K(n%,3,1)+c%*K(n%,4,1)'lI
Pz=K(n%,1,2)+a%*K(n%,2,2)+b%*K(n%,3,2)+c%*K(n%,4,2)'lI
END SUB'lI
''lI
SUB GETxyzlqk(Px,Py,Pz,n%,a%,b%,c%) STATIC'lI
SHARED K() 'lI
I => Compute XYZ-coordinates for Sphere from factors a,b,c'lI
Px=K(n%,1,D)+a%*K(n%,2,O)'lI
Py=K(n%,1,1)+b%*K(n%,2,O)'lI
Pz~K(n%,1,2)+c%*K(n%,2,O)'lI
END SUB'lI
''lI
SUB Disttest(x,y,z) STATIC'lI
SHARED QX,Qy,Qz,MinDist'lI
• => Compute distance (x,y,z) froml ight source'lI
D~SQR( (x-Qx)A2+(y-Qy)A2+(z-QZ)A2) pythagoream theorem'lI
IF MinDist<D THEN'lI
MinDist=D'lI
ELSE'll
IF D<MinDist THEN MinDist=D'lI
END IF'l!
END SUB'll
''lI
SUB Arctan (Pw,xl,yl,x2,y2) STATIC'lI
SHARED Pi,Pd2'll
, Determine pw=arctan((yl-y2)/(xl-x2))'lI
IF xl=x2 THEN'lI
Hw=SGN(yl-y2)*Pd2'l!
ELSE'lI
Hw=AT~( (yl-y2) I (xl-x2) )'!l
263
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
IF xl<x2 THEt;'lI
IF Hw>~O THEN'll
Hw=Hw-pj'll
ELSE'lI
Hw~HwtPi 'll
END IF'll
END IF'll
END IF'll
Pw=Hw'll
END SUB'll
"1I
SUR Calcablq (Pa, Pb, Aioe:, Bi nc, x, y, z) STATIC'll
SHm*:D Qx,Qy,Qz'll
, => a,b = Polar coordinales of light source'lI
, p.a=anglel in XY-plane, pb is vertical'll
CALL Arctan(Ha,y,z,Qy,Qz)g
CALL Arctan(Hb,x,z,Qx,Qz)'ll
CALL Normall',ngle (Pa, HatAinc) 'll
CALL Nonc.alAngle (Pb, Hb+Binc) 'll
END SUB'lI
"II
''ll
SUB t-Imlq3TE'st (n%,x1%,yl%,zl%,x2%,y2%,z2%,x3%,y3%,z3%) STATIC'lI
SHARED Trlle, False, Pi, AMi n, i3Min,AMax, GMax, Ainc, Bine, MinDist en.
I ::::> Determine min t~nd max of a and b<J1
D'.::! ~:,True<J[
'll
RcpeatA:'II
CALL GFTxyzlg(x,y,z,n%,xl%,yl%,zl%)'ll
CALL Disttcst(x,y,z)'II
CALL Calc:a:)]q(Al,I3l ,Ainc,Binc,x,y,z)'lI
<II
CALL Deltasum3(a,Al,A2,A3)'lI
IF a>Pi THEN'il
, => Light source Iwithirl'triangle<Jj
lIMin=-Pi'li
A!V1ri.x--PllI
Ainc~Pi'il
o~~=True<fl
ELSE'lI
IF Al <A,~in THEN AMin Al'lI
IF A2<A,Min THEN A,Min A2'll
IF A3<A,Mjn TIlEN AMin A3'll
'll
IF A:>l\Max THEN AMax AI'll
IF A;/>A,Max THEN l\;-1ax A2'l1
IF 1,3>A,Max THEt' AMax rd'll
'll
IF (A,Mdx-AMin>=P: ) AND (Ainc~O) THEN'll
Ainc-::? i qr
ck~ Falsp'll
264
ABACUS ApPENDIX B- THE TRACER PROGRA\I
ELSE'lI
ok!~True'lI
END IF'lI
END IF'lI
CA~L Dellasum3(b,Bl,B2,J33)'ll
'll
IF b>Pi THEWlI
I => ~ight source lwithin l trianglc1c
BMin=-Pi'll
BMax=Pi'lI
Binc=Pi'll
ELSE'lI
IF Bl<BMin THEN BMin Bl'll
IF B2<BMin THEN BMin B2'lI
IF B3<BMin THEN BMin B3'1[
'lI
IF Bl>BMax THEN BMax Bl'l[
IF B2>BMax THEN BMax B2'1[
IF B3>BMax THEN BMax B3'1[
'I[
iF (BMax-BMin>=Pi) AND (BinccO) THEN'I[
Binc=Pi'll
ok!=False'll
END IF'lI
END IF'I[
'IT
IF ok' <> True GOTO RepeatA'Il
E;;[) SUB'lI
S:J13 ~1ml(J4Tes t ("%, xl%, yl%, z1%, x2 %, y2%, z2%, x3%, y 3%, z3%, xH, y4 %, 24 %) STA"::; C~[
SHARED True, False, Pi, Ainc, Bine, AMax, i3Max, AMin, BMi:i, Mi nDist S:
, => Determine min and max of a and b 'll
ok' ='l';-ue'lI
'lI
RC'peatB:'ll
CALL GETxyzlq (x, y, z, n%, xl%, yl'li, 21%) 'll
CALL Disttest(x,y,z)'l[
CALL Calcablq(Al,Bl,Ainc,Binc,x,y,z)'lI
CALL GETxyzlq(x,y,z,n%,x2%,y2%,?2%)'l[
CALL Disttest(x,y,z)'lI
CALL C.11cablq(A2,B2,Ainc,Binc,x,y,z)S
'lI
CALL GETxyzlq(x,y,z,n%,x3%,y3%,z3%)'lI
CALL Disttest(x,y,z)'I[
CALL Calcablq(A3,B3,Ainc,Binc,x,y,z)'I[
CALL GETxyzlq(x,y,z,n%,x4%,y4%,z4%)'ll
CALL Disttest(x,y,z)'ll
CALL Calcablq(A4,B4,Ainc,Binc,x,y,z)'lI
'll
CALL Deltasum4 (a,Al,A2,A3,A4)'ll
'll
IF o1>Pi Tf!:':,'11
, => Light source 'within' triangle'll
AM:n=-Pi'1L
r·.Max=P i. 'lI
Ainc=Pi'l[
ok! =Tr\Jc<U
265
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMI:-JG
ELSE'll
IF Al<AMin THEN AMin = Al'll
IF A2<AMin THEN AMin = A2'll
IF A3<AMin THEN AMin = A3'll
IF A4<AMin THEN AMin = A4'll
'll
IF Al>AMax THEN AMax = Al'll
IF A2>AMax THEN AMax = A2'll
IF A3>AMax THEN AMax = A3'll
IF A4>AMax THEN AMax = A4'll
'II
IF (AMax -AMi n>=P i) AND (Ainc=O) THEN'll
Ainc=Pi'll
ok!=False'll
ELSE'll
ok!=True'll
END IF'll
END IF'll
'II
CALL Deltasum4(b,Bl,B2,B3,B4)'ll
'I!
IF b>Pi THEN'll
, => Light source Iwithin' triangle'll
BMin=-Pi'll
BMax=Pi'll
Binc=Pi'll
ELSE'lI
IF Bl<BMin THEN BMin Bl'll
IF B2<BMin THEN BMin B2'll
IF B3<BMin THEN BMin B3'll
IF B4<BMin THEN BMin B4'll
'll
IF Bl>BMax THEN BMax BI'll
IF B2>BMax THEN BMax B2'll
IF B3>BMax THEN BtJiax B31I
IF B4>BMax THEN BMax B4'll
'II
IF (BMax-BMin>=P i) AND (Binc=O) THEN'll
Binc=Pi'll
ok!=False'll
END IF'll
END IF'll
IF ok' <> True GOTO RepeatB'll
END SUB'll
"II
SUB MJrJqKTest (n%, xl %, yl %, zl %, x2%, y2%, z2%, x3%, 1'3%, z3%, x4%, yL; %,7.:4%) S'I'ATICSl
SHARED True,False,Ainc,Binc,Pi,AMin,AMax,BMin,BMax,MinDisc'll
, => Determine min and max of a and b'll
ok'=True'll
'll
RepeatC:'ll
CALL GETxyzlqk(x,y,z,n%,xl%,yl%,zl%)'ll
CALL Disttest(x,y,z)'ll
CALL Calcablq(Al,Bl,Ainc,Binc,x,y,z)'ll
'II
CALL GETxyzlqk(x,y,z,n%,x2%,y2%,z2%)'ll
CALL Disttest(x,y,z)'ll
CALL Calcablq(A2,B2,Ainc,Binc,x,y,z)'ll
'll
CALL GETxyzlqk(x,y,z,n%,x3%,y3%,z3%)'ll
266
ABACUS ApPENDIX B- THE TRACER PROGRAM
CALL Deltasum4(a,Al,A2,A3,A4)'ll
IF a>Pi THEN'
, => Light source 'within' triangle'
AMin=-Pi'll
AMax=pi'll
Ainc=Pi'll
ok! =True'll
ELSE'
IF AI<AMin THEN AMin AI'll
IF A2<AMin THEN AMin A2'll
IF A3<AMin THEN AMin A3'll
IF A4<AMin THEN AMin A4'll
'J[
IF Al>AMax THEN AMax AI'll
IF A2>AMax THEN AMax A2'll
IF A3>AMax THEN AMax = A3'll
IF A4>AMax THEN AMax A4'll
'll
IF (AMax-AMin>=P i) AND (Ainc=O) THEN'll
Ainc=Pi'll
ok '=False'll
ELSE'
ok!=True'll
END IF'
, END IF~
267
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
'"
SUB MmlqEllipsoid(n%) STATIC'll
CALL Mmlq4Test (n%, -1, -1, -1, -1,1,-1, 1, 1, -1, 1, -1,-1) ~
CALL Mmlq4Test(n%,-1,-I,-1,-1,1,-1,-1,1,1,-1,-1,1)'11
CALL Mrnlq4Test(n%,-1,1,-1,1,1,--1,1,1,1,-1,1,1)'ll
CALL Mmlq4Test(n%,1,1,-1,1,-1,-1,1,-1,1,1,1,1)~
CALL Mmlq4Test(n%,l,-1,-l,-1,-},-1,-l,-1,1,1,-l,l)S
CALL Mmlq4Test(n%,-1,-1,1,-1,1,1,1,1,1,1,-1,1)'ll
END SUB'll
''ji
InitMinmaxLq:"
I ==-> Compute surface inter-val for shadow computati on in rc~lar (:'c~ord i r::-1Le;;qr
, a ~ angle of X-Axis, b c angle of Y-Axis, mindist minimum distcance t.O 1 iqht
source"
EHASE minmaxlq'll
DIM minmaxlq(NumberK, 6)'11
268
ABACUS ApPENDIX B- THE TRACER PROGRAM
'II
IF K(n%,O,O)~l THEN'll
CALL Mmlq3Test(n%,0,O,0,0,1,0,1,0,0)'ll
END IF'll
IF K(n%,0,0)~2 THEN'll
CALL Mmlq4Test (n%, 0, 0,0,0,1,0,1,0,0,1,1,0) 'II
END IF'll
'II
IF (K(n%,0,O»~3) AND (K(n%,O,0)<6) THEN'll
CALL Mmlq4Test(n%,-1,-1,0,-1,1,0,1,-1,0,1,1,O)'ll
END IF'll
'II
IF K(n%,O,O)~lO THEN'll
CALL MmlqShpere(n%)'II
END IF'll
'II
IF (K(n%,O,0)~20) OR (K(n%,0,0)=21) THEN'll
CALL MmlqCylinder(n%)'ll
END IF'll
'II
IF K(n%,0,0)~22 THEN'll
CALL MmlqCone(n%)'ll
END IF'll
'II
IF K(n%,0,0)~24 THEN~
CALL MmlqEllipsoid(n%)'II
END IF'll
'lI
minmaxlq(n%,O)~Ainc'll
minmaxlq(n%,l)~AMin'll
minmaxlq(n%,2)~AMax'll
minmaxlq(n%,3)~Binc'll
minmaxlq(n%,4)~BMin'll
minmaxlq(n%,5)~BMax'll
minmaxlq(n%,6)~MinDist'll
NEXT n%'ll
RETURN'll
'END of SHADOW-INIT.asc'll
269
ApPEl'OIX B - THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
'START of SHADOWING.ASC~
"ll
*********************************~
* Shadowing *~
*********************************~
'~
SUB IntersectpointPlane(n%,Px,Py,Pz,Rx,Ry,Rz,l) STATIC~
SHAPED Help() ,K() 'll
, C"> 1 ~ exact parametcr~
D~Ry*Help(n%,4)-Rx*Help(n%,3)-Rz*Help(n%,5)~
IF D<>O THEN~
1=( (Px-K(n%, 1,O))*He1p(n%,3)-(Py-K(n%,1,1))*He1p(n%,4)+(Pz-
K (n%, 1, 2)) *He1p (n%, 5)) /D~
ELSE'll
1~-1'll
END IF'll
END SUB'll
I'll
SUB IntersectpointTriangle(n%,Px,Py,Pz,Rx,Ry,Rz,1,a,b) STATIC'll
SHARED Help() ,K()'ll
, -> 1 ~ exact parameter, a,b ~ area parameter'll
D~Ry*Help(n%,4)-Rx*He1p(n%,3)-Rz*He1p(n%,5)'ll
IF D<>O THEN'll
1~( (Px-K(n%,1,0))*He1p(n%,3)-(Py-K(n%,1,1))*He1p(n%,4)+(Pz-
K(n%,1,2))*Help(n%,S))/D'll
IF 1>0 THEN'll
a~FN Det(Px-K(n%,1,0),K(n%,3,0),-Ex,Py-K(n%,I,I),K(n%,3,1),-Ry,Pz-
K in%, 1,2), K (n%, 3, 2), -Rz) /D'll
b~FN Det(K(n%,2,0) ,Px-K(n%,1,0),-Rx,K(n%,2,1) ,Py-K(n%,1,1),-Ry,K(n%,2,2),Pz-
K(n%,1,2) ,-Ez)/D~
IF a<O OR b<O OR a>l OR b>1 OR a+b>1 THEN'll
1~-1'll
END IF~
END IF'll
ELSE'll
1~-1'll
END IF'll
END SUB'll
I'll
SuB IntersectpointEectangle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b) STATIC'll
SHARED HelpO ,K()'ll
, => 1 ~ exact parameter, a,b ~ area parameter'll
D~Ry*Help(n%,4)-Ex*Help(n%,3)-Rz*Help(n%,5)~
IF D<>O THEN~
1 ~ ( (Px-K (n%, 1,0) ) *He1p (n%, 3) - (Py-K (n%, 1,1) ) *Hel p (n%, 4) + (pz-
K(n%,1,2))*Help(n%,5))/D'll
IF 1>0 THEN'll
a~FN Det(Px-K(n%, 1,0) ,K(~%,3,0) ,-Rx,Py-K(n%,1,1),K(n%,3,1),-Ry,Pz-
K(n%,1,2),K(n%,3,2),-Rz)/D'll
b=FN Det (K (n%, 2, 0) ,Px-K (n%, 1, 0), -Rx, K (n%, 2, 1) ,Py-K (n%, 1, 1), -Ry, K (n%, 2, 2) ,Pz-
K(n%,], 2), -Rz) ID'll
~
IF a<O OR b<O OR a>1 OR b>1 THEN'll
270
ABACUS ApPENDIX B- TilE TRACER PROG RA:\I
1 ~-l'll
END IF'll
END IF'll
E:,SE'll
1=-1'll
E~") IF'll
END SUB'll
''ll
SUB I nt:.ersectpoi nt.Ci rcle (n %, Px ?y, pz Hx, Ry Rz, 1, d, b)
I I I STI-\T.: :':':(TI
Si-iARED help () ,K () 'II
I => 1 --': : exact pardrneter, a, b = area parameterqr
D"Ry*Help (n%, 4) -Rx*Help (n%, 3 1-llz*Help (n%, 51 'lI
IF D<>O THEN'll
1= ( (Px-K (n%, 1,0)) ~Help (n%, 3) - (Py-K (n%, 1,1)) *Help (n%, 4) + ( h -
K(n%,1,2))*Help(n%,S))/D!
IF 1>0 TliEN'II
a~FN Det (Px-K (n%, 1, 0) ,K (n%, 3, 0), -Rx, Py-K (n%, 1, 1) ,K (n%, 3, i) ,-Ey, pz-
K(n%,1,2),K(n%,3,2),-Rz)/D'lI
b=FN LJfCt (K (n%, 2, 01 ,Px-K (n %, 1,0) , -Ex, K (n%, 2, 1) ,Py-]'C ([1%,1, 11 , -Hy, F Ire %, 2, ;: ) , p z-
K(n%,1,2),-Rz)/D'll
q1
IF a'~Tb*b>l THEN'll
1= -l'll
END IF'll
END IFc:.
ELSI<'l[
l=-l'll
END IF'ii
END SUB'll
''ll
"IT
SUB AngleInLervaJl (l, n%, a, b) STATIC'll
SHARED Pi,Pm2,Pd2,K()'ll
IF a=O THEN'll
D=Pd2*SCN (bl 'iI
ELSE'll
D~ATN(b/a)'ll
IF a<O TIIEN'll
D = D+Pi'l[
END IF'll
END US
IF ~;<O TilE\'ll
]) = DcPm2'll
E:-JD IF'll
n !l<K(n%,'c,O) OF D>K(n%,5,11 ';'HENS
l-l'll
END IF'll
END SUB'll
''II
''ll
SUB Jntersectpoir~tCi [cleSector (n%, Px, Py , P z, Rx, Ry, R7, ) , a, b) STAT r C'll
SHAlze:;; Help(I,K()1i
1 => 1 = exacL parameter, a,b =- area par0..meter-91
D=Ry*fic1p(n%,4)-Ex*Hclp(r;%,3)-Rz'Help(c<%,5)'II
IF D<>O r ,:::,N'Il
1= ( (Px-K (n%, 1,0) ) *fie.i.p (n%, 3) - (Py-K (re%, 1,1) ) *tlelp (n%, 4) ~ (r 7-
K(n%,1,2))*Help(n%,5))/D'IL
IF l>C TiiEN'lI
a=-Fr~ Det (Px -K (n%, l, :::;} , K (:-It I 3, 0) , -~ I Pl'-K (n%, "---, : ) , K (n%, 3, 1.) , -Ry f ? z-
K(n%,1,2),K(n%,3,2),-Rz)/D'll
271
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
b=FN Det (K (n%, 2, 0) ,Px-K (n%, 1,0), -Rx,K (n%, 2, 1) ,Py-K (n%, 1,:) ,-Ry, K (n%, 2, 2) ,Pz-
K(n%,1,2),-Rz)/D~
~
IF a*a+b*b<=l THEN'll
CALL Ang1eIntcrva11(1,n%,a,b)'ll
ELSE'll
l=-n
END IF'll
END IF'll
ELSE'll
1=-1'll
END IF'll
END SUB'll
''ll
SUB IntersectpointCirc1eRing(n%,Px,Py,Pz,Rx,Ry,Rz, l,a,b) STAT1C~
SHARED He1p() ,K()'ll
, => 1 = exact parameter, a,b = area parameter'll
D=Ry*Help(n%,4)-Rx*He1p(n%,3)-Rz*Help(n%,S)'ll
IF D<>O THEN'll
1=( (Px-K(n%,1,0))*Help(n%,3)-(Py-K(n%,1,1))*He1p(n%,4)+(Pz-
K(n%, 1,2)) *Help(n%,5) )/D'll
IF 1>0 THEN'll
a=FN Det(Px-K(n%,1,0),K(n%,3,0),-Rx,Py-K(n%,1,1) ,K(n%,3,1),-Ry,Pz-
K(n%,1,2),K(n%,3,2),-Rz)/D'lI
b=FN Det(K(n%,2,0) ,Px-K(n%,1,C),-Rx,K(n%,2,1),Py-K(n%,1,1),-Ry,K(n%,2,2) ,Pz-
K(n%,1,2),-Rz)/D'll
'll
D=SQR(a*a+b*b)'lI
IF (D>=K(n%,4,0)) AND (D<=K(n%,4,1)) THFN'lI
CALL AngleInterva11(1,n%,a,b)'lI
ELSE'll
l=-l~
END IF~
END IF'll
ELSE'll
1=-1'll
END IF'll
END SUB'll
''ll
SUB IntersectpointSphere(n%,Px,Py,Pz,Rx,Ry,Rz,l) STATIC'll
SHARED Help () ,K () ,Threshold'll
, => 1 = exact parameter'll
D=Rx*Rx+Ry*Ry+Rz*Rz'lI
p=(Rx*(Px-K(n%,:,0))+Ry*(Py-K(n%,1,1))+Rz*(Pz-K(n%,1,2)) )/D'll
q= ( (Px- K (n%, 1, 0) ) 2+ (Py-K (n%, 1,1) ) 2+ (pz- K (n%, 1,2) ) 2-K (n%, 2, 0) *K (;, %,2, 0) ) / D'li
A A A
D=p*p-q'll
IF D>=O THEN~
l=-p+SQR(D)'lI
Ll=-p-SQR(D)~
IF (Ll<l) AND (Ll>Threshold) THEN'll
SWAP I,Ll'll
END IF'll
ELSE'll
1=-1'll
END IF'll
END SUB'll
''ll
''ll
SUB Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,Original!) STATIC'li
SHARED Help() ,K()'ll
272
ABACUS ApPENDIX B- THE TRACER PROGRAM
273
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPlIIC PROGRAMMING
p~(Pxt*Xt+Pyt*Yt)/D~
q=(Pxt*Pxt+Pyt*Pyt-l)/D~
D=p*p-q~
IF D>~O THEN~
l~-p+SQR(D)~
Ll~-p-SQR(D)~
c~Pzt+l*Zt~
Cl=Pzt+L1*Zt~
IF c>=O AND c<~l THEN'll
CALL AngleIntorva1l(1,n%,Pxt+l*Xt,Pyt+1*Yt)~
ELSE~
1~-1~
END IF~
IF Cl>~O AND Cl<=l "HEN'll
CALL Ang1elntervall(Ll,n%,Pxt+Ll*Xt,Pyt+Ll*Yt)~
ELSE'll
Ll=-l'l!
END 1?'l[
IF (1<-.5) OR (Ll<l AND Ll>Threshold) THEN'll
SWAP :, Ll'll
SWAP c, Cl 'll
END IF'll
a=Pxt+l*Xt'll
b=Pyt+l*Yt'll
ELSE'll
1=-1'll
END IF'll
ELSE'll
1=-l'lI
END IF'll
END SUB'll
''ll
SUB IntersectpointCone(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Origina1') STATIC'll
SHARED Threshold~
I => l=-=-exdct parameter, a!b!c = transform Intersect point coordinates<Jl
CALL Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,Origina1')'ll
D=Xt*Xt+Yt*Yt-Zt*Zt~
IF D<>O THEN'll
p=(Pxt*Xt+Pyt*Yt+Zt*(l-Pzt))/O'll
q=(Pxt*Pxt+Pyt*Pyt-(1-Pzt)A2)/D~
D=p*p-q~
IF D>=O THEN'/!
l~-p+SQR(D)~
Ll=-p-SQR (D) ,
CC'Pzt+l*zt'll
D=Pzt+Ll*Zt~
IF Ll<l AND Ll>Threshold AND 0>=0 AND 0<=1 THEN'
SWAP 1, Ll ,
SWAP c,O'll
END IF'll
IF c<O OR 0>1 THEN'll
1=-1'll
ELSE'll
a=Pxt+l*Xt'll
b=Pyt+1*Yt'll
END IF'll
ELSE'll
1=-1'lI
END IF'll
ELSE'll
274
ABACUS ApPENDIX B- TilE TRACER PROG RAM
l~-l'll
END IF'll
END SUB'll
"IT
SUB Intersec~pointEllipsoid (n%, Px, Py, Pz, Rx, Ry, Rz, l, a, b, c, ~;r; eli :1031 ') S'lATIC'i:
SHARED Threshold'll
, :::=> l::::;exact parameter I a, b , C ;:::: t .:::-ans form Intersect poi nl cc)u,;:-dinatesqI
CALL Basi strans (n%, Pxt, i'yt, Pzt, Xt, Yt, Zt, Px, Py, ?2, Rx, Ry, Rz, Oriqi nell' ) ,
D=Xt*Xt+Yt*Yt+Zt*Zt'lI
IF D<>O THEN'll
p=(Pxt*Xt+Pyt*Yt+Pzt*Zt)!D'll
q=(Pxt*Pxt+Pyt*Pyt+Pzt*Pzt-l)!D'll
D=p*p-q'll
IF D>=O THEN'lI
l=-p+SQR(D)'ll
Ll=-p-SQR(D)'ll
IF Ll<l AND Ll>Threshold THEN'll
SWAP l,Ll'll
END IF'll
a=Pxt+l"Xt'lI
b=Pyt+l*Yt'll
c=Pzt+l*Zt'll
ELSE'll
l=-l'll
END IF'll
ELSE'll
l=-l'll
END IF'll
END SUB'll
''ll
''ll
SUB WhichBody (Kp%,Px,Py,Pz,Rx,Ry,Rz,Original!,Shadown') STATIC'll
SHA.'<.ED
True, False, minmax% () ,NumberK, minmax: q () ,Help () ,K () ,xb%, yb%, Sx, Sy, Sz, Body%, Ac, Bc, Ce,
la,Threshold'll
, => Body% = Nr the body under coordinates xb%,j'o%, S(sx,sy,sz)< poin~ ,
la=intersection line'll
, => if Typ>=20: (ac, bc, cc) = tra1csform Intersect point dinaces'll
la=-l'll
Body%=O'll
'll
IF Shadown! = True THEN 'll
CALL Calcablq(Anglea,Angleb,O!,O!,i'x,Py,Pz)'ll
Dist=SQR(Rx*Rx+Ry*Ry+Rz*Rz)'ll
END IF'll
'll
FOR n%=l TO NumberK'll
IF Original! = Tr~e THEN'll
IF minmax%(n%,O»xb% THEN'll
GOTO Nxtk'll
END IF'll
IF minmax%(n%,l»yb% THEN'll
GOTO Nxtk'll
END IF'll
IF minmax%(n%,2) <xb% THE~'ll
GOTO Nxtk'll
END IF'll
IF minmax%(n%,3)<yb% THEN'll
GOTO Nxlk'll
END IF'll
275
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END IF'l[
'll
IF Shadown! ~ True THEN'll
CALL NormalAng1e(Wa,Ang1ea+minmaxlq(n%,O»'l!
CALL NormalAngle(Wb,Ang1eb+minmaxlq(n%,3»)'l!
IF Wa<minmaxlq(n%,l) THEN'l!
GOTO Nxtk'l!
END IF'l!
IF Wa>minmaxlq(n%,2) TPEN'l!
GOTO Nxtk'll
END IF'll
IF Wb<minmaxlq(n%,4) THEN'll
GOTO Nxtk'll
END IF'll
IF Wb>~inmaxlq(n%,5) THEN'll
GOTO Nxtk'll
END IF'l!
IF Dist<minmaxlq (n%, 6) THEN'll
GOTO Nxtk'l!
END IF'l!
END IF'l!
'II
IF K(n%,O,O)~O THEN'l!
CALL IntersectpointPlane(n%,Px,Py,Pz,Rx,Ry,Rz,l)'l!
GOTO Wkok'l[
END IF'll
IF K(n%,O,O)~l THEN'l[
CALL IntersectpointTriangle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'11
GOTO Wkok'll
END IF'll
IF K(n%,O,O)~2 THEN'll
CALL IntersectpointRectang1e(n%,Px,Py,Pz,Rx,Ry,Rz,1,a,b)'II
GOTO Wkok'l!
END IF'll
IF KCn%,O,O)-J THENi
CALL IntersectpointCircle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'11
GOTO Wkok'll
END IF'll
IF K(n%,O,O)~4 THEN'll
CALL IntersectpointCirc1eSector(n%,Px,Py,Pz,Rx,Ry,Rz,1,a,b)'II
GOTO Wkok'll
END IF'll
IF K(n%,O,O)~5 THEN'l[
CALL IntersectpointCircleRing(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b)'l[
GOTO Wkok'll
END IF'll
IF K(n%,O,O)~10 THEN'll
CALL IntersectpointSphere(n%,Px,Py,Pz,Rx,Ry,Rz, 1)'11
GOTO Wkok'll
END IF'll
IF K(n%,O,O)=20 THEN'll
CALL IntersectpointCylinder(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Original!)'11
GOTO Wkok'll
END IF'l[
IF K(n%,O,O)=21 THEN'll
CALL IntersectpointCylinderSegm(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Origina1!)'l!
GOTO Wkok'l!
END IF'll
IF K(n%,O,O)=22 THEN'l[
CALL IntersectpointCone(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Original!)'l[
276
ABACUS ApPENDIX B- TilE TRACER PROGRAM
GOTO wkok'll
END IF'll
IF K(n%,O,O)=24 THEN'll
CALL IntersectpointEllipsoid(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Original')~
END IF'll
Wkok:'ll
, Work OK''ll
~
IF (l>Threshold) AND (la<=O OR l<la) AND (n%<>Kp% OR K(n%,O,O»=18) THEN'lI
la=l'll
Body%=n%'ll
IF K(n%,O,O»=20 AND Kp%=O THEN'll
Ac=a'll
Bc=b'll
Cc=c'lI
END IF'll
END IF'll
Nxtk:'ll
, Next body'll
NEXT n%'ll
'll
IF Body%>O AND Kp%=O THEN'll
Sx=Px+ 1a *Rx~
Sy=Py+la*Ry'lI
Sz=Pz+la*Rz~
END IF 'lI
END SUB'll
''ll
''ll
SUB SetBrightness(n%,Px,Py,Pz,Mirror,Original!) STATIC'll
SHARED Help(),K(),Mat() ,Qx,Qy,Qz,Ac,Bc,Cc,Sx,Sy,Sz,Nx,Ny,Nz,Nl,Spx,Spy,Spz,Bright
'll
, => Bright=Brightness, SP=Mirror Vector, Mirror=Inlensity of LQ-Mirroring'lI
'll
IF K(n%,O,O)<=9 THEN'll
, Determine Mirror Vektor SP'lI
Nx=Help(n%,O)'ll
Ny=Help(n%,l)'ll
Nz=Help(n%,2)'ll
IF Original!<>True THEN'll
IF FN CosinAngle(Nx,Ny,Nz,Px-Sx,Py-Sy,Pz-Sz)<0 THEN'll
'Normal vector must point to projection point''lI
Nx=-Nx'll
Ny=-Ny'lI
Nz=-Nz'lI
END IF'll
END IF'lI
Dqe~Nx*(Qx-Sx)+Ny*(Qy-Sy)+Nz*(Qz-Sz)'ll
'll
Spx=Sx-Qx+2*Dqe*Nx'll
Spy=Sy-Qy+2*Dqe*Ny'll
Spz=Sz-Qz+2*Dqe*Nz'll
'll
Mirror=FN CosinAngle(Spx,Spy,Spz,Px-Sx,Py-Sy,Pz-Sz)'ll
~
IF Mirror<O THEN'lI
Mirror=O'll
END IF'lI
'lI
Bright=FN CosinAngle(Nx,Ny,Nz,Qx-Sx,Qy-Sy,Qz-Sz)'lI
277
ApPENDIX B- TilE TRACER PROGRA:\I AMIGA 3D GRAPIlIC PROGRAMMING
ELSE'!!
, uetermine mirror vector SPTt
IF K(n%,O,O)=lO THEN'!!
Nx=Sx-K(n%,l,O)'!!
Ny=Sy-K(n%,l,l)'!!
Nz~Sz-K(n%,1,2)'!!
END IF'!!
'll
IF K(n%,O,O»=20 AND K(n%,O,O)<24 THEN'!!
Nx=Help(n%,4)*Ac+Help(n%,1)*Bc'll
Ny=Help(n%,S)*Ac+Help(n%,2)*Bc'll
Nz=Hclp(n%,6)*Ac+Help(n%,3)*Bc'll
IF K(n%,O,O»=22 THEN'll
Nl=SQR(Nx*Nx+Ny*Ny+Nz*Nz)'ll
IF Nl<>O THEN'!!
a= (Ac*K (n%, 2, 0) t 3c*K (n%, 3,0) ) '2'll
a=a+(Ac*K(n%,2,1)+Bc*K(n%,3,1) )'2'll
a=(SQR(d+(Ac*K(n%,2,2)+Bc*K(n%,3,2))A2))/Nl'll
Nx - Nx*a,!!
Ny = Ny*a'll
Nz = N?*a<Jl
b=SQR (Nx*Nx+NY'Ny+Nz*~:?) /Help (nt, 7) '!!
Nx=K(n%,4,O)*b+Nx/b'll
Ny~K(n%,4,1)*b+Ny/b'll
Nz=K(n%,4,2)*b+Nz/b'll
SLSE'll
, If a cone angle:,!!
Nx=K(n%,4,O)'ll
Ny=K(n%,4,I)S
Nz=K(n%,4,2)'ll
END IFCft
END IF'll
END I?'11
IF K(n%,O,O»=24 THEN'll
Nx=Ac*Hclp(n%,l) +Bc*Help(n%,4) +Cc*Help(n%,7)'ll
Ny~Ac*Help(n%,2)+Bc*Help(n%,S)+Cc*Help(n%,8)'11
Nz=Ac*Help(n%,3)+Bc*Help(n%,6)+Cc*Help(n%,9)'ll
END IF'll
'll
IF FN CosinAnqle(Nx,Ny,Nz,Px-Sx,Py-Sy,Pz-Sz)<0 THEN'll
, => Normal vector points to projection point'll
NF-Nx'll
Ny=-Ny'll
Nz=-Nz'iI
END :F'll
Nl=SQR(Nx*Nx+Ny*Ny+Nz*Nz)'ll
Nx Nx/Nl'll
Ny Ny/Nl'll
Nz - Nz/Nl'll
c
Dge=Nx* (Ox-Sx) +Ny* (Qy-Sy) +Nz* (Q7-57) 'll
Spx-Sx-Qx+7*Dqe*Nx~
Spy=Sy-Qy+2*Dgc*Ny'll
Spz=Sz-Qz+2*Dqe*Nz'll
'lI
Mirror=FN CosinAngle(Spx,Spy,Spz,Px-Sx,Py-Sy,Pz-Sz)'ll
II
278
ABACUS ApPENDIX n- TilE TRACER PROGRAM
IF Mirror<O THEN~
Mirror=O~
END IF~
~
Bright=FN CosinAngle(Nx,Ny,Nz,Qx-Sx,Qy-Sy,Qz-Sz)~
END IF~
IF Mat(K(n%,O,2),4»O THEN~
Mirror=1.5*MirrorA(30*Mat(K(n%,O,2),4))~
END IF~
END SUB~
'~
.~
POKE RastPort&+29,4~
• RastPort->AreaPtSz ~ 4 (=> 4A2 = 16)~
~
CALL RectFill &(RastPort&, x1%, yl 't, x2%, y2%) ~
END SUB ~
'~
SUB ExtendedFill (xl %, yl %, x2%, y2%, Bright, Brightl, Bright2, Co 11 ,Co12%) ST1\T~:::~
SHARED NumberPatternX%,PatternHX() ,PatternX&,RastPort& <;i
, draw rectangle in standard fill pattern~
• binary search for optimal pattern ~
m=(Bright-Brightl)/(Bright2-Brightl)~
Min=IE+35~
Nr%=O~
Ug%=O 'top limit~
Og%=NumberPatternX%*2 '~ower limit~
Repeat3:~
Mitte%=INT«Ug%+Og%)/2)~
IF ABS(m-Pat.ternHX(Mitte%)) <Min THEN~
Min=ABS(m-PatternHX(Mittc%))~
Nr%=Mitte%~
END IF~
IF m>PatternHX(Mitte%) THEN~
Ug%=Mitte%+l~
ELSE~
279
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
Og%=Mitte%-I'l[
END IF'll
IF (Ug%<=Og%) AND (Min<>O) THEN GOTO Repeat3'l[
'll
CALL SetAPen&(RastPort&,Coll%)'ll
CALL SetBPen&(RastPort&,Co12%)'ll
'll
POKEL RastPort&+8, (PatternX&+Nr%*32) 's.o. 'll
POKE RastPort&+29,4'l[
'II
CALL RectFill& (RastPort&,xl%,yl%,x2%,y2%) 'II
END SUB'll
''ll
SUB SetPoint (xl %, yl%, x2%, y2%, Bright. r, Bright.g, Bright. b) STATIC'll
SHARED MaxColour%,Colour(),RasterHI%,RasterWI%,RastPort&'ll
SHARED NumberPatternX%,PatternX&,PatternHX()'l[
IF x2%>RasterWl% THEN x2%=RasterWI%'l[
IF y2%>RasterHl% THEN y2%=RasterHl%'l[
'II
'search colors for simialr color tone:'lI
'll
Min=lE+IO'l[
Nrl%=I'lI
'll
'Convert colors to Polar coordinates:'ll
'll
dh=SQR(Bright.r*Bright.r+Bright.g*Bright.g)'ll
IF dh>O THEN'll
IF Bright.r>O THEN'll
ah=ATN(Bright.g/Bright.r)'ll
ELSE'll
ah=l. 570B'll
END IF'll
bh=ATN(Bright.b/dh)'ll
dh=SQR(dh*dh+Bright.b*Bright.b)'l[
ELSE'll
a=.7854'll
IF Colour(n%,3)=0 THEN'll
b=.7854'lI
ELSE'll
b=1. 5708'll
END IF'll
END IF'll
'll
'search for optimim colors:'ll
'll
FOR n%=l TO MaxColour%'l[
D=SQR(Colour(n%,I)A2+Colour(n%,2)A2)'ll
IF D>O THEN'll
IF Colour(n%,l»O THEN'll
a=ATN(Colour(n%,2)!Colour(n%,I))'ll
ELSE'll
a=l. 5708'll
END IF'll
b=ATN(Colour(n%,3)!D)'l[
D=SQR(D*D+Colour(n%,3)*Colour(n%,3))'ll
ELSE'll
a=.7854'lI
IF Colour(n%,3)=O THEN'lI
b=.7854'l[
280
ABACUS ApPENDIX B- THE TRACER PROGRAM
ELSE'll
b~l. 5708'll
END IF'll
END IF'll
h~(a-ah)A2+(b-bh)A2+ABS(D-dh)'ll
IF h<Min THEN'll
Min~h'll
Nrl %=n%'ll
END IF'll
NEXT n%'ll
'Il
'Determine best pattern and second color for color combination'll
Min=lE+lO'll
NrM%=O'll
Nr2%=1'll
FOR n%~O TO NumberPatternX%'ll
FOR Nr%~O TO MaxColour%'ll
IF Nr%<>Nrl% THEN'll
h.r~PatternHX(n%)*Colour(Nrl%,l)+(l-Patternl~(n%))*Colour(N~%,l)'lI
h.g~PaLLernHX(n%)*Colour(Nrl%,2)+(1-PatternHX(n%))*Colour (Nr%,2)'ll
h.b~PatternHX(n%)*Colour(Nrl%,3)+(1-PatternHX(n%))*Colour(Nr%,3)'ll
h~(Bright.r-h.r)A2+(Bright.g-h.g)A2+(Bright.b-h.b)A2'll
IF h<Min THEN'll
Min~h'lI
NrM%~n%'lI
Nr2%-Nr%'ll
END IF'l[
h. r~PatternHX (n%) *Colour (Nr%, 1) + (l-PatternflX (n%) ) *Colour (Nrl %,1) 'lI
h.g=PatternHX(n%)*Colour(Nr%,2)+ (1-PatternHX(n%))*Colour(Nrl%,2)'ll
h.b-PatternHX(n%) *Colour(Nr%,3) + (l-PatternHX(n%))*Colour (Nrl%,3)'ll
h~(Bright.r-h.r)A2'(Bright.g-h.g)A2+(Bright.b-h.b)A2'll
IF h<Min THEN'll
Min=h'TI
NrM%=-n%'Il
Nr2%=;,r%'ll
END IF'll
END IF'll
NEXT Nr%'lI
NEXT n%'ll
IF NrM%<O THEN'll
ClrM%--NrM%'i!
SWAP Nrl%,Nr2%'ll
ENl IF'll
'll
CALL SetAPen& (RastPort&, CINT (Colour (NrI %,0) ) ) 'll
CALL Setm'en& (RastPort&, CINT (Colour (Nr2%, 0) ) ) 'll
E"Ij SUB'll
"lJ
''ll
SUB ReProjection(xr,yr,zr,x,y,z) STATIC'll
SHARED Sina,Sinb,Slnc,Cosa,Cosb,Cosc,Hx,Hy,Hz'll
, 2D->3D'll
281
ApPENDIX B - TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAi\I\\l1'(;
computepo.int: 'l[
, =>Compute Brightness of the point => stack'l[
St~ck?tr% St~ackPtr% + l~
C)":.l, ~\1hic!·lB()ciy(O,Px,Py,Pz,Rx,Ry,Rz,Original ~ ,t'alse:SI
9!
:F :lody% > 0
CALL Sf;:-hr~ght;'.c.ss (Body%,Px,Py,Pz,Mirr-or-,Origi,iliL') <IT
Py Sy~
pz Sz'lI
Origir:cl J.! False'll
282
ABACUS ApPENDIX B- TilE TRACER PROGRAM
Bright.g=-I'll
Bright.b=-l'll
ELSE'll
Bright.r~O'll
Bright.g=O'II
Bright.b=O'II
END IF'll
END IF'll
Stack(StackPtr%,O)~Bright.r'll
Stack(StackPtr%,l)~Bright.g'll
Stack(StackPtr%,2)~Bright.b'll
RestLght(StackPtr%)=O'lI
Stackptr% ~ StackPtr%-l'II
RETURN'll
''lI
''lI
Shadows:'lI
Initialization
Status$ ~ " Status: Shadows"+CHR$(O)'II
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'II
GOSUB DeleteMenu'II
'lI
Status$ = " Status: Init"+CHR$(O)'II
CALL SetWindowTitles& (NWBase&,SADD(Status$),O)'ll
GOSUB InitShadows'll
CALL Scron'll
283
ApPENDIX B- TilE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
ELSE'lI
YBOff l'lI
END IF'lI
'lI
Body%~O'lI
'lI
FOR yb%~YStart%+BoxH%/2 TO Yend%+BoxH%/2 STEP BoxH%'lI
FOR xb%~XStart%+BoxW%/2 TO XEnd%+BoxW%/2 STEP BoxW%'lI
Pxl Px'll
Pyl Py'll
PzI Pz'll
'Il
Original! =- True'll
GOSUB Compulepoint.'Il
'lI
Px Pxl'll
Py Pyl'll
pz PzI'll
'll
IF Stack(O,O»~O THEN 'If no Intersect point => -1'lI
Bright.r~Stack(O,O)*Qh.r'll
Bright.g~Stack(O,l)*Qh.g'll
Bright.b~Stack(C,2)*Qh.b'll
CALL OSSetPoint& (CLNG(xb%-BoxW%/2+XAOff),CLNG(yb%-
BoxE%/2+YAOff) ,CLNG (xb%+BoxW%/2-XROf[), CLNG (yb%+BoxH%/2-
YBOff) ,CLNC (l 0/4 xl:lriqht. r) ,CLNC (1 024'Bright. q) ,CLNG (lUL4*Bnght. b) ) ~I
END IF'll
NEXT xb%'ll
'll
IF INKEY$ <> "" Tflc'.N'll
IF yb% < Yend%+BoxH%/2 THEN'll
'll
CALL Scroff'll
a$-"Ncxl line:"fSTR$(yb%,FloxH%)'ll
CALL PrintIt(a$, lJO,False)'ll
CALL DialogBox("Continuc",O,True,xla%,yla%,x2a%,y2a%,False)'];
CALL Djalog8ox("Stop",2,~alse,xlb%,ylb%,x2b%,y2b%,False)'Il
'll
CALL DoDialoq(n%,O,xla%,yla%,x2a%,y2a%,-1,-I,-I,-I,xlb%,ylb%,x2b%,y2b%)'ll
'll
CLS'll
IF n% = 0 THEN'll
'll
CALL ScrunS
ELSE'll
GOTO ShadowEnde'll
END IF'll
END IF 'll
END IF'll
NEXT yb%'ll
'll
284
ABACUS ApPENDIX B - TilE TRACER PROGRA\I
shadowEnde:~
'lI
CALL scroff'lI
CLS'll
GOSUB MakeMenu 'll
RETURN'll
'END of SHADOWING.ASC'll
''ll
285
ApPENDIX B- TIlE TRACER PROGRAM AMIGA 3D GRAPIlIC PROGRAMMING
SERVICE.ASC'll
****************~***************~
CLS'll
IF dn$<>"" THEN'll
dn$ = dn$ + ".LIST"'ll
OPEN "O",#1,dn$,102,1'll
PRINT #l,NumberK'll
FOR n%=l TO NumberK'll
FOR p%=O TO 5'll
PRINT #1,K(n%,p%,0),K(n%,p%,1),K(n%,p%,2)'ll
NEXT p%'ll
NEXT n%'ll
CLOSE #l'll
'The following will deleLe icons when included:'ll
dn$ = dn$+".info"'lI
KILL dn$'ll
END IF'll
CLS'll
GOSUB MakeMenu'll
RETURN'll
''ll
Loader:'ll
, Load array K () f rem disk'll
GOSUB Directory~
LOCATE 3, I'll
PRINT" Which object do you wish to load?"'ll
PRINT 'll
PRINT " Filename: ";'ll
dn$ = "'''!I
CALL ForrnInputString (dn$,38')'lI
CLS'll
286
ABACUS ApPENDIX B - TilE TRACER PROGRAM
287
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRA:\tMII'G
LOCATE 6,1'll
PRINT " Total n;x;n Objects (n+dn$+")."'ll
PRINT 'II
PRINT " Sufficent memory for "; MaxNumber-NumberK;" Object s. "S
PRINT'll
PRINT " How many merges? "; 'II
num .;::: xqr
CALL FormlnputInc (num,30!,l',l880!)'![
IF
num>~l THENS
FOR n%~NumberK+1 TO NumberK+num'II
FOR p%=o TO 5'II
INPUT #1,K(n%,pt,O),K(n%,p%,1),K(n%,p%,2)'ll
NEXT p%'II
NEXT n%'ll
NumberK ~= NumberKtnum'll
Newone' = True'll
Start% = 1 'll
END IF'll
CLOSE #1 'II
END IF'll
END IF'll
CLS'II
GOS:JB MakeMenu'll
RETURN'll
''II
Arraylnit:'ll
I Create new array K() ~
Status.> ~ " Status: New array creation"+CHR$(O)'II
CALL SetWindowTitles& (NWBase&,SADD(StatusS),O)'II
'll
Cc)SUB DeleleMenuqr
<1
LOCATE lO,l'll
PRINT " Maximum ~\~nber of objects
a = MaxNulrl)e dJ
CALL Formlnputlnt (a,30!,O!,lOOO!)'ll
'II
IF MaxNumber <> a THEN'll
MaxNumber = a'll
NumberK~O'll
ERASE K'II
DIM K(MaxNumber,S,2)'ll
Start% - O'll
END IFS
CLS'lI
GOSUB MakeMenu'II
RS~URN'll
''II
1)1
LoadMat:'ll
C;OSUB Directory'll
'II
Status$ = " Status: Matercal constants loaaer"+CHR$(O)'ll
CALL SetWindowTitles& (NWBase&,SADD(Status$),O)'lI
288
ABACUS ApPENDIX n- THE TRACER PROGRAM
'll
LOCATE 3,1'll
PRINT" Which material would you like to load?"'ll
PRINT 'll
PRINT " Filename: ";'ll
'll
dn$ = •....i[
CALL FormInputString (dn$,30!)'ll
'll
IF dn$<> '''' THEN 'll
dn$=dn$+" . MAT " 'I[
OPEN "i",#l,dn$'ll
matptr = 1'1[
INPUT #l,NumberMat'll
ERASE Mat'l[
DIM Mat(NumberMat,6)'I[
WHILE NOT (EOF (1) ) 'I[
FOR i=O TO 6'1[
INPUT #l,Mat(matptr,i)'ll
NEXT i'll
matptr = mdtptr+l'l[
WEND'll
CLOSE #1'll
END IF'll
CLS'I[
GOSUB MakeMenu'll
RETURN'll
''ll
''ll
ScreenSaver:'ll
GOSUB Directory'll
'll
Status$ = " Status: Screen saver"+CHR$(O)'I[
CALL SetWindowTitles& (NWBase&,SADD(Status$),O)'ll
'll
LOCATE 3,1'1[
PRINT" Under what name would you like the screen saved?"'1[
PRINT 'I[
PRINT" Filename: ";'ll
IFFFile$ ""'ll
CALL FormInputString (IFFFile$, 3D!) 'll
'll
IF IFFFile$ <> THEN'll
'I[
Handle& = . File Handle'll
Buffer& = 0 °
, reserve buffer'll
, Buffer memory'll
Null& = O'll
PadRyte% O'll
'll
289
ApPE:'>DIX B- Tm: TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMl\lI:\G
Length& =
xWri tc& (Handle&, "ADD (Ch,,c,k$), 4) 'll
Length& x~lritcc& (Handle&,Vr\;\PTH (FC;,~lSize&) ,4)9;
=
; + ILHM for fll U1ap-File91
ChunkS =~ .. ILBM 91 lJ
, BMHD-Chunk 'II
ChunkS :.::, !lBM1~DIf91
Length& xWrite& (Handle&,SADD(ChunkS),4)'il
Lenglh& xWrite& (Band] e&, VARPTR (BMHDSi ze&) ,1) 'il
Length& xWrite& (Hand le&, V./\RPTR (RasterW%) ,2) 'll
Length& ~ xWri te& (Handle&, VARPTR (FasterH%) ,2) 'il
Length& xWri te& (Handl e&, VAFPT? (}inll &) ,4) 'l[
Temp% ~ (256* FasterT%) , tJo t1l\.S;~iNG'l[
Length& x'lir i :cc& (Handle&, VI>.RPTC<: ('l'erc.p%) ,2) 'll
Temp% = 0 I No Pdcki nq!Jr
Length& xi;;cite& (Handle&,VI'"".?TE(Tc:1tp%) ,2)'l[
Temp% O'l[
Lenq~h& ~ xWrite& (Handle&,VA.1<.PTR(Temp%) ,2)'i1
Leligth& xWrite& (Handle&,VARPTR(Aspect%) ,2)'11
Lengtn& xWri tee& (Han61c&, VARPTR (Raste,-W%) ,2) 'II
Length& ~ x;,d t.c& (Handle&, VNVfF iFasterfl%) ,2) 'l[
q
290
ABACUS ApPENDIX B- THE TRACER PROGRAM
291
ApPENUlX B - THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
''ll
ScrcenLoader:'ll
GOSUB Directory'll
'I!
StatusS ~ " Slatus: Screen Loader"+CHRS(O)'ll
CALL SetWindowTitles& (NWBase&, Sr,DD (Slatus$), 0) 'll
LOCATE 3,1'll
PRINT" Which IFF-File wou:d you like to load?"'ll
PRINT 'll
PRINT" Filename: ";'ll
IFFFile$ '''''ll
CALL FormInputString (IFFFileS, 3D!) 'll
'lI
IF IFFFile$ <> "" THEN'll
'lI
BMHD False'll
CMAP False'll
CAMG False'll
Body =, False'll
'll
Ilandle& O'll
Buffer& 091
'lI
, reserve buffer'll
Flags& ~ 65537& , MEMF PIJBLIC ! MEMF CLE..l\P.'ll
BufferSize& ~ 360'lI
Buffer& = AllocMem& (BufferSize&,Flags&) 'll
IF Buffer& ~ 0 THEN91
DialogS = "No more memory! ! ! "'ll
GOTO EndLoad'll
END IF'll
Length& ~ xRead&(Handle&,InputBuffer&,12)'II
ChunkS = 1I11<Jr
FOR n% ~ 8 TO II'll
Chun"S ~ ChunkS + CfiR$ (PEEK (InputBuffer&+n%) ) 'll
NEXT'll
292
ABACUS ApPENDIX n- THE TRACER PROGRA\!
'!I
IFF-Picture adapted to Display-Screen ?'ll
IF (RWidth% <> RasterW%) OR (RHeight% <> RasterH%) THEN'll
Dialog$ = "Format error: "tSTR$ (RWidth%) +" x"+STRS(RHeight%)'ll
GOTO EndLoad'll
END IF'll
'II
ELSEIF ChunkS = "CKI\P" THEN 'Color-PaletteS;
LeClQth& ~ xRead& (;:andle&,ColorBuffer&,Chunk·",jnlen&) C"
CMAP = True'll
, Color-Palette set up'll
FOR nl = 0 TO RMaxCo:ors% - 1'll
redl - PEEK (ColorBuffer&+ (n%*3) )/l6'll
green% PEEK (ColorBuffer&+ (n%*3)+1)/16'll
blue% PEEK (ColorBuffer&+ (n%*3)+2)/l6'1l
d\l;nmy = SctRGB4 (Vi ewport&, n%, red%, green%, hl ue%) 'II
'II
POKEW OSColour&+n%*8+2, red%/15*1024'k
POKEW OSColour&+n%*8+4,green%/15*1024'll
POKEW OSColour&+n%*8+6,blue%/15*1024'1l
NEXT'll
'll
ELSE IF ChunkS "BODY" THEN 'BitMap Loader'll
CALL Scron'll
Body = True'll
IF Compression% = 0 THEN IN:.) compression<Ji
FOR yl = 0 TO RHeighl% -I'll
FOR b = 0 TO RDepLh% -1'll
IF b<RasterT% THEN'
Adress& RitPlanes& (6) + (yl*BytesPerRow%) 'll
ELSE'll
Adress& Buffer&'ll
END IF'l[
Lenglr.& x?ec.d& (Handlc&, Adress&, BytesPcrRow%) 'II
NEXT'l[
NEXT'll
'II
ELSEIF Compression% THE~~ I CmpBy~0KJnl compressicF'I~
293
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
294
ABACUS ApPE~DJX B- THE TRACER PROGRAM
LoadOK:<JI
DialogS "Loading OK"<JI
EndLoad:'lI
IF Handle& <> 0 THEN CALL xClosfO&(Bandle&)<JI
IF Buffer& <> °
THEN CALL FreeMem& (Buffer&,BufferSize&) 'I!
CALL DialogBox(Dialog$,1,T:-ue,xll:::%,y1b%,x2b%,y2b%,False)'T:
CALL DoDialog(n%, 1, -1,-1,-1,-J ,xlb%,ylb%,x2b%,y2b%, -1. -I, -1, -1) 'l!
END IF<JI
CLS<JI
GOSUB MakeMenu<JI
RETUfu'J'l!
"1I
''II
HardCopy:'lI
Status$ ~ " Status: Scree" hardcopy"+CHR$(O)'TI
CALL SetWi ndowTi tlcs& (Nl'iSase&, SADD (Status$) ,0) 'I!
COSUB DeleteMenu'll
sigBit% = AllocSignal%(-l)'ll
Flags& = 65537& ' MEMF PUBLIC I MEMF CLEAR'TI
MsgPort& = Allodlem&(40,Flags&)'II
IF MsgPort& = 0 THEN'll
DialogS = "No 'MsgPort' !! !II~
GOTO EndPrinter4'i1
END 1F'11
'11
POKE(MsgPort& + 8), 4 q
POKE(MsgPort& + 9), 0 '11
Nam$ = "PrtPort"+CHR$(O)'11
POKEL(MsgPort& + 10), SADD(Clam$)'Jl
POKE(~lsgPort& + 14),0 'II
POKE(MsgPort& + 15), sigBit%'l!
SigTask& = F~ndTdsk&(O)'11
POKEL(MsqPort& + 16), SigTask&'iI
295
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
GOTO EndPrinter2'lI
END IF'll
'll
POKEW(ioRequest& + 28) , 11 I
DumpRastport to Printer'll
POKEL(ioRequest& + 32), RastPort& I
Print entire screen 'll
POKEL(ioRequest& + 36) , ColorMap&'ll
POKEL(ioRequest& + 40) , Modes%'ll
POKEW(ioRequest& + 44), O'll
POKEW(ioRequest& + 46) , O'll
POKEW(ioRequest& + 48) , RasterW%'ll
POKEW(ioRequcst& + 50) , RasterH%'lI
POKEL(ioRequest& + 52) , O&'ll
POKEL(ioRequest& + 56) , O&'ll
POKEW(ioRequest& + 60) , &H84'll
'lI
CALL Dialog30x ("P rint ing ... ",1, False, xla%, yla%,x2a%, y2a%, False) 'll
EndPrinter3: 'lI
CALL RemPort (MsgPort&) 'II
POKE(MsgPort& + 8), &HFF 'if
POKEL(MsgPort& + 20), -I'll
CALL FreeSignal (sigBit%)'lI
CALL FreeMem& (MsgPort&,40)'ll
'lI
EndPrinter4:'lI
CALL Dialog8ox(Dialog$,1,True,xlb%,ylb%,x2b%,y2b%,False)'ll
CALL DolJialog(n%,I,-I,-I,-I,-I,xlb%,ylb%,x2b%,y2b%,-I,-I,-1,-1) 'll
END IF'll
CLS,!!
GOSUB MakeMenu 'll
RETURN'lI
''ll
LoadEditor:'ll
Status$ ~ " Status: Editor loading"+CHR$ (0) 'll .
CALL SetWindow::'itles&(NWBase&,SADD(Status$),O)'ll
'll
GOSUB DeleteMenu'lI
296
ABACUS ApPENDIX B- THE TRACER PROGRAM
CALL DoDiaioq(n%,O,xla%,yla%,x2a%,ya2%,-l,-l,-1,-l,xlc%,ylc%,x2c%,y7c%) 1
CLS'IT
IF n'!, = 2 THEN'IT
UiDIR "C' racer:" 'IT
GOS'JB Closel t 'IT
CHAIN "Editor <j'[ ll
END IF'IT
GOSUB ~akeMenu 'IT
E:;J'IT
'IT
C~earScreen:'li
Status$ = " Status: Clear screen"+CHR$(O)'IT
CAL~, SetW indowT i ties& (NWBase&, SADD (Status$) , 0) 'IT
'IT
CALL SetRast&(RastPort&,O)'
Hg 0 TrueS
'IT
GOSUB NOOP'IT
Rf::'URN'IT
"ll
lSI
Info: 'IT
, Information about free elements of K()'IT
Status$ = " StaLus: Info"+CHR$(O)'IT
CALL SetWindowTitles&(NWBase&,SADD(StatusS),O)'IT
GO::U:J DeleteMenu,![
11
Cl.. I,lJ Print.:t (1I3D - CAD l1 ,60,False)<J[
CAU Pri:,tIt("Original-Version: Pete:- Schulz (c) :986",/S,False)'![
CALL L°rintIt ("Amiga-Version: Bruno Jennrich (c) 1987",90,False)'IT
0:
" as = "MaX1n',um r.dn:ber of objects: lI+STR$ (Ylax'Number) en
CALL Pr~ntll(a$,105,False)'![
''II
Help:'![
, Which key press for which dction~
StatusS = " Status: Help"+CHRS(O)'11
CALL SetWindcwTitles&(NWBase&,SADD(Status$),O)'![
GOSUB Dclete:-\enu'![
LC'CATE 2, ~ 11
297
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAM:'vUNG
GOSUB Pause'll
CLS'll
GOSUB MakeMenuS
RETURN'll
''l[
"
SUB Sky(a%,Col%,num%) STATIC'!I
SHARED WScreen&, N'dBase&, RasterW%, RasterHi, RasterW] %'!!
SHARED RasterH1%,R2sterW2%,RasterH2%,RastPort&'ll
CALL Scron'll
'!I
CALL SetAPen& (RastPort&,Col%)'!I
CALL SetRast&(RastPort&,O)'ll
'll
FOR n%=1 TO nuC'%'ll
RANDOiviIZE TIMEF'ii
IF a%<4 THEN'll
I~ a% AND 1 THEN'!I
x%oRasterW2%+RasterW2%'RNDkRND* SGN (RND-. S) ~I
y%=RasterH2%+RasterH2%*RND*RND* SGN (FND-. 5)"\
ELSE'll
x%=RND*RasterWl%'ll
y%=RND*RasterHl%'ll
END IF'll
'll
IF a% AND 2 THEN'll
IF x%=RasterW2% AND y%cRasterH2% THEN'!I
durmny = WritePixel (RastPort&,x%,Y%)'!I
ELSE'll
x:%= (x%-Rasc.erW2't,) +x%~
y1%=(y%-RasterH2%) ".1+y%!
*.,
IF xl%>-,Q Ai\D xl%<Rasterl'i% AND yl%> 0 AN;) yH<Rast.erf''t''dEcN
CALL Move&(RastPort&,x%,y%)!
CALL Draw& (RasLPoI:&,xl%,y1%)'
END IF!
END IF'!I
ELSE'll
298
ABACUS ApPENDIX B- TilE TRACER PROGRAM
ELSE'll
CALL Move&(RastPort&,x%-l,y%)'lI
CALL Draw&(RastPort&,x%+l,y%)'lI
CALL Draw&(RastPort&,x%,y%-l)'ll
CALL Draw&(RastPort&,x%,y%+l)'lI
END IF'll
END IF'll
ELSE'll
'll
x%=RND*RasterWl%'ll
y%=RND*RasterHl%'lI
CALL Move&(RastPort&,RasterW2%,RasterH2%)'lI
CALL Draw& (RastPort&,x%,y%) 'lI
END IF'll
NEXT n%'ll
'll
CALL SetAPen&(RastPort&,l)'ll
'll
CALL Scroff 'll
END SUB'll
''ll
SUB Fhg(Colollrsl%,Colours2%) STATIC'll
SHARED RasterWl%,RasterHl%,Colour(),MaxColour%,WScreen&'ll
SfffiRED NWBase&,RastPort&,OSSetPoint&,OSModus&,OSMaxColour&'ll
, Produce floating passage between Colours} and Colours7'll
CALL Scron'll
'll
red. s=Colour (Coloursl%+l,l)'lI
green.s=Colour(Coloursl%+1,2)'ll
blue.s=Colour(Coloursl%+1,3)'ll
red.e=Colour(Colours2%+1,1)'lI
green.e~Colour(Colours2%+1,2)'lI
blue.e=Colour(Colours2%+1,3)'lI
'll
IF (PEEKW(OSModus&) AND &fl800) - &H800 THEN 'HAM'll
'll
'Background limited to 16 Colors, or else Objects disturbed.'ll
'll
POKEW OSMaxColaur&,16'll
FOR y%~O TO RasterHl%'lI
red=reri. s+ (y%/RasterHl %) *(reri.e-red.s)'l[
green=green.s+(y%/RasterHl%)*(green.e-green.s)'ll
blue=blue.s+(y%/RasterHl%)* (blue.e-blue.s)'ll
CALL SetPoint(0,y%,RasterW1%,y%,red,green,blue)'ll
CALL
OSSetPoint& (O,y%,RasterW1%,y%,CLNG(1024*red),CLNG(1024*green),CLNG(1024*blue))'ll
NEXT y%'ll
POKEW OSMaxColour&,64'll
ELSE'll
FOR y%=O TO RasterHl%'ll
red=red.s+(y%/RasterHl%) * (red.e-red.s)'ll
green=green.s+(y%/RasterH1%)*(green.e-green.s)'ll
blue=blue.s+(y%/RasterHl%)*(blue.e-blue.s)'ll
CALL SetPoint(O,y%,RasterWl%,y%,red,green,blue)'ll
CALL
OSSetPoint & (0, y%, RasterWl %, y%, CL"G (1024 * red) ,CLNG (1024 *green) ,CLNG (1 C2 4 *bl ue) ) 'll
NEXT y%'[
END IF'i]
CALL Scraff'll
Et;O SUB'll
299
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAM:-.tING
"1I
BacKground:'ll
, Background Determine'll
Status$ = " Status: Background seiection"+CHR$(O)'lI
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'lI
'lI
GOSUB DeleteMenu'll
'1l
CALL DialogBox("Pattern",0,True,xla%,yla%,x2a%,y2a%,False)'1l
CALL DialogBox("Load screen",2,False,xlb%,ylb%,x2b%,y2b%,False)'II
'lI
CAlL DoDialog(n%,O,xla%,yla%,x2a%,y2a%,-1,-1,-I,-1,xlb%,ylb%,x2b%,y2b%)'ll
CLS 'll
'll
IF n%~2 THEN'll
GOSUB ScreenLoader~
Hg = True'll
Ei,sE'll
CALL DialogBox("Pattern",O,True,xla%,yla%,x2a%,y2a%,False)'ll
CALI, DialogBox ("Sky", 1, Fal se, xlb%, ylb%, x2b%, y2b%, False) 'II
CALL DialogBox("Floating",2,False,xlc%,ylc%,x2c%,y2c%,False)'lI
'lI
CALL DoDialog(n%,O,xla%,yla%,x2a%,y2a%,xlb%,ylb%,x2b%,y2b%,xlc%,ylc%,x2c%,y2c%)
'II
CLS'IT
'II
IF nl - 0 THEN 'II
'lI
CALL PrintIt ("Background Pattern",40,False)'ll
'lI
LOCATE lO,l'lf
PEINT " Number of the pattern (0 .. 34) ";'ll
a = O'll
CALL formInputInt (Hx,30',O!,31!)'lI
Xpattern% = ri'll
300
ABACUS ApPENDIX B - THE TRACER PROGRA:\1
'][
IF n% = 1 THEN'][
LOCATE 3,1'][
PRINT " Sky type: "'][
PRINT" 0 Stars (scattered)"'][
PRINT" 1 Stars (centered)"'][
PRINT" 2 Lines (scattered) "'ll
PRINT" 3 Lines (centered) "'ll
PRINT" 4 Lines (middle centered)" 'll
'll
LOCATE 10,1'][
PRINT" Type : "; '][
a = Art%'][
CALL FormInputInt (a,30!,O',4!)'ll
Art% = a'][
'][
LOCATE 11,1'][
PRINT" Color : ";'][
a = 1'][
CALL FormInputInt (a,JO',O',CSNG(MaxColour%-l))'][
HCo1r% = a'll
'll
LOCATE 12,1'][
PRINT" Number: ";'ll
a = 100'][
CALL FormInputlnt (a,30',O',SOO!)'ll
num% = a'll
'][
CLS'][
CALL Sky (Art%,HColr%,num%)'ll
Hg = True'll
END IF'][
'][
IF n% = 2 THEN'][
CLS'][
'][
CALL Print It ("Floating Background",40,False)'ll
'll
LOCATE 10,1'll
PRINT " from color: ";'ll
F1 = O'll
CALL Formlnput (F1,30',0!,CSNG(MaxColollr%-1))'l[
Colours1 %=Fl 'll
LOCATE 12,1'll
PRINT " to color: "i'1I
F2 = 1'll
CALL FormInput (F2,30',O',CSNG(MaxColour%-1))'ll
Colours2%=F2'll
'II
CALL Fhg(Colours1%,Colours2%)'II
Hg = True'][
END IF'll
END IF'll
CLS 'II
GOSUB MakeMenu'll
RETURN'll
301
ApPENDIX C - TIlE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
The following pages contain the complete listing of the editor program
contained on the optional diskette.
302
ABACl;S Al'PE:\IJlX C - I'm: EIJIToJ{ PI{()CJ{\,\)
'II
GOSUB init 'I~icial~zrlLicn al: vJr'i~bles and s(:re~~
WHILE quit=O 'wait_ unt_1J end is sign-11ed by cr,lit -:q
a$cclt\KEY$'J!
IF .3.$><"11 THE~C[
(;~;SUB S!;Drtc~:t s I C::cL ,0\ key c::!.:'C:: c~<"".Darc ',,; ~ ~ n
SND L~' ~
'd;~N!)<r
END'!!
'Ji
'!!
!*A**.**W~*X*******~7**+**~
~NI?TA~IZA~[nN .*~
gr
:nlt:'II
DIM qadgcts% (400), sadget% (l0, 7) '!!
FOR i·o 0 TO 10 lC}p.3r ali gadgets (sec be1ow')91
g~duet%(i,O)=-l~
t'~~';XT i SI
ni-)%-=:(J~~
",3% ,I:',
[: r~) % "'-UC::
;-:~(t, - :)?
LOCflTE 1]\f;cL) q::dJ.h
Pi-<.r)JI' " '\8 n~·;
(5,5) - (6~, 2C)"
C;ET (5/~) - {65, 20) ,g(~1aqct 5% (200) q[
LOG\';'E 2,1 '!!
FF1NT " YES "
LI0JE (5,5) - (rJS, 20)" b'TI
CErr {5,5)-(45,:-;:O)rqc18CJ(;~.s~('CC) ('"
: ,UCT\'TT f ~ SI
rr.ax! lCOOO
ptr-O
303
ApPENDIX C - THE EDITOR PROGRAM AMIGA 3D GRAPIIlC PROGRAM\IJ:"G
k' (1,0,1)=1+1'll
NEXT i'll
FOR i=l TO matnum'll
mat! (1,0) =-1 ,
mat! (1,1)=1+1'
NEXT i ,
typ$ (0) =HPlane u I dr-ranqe by ::.ype and name<J1
typ$(l)="Triangle"'lI
typ$ (2) ="Parallelogram"'TI
typ$(3)="Circle"'ll
typ$ (4)="Circle segm<'nt'''ll
typ$(5)="Arc"'iI
typ$ (10) ="Sphere"~:
typ$(20)="Cylinder"'i:
typ$ (21) ="Cyl incier segment'"
typ$ (22)~"Cone"'ll
typ$(24)="Sp':eroid" ,
t(1)=O 'Arrange by menu line and lype'll
t(2)=1'll
t D)2'll
t(~)~3'll
t (5) =4'
t(6)=5'll
t (7)=10'
t (8)=20'
t (9)=21'
t(10)=22'll
t (11) =24'
xcorrfac!=1.88 'Correction factor for the horizontal resolution~
maxlines oc 20 'Maximum number of lines available for circle drawing'll
pi2'=6.283185 '2*3.141S92'll
factor' =1 'Sizing factorll
mx' ,=0 'Fo,;i lion of upper left SC,~("'" :::cr9
my'=1l6<J:
mz!~116q]
,
file$="objects/" 'contains all t'ileClames, used by disk oper at i or:s":
,
LIBRARY dir$+"gra!Jhics.llbrary" 'adci the procedure set.drmcs:
SCREE~~ J, 61;0,256,2,?<JI
WI:\JOW ;, "XY-PU\NF", (0,0) - (298, 115),7,1 ql
WINDOW ),"XZ-P~~NE", (320,0)-(617,115), 7,lSi
WINDOW :i,"YZ-PLi\\E", (320,85)-(617,190), 1,19',
WIt-iDOW 4, "RAY-l'RhCl:\G-EDITOR", (0,85) - (31 /, 19() ,n, ! 'II
buffer&=allocmcm& (68*2,2) 'Memory for IT,:JLSC pOJnt.(':rqr
304
ABACUS ApPENDIX C - TilE EDITOR PROGRAM
'll
MENU ON'll
ON MENU GOSu~ choice'll
'll
MOUSE ON'll
ON MOUSE GOSUB click'll
'll
PRINT"Body :0" 'Create input window'll
LOCATE 9,1'll
PRINT"Segrnent :0,116,116"'11
PRINT"Mouse : 0, 0, O"'ll
PRINT "Factor: 1 Lines : 20"'11
LINE (O,7*ch%+2)-(39*8+3,7*ch%+2)'11
RETURN'll
'II
I***************~
,** EEND **'11
'*************** ~
'll
ende:'ll
MENU OFF 'Close window screen and libraries'll
ME!,;U RESET'll
MOUSE OFF'll
'II
WINDOW CLOSE 2'll
WINDOW CLOSE 3'11
WINDOW CLOSE 4'11
SCREEN CLOSE I'll
ON ERROR GOTO Problem'll
WINDOW 1,"Call Tracer" , AMIGABasic needs WINDOW l'll
Problem: ' this command checks errors'll
, it is necessary'll
CALL freemem& (buffer&, 68*2) 'Release memory again'll
LIBRARY CLOSE'll
CHAIN "tracer"'ll
RETURN'll
'll
I*****************~
'** SHORTCUTS **'ll
I*****************~
'll
shortcut s: 'II
a~ASC(a$) 'ASCII-Value of pressed key'll
MENU OFF 'Compare with valid keys'll
IF a=4 THEN'll
IF mat -,0 THEN'll
CALL deleter (ptr) 'Delete List e] ement 'll
ELSE'll
CALL deletermat (matptr) 'Delete Matcr;al'll
END IF'll
END IF'll
IF a=42 AND mat=O THEN'll
CALL factor2(factor!) 'factor=factor*2'll
END IF'll
IF a=47 AND mat=O THEN'll
CALL factorhalf(factor') 'factor=factor*O.5'll
END IF'll
IF a=ll~ THEN'll
IF mat=O THEN'l
CALL right.s (ocr) 'go to right element~
ELSE'll
CALL rightsmat(matptr)'ll
305
ApPENDIX C - TilE EDITOR PROGRAM AMIGA 3D GRAPIIIC PROCRAMMIl'iC
END IF'll
END IF'll
IF a~108 THEN'll
IF mat~O THEN'll
CALL lefts (ptr) 'go to left element'll
ELSE'J!
CALL left coma>: (matpt r) '!I
END IF'll
END IF'll
IF a=l1 THEN'll
IF mat=O TBEN'IT
CALL getelem(ptr) 'correct: current. element'll
ELSE'll
CALL getmat(matptr)'ll
END IF'll
END IF 'll
IF a=115 AND mat=O THENCJI
CALL showandwait (ptr) 'show CUrIcent. element on OL:tput wi ndO\,'ll
END IF'J!
IF a -18 AND IT,at"O THEt\S
c
1*******************~
'll
choice:'ll
MENU OFF I select indivual menu -j terns and subrout-i nes11
ti tle=MENU (0) S
chose" HENU (1) 'i[
'll
'll
IF title=l THI<N 'TrdrtJfonraL:::·n91
IF chose=l THEN'll
CALL rotation(ptr)'ll
END IF'!!
IF chose=2 'i'HEN'll
CALL translation (p,r) '!I
END IF'!!
IF chose=3 THEN'll
CALL sizjng(ptr)'ll
END JF'll
IF chose=4 THEN'll
CALL copier(ptr)'ll
END IF'll
IF chose=5 THEN'll
CALL deleter(ptr)?,
END IF 1i
IF chose=6 THENS
CALL getel ee', (ptr) c:
END IF '!I
END IF'll
'!I
IF title=2 THEN 'Body'll
CALL entry (ptr)'ll
306
ABACUS Al'l'DiDIX C - TIlE EDITOR PROGRA~1
END IF'll
'll
IF title=3 THEN '::iiskette opera,-} ons'll
IF chose=l THE~'l[
CALL 1 oadli s t 'l!
El\D IF'l!
IF chose=2 THEN'l[
CALL loadmat'l[
END IF'l!
IF chose=3 THEN'ii
CALL savelist'l!
END IF'll
IF chose=4 THEN'll
CALL savemat'll
E~D IF'll
E~i) IF 'll
'll
IF title=4 THEN 'Operation'll
IF chose=l THEN'll
CALL lcfts(ptr)'ll
END IF'll
IF chose=2 THi':N'll
CALL rights (ptr) 'll
END IF'll
IF chose=3 THEN'll
CALL l i ob (rnx I , :~y I , mz ! ) s:
END IF'll
IF chose=4 THEN~
CALL setfactor(factor!)'ll
END IF'll
IF chose=5 THEN'l!
CALL factor2(factor!)'ii
END IF 'll
IF chose~6 THEN'll
CALL factorhalf(factor!)'ll
END IF'll
IF chose=7 TIIEN'l!
CALL mateddy'l!
END IF'l!
IF chose=8 THEN'll
CALL refresh'l!
END IF'll
IF chose=9 TIIEN'l!
CALL ShowdCldwait(ptr)'ii
END IF'll
IF chose~10 THEN'll
CALL setl ines (maxU nes) 'l!
El\D IF 'll
IF chose=ll THi':N'l!
CALL finish(qClit)'ll
END IFS
END IF'll
'll
'll
IF title=5 THEN 'Mate;'a! editcr~
IF chose=l THEN'll
CALL leftsmat (mat.pcr) 'll
END IF'l!
IF chose=2 THEN'll
CALL rights~at (matptr)~
END IF'll
IF chose=3 THEN'll
307
ApPENDIX C- TilE EDITOR PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING
CALL deletermat(matptr)~
END IF~
IF chose=4 THEN~
CALL getmat(matptr)~
END IF'll
IF chose=5 THEN~
CALL matinput(matpcr)'ll
END IF ~
IF chose=6 THEN'll
CALL fini shmat ~
END IF~
END IF~
~
MENU ON~
RETURN'll
'll
'~*****************~
'** READ MOUSE **~
I******************~
'll
click: ~
dummy=MOUSE(O)~
x!=MOUSE(3)/(factor!*xcorrfac') 'Get mo'~se positlon ami compute~
y!=MOUSE(4)/factor''ll
n=WINDOW(O) 'window clicked'll
oldwindow~WINDOW(l) 'output window'll
CALL activatewindow&(WINDOW(7))'ll
IF n<4 THEN 'was projection window clicked?'ll
WINDOW OUTPUT n~
LINE (MOUSE(3)-1,MOUSE(4))-(MOUSE(3)+1,MOUSE(4)),3 'Draw circle'll
LINE (MOUSE(3),MOUSE(4)-1)-(MOUSE(3),MOUSE(4)+1),3'll
IF n=l THEN 'compute spatial coordinates'll
mox! =mx' +x! 'll
moY'=my!-y!~
ELSE'll
IF 11'-2 THENq(
mox!=mx!+x!~
moz'=mz!-y!'ll
ELSE 'll
IF n=3 THEN'll
moy!=my!-x!~
moz!=mz!-y!'ll
END IF~
END IF'll
END IF~
mox!=FIX(mox!+.5) 'round'll
moy!=FIX(moy!+.5)'ll
moz'=FIX(moz'+.5)'ll
WINDOW OUTPUT 4'll
mo$=STR$ (mox!) +", "+STR$ (moy! )+", "+STR$ (moz') 'll
LOCATE 10,8 'delete old [muse values and c:iisplay ne'.-J ones'll
PRINT SPACE$(26) 'II
LOCATE 10,8'll
PRINT MID$(mo$,1,26) 'Il
WINDOW OUTPUT oldwindow'll
ELSE'll
CALL checkgadget 'was a gadget clickcd?'ll
END IF'll
RETURN 'll
'll
'll
308
ABACUS ApPENDIX C- THE EDITOR PROGRAM
'*************'11
'** INPUT **'lI
1*************91
'lI
SUB entry (ptr) STATIC'lI
'TASK :Read data for a new body'lI
'PARAMETER:~> ptr points cO old body'lI
<= ptr points to specified body'lI
SHARED k' () ,t(),chose'lI
CALL newelem(ptr)'lI
k' (ptr,O,O)~t(chose)'lI
CALL showelem(ptr)'lI
CALL getelem(ptr)'lI
IF k' (ptr,5,2)=1 THEN'lI
CALL drawelem(ptr)'lI
END IF 'lI
END SUB'lI
'lI
SUB getstring(old$,a$,z$,z,s,inplen)STATIC'lI
'TASK :Reads two strings 'which can be edited from the input line'lI
using cursor left/right,backspace and delete.'lI
In addition the string scrolls when the input extends past'lI
the screen line 'lI
'PARAMETER:~>old$ old value of string to be read'lI
a$ key pressed 'lI
z$ valid characters'lI
z line'lI
s column'lI
inplen Length of input window'lI
<=old$ specified string'lI
IF inplen =1 THEN 'if only one char entered? ~> no Return'lI
old$=a$'lI
WHILE INSTR(z$,old$)=O'lI
CALL getkey(old$,z,s)'lI
WEND'lI
LOCATE z,s'lI
PRINT oldS'lI
ELSE'lI
i=l 'points to current string position'lI
position-l 'points to current screen position'lI
WHILE ASC(aS»<13'lI
IF INSTR(z$,a$»<C THEN 'valid character?'lI
old$~LEFT$ (old$, i-I) +a$+RIGHT $ (old$, LEN (old$) - i + 1) 'lI
i~i+1'lI
position=position+1'lI
IF position>inplen THEN'lI
position~inplen 'lI
END IF 'lI
ELSE 'lI
IF ASC(a$)=30 AND i<=LEN(old$) THEN 'Cursor right?'lI
i=i+1'][
position=position+l'J[
IF position>inplen THEN'lI
position~inplen 'lI
END IF 'lI
ELSE'll
IF ASC(aS)=31 AND i>l THEN 'Cursor left?'lI
i=i-l'lI
position=position-l'll
IF position-O THEN'll
position=l'lI
END IF 'lI
309
ApPENDIX C - THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
ELSE'll
IF ASC (as)' 127 MD i<=LEN(old$) THEN 'delete?S
old$=LEFT$ (old$,i-l) ,RIGHT$ (old$,LEN(old$)-:)'l[
ELS~~
~F AS2(a$)=!3 liND i>l THEN 'tlaekspace?'ll
i~i-l'll
posiLion=position-l'
IF posi tion=O THEN'll
posiLion=l'll
,,:N;) IF'll
oldS=LEFT$(old$,i-l)+P:GET$(old$,LE~(old$)-i)'ll
END IF'll
END IF'll
END IF'll
END IF'll
f,:,D IF'll
=_OCATE z, sS:
PRINT MID$(old$+" ",i-position+1,inplen 'String output'll
CALL getkey(a$,z,s+position-l) 'get nexl key'll
WEND 'lI
END le'll
IF i><positien THEN'll
CALL putstring(o:d$,z,s,inplen I'll
END IF 'll
END SUB'll
'll
SUB gctint(i!,aS,z,s,inplC'r'. ,unt!,ob~) STATIC <n
lTt~SK :Read int..eqer valucll
'?ARAMETER:::::>i! old va:uetJ!
el$ pressed key'll
z line'll
s enl ',lmr,~1
i f1t1ler1 Len']U-! 0: inplJt ~ i ry'Tl
llnt' lower Limit'll
ob! upper limit'll
<=i! speci fieel valueSI
C!\',L eonreaL,tr (L', j$) q:
loop:'
i$~j$ 'll
CALL ge:,sLring(i$,ilS,"1234567890-",z,s,inplen I'll
j$=i$'ll
CALL constrn~al(i$,i')'ll
[l·' i$- 1111 OE i~<lJn:! OR j !>Ct;: THEN IY,(:CF search_:nq '.-.':-;ile inp',ll: i:3 valid'11
a$=11"qr
C;01'0 1 e"p'll
END IF'll
E~D SUR'll
'll
SUB gc~real (i!,aS,z,s,inplcn ,unt:,ob: I STATIC'll
'TASK :Read in reell vaiue~
'PARAMETER> >i I old value'll
a$ pressed key'll
z ~inc'll
s co Llmn'll
lengt~ of input ,ine~
unt! lower limit'
ob! upper limit~
speci fied value,,!
<~i!
CALL conrealstr(i', jS)'ll
loopl: 'll
i$=jS~
CALL gets~ring(i$,a$,"123456,)89C-,",z,s,inplen I'll
310
ABACUS ApPENDIX C - TilE EDITOR PROGRAM
j$~i$'ll
CALL constrreal(i$,i')'ll
IF i$~"" OR i!<unt! OR i!>ob! THEN'll
a$=" IiqI
GOTO loopl'll
END IF'll
END SUB'll
'll
SUB get3real(il!,i2!,i3!,a$,z,s.i~pler ,unt!,ob! ,~~(~us) STATIC~
'TASK :read 3 Real values in'll
'PARAMETER:=>il!,i2!,i3' o~d value'll
a$ key pressed'll
z line'll
s column'll
inplen Lenght of input line'll
unt! lower limit'll
ob' upper limit'll
modus i[=O no mOLS\:: crlLrl''l1
if=-: mOllse ~~piJt. (position vccto~)~
if>O mous(~ inpuL (Differc;)ce vector)'l1
<=i1!,12!,13' specified valueS
SHl.RED max! I moy! , moz ! , k! () qr
CALL con3realstr(il!, i21, i3', j$)'ll
IF a$="" THEN'll
CALL getkcy(a$,7,s)'ll
El'JD IF 'll
IF ASC (a$) ~13 r,\1! rnodus><O Tl'c,,~.
IF modus=-l THEN'li
i1: =rnox! 'll
i21=moy!'ll
13! ~moz! 'll
ELSE'll
ill =rnox ! - k! (modu s, 1 , 0) 'll
i2!~moY'-k' (moGus, 1, 1) 'll
i 3 ! =moz ~ - k! (f:!odu s, 1, 2) 'JI
END IF'll
CALL pu t, 3 ; (; 0 L (i '1 : , :i 2! , i 3 ! , z, -" 2 (;) S;
fOLSE'll
100p2:'lI
i$=j$ 'll
CA1.L getstring(i$,aS,"1234S67890-.,",z,s,i;,plen )'ll
j$=i$'ll
CALL constr3real (i$, iI', i2' ,L 3!) 'I
IF i$="11 OR il!<unt! OR i2!<unt~! (J~ ~3!<unt: OH il''>ob! OR. i2!>ub! i3'>ob'
THEN'll
a$=11 "qr
GOTO loop2'Ji
END IF'il
END IF'll
END SUB 'll
'Il
SUB getkey(a$,z,s)STATlct
'TASK :RC,1d o~e character j:~~
'Pi\RAMETER:=>z :ine91
s urrr,'l1
<=a$ pressed keyCf
CALL seccursor(z,s) 'Il
a$='''''i1
WHILE a$~""'i1
a$=INi<EYS'll
WEND'll
CALL setcuL';nr (z, 51 'll
311
ApPENDIX C - TilE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END SUB'll
'll
'll
SUB setcursor(z,s) STATICTc
'TASK :set cursor at specified position'll
'PARAMETER:=>z line'll
s column'll
SHARED cw%,ch%'ll
CALL setdrmd& (WINDOW (8) ,2)'ll
LINE (s*cw%-cw%, z*ch%-c'1%-l) - (s*cw%, z*ch%-1), J, bf\:
CALL setdrmd& (WINDOW (B) ,l)'ll
END SUB 'll
'll
I******************~
,~* DATA ENTRY **'ll
'******************~
'The following proceures are similar to the ones en
'documented earlier.'ll
'll
SUB getplane(ptr) STATIC'll
'TASK :Read the data for one Plane'll
'PARAMETER:=>ptr points to the element to be read'll
SHARED k! (),tabs(),min!,max!'ll
tabs(O,O)~2 'set tabs for menu'll
tabs(1,O)=2'll
tabs(2,O)=JTt
tabs(3,O)=4'll
tabs(4,O)=S'll
tabs(O,1)=10'll
tabs(1,1)=22'll
tabs (2, l)=4'll
tabs(3,1)=4'll
tabs(4,1)=4'll
nr=O'll
WHILE nr<=4 'wait until last line is overwritten'll
CALL gctkey{a$,tabs{nr,O),tabs{nr,l))~
IF ASC(a$)=28 THEN 'cursor Up?'i]
IF noO THEN'll
nr=nr-l'll
END IF '11
ELSE '11
IF ASC(aS)=29 THEN 'cc;rsor dowr?'ll
nr=nr+1'11
ELSE'll
IF nr=O THEN 'can you see it? read it 'll
CALL getstring(b$,a$,"yn",tabs(nr,O),tabs(nr,1),1)'ll
IF b$="y"THEN 'not input'll
k' (pt r , 5, 2) =l 91
ELSE'll
k! (ptr,S,2)=O'II
END IF'll
END IF'lI
IF nr=l THEN 'Read M'I1
CALL getint (k' (ptr, 0, 2) ,as, tabs(nr,O), tabs (nr, 1),5, l' ,max') Tt
END IF 'II
IF nr=2 THEN 'A read'll
CALL
get3real (k! (ptr, 1, 0) , k' (ptr, 1,1) ,k' (ptr, 1, 2) ,as, tabs (nr, 0) ,tabs (nr, 1) , 26, mit'.! ,max' ,
-1)'11
END IF'll
IF nr=3 THEN '8 read'II
312
ABAC1JS ApPENDIX C- TilE EDITOR PROGRAM
CALL
get3real (k' (pt r, ~, 0) , k: (ptr, ~, 1 ) , k 1 (pt r, 2,2) ,as, tabs (n::, 8) , t,~ (cC; (:c c, :.) , 76, [;',.'.n 1 , max 1
,ptr) 'II
ENG IF'll
I~ ~r 1 Tf~~~ Ie ~e~(~S
CAl,)
get 3real (;': (pc r, 3, C) , k! (F'::,:', ] ) , k : (pc,::, 3,2) ,a$, tabs (n r, C) , - ; ~\::- f ~ ) , ;) 6, rn i r. ! , max! ,
ptr) 'II
END IF'll
nr=nrtl'II
END IF'll
END IF'll
WEND'll
END SUB 'II
'II
SUB getcrseg(ptr) STATIC'll
SHARED k! (),tabs(),min!,max!,grad',rad''ll
tabs(O,O)=2'll
tabs(1,G)=2'll
tabs(2,O) 03 'II
tabs(3,O) 4':
tabs(4,8)=5<;'
tabs(5,8)=6S:
tabs(6,O)~6'll
tabs(O,l)=lC'll
tabs(1,1)::o7791
tabs(2,1)=4'II
tabs(3,1)=4'll
tabs(4,1)=4'll
l.abs(5,1)=4'll
tabs (6,1)=16'll
nr·- OS[
WHILE nr<=,6'll
CALI getkey(a$,tabs(nr,O),tabs(nr,l))'1
IF A3C(aS)=28 THEN'll
IF n!:':·"r, TH:.N91
nr=r.l-'S:
EN!) .'." 'II
ELSE?,
IF ASC(~5)-) ~HEN'l1
nr :lr 1 sr
ELSE'0
IF' :l! -0 THF,\ig
CilLL getstring(b$,a$,"yn",tab.s(nr,O),tabs(nr,l),l)'lI
IF b$="y"THEN'll
k! (ptr, 5,2) =l'll
ELSE'll
k' (ptr, 5, 2) =O'll
END IF'll
END IF'll
IF nr~,l THEN'll
CALL getint(k! (pcr,O,2),aS,tar,s(rcr,O),tabs(nr,1I,c,11,max ' )'ll
EN!) IF 'iI
IF nr ; "',T::tJ'iI
Cl\~, L
get.Jrca~ (i<' (p~_::-, l, 0),", I (~)~r, 1 1), i<! (p:c, 1, 2) ,r'lS, tdbs (;-;:--,
f ",' (r-,' I - I I' f- ,., ~:-'.: ,max! ,
-1) 'll
E~~D I ="~
I ~ '-if - J -: dE~~~l
Ch~Jl,
get 3redl (k! (pt r, 2, 0) ,1<. ! (pt.r, 2, J ) , :.::: (ptl, / ,2) , as, tabs (n r, (}) , :,abs (or, 1) , ? 6, mi n : , max ~
,ptr)'l[
313
ApPEl'iIHX C- THE EDITOR PROGRAM AMIGA 3D GRAPIIIC PROGRAMMI:\G
END It''ll
IF nr=4 Tt-it.:N'TI
CALL
get 3real (k: (ptr, 3,0) , k ~ (pL:-,.3, 1) , k! (pt r, :3 2) , as tabs (n r, 0)
f I I ~ dbs (nr , 1 ) ,26, rni n ~ , max: ,
ptr) 'I!
END IF'll
IF nr:=5 ~HF~\'q[
k!~k! (ptc, 5, 0) *grad''ll
CALL "cLreal (k!, as, tabs (nc, C), tabs (nr, 1),8, r.:, ~:ax!) q[
k! (ptr,.'i,(1)~rad!*k!'II
END IF Tt
IF nr=6 THEN'll
k!=k! (ptr,5,] )*grad''II
CI\LL getreal(k',aS,t.abs(nr,O),tabs(",:,1),8,min',max'J'j
k! (pt r, 5, 1 ) r ad ' * k' 'll
0
END IF 'f
n r:::::nr+ :_ ~
END IF'll
END IF'll
WEND 'll
END SUB'll
'II
'll
SUB getcrarc(ptr) STATIC~
SHARED k! (), tabs (), min!, max! I CjTdd:, ~-a:l ~ en
tabs (0, 0) ~,'2'll
tabs(I,O)~2'll
tabs(2,O)~3'll
tabs (3, 0) =4'll
L)bs(~,O)o5'1l
tabs(5,O)=6'1l
tabs(6,O)=6'1l
tabs (7, OJ = 7 'I!
tabs(8,O)=7'j[
tabs (0, 1) =elOS!
(abs(I,1)=22",
tabs (2, 1) ~'-Il?
tabs (3,1) c4'J]
tabs(4,l) =4 'II
tabs (5, : ) cc4'1l
tabs (6,',) =16'll
tabs(!.1)=4'1l
tabs(8,l)=16S
nr=O'l!
vJHILE nr<::8(n
CALL qctkcy ('~J::-'f ~.ar)s (:lr, 0), L~:;> ([1:-,.)) Sl
IF' J-.JSr: (,1$) -=28 TH~N~l
iF nr>Q THE~J91
".1'=nr-1 'II
'F 'II
EL 'II
ie' ASC(a5)=29 "f'E'!'j
nr=nr+l<t[
ELSE'll
IF nr~-G
CALL geLst.ring{b$,a$,lIyn",taos{nr,O) ,tabs{nr,l.),l)qr
IF b$="y"THEK'iI
k! (ptr,5,2)c'J~[
ELSE 'I!
k! (ptr,5,2) clJ,![
ENl) 1 F'1i
END E':i
314
ABACUS ApPENDIX C- TilE EDITOR PROGRAM
IF nr=1 THEN'll
CALL getint (k' (ptr, 0, 21 ,a$,tabs(nr,OI, tabs (nr, 1),5, I' ,,",ax' I 'IT
END IF 'll
IF nr=2 THEN'll
CALL
get3real (k' (ptr, l, 0) , k' (ptr, 1., 1 I , k! (pt r, l, 2) , a$, tabs (nr, 01 , tabs (nr , ~ I , 26, min! , max! ,
-II'll
END IF'll
IF nr=3 THEN'll
CALL
get3real (k! (pt r, 2, 0) , k! (ptc, 2, 1 I , k I (ptr, 2, 2 I ,a$, tabs (nr, 0) , tabs 1r, c, : I , 26, ffiln I , rndX I
,ptr)'ll
END IF'll
IF nr=4 THEN'll
CALL
get3real (k! (ptr, 3, 01 , k' (ptr, 3, 1 I , k I (pt.:-, 1,2 I ,a$, tabs (n r ,: I , ~ abs (nr, 1 I , 2 E, m'cnO ' , max'
,ptrl'll
END IF'll
IF nr=5 THEN'll
k!=grad!*k! (ptr,5,O)'ll
CALL getreal (k ' ,as, labs (nr, 0), tabs Inr, ~I, 8,min' ,max! I 'll
k! (ptr,5,O)=rad'*k ' 'lI
END IF 'll
IF nr=6 THEN'll
k!=grad'*k! Iptr,S,ll'll
CALL getreal (k',a$,tabs(nr,C),cclbs(nr,l) ,8, ;::,ITIdX ' )9]
k! (ptr,5, l)-rad!*k!9]
END IF 'II
IF nr=7 THEN'll
CALL getreal(k' Iptr,4,O),a$,tabs(nr,0),tabs(nr,l),8,O!,l'I'II
END IF 'll
IF nr=8 THEN'll
CALL get real (k' (ptr, 4, l) ,a$, tabs (nr, 01, tabs (nr, l) ,8, O! ,l ! I 'll
END IF 'll
nr=nr+19]
END IF'll
END IF'll
WEND'll
END SUB 'IT
'll
'IT
SUB getsphere(ptrl STATIC'll
SHARED k' (),tabsl),min!,max!9]
tabs(0,0)=2'IT
tabs(l,01=2'll
tabs(2,0)=3'll
tabs(3,0)=4'll
tabs (O,ll=lO'll
tabs (1,1) =22'll
tabs (2,l)=4'll
tabs(3,l)=4'll
nr-O'll
WHILE nr<=3'll
CALL getkey(a$,tabs(nr,O),tabs(nr,l))'ll
IF ASC(a$)=28 THEN'll
IF nOO THEN'll
nr=nr-I'll
END IF 'll
ELSE'll
IF ASC(a$)=29 THEN'll
nr=nr+;'ll
ELSE'll
315
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
IF nr=O THEN'l[
CALL getstring(b$,a$,"yn",tabs(nr,0),tabs(nr,1),1)1!
IF bS="y"THEN'l[
k' (ptr,5,2)=1'l[
ELSE 'l[
k! (ptr, 5, 2) =O'l[
END IF'l[
END IF'l[
IF nr=1 THEN'l[
CALL getint (k! (ptr, 0, 2) ,as, tabs (nr, 0), tabs (nr, 1) ,5,1! ,max!) 'II
END IF 'l[
IF nr=2 THEN'l[
CALL
get3real(k! (ptr,l,O),k! (ptr,l,l),k! (p~r,1,2) ,a$,tabs(nr,O) ,tabs(nr,I),26,-
1000!,1000!,-1)'l[
END IF'l[
IF nr=3 THEN'l[
CALL get real (k' (ptr,;:>, 0), as,tabs (nr, 0), tabs(nr, 1),8,0' ,max!) 'II
END IF 'II
nr-nr+1'll
END IF'll
END IF'll
WEND 'l[
END SUB 'II
'l[
'l[
SUB getcyl(ptr) STATIC'l[
SHARED k! () ,tabs () ,min!, max! 'II
tabs(0,0)=2'l[
tabs(1,0)=2'l[
tabs(2,0)=3'l[
tabs(3,0)=4'lI
tabs(4,O)=5'l[
tabs(5,0)=6'11
tabs(O,l) =10'11
tabs(1,1}=22<Jl
tabs(2,1)=4'll
tabs(3,1)=4'll
tabs(4,1)=4'll
tabs(5,1)=4'll
nr=O'll
WHILE nr<=5'll
CALL getkey(aS,tabs(nr,O),tabs(nr,l))'11
IF ASC(aS)=28 THEN'll
IF nr>O THEN'l[
nr=nr-l'l[
END IF 'l[
ELSE 'l[
IF ASC(aS)=29 THEN'll
nr=nr+1'll
ELSE'l[
IF nr=O THEN'll
CALL getstring(b$,a$,"yn",tabs(nr,O) ,tabs(nr,l),l)'Il
IF bS="y"THEN'Il
k' (ptr,5,2)=1'll
ELSE'll
k! (ptr,5,2)=0'll
END IF'l[
END IF'll
IF nr=l THEN'll
CALL getint(k! (ptr,O, 2) ,a$,tabs (nr, 0), tabs (nr, 1) ,5, l' ,max!) 'l[
END IF 'l[
316
ABACUS ApPENDIX C- THE EDITOR PROGRAM
IF nr=2 THEN'lI
CALL
get3real (k! (ptr, 1, 0) ,k! (ptr,l,l) ,k! (ptr, 1,2) ,a$, tabs (nr, 0), tabs (nr, 1) ,26,min! ,max!
,-1) 'lI
END IF'lI
IF nr=3 THEN'lI
CALL
get3rea1 (k! (ptr, 2, 0), k! (ptr, 2, 1), k' (ptr, 2, 2) ,a$, tabs (nr, 0) ,tabs (nr, 1), 26,min!, max!,
ptr)'lI
END IF'll
IF nr=4 THEN'lI
CALL
get3real (k! (ptr, 3, 0), k! (ptr, 3, 1), k! (ptr, 3, 2), a$, tabs (nr, 0) ,tabs (nr, 1),26, min! ,max!,
ptr)'lI
END IF'lI
IF nr=5 THEN'lI
CALL
get3rea1 (k! (ptr,4, 0) ,k! (ptr,4,1), k! (ptr, 4,2) ,a$,tabs (nr, 0) ,tabs (nr,1) ,26,min! ,max!,
ptr)'lI .
END IF'lI
nr=nr+l'lI
END IF'lI
END IF'lI
WEND'lI
END SUB 'll
'lI
SUB getcylseg(ptr) STATIC'll
SHARED k! () ,tabs () ,min!, max!, grad! ,rad! 'll
tabs (0,0)=2'lI
tabs (1,0)=2'lI
tabs (2,0)=3'lI
tabs(3,0)=4'lI
tabs(4,0)=5'lI
tabs (5,0)=6'lI
tabs (6,0)=7'll
tabs(7,Oj=7'lI
tabs(0,1)=10'lI
tabs (1,1) =22'lI
tabs (2, 1) =4'lI
tabs (3,1)=4'lI
tabs(4,1)=4'lI
tabs(5,1)=4'lI
tabs (6,1)=4'lI
tabs (7,1) =16'll
nr=O'lI
WHILE nr<=7'lI
CALL getkey(a$,tabs(nr,O),tabs(nr,l»'lI
IF ASC(a$)=28 THEN'lI
IF nr>O THEN'lI
nr=nr-1'lI
END IF 'lI
ELSE 'lI
IF ASC(a$)=29 THEN'll
nr=nr+1'lI
ELSE'll
IF nr=O THEN'll
CALL getstring(b$,a$,"yn",tabs(nr,O),tabs(nr,l),l)'lI
IF b$="y"THEN'lI
k! (ptr,5,2)=1'lI
ELSE'lI
k! (ptr,5,2)=0'll
END IF'l!
317
ApPENDIX C- TilE EDITOR PROGRAM AMIGA 3D GRAl'lllC PROGRAMMING
END =~c'll
IF nr=i ';HEN'Il
CALL getir,t (k I (ptr, 0, 2), as, tabs (nc, 0), tabs (nr, :),5,1!, max!) 'Il
END IF 'i!
IF nr~2 THEN'i!
CALL
qet3rea 1 ('<! (p~ r, " , 0) , k I (ptr. 1 , 1 ) , k I (ptr, 1,2) , as, ti'lDS (n r, 0) , tal)S (n r, 1) , 26, min I , max:
,-1) 'Il
END IF'i!
IF nr=3 THEN'i!
CA~L
get 3 real (k! (ptr, 2, 0) , k! (pt.::-, 2, 1) , k! (pt r, 2, 2) , a$, tabs (:cr, 0) , t ,lbs (nr, 1) , 26, mi n I , max! ,
ptr)'i!
END IF'll
IF nr~4 THEN'll
CALL
(Jet 3real (k! {pt::", 3, 0) , k! (ptr :3, ~} 1(': (pt r·, 3,2) , ~l$, L1CS (n riO) , taj~~:: (:' r, 1 ) , 26, m.l r: ! , rnax ~
f f
ptr) 'Il
END IF1!
IF nr=-5 'i'HENcrf
CALL
getJreal ik ' (ptr,4,O),k ' (ptr,4,1),k ' (ptr,4,)),a$,tabs(n:c,O),tabs(nr,1),2G,min',max!,
ptr)'i!
END IF'lI
IF :".::- 6 TfiEN'Il
k"'qrad'*k! (ptr,J,:J)qT
CALL qctreal {k! , as, t.abs (nr, 0) , tabs (ilr, 1) ,;., 6, mi n! ,fi.ax' ) ~
k ~ (pt r, 5, 0) :::: r ad! * k : ~
END IF",
IF nr'~7 THEN'i!
k!=grad!*k' (ptr,5,1)'Il
CALL get rea 1 (k: ,,,$, tabs (nr, 0) ,tacs (nr, 1) ,26, min! ,max I) 'li
k' (ptr,S,i),crad'*k!'l[
END ~;,-S;
n 'r-=~' -:--+ ~ q]
END JFS
I'JEND'l[
END SUR 'll
S
'll
I ******-k******l1
318
ABACUS ApPENDIX C- TilE EDITOR PROGRAM
IF k! (ptr,S,2)=0 THEN'll
PRINT "n"'II
ELSE 'II
PRINT "y"'II
END IF'll
LOCATE 2,13'II
PRINT "Material:"'II
CALL putreal(k! (ptr,0,2),2,22,S)'II
IF typ=10 THEN'll
LOCATE 3, I'll
PRINT "M : "'II
PRINT "r : "'II
CALL put3real (k! (ptr, 1, 0) ,k' (ptr, 1,1) ,k' (pt!, 1,2) ,3, f;, 26) 'II
CALL putreal(k! (ptr,2,0),4,4,8)'II
ELSE'll
LOCATE 3,1'II
PRINT "M : "'II
PRINT "A : "'II
PRINT "B :"'II
CALL put3real(k! (ptr,l,O),k! (ptr,l,l),k! (ptr,1,2),3,4,26)'II
CALL put3real (k! (ptr, 2, 0) ,k! (ptr, 2,1) , k! (ptr, 2, 2) ,4,4,26) 'II
CALL put3real(k! (ptr,3,0) ,k! (ptr,3,1),k! (ptr,3,2) ,S,4,26)'II
IF typ>=4 THEN'll
IF typ>=20 THEN'll
LOCATE 6,1'II
PRINT "C :"'II
CALL put3real(k! (ptr,4,O),k! (ptr,4,1),k! (ptr,4,2),6,4,26)'Il
IF typ=21 THEN'll
LOCATE 7,1'II
PRINT "sw:"'II
LOCATE 7, l3'II
PRINT "ew: "'II
CALL putreal (grad!*k' (ptr,S,O), 7,4,8)'11
CALL putreal(grad!*k' (ptr,S,l), 7,16,8)91
END IF'll
ELSE'll
LOCATE 6,1'II
PRINT "sw:"'II
LOCATE 6,13'll
PRINT "ew:"'ll
CALL putreal(grad!*k! (ptr,5,O),6,4,8)'11
CALL putreal(grad'*k! (ptr,5,1),6,16,8)'11
IF typ=5 THEN'll
LOCATE 7, I'll
PRINT II ri: II<J[
LOCATE 7,13'11
PRINT "ra: '''ll
CALL putreal (k' (ptr,4,O), 7,4,8)'ll
CALL putreal(k' (ptr,4,1), 7,16,8)'ll
END IF'll
END IF'll
END IF'll
END IF'll
END IF'll
END SUB'll
'Il
SUB putstring (s$, z, s, inplen ) S'~ATIC'll
'TASK :output of a string of a cerlain length'll
'PARAMETER:=>s$ the string'll
z line'll
s column'll
.inplcn IJength (Jf O\Jtput window~
319
ApPENDIX C - THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
320
ABACUS ApPENDIX C- THE EDITOR PROGRAM
i$="I1Cj[
END IF 'll
END SUB'll
'll
SUB constr3real(iS,il!,i2!,i3!) STATICil
'TASK :convert one string into 3 real values'll
'PARAMETER:=>i$ the string'll
<=i1' ,i2!,i3' the real va:ues'll
i$ if conversion error is=·"'
Problem=O'
i$=i$+","cn
FOR i=1 TO 3'
comma=INSTR(i$,",") 'Mark comma position'll
IF comma<=l THEN 'Problem ?'ll
Problem=l'll
ELSE!
a$=MID$ (i$, I,comma-I) 'truncate string to be converted'll
i$=RIGHT$(i$,LEN(i$)-comma) 'mark the rest'll
CALL constrreal(a$,i! (i)) 'convert'll
IF a$="· THEN 'Problem?'ll
Problem=I'll
E~D IF 'll
END IF!
NEXT i'll
IF Problem=l THEN!
i$="" 'IJ
ELSE!
i$=" "<J{
il! =i! (1) 'll
i2!=i!(2)'ll
i3'=i! (3) 'IT
END IF'll
END SUB 'IT
'IT
jI
SUB con3realstr(il!,i2',i3',i$) STATIC'll
'TASK :convert 3 real val~es into vector string~
'PARAMETER:=>i1!,i2',i3! the J Real values'll
<=i$ the string'll
CALL conrealstr(i1!,iIS)'ll
CALL conrealstr(i2!,i2S)'ll
CALL conrealstr(i3',i3S)'ll
i$:-i1$+", "+i2$+u, u+i3$<JI
END SUR'll
'll
'll
I**************~
321
ApPEl"D1X C - Tm: EDITOR PROGRAM AMIGA 3D GRAPIIIC PROGRAMMI;>;G
by : =k! (p t r , 3, 1 ) <fi
bz ! ,-: k! (pt r , :3, 2) q[
WINDU\,oJ O(Y~?V~' : q
CA.LL setpCl:lt. (ax: +-r:lX!, ay! -!my!) en
CALL drat';}::le (mx! , rry!) 9I
CALL drawline(rnx:+bx!,my!+by:) q[
WINDOW OUTPClT 7'TI
CALL setpGint (ax ',rrex', az I t'"'z!) ~[
CALL dra"line (rnx' ,mz!) 'll
CALL drawline{mx!+bx~,:T\z!+b2~) qr
WIND()W CUTPUT 3'IT
CALL setpoint.(ay!+my!,az!+mz!)<n
CALL draw 1 i ne (my! , mz ! ) en
CALL rirawlin~ (my I + by I , m7 '+bz I ) 'll
WINDOW OUTP~T 4'![
END SGb'll
'IT
SUB drawtriangle(ptr) STATIC'
SHARED k 1 () ~,
mx!::~k! l:ptrrl,C)S
rry'=k ' (ptr, 1, l)'ll
me! =k I (pu, 1,2) 'll
ax'ek' (ptr,2,8)~1
ay: k: (ptr,2, l)\~
az'=k' (p'~r,2,2)'![
bx'=k! (pt[,3,O)'ll
by'=k I (ptr, 3, 1) 'll
bZ'~K: Iptr,3,))'
WINDOW OC~?UT 1'll
CALL set,'s i:ot (mx: ,rey 1) 'll
CA:,Lrir·w; in" (,lX! +rnx I, ay' tmy') 'll
CALL drc"wiine (bx' +mx I, Ly! +my I) 'l!
C:,i\T ,\. ,
dra'""lint(rnx:,[T!Y!}
WINDOW OUTP:JT 2'll
tnt (mx! ,mz ~) 9i
ay!--:;: (ptr,2,:)'lI
az'=k! (ptr,2,2)'ll
bx'=k! (ptr,3,O)'lI
by>k ' (ptr,:i,l)'lI
bz ' ,+k! (ptr,3,))'TI
WINDOW eJUTP'JT l~'
CALL seLpoi nt (mx: ,rey 1) 'll
CALL d["awl in2 (ax! +mx! , ay! +my ~) ~
CALl, drawlinc(c1x!-t-bx~ ·:;.x!,ay!-t-cy!+my!)<f
322
ABACUS ApPEl'\DIX C- TilE EDITOR PROGRAM
323
ApPENDIX C- TilE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
WINDOW OUTPUT 3~
CALL drawellipse (ay! ,az! ,by! ,bz' ,;e,y' ,mz', sw! ,ew!) 'iI
CALL setpoint (ay! *COS (sw') +by! *SIN (sw! )+my! ,az! *COS (sw!) +'oz' *SIN (sw') +mz!) ~
CALL drawline(my!,mz')~
CALL drawline (ay! *COS (ew!) +by' *SIN (ew') +my! ,az' *COS (ew!) +bz! *SIN (ew') +mz') ~
WINDOW OUTPUT 4'll
END SUB 'iI
~
SUB drawcrarc(ptr) STATIC~
SHARED k' () 'll
mx!=k' (ptr, 1,0) 'iI
my'=k! (ptr, 1, 1) 'll
mz'=k! (ptr,1,2)'l[
ax!=k' (ptr,2,O)~
ay!=k! (ptr,2,1)'ll
az'=k! (ptr,2,2)'l[
bx!=k! (ptr,3,O)~
by'=k! (ptr,3,1)~
bz!=k! (ptr,3,2)'ll
sw!=k! (ptr,5,0)'ll
ew'=k! (ptr,5,1)~
ri!=k! (ptr,4,O)~
ra!=k! (ptr, 4, 1) 'll
WINDOW OUTPUT l'll
CALL drawellipse (ax! *ra! , ay! * ra! f bx! *ra! , by ~ * ra! I mx! ,my! I Sw! , cw! ) Ijj
CALL drawellipse (ax! * ri! , ay! * ri! bx! *r i! by! * ri! mx! ,my! , sw! ,ew! ) en
I I I
CALL
setpoint (ax! *ra'*COS (sw') +bx' *ra'*SIN(sw') +;ex' ,ay' *,-a' *COS (sw:) +by' ',-a' *SIN (sw') tmy
!) ~
CALL
drawline(ax!*ri '*COS(sw!) +bx! *ri '*SIN(sw') +t:'x! ,ay' *ri' *COS (sw') +by' *d' 'SIN (sw') tmy
! )'iI
CALL
setpoint(ax'*ra!*COS(ew!)+bx!*ra!*SIN(ew!)tmx',ay!*ra!*COS(ew!)+by'*ra!*SIN(ew!)+my
!) 'iI
CALL
drawline (dx!*ri ! ""COS {ew! ) -rDx! *ri !*SlN(ew!) +mx! fay! *r:! *eos (e',.,;: )+by! *[~! *SIN (ew!) +my
!)'ll
WINDOW OUTPUT 2'll
CALL drawellipse (ax! * r a ~ , az! * ra ! , ox! * ra ~ , bz ! * ra! iTx! , mz ! 5''''; : , ew! ) q[
I I
324
ABACUS ApPENDIX C - THE EDITOR PROGRAM
CALL
setpoint (ay! *ra! 'COS (ew! ) +by' *ra! *SIN (ew') +my! ,az' *ra! *COS (ew!) +bz! *ra! *SIN (ew') +m
z!) 'll
CALL
drawline (ay! *ri! *COS (ew') +by! *ri! *SIN (ew!) +my!, az' *ri! *COS (ew') +bz! * ri! *SIN (ew!) +m
z! )'ll
WINDOW OUTPUT 4'll
END SUB 'll
'll
SUB drawsphere(ptr) STATIC'lI
SHARED k' () ,pi2''lI
mx'~k! (ptr,l,O)'lI
my!=k! (ptr,l,l)'ll
mz'~k' (ptr,1,2)'ll
r'=k! (ptr, 2, 0) 'lI
WINDOW OUTPUT 1'll
°
CALL drawell ipse (r! ,0 ! , o! , r! ,rnx! ,my! , ! , pi2' ) 'll
WINDOW OUTPUT 2'll
CALL drawellipse (r! ,O!, O! ,r! ,rnx' ,mz! ,a! ,pi2') 'll
WINDOW OUTPUT 3'll
CALL drawellipse(r!,0!,0!,r!,my!,mz',0!,pi2!)'ll
WINDOW OUTPUT 4'll
END SUB 'll
'll
'lI
SUB drawcone(ptr) STATIC'll
SHARED k! () , pi 2 ! 'lI
mx'~k! (ptr,l,O)'ll
my!~k! (ptr,l,l)'ll
mz!~k! (ptr,1,2)'ll
ax'=k! (ptr,2,O)'ll
ay!~k! (ptr,2,1)'l[
az!=k! (ptr, 2, 2) 'll
bx!~k! (ptr, 3,0) 'll
by!=k! (ptr,3,1)'ll
bz!=k! (ptr,3,2)'l[
cx!=k! (ptr,4,O)'ll
cy!=k! (ptr,4,1)'lI
cz!=k! (ptr,4,2)'ll
WINDOW OUTPUT I'll
CALL drawellipse (ax', ay! ,bx' ,by! ,mx' ,my', 0' ,pi2') 'lI
CALL setpoint(ax'+mx!,ay'+my!)'lI
CALL drawline(ex!+mx',cy!+my')'lI
CALL dra""line (mx!-ax! ,my! -ay!) 'lI
CALL setpoint (bx' +rnx!, by' +my! ) 'lI
CALL drawline(cx'+rnx!,ey!+my!)'lI
CALL drawline(mx!-bx',my'-by!) 'lI
WINDOW OUTPUT 2'lI
CALL drawellipse (ax! ,az! ,bx! ,bz! ,rnx! ,mz! ,O! ,pi2!) 'll
CALL setpoint(ax!+mx',az!+mz!)'lI
CALL drawl ine (ex! +mx!, ez! +mz! ) 'lI
CALL drawline(rnx!-ax!,mz'-az!) 'lI
CALL setpoint(bx!+mx!,bz!+mz')'l[
CALL drawline(ex!+mx',ez'+mz')'ll
CALL drawline(rnx'-bx!,mz!-bz!) 'lI
WINDOW OUTPUT 3'll
CALL drawellipse(ay!,az',by',bz',my',mz',O',pi2')'lI
CALL setpoint(ay!+my!,az'+mz!)'ll
CALL drawline(ey'+my!,ez'+mz')'lI
CALL drawline(my'-ay',mz!-az') 'lI
CALL setpoint(by'+my!,bz'+mz')'lI
CALL drawline(cy'+my!,cz'+mz!)'ll
325
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
326
ABACUS ApPENDIX C- THE EDITOR PROGRAM
bx'~k!
(ptr,3,0)'ll
by!4' (ptr, 3, 1) 'll
bz!-k! (ptr,3,2)'lI
ex!~k! (ptr,4,0)'lI
ey!=k! (ptr, 4, 1) 'lI
ez'=k' (ptr,4,2)'ll
sw'=k! (ptr,5,0)'lI
ew'=k! (ptr,5,1)'lI
WINDOW OUTPUT 1'lI
CALL drawe11ipse(ax' ,ay',bx!,by',rnx'+ex',my'+ey',sw',ew')'ll
CALL drawell ipse (ax!, ay! ,bx! ,by! ,mx!, my! ,sw', ew' ) '![
CALL setpoint(mx!,my!)'ll
CALL drawline(mx!+ex!,my'+ey')'![
CALL
drawline (ax! *COS (ew' ) +bx' *SIN (ew! ) +mx' +ex I , ay' *COS (ew I) +by 1 *SIN (ew' ) +my! +ey I) 'll
CALL drawline(ax'*COS(ewl)+bx!*SIN(ew:)+mx',ay!*COS(ew')+by!*SIN(ew ' )+my:)'l[
CALL drawline(rr~' ,myl)'l[
CALL drawline (ax' *COS (sw!) +bx! *SIN (sw') +rnx! ,ay! *COS(sw:) +by' *SIN (sw!) +my:) '![
CALL
drawline (ax! *COS (sw!) +bx' *SIN (sw!) +mx! +ex!, ay' *COS (sw!) +by! *SIN (sw') +my! +ey!) 'll
CALL drawLine(mx!+ex!,my'+ey')'lI
WINDOW OUTPUT 2'lI
CALL dr<1wellipse (ax!, az! ,bx ' ,bz! ,mx! +ex!, mz 1 +ez!, sw!, ew!) 'lI
CALL drawellipse (ax' ,az I , bx! ,bz I , mx! ,mz I , sw!, ew!) '![
CALL setpoint (mx! ,mz!) 'll
CALL drawline (mx 1 +ex', mz! +ez!) 'll
CALL
drawline(ax!*COS (ew l ) +bx! *SIN (ew! )+rnx' +ex: ,az!*COS (ew l ) +bz' *SIN (ew' )+mz '+ez') ~[
CALL drawline (ax! *COS(ew') +bx' *SIN (ew ' )+mx' ,az' *COS(ew ' ) +bz! *SIN (ew' )+mz') 'll
CALL drawline(mx!,mz!)'lI
CALL drawline (ax! *COS (sw!) +bx ' *SIN (sw! )+mx! ,<1Z ' *COS(sw ' ) +bz ' *SIN (sw' )+mz') 'll
CALL
drawline (ax! *COS (sw') +bx!*SIN (SW') +mx'+ex ' , az! *COS (SW') +bz ' *SIN (sw!) +mz' +ez')'Il
CALL drawline (mx! +ex I , mz 1 +ez! ) 'lI
WINDOW OUTPUT 3'l[
CALL drawell ipse (ay' ,az I , by I , bz I , rr,y' +ey' ,mz 1 +ez!, sw' ,ew I) 'll
CALL drawellipse (ay' ,az! ,by! ,bz! ,my' ,mz!, sw! ,ew!) 'Il
CALL setpoint (my! ,mz!)'ll
CALL drawline(my!+ey!,mz!+ez!)'ll
CALL
drawline(ay!*COS(ew!)+by'*SIN(ew!)+my!+ey!,az!*COS(ew!)+bz!*SIN(ew')+mz!+ez!) '![
CALL drawline (ay' *COS(ew!) +by! *SIN (ew l )+my',az! *COS(ew ' ) +bz! *SIN (ew l ) +mz I) 'If
CALL drawline(my!,mz!)~
CALL drawline (ay' *COS (sw!) +by! *SIN (s',; I) +my', az 1 *COS (S,I' ) +bz' *SIN (sw' )'ooz' ) 'l[
CALL
drawline(ay!*COS(sw!)+by!*SIN(sw!)+my!+ey!,az!*COS(sw')+bz!*SIN(sw!)+mz'+cz')'ll
CALL drawline(my!+ey!,mz'+ez!)'ll
WINDOW OUTPUT 4'lI
END SUB 'II
'II
SUB drawspheriod(ptr) STATIC'll
SHARED k' (),pi2 ' 'l[
mx'~k! (ptr, 1, 0) 'll
my :~k' (ptr, 1, 1) 'll
C1I.'=k! (ptr,1,2)'l[
ax!4' (ptr,2,0)'If
ay!=k' (ptr, 2, 1) 'lI
az!=k! (ptr,2,2)'lI
bx!=k' (ptr, 3, 0) 'll
by' =k' (ptr, 3, 1) 'Il
bz'~k' (ptr,3,2)'Il
ex' =k! (ptr, 4, 0) 'll
327
ApPENDIX C - THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
cy!=k! (ptr,4,1)'lI
cz!=k! (ptr,4,2)'lI
WINDOW OUTPeI' 1'lI
CALL cLcawellipse(ax!,ay!,bx!,by!,mx!,r:'Ly~/C!,pi2!)~
CALL drawelljF)Se (ax! lay! I ex: ICy! ,mx! ,::Jy: (O! ,pi2!) <Jl
WINCOW OUTPUT 2~
CALL drawellipse (ax' ,az! ,bx! .bz! ,mx! ,mz! ,O! ,pi2') 'lI
CALL drawellipse (ax! ,a2 ~ ,ex! fez! ,rnx! ,m2!, 0 ~ ,pJ2!) <Jr
WINT)OW OUTPUT 3'lI
CAI.L drawellipse (ay! ,az! ,by! , DZ! ,my!, m2! ,O! , pi2! ) qr
CALL drawellipse (ay! ,a2! ICy! fez! ,my! ,mz!, O! ,pi2!) 1[
WINDOW OUTPUT 4'lI
END SUB 'll
'll
'IT
'll
SUB dr d",rellipse (ax! I ay! ,bx! , by! , mx!, my ~ I SW: I ew! ) STATICs;.
'TASK : draw ellipse in current output window'll
'PARAMETER:~>ax!,ay!,bx',by! span of ellipse'll
mx' ,my' center poi nt of ell ipse'll
sw!,ew! the start angle and end angleq[
to be \lsed~l
SH~~ED maxlines,pi2!'ll
alpha!=sw''ll
numlines cABS (sw! -ew!) *maxlines/pi 2! 'Compute number of lines'll
IF numl ines~C THF,N'll
numlines=maxlines 'if sw!=ew!, draw full ellipseq[
beta!=pi2'/maxlines~
ELSE 'lI
beta!=ABS(sw!-ew')/numlines 'compute increment angle'll
END IF'll
x Icax' *COS (aJpha' ) +bx' *SIN (alpha! ) +mx' 'compute start point'll
y! =ay! *COS (alp~a!) +by! *SIN (a~_pha!) +m~/! S
CALL setpoint(x!,y') 'Start point output'!!
FOR i=l TO rlumlines91
alpha! =alpha! +beta; compute new anqlell
I
328
ABACUS ApPE:\D1X C- TilE EDITOR PROGRA:\f
'll
SUB drawline(x' ,y')STATIC'll
'TASK :draw line from :ast point to specified point~
'PARAMETER:~>x!,y' Point coordinates'll
SHARED mx!, my! f mz! , factor! f xcorrfac!, colour<Ir
swindow~WINDOW(l) 'll
IF swindow~l THEN'll
LINE - ( (x! -rnx! ) *xcorrfac! *factor! , (my! -y!) * factor! ) C~) ~
f :--S
ELSE'll
IF swindow~2 THEN'lI
LINE -( (x!-mx!) *xcorrfac' *factor', (mz! -Y') *facLor!), colour91
ELSE'll
IF swindow;3 THEN'll
LINE - ( (my! -x!) *xcorrfac' * factor', (mz' -y' ) *factor! ) ,colour'll
END IF'll
END IF'll
END IF'll
END SUB9I
'll
I**************~
'** DISKETTE **~
I**************~
91
SUB loadmat STATIC9I
'TASK :load the Material list from disk91
WARNING' no test fOI existing file 91
SHARED mat! () ,matnum,matptr,.iegchar$,FileS~
WINDOW 5,"Load Material", (O,129)-(3:4,:S[l),O,191
PRINT "Name:"'ll
CALL getstring(File$," ",legchar$,1,6,lO) 'get filename91
IF File$>< .... THEN 'if file$~"" then canccl91
OPEN File$+".mat" FOR INPUT AS 191
INPUT #l,quantity'll
WHILE NOT(EOF(l))'lI
CALL newmat(matptr)'ll
FOR i~O TO 6'll
INPUT #I,mat' (matptr,i)'lI
NEXT i'll
WEND 91
CLOSE 191
END IF'll
WINDOW CLOSE 5'1l
WINDOW OUTPUT 4'll
END SUB'll
'll
SUB savemat STATIC'll
'TASK : save material list currently in memory to disk91
SHARED mat! () ,matnum, legchar$, Fil c$S
WINDOW 5,"Save Material", (O,129)-(3:4,:70),O,lS
PRINT "Name:"'lI
PRINT "from:l"'lI
PRINT "to :"'lI
mfrom!;l'll
mto!~matnumS
CALL putreal(mto',3,6,lO) 'Read all data'll
CALL getstring(File$," ",legchar$,1,6,lO)91
CALL getint(mfrom!,n !1,2f6,l.O,1!,rnatnum*1!)~
CALL getint (rnto!, 11,3,6, lC,m:rom: ,matnum*l!) qr
11
329
ApPENDIX C- TIlE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
WEND '!!
PRINT #l,mto'-mfrom'+l'!!
FOR ptr=mfrom! TO mto!,!!
FOR i=O TO 6,!!
IF mat! (ptr, 0) =-1 THEN'!!
ELSE '!!
PRINT #1, mat! (ptr, i) '!!
END IF'!!
NEXT i'l!
NEXT ptr'!!
CLOSE I'!!
KILL File$+". MAT. info"'!!
END IF'!!
WINDOW CLOSE 5'l!
WINDOW OUTPUT 4'!!
END SUB'!!
'll
SUB load: i st STATIC'!!
'TASK :See corresponding routine for material list S
SHARED k' (),knum,ptr,legchar$,File$'!!
WINDOW 5, "Load List", (0,129)-(314,150),O,1'!!
PRINT "Name: "'!!
CALL getstring(File$," ",legcharS,1,6,lO)'!!
IF File$><"" THEN'll
OPEN File$+".1i st" FOR INPUT AS 1 '!!
INPUT #1,quantity'!!
WHILE NOT(EOF(I))'l!
CALL newelem(ptr)'l!
FOR i=O TO 5'll
INPUT l/l,k! (ptr,i,O),k! (ptr,i,l),k' (ptr,i,2)'ll
NEXT i'!!
WEND '!!
CLOSE I'!!
END r,.''ll
WINDOW CLOSE 5,!!
CALL showelem(plr)'!l
END SUB'll
'!!
SUB savelist STATIC'!!
'TASK : See corresponding routine for materIal list '!!
SHARED k! (), knum, legchar$,File$'!!
WINDOW 5, "Save List", (0,129)-(314,170),O,1'!!
PRINT "Name:"'!!
PRINT "from:l",!!
PRINT "to :"'l!
mfrom!=I'l!
mto'=knum'l!
CALL putreal (mto!,3,6,10)'!!
CALL getstring(?i1e$," ",legchar$,1,6,lO)'!!
CALL getint (mfrom! ,II ",2,6,lO,1!,knum*1!)qr
CALL qel"nt (rr,to' , " ",3,6,lC,mfrom!,knum*l')'II
IF FileS><"'l THEN~
OPEN FLe$+".LISc'" FOR OJTPUT AS 1'II
quantity~O'lI
FOR i=mfrorn! TO mto ~ I determine number of elements tc be savc:dSl
IF k' (i,O,O) ><-1 THEN'lI
quanU tY=qllanti ty+ 1 'II
END IF'll
NEXT i'l!
PRINT #l,quantity 'l!
330
ABACUS ApPENDIX C - TilE EDITOR PROGRAM
331
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
END IF'll
END IF'll
Et;D SUB'll
'll
SUB translation (plr) STATIC'll
'TASK :move one body by one vector'll
'PARAMETER:=>ptr points to the body'll
SHARED k' (),min!,max!'ll
IF ptr><O THEN'll
WINDOW 5, "Translation", (0,129) - (314,170) ,4,1 'II
LOCATE 2,1'll
PRINT"V :"'ll
PRINT"q<uit,d<o,c<opy&do :"'ll
CALL put3real(vx!,vy',vz',2,4,26)'ll
CALL get3rea1 (vx!, vy!, vz', .... , 2,4,26, min' ,max', -1) 'II
CALL getstring(a$," ","qcd",3,21,1)'ll
WINDOW CLOSE 5'!!
WINDOW OUTPUT 4'!!
IF a$><"q" THEN'll
IF a$="c" THEN'!!
CALL copy(ptr)'ll
END IF'll
k' (ptr,l,O)=vx!'ll
k! (ptr, 1, 1) =vy! 'II
k! (ptr, 1, 2)=vz!'!!
CALL showelem(ptr)'ll
IF k! (ptr,S,2)=1 THEN'!!
CALL drawelem(ptr)'ll
END IF 'II
ELSE '!!
WINDOW CLOSE 5'll
END IF'll
END IF'll
END SUB'll
'II
SUB sizinglptr) STATIC'll
I T,7\,SK :sizc one body'
'PARAMETER:=>ptr points to the body'll
SHARED k! (),min',max''ll
IF ptr><O THEN'll
WINDOW 5,"Sizing", (O,129)-(314,170),4,1'll
LOCA'c'E 2, 1 'II
PRINT"V :"'!!
PRINT"q<uit,d<o,c<opy&do :"'ll
CALL put3real(vx!,vy!,vz!,2,4,26)'ll
CALI-J get3real (vx! ,vy! ,vz!," ",2,4, 26,min! ,max!, 0) 9I
CALL getstring(a$," ","qcd",3,21,1)'ll
WINDOW CLOSE 5'll
WINDCftl OUTPUT 4'll
IF a$><"q" THEN'll
IF a$="c" THEN'lI
CALL copy(ptr)'ll
END IF'lI
IF k! (ptr,O,O»=20 THEN '!!
til=4'!!
ELSE'!!
til=3'll
END IF'!!
FOR i=2 TO til '!!
k! (ptr,i,O)=vx!*k! (ptr,i,O)'!!
k! (ptr,i,l)=vy!*k! (ptr,i,l)'ll
k! (ptr,i,2)=vz!*k! (ptr,i,2)'ll
332
ABACUS ArrEl"DIX C - TilE EDITOR PROGRAM
NEXT i'll
CALL show'E:'" c'rn (p:- 9T
fF k: (Ft rr.s . )) -: THENq[
CALL, d~a~c~c~(pLr)~
F',Nn IF C'
ELSE <;
END [e."'C
END IF S
END SUB'll
q;
q]
1*~~******~***********~
'*~ SYSTEM ROUTINES **'ll
I**~**~****~**********~
'll
'll
SUB copy (ptr) STi\T1C'll
'TASK : r:':::FY l: -::-oy<Jl
1 PARAME'::'EE: :s to the body]
SHI'.RSD k' (\ 'll
IF ptr>,~(j f-:e stc1rti.nq e::_crr,ent1~
'~c 1 copy1!
j -C; 1'8 ;q[
1<1 (pLr,i,j)~k: (olj,.i, j)qj
NEXT 'j'll
N2XT i'f[
END IF'll
ENIl SUB'll
'll
SUB copier (per) STATIC'll
'TASK :copies a body ~r~C sp1_~y'; caLa'll
IPARA;;'!£TER:=>pt.~ poj.nts t~l(' bodyqJ
IF pc"
CP\~_.T :-'::-'~-;y (r'::::) <:1
CALL (ptr)S
END 1 Fg[
END SUB ~i
'll
r~\JS SUB<jf
<IT
'Pl\"c~ME;TEE:=>ptr points c-
S'i",,'l,Ef) k I () 'll
333
ApPENDIX C- TilE EDITOR PROGRAM AMIGA 3D GRAPIllC PROGRAMMING
IF ptr><O THEN ~
ptr~ptr-l'll
END IF'll
WHILE k~ (ptr,O,O)~-l~
ptr~ptr-1 'll
WEND'll
CALL showelem(ptr)'ll
END SUB 'll
'll
SUB rights (pt r) STATIC'll
'TASK : gel element to ri.qht u[ current elemenL'll
'PARAMETER:~>ptr pointer to ourrent body'll
SHARED k! (),knum'll
old=pt,'ll
IF ptr<knurn THEN'll
ptr=pt r+ 1 ~
END IF9I
WHILE k! (p:r, 0, 0) =-1 AND p:,<k[1\Jm~
ptr=pt r+ 1 'li
WEND'll
IF k~ (ptr,O,O)~-l THEN91
ptr=old 'll
ELSE91
CALL showelem(ptr)91
END IF'll
END SUB'll
'll
'11
'll
SUB liob(rnx' ,my! ,mz~) STATIC91
'TASK : read ooordinates of upper ler:. hand corner'll
'PARAMETER:=>rnx! ,my' ,mz' old coordindl.es'll
<:O-ffiX! , my ~, mz! new coordinat(~:}l1
SHARED mi n! , IT'J.x! 'H
CAL L ge t 3 :- C d 1 {mx ! , my ! , mz ! , II II ,. 9, : :) , ? 6, !1".i n : , !:'.,:1 X T , ~ 1 ) g
END S(JR91
334
ABACUS ApPENDIX C- THE EDITOR PROGRAM
ENJ SUB'll
'll
SUB setl 1nes (cnaxlines) STA'l'IC'll
'TASK : read max number of lines allowed for drawing a circle'll
'PARlI.'1ETER: =>maxlines old val ue'J
<=maxlines new va~ ue'J[
i'=maxlines'iI
CALL getint (i ".2~,24,3,11,5G!)qr
rr:axl ines=i ! ~
l=..:·JD SUB 'lI
'il
SUB showandwait(ptr) STATIC'il
'TASK : display data for a body then moves the upper left 'II
corner so that it appears in the middle of the scrcen'J[
or the body appears on the screer, in cocor'll
'P)lJi}\METER:<=ptr pojn~.s to desireo Lo'/'f
SHARED knum, K! (), factor! ,rnx! Imy! ,f7']:, ~::Glour,xcorrfac: q[
IF ptr><O THEN'll
WINDOW 5,"51oow", (O,l7.9)-(314,1 ;O),r.,cS
LOCATE 2,1'il
PRINT"Body : "'J[
PRINT"D<ata,M<iddle,C<olor :"'II
CALL putee"l (ptr*l!, 2,9, i 0) 'll
p!=ptr'll
CALL getreal(p:,u ",2,9.10,11,k::u!T.*"1:)<[
CALL getstring(a.S," 1I,"dJ11C ,J,23,1)1:J[ Il
IE a$><"d" THEN']
IF a$::--::umn THI·:~qr
mx!cck: (pc r, 1, 0) -149/xcorrfac' Ifactor! 'comput...c nCi-l upper left corner
mY'~k! (ptr,1,l)+57/factor''!l
mz: =k: (ptr,l, 2)+57/factor! 'iI
CALL put3real(mx!,my:,mz!,9,12,26) 'and displayq[
Li5ESI
c()1,)ur~3'll
335
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
336
ABACUS ApPENDIX C- THE EDITOR PROGRAM
IF typ=5 THEN'll
CALL getcrarc(ptr)'l!
END IF'll
IF typ=lO THEN'll
CALL getsphere(ptr)'lI
END IF'll
IF typ=20 OR typ=22 OR typ=24 THEN 'lI
CALL getcyl(ptr)'ll
END IF'll
IF typ=21 THEN'lI
CALL getcylseg(ptr)'ll
END IF'll
IF k! (ptr,5,2)=1 THEN'll
CALL drawelem(ptr)'ll
END IF 'll
END SUB'll
'lI
SUB finish(quit) STATIC'll
'TASK :Confirms quitting program'll
'PARAMETER:=>quit =O'll
<=quit =0 =>no cancel'll
=1 => cancel'lI
SHARED gadget%()'ll
WINDOW 5," QUIT", (0,129) - (314, 150),0, 1'lI
PRINT "Really ? "'lI
CALL initgadget(110,3,lS,30,1,S,nr1%,100,-1)'lI
CALL initgadget(160,3,15,60,1,S,nr2%,200,-1)'ll
WHILE gadget%(nr1%,4»<0 AND gadget%(nr2%,4»<0'll
WEND'll
IF gadget%(nr1%,4)=O THEN'll
quit=l'll
END IF'll
WINDOW CLOSE 5 'll
CALL deletegadget(nr1%)'ll
CALL de1etegadget(nr2%)'lI
END SUB'll
'll
SUB newelem(ptr) STATIC'll
'TASK :get address of free place in list'lI
'PARAMETER:<=ptr points to this area'll
SHARED kfree,k' () ,knum'll
IF kfree<knum THEN'lI
ptr=kfree'll
kfree=k! (ptr, 0, 1) 'll
k! (ptr,O,O)=O'll
k! (ptr,O,l)=O'll
k! (ptr,0,2)=1'll
END IF 'll
END SUB'll
'll
'll
SUB act1with4 STATIC'll
'TASK :actjvate Menu 1 to 4'lI
CALL busymouse 'll
MENU 1, 0,1, "Transform. "'ll
MENU 1,1,1,"Rotation "'ll
MENU 1,2,1,"Translation "'ll
MENU 1,3,1,"Enlarge "'ll
MENU 1,4,1,"Copy "'ll
MENU 1,5,1,IIDelete AD"'lI
MENU 1,6,1,"Correction "'KII1!
'll
337
ApPENDIX C - THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
338
ABACUS ApPENDIX C - TilE EDITOR PROGRAM
339
ApPENDIX C- TilE EDITOR PROGRAM AMIGA 3D GRAPIIIC PROGRA:'.fMING
'![
SUB newmat(matptlC) STATIC'!!
I TASK ~See corresponcii!l9 rouLine for the b()dy listll
SHARED mat free, mat I ( ) , matnumq[
IF matfree<matnum THEN'll
matptr~matfree'll
mat f rce=mat! (matptr, 1 ) ~l
mat! (matptr,O)=O~
mat! (matptr, 1) =O'll
END IF 'll
END SUB'II
'll
SUB finishmat STATIC'll
'TASK :See corresponding routine for the body list'l!
SHARED mat,gadget%()'ll
WINDOW 6," QUIT ",(0,129)-(314,150),O,H
PRINT "Really? "'ll
CALL initgadgpt (110,3, ]5, 30, 1, 6,nrl%, 100, -1) ~I
CALL initgadget(160,3,15,60,1,6,~,2%,200,-1)'I1
WHILE gadget%(nrl%,4»<C AND gadgel%(nr2%,fJ»<O'll
WEND'll
IF gadget%(nrl%,4)=O THEN~
matO'll
WINDOW CLOSE S'll
WINDOW CLOSE 6'll
CALL deacU v5'll
CALL actlwic~.f;'l!
PALETTE 2,0, 0,0'
ELSE'll
WINDOW CLOSE 6 ,
END IF'll
CALL drcletegadget (nrl %) ~I
Cl',LL deletegadget (nr2%) q[
END SUB'
~
::)ud deleL.{3r m"::lt (rr~dtptr) STi,,"i'IC':il
'TASK :See correspondinq routine for the Dcxiy 1 ist91
SH~qED mat' (),matfree'l!
IF matptr><O THEN'
FOR i~C TO 6'i1
mati (matptr,i)=O'
NEXT i 'll
mat! (matptr,O)=-l'll
mat' (matptr,l)=matfrec'II
matfree=matptr'l!
CALL leftsmat (matptr) 'II
END IF ,
r:ND SUB'l1
'lI
SUB leftsmat(matptr) STATIC'll
'TASK :See corresponding routine for the body] ist1!
SHARED ma.t ~ (), nrl%, nr2%, nr3%, nr4%, nr5%, n~6%~
IF matptr><O THEN 'II
matptr~matptr-l'll
END IF'll
WHII"E mat! (matptr,C)=-l'!l
matpt ,"matptr-l'!l
WEND'll
CALL showmat(matptr)'ll
CALL de1etegadget (nLl %) 'll
CALL delet.egadgec (nr2%) 'll
CALL deletegadgec(nr3%)'!1
340
ABACUS ApPEl"DIX C- Tm: EDITOR PROGRAM
CALL deletegadget(nr4%)~
CALL dcle~egadqel (nrS%) 'I!
CALL deleteqadget(nr6%)'Il
END SUB 'll
~
S'.JB rigntsrc""t (mdtntr) STATIC'll
'TASK :Sce correspondi::C] routin.e ~_or the ~~~-:dy l'~-:':-S'L
SHARED mat! (),matnum,nrl%,r,r2%,nr3%,nr'1%,nr)t,nr6%qr
old=miltptr'll
IF mdtptr<matnum ,HEN'll
matptr~matptr+l'll
END IF'll
WHILE mdt! (mdtptr,O)~-l AND matptr<matnum'll
matptr=matptr+I'll
WEND'll
IF mat! (matptr,O)=-l THEN'll
matptr=old 'II
ELSE'll
CALL snowmat(malptr)"I
CALL deletegadget(nrl%)'J!
CALL deletegadget(nr2%)'ll
CALL deletegadget (nr3%) 'II
CALL deletegadget(nr4%1'll
CALL deletegadget(nr5%1'lI
CALL deletegadget(nr6%1'II
END IF~
: tiD SUB'lI
WEND 'I!
mat' (matpte, 0) =gadget% (nrl%, ,1) IIOl'll
mat' (miltptr, 1) =gadgel.% (nf?%, 4) I' O· 'll
mat' (matptr,2)ccgadget% (nr3%,4)/lO:'ll
mat! (matptr, 3) =gadget% (nr4%, 4) /lC1 'I!
mat' (matptr, 4) =gadget% (nr5%, ~) 1101 'll
CALL deletegadgct(nrl%)'Il
CALL deletegadget(nr2%)'ll
CALL deletcgadget (nr3%) 'll
CALL de1eteqadget (r.rA%) 'll
CALL deletegadget(nrS%)~
CALL dcle~egadge: (nr6%)'ll
"roO SUR'll
'!]
SUB snowmat (rratptr) STATTC'll
341
ApPE;-';DIX C - TilE EDITOR PROGRAM A\lIGA 3D GR,\!'IIIC PROGRAMMI~G
LOCAr::: 1,20'li
PRINT 'lR+G"tB="~
PAL£T':'E 2,rnat.! {ma:.:.ptr,;:n ,n:a:':': (rru:1c-pt.:-, 1) f:~l2~; (rrc..;.:.p::,/') ':.
LINE (250,C)-(260, 7),2,bf~
PR=~T "Red : liS[
PRINT 'lI
PRINT lI(;reen :"'lI
PRINT 'lI
"Blue :"<Jl
PRINT 'lI
i'RINT "Shadow :"~
PRINT 'lI
PRINT "Mi Ironing : "'lI
wl%~mat I (mat.Dtr, 0) *10] 'lI
w2%~mat! (rr.atptr, 1) *101 'll
w3%~mat' (matptr,2)*lO'-~
w4%--==mat! (matpcr, 3) xlOl'i[
w5%=mat I (matotr, 4) *1Q1 'II
CALL in i t gad ge t ( 11 :], E I ~ 0, 1 02 , w1 %
I ::, :-~ r 1 %, - ~ -}) c::
CALL initgadget(11C,?4,;O,J02,w2%,5,nr2%,- ,-l)S
CALL inil.gadgot(110,40,lO,lC2,wJ%,5,f1!"3%,- ,-1)'11
CALL initgadget(110,56,lO,102,w4%,5,nr4%,- ,-;)0
CALi. Ini'.gadqet (110, 72, 10, '-22,w5%, 5,r:~5%, - _1 i 'lI
CALL initgadget(1l0,88,15,30,1,S,r.r6%,O,-l)'ii
END IF'll
END SUB'II
q;
Ik****~*****~**~~
valu%=ax-x%-l'll
LINE (valu%+x%+l,y%+l)-(valu%+x%-l,y%'h%-:) ,3S
gadget %(i, 4) =valu% 'get r,ew v21ue'II
ELSE1I
IF none%~-l THEN'll
IF THEN 'first time, invert it'll
valu%~l
gadget%(i,4)=C'l
LINE !x%,y%)-(x%+~%,y%+h%i ,J,bf'
PUT (x%,y%) ,gadgets%(yes%),P~ESE;~
ELSE 'll
qadqet%(i,4)~1 'else rctLlrr ~
342
ABACUS ApPENDIX C- THE EDITOR PROGRAM
343
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
gadget%(nr%,4)=valu%~
gadget%(nr%,5)=wind%~
gadget%(nr%,6)=yes%~
gadget%(nr%, 7)=none%~
END IF ~
MOUSE ON'll
WINDOW OUTPUT old'll
END IF'll
E:\D SUB'll
'll
SUB deletegadget (i) STATIC'll
'TASK :delete a gadget~
'PARAMETER:=>i Index of gadgets in array 'll
SHARED gadget% () 'll
IF i>=O AND i<=10 THEN~
gadget%(i,O)=-l~
END TFl[
END SUB 'll
'll
I******************~
'** MOUSE POINTER**'ll
'******************~
'[
SUB busymouse STATIC~
'TASK :thc mouse pointer in busy mode'll
SHARED buf fer& 'll
FOR i=l TO 4'll
WINDOW OUTPUT i'll
CALL setpointer& (WINDOW (7) ,buffer&, 15, 16, -8, -7) 'll
NEXT i 'll
END SUB'll
'll
sr.:s lazymollse STATIC'll
'TASK :Change mouse pointer to cross hair'll
SHARED Juffer&'1[
E'OR i - 1 :-;) 4 'lI
WI;\IDOW OUTPUT i~
CALL setpointer& (WINDOW (7) ,buffer&+68,15,16,-8,-7)'ll
NEXT i'll
END SUB'll
~
Slm ini Lmaus STATIC~
'TASK :save two mouse pointers'll
SHARED buffer&~
mO\1sedata:~
DATA O,O~
DATi\ 0,1,0,-32767,0,-18751,0,-1,0,-18751, 0,-32767'1I
DATA 14016, -32767, 14016, -14011, 14016, -32767, 0, -32761'll
DATA 13848,-18919,13848,-1. 13848,-18919, 0,-32767, O'll
DATA -32761'll
DATA O,O'll
DATA O,O~
DATl, 256, 0, 256, 0, 256, 0, 256, 0, 256, 0, 256, 0, 256, O'll
DATA -258, 0, 256, 0, 256, 0, 256, 0, 256, 0, 256, 0, 256, 0'
DATA 256, 0'
DATA O,O'll
RESTORE mousedata'll
FOR ioO TO 67~
READ va':'u%'ll
POKEW buffer&+i*2,valu%'ll
NEXT i'll
END SUB'll
344
ABACUS ApPENDIX D - I'm: SETPOINT PROGRA'"l
_LVOOpenLibrary -552
_LVOCloseLibrary -414
LVOReadPixel -318
LVORe :tFill -306
LVOSetAPcn -342
LVOSetBPen -348
HAM $800
rpl;reaPtrn 8
rp _FgPcn 25
rp_BgPen 26
rp_AreaPtSz 29
NumPattern 11
sinc"15'4
xl~4+sinc
yl~8+sinc
xr~12+sinc
yr~16+sinc
red~22+sinc
green=26+sinc
blue~30+sinc
CA!.LSYS:MACEO $\1
JSR LVO\l (A6)
ENDM
;open libraries
MOVEM.L DO/Dl/AO/A:/l\6,-(SP)
MOVEQ #O,DO
LEA GfxName,Al
MOVE.L 4,A6
CALLSYS OpenLibrary
LEA GfxBasc,AO
MOVE.L DO, (AD)
MOVEM.L (SP)+,DO/Dl/AO/Al/A6
345
ApPENDIX D - TilE SETPOINT PROGRAM AMIGA 3D GRAPIliC PROGRAMMING
RTS
CloseGfx;
; close libraries
MOVEM.L DO/Dl/AO/A1/A.6,-(SP)
MOVE.L GfxBase,OO
BEQ.S \R
MOVE.L DO,AI
MOVE.L 4,A6
CALLSYS CloseLibrary
\R:
MOVEM.L (SPl+,DO/OI/AO/Al/A6
HTS
SetPoint:
; (xl,yl,xr,yr,red,g.reen,blue)
MOVEM.L DO-A6,-(SP)
MUVS.L GfxBase,DO
BEQ \R
MOVE.L DO,A6
MOVE Modus,DO
ANDI #Hk'1, DO
SEQ \NORMAL
; Determine color of last pi xe 1 :
LSL #3,CO
LEA Colour,AO
LEl\ 2 (AO, DO) ,AI ;" oldcolor
MOVEM (A1l,D3-DS ;red,green,blue
ADD #l28,AO ; Start the Ii st for HA.M-Colu..:-s: :.28=1 G*8
346
ABACCS ApPE:SDlX D - TilE SETPOI:ST PR()r,RA~1
ADOQ.L #6,AC
AOO #64,05
\SHIB:
OBRA OO,\SHLB
MOVE 4 (Al),OS ;old blue-Intensity
\I'ORMAL:
LEA Colour,AO
MOVE MaxColour,OO
MOVEQ #-1,07 ;Minimum
MOVE. LAO, Al
BRA.S \INl
\LP1:
CMP.L 01,!)7
BLS. S \NXT:
MOVE.L 01,07
MOVE.L AO,A1
347
ApPENDIX D - TilE SETPOI],;T PROGRAM A;\1IGA 3D GRAPIIIC PROGR,U[MI1\G
\NXT1:
ADLlQ.L #8,AO
\I~l:
DBM DO, \LPi
LEA Colour,AO
MOVE MaxColour, DC
MOVEQ #-1, D7 ;Mini"num
MOVE.L AC,A2
BRA.S \IN2
\LP2:
CMP.L D1,J7
I3LS.S \NXT?
MOVE.L U:,D'/
MOVE.L AO,A2
\NXT2:
ADDO.I. #fJ,AO
'"IN:? :
DBRA 00,\]'P2
MOve: (Al),D7
MO'vG (A2), DO
~10VE. I. ?ascPort, II.]
MOVE. L A] ( rp_T.. rE'c Pl rn (A 1. )
~"OVE. B # 4, rp _AreaPtSz (Al)
MOVE.~. A1,-(5,»)
CALL.s~S S0tAPcr,
348
ABACUS ApPENDIX D- THE SETPOINT I'ROGRA'H
;Clipping:
\c,:
MOVSM.L (SP)+,00-1\6
RTS
\SEARCH PATTERN:
LEA PATTERN,"')
LEA 2 (AD) ,A3
MOVEQ #<, IJ7
MOVEQ #NumPaltern-l,OO
\LPM:
MOVE (AO),O~
MOVE #1024,02
SUB 01,02 ; I-BkgkPClttern
t·:OVE 2 (A ~ ) , 06
BEQ.S \El
MeLU 02,06 ;Colorl.rcd*(l-BkgnPattern)
OIV;} #l07~, 06
\£1:
!'lOVE 2(A2),05
BEQ.S \102
MU~~U 01, D5 ;Color2.red*BkgnPattern
oIVU #1024,05
\E2:
I\DD 0:', ';6 ;Color:.red
SUB red+'; (SP) ,06 ; Oi fferenee
t1CLS 1)6, lJ6 ;The quadrant
MOVE 4(A1),0';
:3EO.S \E3
flULU 02,04 ; Color:. qreen* (l-BkgnPat tern)
DIVe #1024,04
\E3:
MOVE 4 (A2), lJ,)
BEQ.S \E4
MULU 0~,05 ; Color2 . qreen*BkgnPa ttern
3.t9
ApPENDIX D - TilE SETPOI;\T PROGRAM AMIGA 3D GRAPllIC PROCRA "1:\11 ",0(;
OlVU #1024,05
\"0 .
ADD 05,;)4 ;Co1or .green
SUB green+4(SP),04
MULS 04,04
AOO.L C4,06
CMP. L ;)6,0"1
'lLS.S \:,XTM
LEA 2 (AO) ,A3
MOVE.L 06,07
REO.S \FNO
\NXTM:
ADD #34,AO
~)IlRA DO, \ LPM
\c'N~-) :
ETS
\COMPAR:'~ Culour:
CMP.L Ai ,1'.0
BEQ. S \CFI~
MOVE :2 (AI) ,Dl
CM? 2(AO),01
BNE. S V:oro-E
MOVE 4 1M) ,01
CMP t,IAO),Dl
FlNE.S \CFR
r',OVE 6111.1),01
C'1P 6 (AO), Dl
\CFR:
RTS
G~xName:~C.B 'graphics.librarY',D
ALIGN
GfxBasc: ~C. L U
'\a stPort : DC . L 0
MaxColour:DC.W C
Modus:DC.W 0
RasterWl:DC.W 320
RasterHl:DC.W 200
350
ABACIJS ApPENDIX D- THE SETPOIlW PROGRAM
Pfl,TTERN:
DC .'11 0
DC.W $0000
DC.W .$JO('8
DC.'V-l
DC.W $00:)0
DC.W $0000
DC.W SOOOO
DC.W SOOOO
DC.h; sec-cc
DC.W $ODOD
DC.W $0000
DC.vl $0000
DC.W $0000
DC.I~ ·SODoe
DC.W SOUlO
DC.r:J $CCcJ
DC.It; $0000
DC.W
UC.W S80C:J
DC.W '>0020
DC.W $0000
re.,,! SOOOO
DC. ~"4 $0000
DC.W ;~;OOOO
DC.W $CCOc)
DC.W $GOCO
DC.W $0000
DC.W $0000
DC.W $0:::00
DC.~I SOCCjO
DC.W ~OCDO
:.JC.W $0000
DC.W $oooe
DC.W $0000
DC.W 8
DC.W $8000
DC.W SOOCO
;JC .1'1 SOOOO
DC.W $0000
DC.I" $0:,08
DC.W
DC.'0-: $0000
SOOOO
S0080
,,'8
DC.W SC00C
DC.W :~SOOD
LC.W SOOOO
DC.Vi $0000
DC.W $0000
DC .\~ S080n
DC.\-i S:'J '2 no
DC.W 16
DC.W $8088
DC W $CCCO
DC.\'J SOl)8J
DC.1fJ $0COO
DC.W .$0000
[Je. !h $0000
351
ApPENDIX D- THE SETPOINT PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DC.W $0000
DC.W $0000
DC.W $8080
DC.W $0000
DC.i~ $0000
DC.W $0000
DC.W $0000
DC.W $0000
DC.W $eOOO
DC.'W $0000
DC.W 32
DC.W $8080
DC.W $0000
DC.W $0000
DC-W $0000
DC.W $0808
DC.W $0000
DC.W $0000
DC.W $0000
DC.W $8080
DC.W $0000
DC.W $0000
DC.W $0000
DC.W $0808
DC.Vi $0000
DC.W $0000
DC.Vi $0000
DC.W 64
DC.W $8888
DC.W $0000
DC.W SOOOO
DC.W $0000
DC.W $8lHlfl
DC.W SOOOO
DC.W $0000
DC.vl $0000
DC.W $8888
DC.W $0000
DC.W $0000
DC.W $0000
DC.W $8888
DC.W $0000
DC.W $0000
DC.W $0000
DC.W 128
DC.W $8888
DC.W $0000
DC.W $2222
DC.W $0000
DC.W $8888
DC.W $0000
DC.W $2222
DC.W $0000
DC.W $8888
DC.W $0000
DC.W $2222
DC.W $0000
DC.W $8888
DC.W $0000
352
All AC{)S ApPENDIX D- THE SETPOI~T PROGRA'.1
DC.W $2222
DC.W $0000
DC.W 256
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $OOOll
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $0000
DC.W $AAAA
DC.W $0000
DC.W 384
DC.W $AAAA
DC.W $llll
DC.W $AAAA
DC.W $4444
DC.W $AAAA
DC.W $llll
DC.W $AAAA
DC.W $4444
DC.W $AAAA
DC.W $llll
DC.W $AAAA
DC.W $4444
DC.W $AAAA
DC.W $Ull
DC.W $AAAA
DC.W $4444
DC.W 448
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $444~
DC.W $AAAA
DC.W $5555
DC.Vi $AAAl\
DC.W $4444
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $4444
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $4444
DC.W 512
DC.W $AAAA
DC.W $5555
DC.W $ATIAA
JC.W $:'555
353
ApPENDIX D - THE SET POINT PROGRAM AMIGA 3D GRAPHIC PROGRAMMING
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $5555
DC.W $AAAA
DC.W $5555
DC.I" $AAAA
DC.W $5555
DC.W $AAA..X>,.
DC.W $5555
Colour:
DS.B 64*B ;ColorNr,red,green,blue
END
DATA 34,28,0,';, 94, 6F, n ,5 6, C5, C2, D2, 82,34,28, 0,6, 94, 6F, 0, 5A'll
DATA C5,C2,D2,82, 81,63,4,2S,l,24,48,SO,88,51,C8,FF,CC,61,5C'll
DATi\ 76,7,28,48, 49,61,54,Se:,8J,65,4,C5,49,26,4C,3E,1l,30,129[
DATA 22,7A,l,C,2J,s3,O,8,13,7C,C,4,O,lD,2F,9,4E,AE,FE,)\.A'll
DATA 22,57,.3C,7,4E,AE,FE,A4,22,5F,~C,EF,O,F,0,40,4C,BA,0,30'
DATA 0,EE,HJ,4~,62,14,32,~5,62,lO,B4,44,63,2,34,4.B6,45,63,2,
354
AllAClJS
;:)1\ 'fA 4, 0, 88, I~ 5, 98, 6F, 0, 5 E, C9, C·1, ~)C, 84 f BE, f; '~, t ~~, 8, ~ ".i • g - , '- ,
DATA 2E,6,t\7,8,eO,FC:,O,2,2,51,CHrFF,82,4E,~' IC~,C9,6), ,~-,
;]AT 1\ G, 2, B2 6.3 r r: , :?, 66, 12 32, 29 , 'J, ,~, 137, (~, 0 , ,~, 6( , R.-
I f ~?, 2 ~}S:
DA~A Of~' B2, 6P, 1"',6, 4E, --;'5, f:7, 'J2, 6], '70: 'eF , /'1, E:-3, '7:-:<, - ~',l
DAr;..",!\. 5'::,55, AA, l'-J~, 1I"j, 4,j, T\l\, N~, .:).),55, AA, M, '1'1,4·1, A!\, AA,
DATA 44,·1 '1,2,0,1\(.>.,1\/\, 5j, 55, At-"'\, AA., 5S, 55, ;,.1\, fl.l" 5,), S5, A/\, [\1\, - . :. qr
DATA M, AA, SS, 55, AA, M, 55, 55, Ai!", A]\, 5,~, 55, A,A./ ,\.t., ~:)f 55, ~_',::; . ~;~;
DATA C,O,O,O,C,'J,O,O,O,O,O,O,C,O,O,O,8,D,0,OCfl
DATA 0, C, 0, 0 U U, 0, 0, 0, 0, C; fe, 0 0, J, r:'! ,:J, (i 'g]
I I I
lJl.. TA O,G,C,C,O,O,O,:J,U,C,O,O,OrO,C,O,O,O,O,09]
Cl",TA O,O,Q,O,J,O,O,O,Cl/O,O,O,O,C,O,O,O,D,O,C,,!!
DA":A ,0,O,C,O,:J,~,O,O,O,C, ,-,C,O,D, ,a,O,G'Jl
DAr_:"!-\. C,'J,O,C:,C,J,O,O,O,:J,:;,Q, ,O,O,O,C,U,J,Oq:
[lA':'A ", C, 0, Ci, C;, r" ';, (), 0,0, [I, (), ,0,0,0,0, (j, '" G'i!
DATA 0,0,0, C, 0, 0, 0, Of 0, 0, 0, 0, 0, 0, 0, ll, 0, 0, 0, Cq[
'JATA O,O,O,O,O,O,O,O,O,O,O,O,O,G,G,O,O,O,O,Cq
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0 , 0, 0, 0 , 0, 0, 0, 0 ~
DATA C,~,O,O,O,[).c:"O,O,O,O,O,8,O,O,O,O,0, ,O'Jl
DATA Of ,0,0,0,=:,0,0/0,0,0,0, ,0,0,0, O,J,tJqr
JATA O,O,O,O,O,O,O,O,O,D(O,O, ,0,8,0,0,0, ,C~
Of..TA 0, 0, 0, (_;, 0, 0,0, ,0, 0,0,0,0,0,0, C, 0,0, C'r OTt
DATA 0, 0, :J, C, 0, 0,0, 0,0,0,0,0 f 0,0, C), Cl, 0,0,0 r J'I
DAT,\ ,J,G,O,G, ,O,O,O,C, ,0, 0,J r:,0,:i,J~
DATA ,J,C,O,:=·,:;,O,O,O,O,O, I,CI,8,0 -1'~-'I~;JQ9t
DA-::--A ~;,8,CJ/(_',{C:'~;fO,O,O, ,':l,D,O, r':;I~-',CJ91
DATA O,J,O, ~,O,O,O,O~
\PPENDIlI E- TRACER ERROR MESSAGES AMIGA 3D GRAPIIIC PROGRA'IHII!':G
----_._--,-,,----------------------
E. Tracer Error ~essages
While the program is running, different errors can occur. The most
frequent error is an input/output error, which arises when, for example,
you try to access a nonexistent file, or when the disk has a read/write
error.
Such errors are processed in the tracer rou tine Err 0 r Han d 1 in q.
Also, when the modules are merged incorrectly, errors are handled in
this routim:.
Errors occuring during the transfer of IFF graphics to and from disk arc
not processed by this routine. ErrorHandl ing is activated by ON
ERROR.
When you present one of the three vectors by using the other two
vectors ([or example a = x*b + y*c), only one plane or one line and no
space is spanned causing an crror.
356
Index
A Error messages 356
AC/BASIC compiicr 193 Exiting tracer progmm 159
Addition theorem 55
Algorithm 10,167,179 F
AmigaBASIC 19,193 File manipulation 154
Angles 184
Arc 17,149 G
ASCII format 51 Gadgel'> 77
Graph paper 173
8
B-splines 167 H
Background 73,157 HAM mode 40,173
Bezicr 167 Hardcopy 117
Brightness 9 Hidden line algorithms 7
Hidden surface algoritllllls 7
C
Cartesian coordinates 45,58
Circle 13,148 Interchange File Fonnal (IFf" ! 14,117,
Color 10,173 169,193
Compiling 194 Intersection point 22.187
Componenl<; 181
Cone 14,151 K
Coordinates 12,181 Keyboard shortcul~ 126,163
Cosine 53
Cray 48
Cylinder 14,150 L
Light rays 9
D Light source IU61,170,174
Data slmcture 16 Loading Materials 157
Determinant 23,188
Difference vectors 179 M
Direction vector 37 Main point 52
Display II 152
Material editor
Memory management 93
E Menus 84
Editor 74-75,145-159, Modules 75
167,179,302-344 Multiple light sources 170
Editor data manipulation 94
Editor instructions 145-159 0
Editor sample run 78
Objcctdata 146
Ellipsoid 14
Object rotation 168
Enhanced objects 167 7,[46,167
Objects
Enlargement 58,94,160,174 44
Optimization
Equal vectors 179 78,193
Optional disk
357
AMIG A 3D GRi\ Pll k' PIWGR,\\1.\II:\G
p V
Paral tc !('!:tTUl ll 11,148 Vectors 22,179
Pcrccpti UJ1 19 Visual rays 9
Pe rpc ndi~ I} I,tf 13
Pcr:>jx '\: u w 55 W
Pixel ", ! /.;..' 161 Wiremodcl 51,10..1,160,174
8,161,174 Word processor 74
Plane 11,1 47,182
Pl an ning graph i,::; 173 X
i>oin! \11 V I l'11 174 X coordinate 51
Polar c { )() rd i n;J k~ 14
Print ing ~rap hics 158 y
Proj ecti o n po inl 22,174
Y coordinate 51
PYl/laf:,l)rC<ln [hcon:rn 185
R Z
Z coordinate 51
:~ a y [J, h: U iH (: ~·ra · : , \',', frrJ «'"
: ~ :\V !~""If) ~ 7
'7
K( nan~: k 22, I ()O
f~ eC LJr :\ l t \ n 10
R C. re n: I) ~T r~ l ; f1( 94
l<c lk -.:lI llTi 9
Rcqucsll:r 131
Rcsol ul1 (>!1 173
Rotati on 52,55
s
SL.! Vl flJ!, hlaph ~ l. s i58
Scalar 22
S~ lP ()i ll !. rr' )~ rd I) I<) U45-.~55
Shad in!; 173
Shadfj Vo. ' 7.160
Sh dW :: . Hi'. 1 P ~{ ';'~ " Iil l 193
53
:) m ()(;~h ~: ) ; {d i!l c' 168
Spilc;, 1l , l50J82
Spi1,:rOlli i51
T
T a n ~; (' m 53
Tracer 1\!. i 04 ,119,145 -163
, I (i7,! 79,207-30 1
Tr,ln :r i n ~ l~ d l 11t,lf l:-: 155-163
Tracer m C!ll! ~ 155-163
T racer tll odlJ k ~, 203-206
Tr,m.;parCfll") 10,169
Triangle 7.147 ,167
Trjck~ and lip'; 173
T wo d:m e n s i tl~ illl 1'.1 :": 1\ 14
358
Optional Diskette Offer
3D Graphic
Programming
In BASIC
Optional diskette
For your convenience, the program listings contained in this book are available on an
Amiga format 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 to suit
your particular needs. The diskette is available for $14.95 plus $2.00 ($5.00 foreign) for
shipping and handling.
When ordering by mail, please give your name and shipping address. Enclose a check,
money order or credit card information. Mail your order to:
Abacus.
5370 52nd Street SE
Grand Rapids, MI 49508
ew! --
I'l, Amiga ·c· Amiga C for Beginners Amiga Machine Language
i for Beginners ·an inlroducllon 10 learnrng Ihe popularC language. Explains ·is a comprehensive inlroduction 10 68000 assembler ma o
Ihe language elemerls using examples specifically geared chine language programming and is THE praclical guide for
·'·e
.~····]
10 Ihe Amlga Describes C library roullnes . how Ihe compiler learni ng 10 program Ihe Amiga in ultra·fasl ML. Also covers
, ' . ' I
I works and more 68000 microprocessor address modes and archileclure,
I ISBN 1-55755-045-X $19.95 speech and sound from ML and much more. I ,
AbacusE!! ISBN 1-55755-025-5 $19.95
'~~~--I
Amiga Disk Drives Inside & Out AmigaDOS Quick Reference'
'IS Ihe mosl In·deplh reference availablecovering the Amiga's ·an easy-Io·use refe rence 1001 for begrnners and advanced
i disk dllves Learn how 10 speed up dala Iransfer, how copy programmers alike. You can quickly find commands for your
! ;~!
prolecllon works. compuler viruses. Workbench and Ihe CLI Amiga by using Ihe Ihree handy indexes designed with Ihe
DOS funcllons, loading. saving, sequenlial and random file user in mind. All commands are In alphabehcal order for easy
i -~IiiB -J I oiganization . mOit: ieference. Includes Workbench 1.3
, . !SBN1-5S755-042-5 $29.95 ISBN 1-55755-049-2 $14.95
seller!
a eSI,I/lli).'<1/1.1S/C AmigaBASIC Inside and Out
Inside and Out .THE def,n,ll ve slep·by·slep gUide 10 programming Ihe Amlga
Save Time and Money!·Oplional program disks are avail·
In BASIC. Every AmlgaBASIC command is fully descllbed
able for man y of our Amiga reference books. All programs Iisled
New Software All Abacus software runs on the Amiga 500, Amiga
1000 or Amiga 2000. Each pac/wge is fully compatible
with our other products in the Amiga line
The Ideal AMIOA wordprocessor
AMIGA BeckerText
Tex tPro A MIGA upholds the true spirit of the AMIoA:
it's powerful, it has a surprising number of "extra" AMIGA
features, but it's also very easy to use. TextPro
AMIGA-the Ideal AMIoA word processor that proves This is one program for ~ AMIoA owners.
just how easy word processing can be. You can write BeckerText Amiga is more than a word processor. It
your first documents immediately, with a minimum of has all the features of TextPro AMIGA, but it also has
learning-without even reading the manual. But features that you might not expect:
TextPro AMIGA is much more than a beginner's
package. Ultra-fast onscreen formatting, graphic merge • Fast WYSIWYG formatting
capabilities, automatic hyphenation and many more • Calculations within a text-like having a spreadsheet
features make TextPro A MIGA ideal for the program anytime you want it
professional user as well. TextPro AMIGA features: • Templates for calculations in columns
• Line spacing options
• High-speed text input and editing • Auto-hyphenation and Auto-indexing
• Functions accessible through menus or shortcut keys • Multiple-column printing, up to 5 columns on a single
• Fast onscreen formatting page
• Automatic hyphenation • Online dictionary checks spelling in text as it's written
• Versatile function key assignment • Spell checker for interactive proofing of documents
• Save any section of an AMIGA screen & print as text • Up to 999 charac ters per line (with scrolling)
• Loading and saving through the RS-232 interface • Many more features for the professional
• Multiple tab settings
• Accepts IFF format graphics in texts BeckerText AMIGA
• Extremely flexible printer adaptations. Printer drivers is a vital addition for
for most popular dot-matrix printers included C programmers-it's
• Includes thorough manual an extremely flexible
• Not copy protected C editor. Whether
you're deleting,
8edferText
TextPro AMIGA adding or duplicating AM/GA-........
sets a new standard a block of C source-
for word processing
packages in its price
TextPra code, BeckerText
AMIGA does it all,
..-.\.
range. So easy to AM/GA· ~~)
automatically. And
use and modestly
priced that any
AMIGA owner can
--- V~ \~~
~~_.-
the online dictionary
acts as a C syntax
checker and finds
use it-so packed
"::6 syntax errors in a
with advanced ~m_
flash.
features, you can't BeckerText AMIGA. When you need more from your I
pass it up.
$79.95
.oro p'="m thMi." 'orop'oc",iog . .$150.~O
Suggested retail price: _
J
Suggested retail price:
Imagine the ~ database
DataRetrieve
AMIGA
Imagine, for a moment, what the perfect database for
your A'vllGA would have. You'd want power and speed,
for quick access to your information. An unlimited
amount of storage space. And you'd want it easy to
use---no baffling commands or file structures-with a
graphic interface that does your AMJQA justice. Not jlist for the experts
Enter DataRetrieve AMIGA. It's unlike any other
database you can buy. Powerful, feature-packed, with
the capacity for any business or personal application-
mailing lists, inventory. billing, etc. Yet it's so simple to
use, it's startling. DataRetrieve AMIGA'S drop-down
AssemPro
menus help you to define files quickly. Then you con-
veniently enter information using on-screen templates.
AMIGA
DataRetrieve A MIGA takes advantage of the Amiga's
multi-tasking capability for optimum processing speed.
Assem Pro AMIGA lets every Arniga owner enjoy the
DataRetrieve AMIGA features: benefits of fast machine language programming.
• Open eight files simultaneously Because machine language programming isn't just for
• Pa~sword protection 68000 experts. AssemPro AMIGA is easily learned and
• Edit files in memory user-friendly-it uses Amiga menus for simplicity. But
• Ma-.;.imum of RO index fields with variable precision AssemPro AMiGA boasts a long list of profession~11
(1-999 characters) features that eliininate L'ie tedium and repetition of ~T'lIL
• Convenient search/select criteria (range, ;u~D / OR programming. AssemPro Ai\UGA is the complete
comparisons) developer's package for writing of 68000 machine
• Text, date, time, numeric and selection fields, IFF file language on the Amiga, complete with editor, debugger,
reading capability disassembler and reassembler. AssemPro AMIGA is the
• Exchange data with other software packages (for form perfect introduction to machine langage development
letters, mailing lists, etc.) and programming. And it's even got what you 68000
• Control operations with keyboard or mouse experl~ need.
• Adjustable ~('Teen masks, up to 5000 x 5000 pixels
• Insert graphic elements into screen masks (e.g., AssemPro AMIGA features:
rectangles, circles, lines, patterns, etc.) • Written completely in machine langu~ge, for ultra-fast
Screen masks support different text styles and sizes operation
• Multiple text fields with word make-up and • Integrated editor, debugger, disassembler, reassembler
formatting capabilities • Large operating system library
• Integrated printer masks and list editor. • Runs under CLI and Workbench
• Maximum filesize 2 billion characters • Produces either PC-relocatable or absolute code
• Maximum data record size 64,000 characters • Macros possible for nearly any parameter (of differellt
• Maximum data set 2 billion characters types)
• Unlimited number of data fields • Error search function
• Maximum field size 32,000 characters • Cross-reference list
• Menu-controlled conditional and repeated a,:,'~mbly
DataRetrieve AMIGA -it'll handle your data with the • Full 32-bit arithmetic
speed and easy operation that you've come to expect • Debugger with 68020 single-step emulation
from Abacus products for the AMIGA. • Runs on any A~nGA with 512K and Kickstart 1.2.
ROFESSIONAL
Professional DataRetrieve can perform calcul ations and searches using complex
mathematical comparisons using over 80 functions and con stants .
5370 52nd St. SE Grand Rapids MI 49508 - Order Toll Free! 800-451-4319
••• •
•
• Name •
•
•
• Address •
•
••
•
•
City
Phone
State Zip
••
•
•
• Where did you purchase your Abacus Amiga Product? •
• What other Abacus Products would you be interested in? •
•• 0 Please send me additional infonn:ltiol1 on other Amiga products. •
•
._-------------------------------------_.