0% found this document useful (0 votes)
145 views

Amiga 3 D Graphic Programming in Basic

Uploaded by

Rata Piojosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

Amiga 3 D Graphic Programming in Basic

Uploaded by

Rata Piojosa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 372

Amiga

3D Graphic
Programming
in BASIC
Jennrich
Massmann
Schulz

:::' ... -:-:.:....

A Data Becker Book


Published by

Abacus~
First Printing, February 1989
Printed in U.S.A.
Copyright © 1987, 1988 Data Becker GmbH
MerowingerstraBe 30
4000 Dusseldorf, West Germany

Copyright © 1989 Abacus


5370 52nd Street, SE
Grand Rapids, MI49508

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

2. The Basics of Ray Tracing ................................................. 5


2.1 Natural Objects .......................................................... 7
2.2 In the Computer ........................................................ 8
2.2.1 Light and Darkness ..................................................... 8
2.2.2 Shadows ................................................................... 9
2.2.3 Reflection ................................................................. 9
2.2.4 Transparency ........................................................... .l0
2.2.5 Limitations .............................................................. 10
2.3 Presentation in the Computer ...................................... 11
2.3.1 Data Structure .......................................................... 16
2.4 Simulating Perception ............................................... 19
2.4.1 What Do You See? ................................................... 22
2.4.2 What You Should See ................................................ 31
2.4.3 The Dark Side of the World ........................................ .37
2.4.4 Reflection ................................................................ 38
2.4.5 Bringing Color to the Screen ...................................... .40
2.5 Optimization ........................................................... .44

3. The Tracer Program ........................................................ .49


3.1 Wire Models ........................................................... .51
3.1.1 From 3D to 2D ....................................................... .51
3.1.2 Objects and Surfaces ..................................................61
3.2 The Editor ............................................................... 74
3.2.1 Why an Editor? ........................................................ 74
3.2.2 The Tasks Required of the Editor .................................. 75
3.2.3 Individual Components of the Editor............................. 78
3.2.3.1 The Input ................................................................ 78
3.2.3.2 The Output. ............................................................. 86
3.2.3.3 The Graphics ............................................................ 89
3.2.3.4 Data Operations ........................................................ 92
3.2.3.5 Disk Operations ........................................................96
3.2.3.6 Mouse and Gadgets .................................................... 98
3.2.4 Tips on Writing an Editor......................................... l02
3.3 The Main Program .................................................. 104
3.3.1 The Remaining Tracer Routines ................................. 104
3.3.2 Merging Tracer Modules into one Program .................. 141

4. Using the Program ........................................................ 143


4.1 Editor Documentation .............................................. 145
4.1.1 Input-General Information ...................................... 145
4.1.2 Entering Object Data ............................................... 146
4.1.3 The Operations Menu .............................................. 152
4.1.4 The Material Editor ................................................. 152
4.1.5 The Transform Menu ............................................... 153

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

5. Program Enhancements .................................................. 165

6. 3D Tricks and Tips ........................................................ 171

7. Mathematical Basics ...................................................... 177


7 .1 Vectors ................................................................. 179
7.2 Using Vectors ........................................................ 182
7.3 Angles Between Two Vectors .................................... 184
7.4 Intersecting Lines and Planes ..................................... 187

8. The Optional Disk ........................................................ 191


8.1 Compiling the Programs .......................................... 194
8.1.1 Compiling the Editor ............................................... 194
8.1.2 Compiling the Tracer ............................................... 196

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

Index ................................................................................... 357

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.

There is one thing we should mention before starting. Programming


three dimensional graphics requires a knowledge of mathematics. There-
fore, this book has a mathematical basis. If you don't know much
about math, don't panic. We'll do our best to explain the subject to you
in understandable terms. When you finish reading this book you'll
know more about the subject than you did before you read the book.

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------ -------------- -- -- -----~

1. INTRODUCTION AMIGA 3D GRAPHIC PROGRAMMING

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).

Many programmers consider this the best method of 3D graphic


reproduction, because ray nacing produces very lifelike effects. The
photograph on the cover of this book is a result of ray tracing, and the
entire book discusses the subject of ray tracing in AmieaBASIC.

Algorithms This is a common buzzword in computing. An algorithm describes a


plan for solving a problem, usually using a computer program. This
book, for example, lists algorithms for performing such tasks as
drawing geometric figures on a computer screen, then adding data to
these figures that will implement shadows, color, etc.

4
2.
The Basics of
Ray Tracing
ABACUS 2. THE BASICS OF RAY TRACING

2. The Basics of Ray Tracing


Hidden line Computer graphics of any kind look great on the Amiga. But three
algorithms dimensional computer representations of familiar objects are fantastic.
String art graphics are a very simple example of 3D graphics. A
computer can go one step further and display only the visible lines of a
3D graphic. Hidden line algorithms display the visible surfaces only.
The results achieved using hidden line algorithms are very good.
However, hidden line algorithms make it difficult to remove objects or
to display objects covered by other objects.

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.

2.1 Natural Objects

Before we go on to develop a ray tracing algorithm, we must first take


a look at objects and how they appear in the real world. Imagine a green
cube lit by the sun. The cube absorbs all light rays in colors other than
green, and reflects all the green light rays back to your eyes.

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

2.2 In the Computer

To duplicate the green cube as a computer generated 3D object, you


must get past some obstacles. First, your computer has only one visual
receptor (the screen) to replace your two eyes. In addition, the light
source is very low powered-it simulates light as a small group of
pixels on the screen. Our own sun sends out an extremely large number
of light rays: So many that all the computers on this planet couldn't
reproduce this phenomenon in a reasonable amount of time.

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

2.2.1 Light and darkness

Think of our imaginary green cube in the form of a computer image,


based on the data presented so far. Right now all you really have on the
screen is the green outline of what could be a cube. One important
factor in ray tracing makes an image three dimensional: Shading. If you
think of a real cube lit by the sun, the sides most directly exposed to
light are brighter than those sides less directly lit. The more

8
ABACUS 2.2 IN THE COMPUTER

perpendicular that you place a light source to a side, the brighter that
side appears.

It isn't hard to program the computer to understand the brightness of a


side. The same calculations can determine whether the side of an object
faces toward or away from the light source.

2.2.2 Shadows

The computer model becomes really interesting if it includes shadows


that a real object might cast. Shadows occur when an object blocks the
path of light rays. Imagine our sunlit cube again. The cube interrupts
the sunlight's path as it travels toward the base on which the cube
stands. This interruption appears on the base as a shadow.

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.

This process repeats until the visual rays encounter a non-reflecting


surface, a dull surface, or no surface at all. Then the visual rays create a

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.

Normal surface Reflecting


n

£7 .L

Reflecting and transparent


Transparent

Figure 2.2
L/
~
U
2.2.5 Limitations

The algorithms developed here can be modified to simulate colors,


shadows and reflections. There are limitations, however. First, since
you are working with visual rays instead of true light rays, you cannot
simulate the light source actually reflecting in a mirror image. Also,
graphics created by the algorithms have none of the effects caused by
ambient, indirect or refracted light

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

2.3 Presentation in the Computer

A computer must have the outside world described to it mathematically


before it can generate 3D graphics. Fairly simple three dimensional
geometrical formulas let you define lines, planes and circles (sec
Chapter 7 for brief descriptions of the math used).

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
)

Our algorithm divides any body into triangles, so we need triangles in


the basic figures. This requires a coordinate system and the equation:

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

This requires figuring out the polar coordinates. Polar coordinates


correspond in the 3D computer model to rotation in the real world.
Compute the polar coordinates from eu,v). You must limit w, just as
you had to limit 1 for the circle ring.

Isector!

Figure 2.7

To conclude, you also limit wand 1. The resulting figure is a circular


arc.

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

r 1 is the midpoint of the sphere and rd is the radius. We will leave


this discussion at the sphere and not try to master any new objects.

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.

Until now you have formed additional objects by placing restrictions on


already existing objects. This is impossible with the sphere because
there arc no other parameters besides the midpoint and radius. Now
we'll define a three dimensional space for two dimensional objects:
r = rl + u*r2 + v*r3 + w*rf,

r, r 1, r 2, r 3, and r 4 are vectors and u, v and w are scalars. In


addi tion, r 2, r 3 and r 4 should be perpendicular to each other. r 2, r 3
and r4 may not be co-planar, otherwise they would only form one
plane. Keep u, v and w unrestricted so that every point in your
computer universe is a point in your room.

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

This time there is no inequality because you don't want a filled


cylinder. Limit w to values between 0 and 1 to keep your cylinder at a
definite length:

u2 + v2 = 1 and O<=w<=l

ICylinder I

Figure 2.8

The cylinder is complete. You can give it a further limitation as you


did to the circular surfaces: Assign an angle interval so that you get a
cylinder section. Because the procedure is identical to the circular
surface, specify additional limitations and it becomes a cone.

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:

x+SQR (u2 + v2)

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

is a circle, but so is the vertical cross-section. The limitations are


similar to those for the cone, but this time a different equation is
oo:ded:
u2 + v2 + w2 ~ 1.

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.

2.3.1 Data Structure

We must establish a data structure for the parameters of the objects to


be displayed by our program. Because we defined the algorithm in
BASIC, we used a multidimensional array named KO (see the
Appendices for the complete program listings). We need four vectors
for each element of K. These vectors contain information about the
object type, the material constants and the restrictions. We came up
with K(MaxNumber,5,2). MaxNumber is the maximum number of
objects that can be placed in the computer's environment. The elements
of K are assigned the following parameters:

K(n,O,O): n = Type of Object. This element checks if the n object is


handled as a plane, a sphere or other object. The following values
correspond to the following basic objects:

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.

Note: Some later references to the KO array include periods in parentheses.


These periods represent allowed values. For example, K(n,l,.) also
refers to K(n,l,a), K(n,l,l), K(n,l,2), etc.

K(n,l,.) always contains the vector rl. K(n,l,a) is the x component,


K(n,l ,1) is the y component, and K(n,l,2) is the z component of the
vector, which also works in conjunction with other vectors. K(n,2,.)
through K(n,4,.) contain the vectors needed for their respective objects
(vectors r2 through r4). For example, K(n,2,a) contains the radius of
the sphere.

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, 2, 0) radius for sphere or


K(n, 2, .) r2

K(n, 3, .) r3

K (n, 4, .) r4 or if circle arc


K (n, 4,0) lower limit (inner radius)
K(n, 4,1) upper limit (outer radius)

For circle section, circle arc or cylinder segment:


K(n, 5, 0) = start angle
K(n,5,1) = end angle

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

material a small value-a larger value makes it difficult to differentiate


between shadows and where light actually falls.

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:

• Initial material brightness'


, mat (n, 0) Red material brightness'
, mat(n,l) Green material brightness'
, mat(n,::» Blue material brightness'
, mat (n, 3) Factor for unlit/shadow'
I mat(n,4) Factor for mirroring'
I mat (n, 5) Factor for transparency (not implemented)'
I mat(n,6) reserved'll

All values must be between zero and one.

Here's an example. When you want to know the reflection factor of


object number 47, get the material index:
PRINT K(47,0,2)

Imagine that you get the value 12. Now you can specify the reflection
factor with:

PRINT Mat (12, 4)

The abbreviated enLY"'Ij for this data is as follows:


PRINT Mat(K(47,0,2),4)

This syntax is the form used by the routines presented in the program.

18
ABACUS 2.4 SIMULATING PERCEPTION

2.4 Simulating Perception

The data structure assembles an artificial reality in our computer, and


now we must bring it to the screen. First we must determine the point
of view from which we want to see the graphic.

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.

I Projectlon point P Maln pOlnt H I


l screenl

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

end of a line of BASIC code. These characters indicate when the


<Return> key should be pressed in the BASIC editor.

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

The above routine starts by initializing an open window, shadowing


and the area to be shadowed. The important section begins with the two
FOR-TO loops which check all of the screen points. BoxW% alld
BoxH% specify the width and height of the screen points in pixels
(usually a value of 1). The loop calculates the three dimensional
coordinates from the two dimensional screen coordinates.

Reprojection works like a return function to Projection,


which projects three dimensional coordinates on the screen. The

21
2. TilE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING

functions Xresc and Yresc help configure later enlargements of the


screen area. Next, the vector runnig from P in the direction of the
screen points is computed (Rx,Ry,Rz). Then P is saved and the
CornputePoint function is called, which computes the color of the
screen points. The result of the computation is stored in the zero
element of StackO. The red element of the color passes Stack(O, 0),
the green element to S t a c k (0,1), and the blue element to
St a c k (0 , 2). The stack is there mainl y for reflections.

When Stack(O,O) is negative, this screen point contains nothing, and


we leave the background as it was. Otherwise the program considers the
color of the light source (Qh.r = red element, Qh.g = green element,
Qh.b = blue element) and displays the point with the OSSetPoint&
routine. This presents a problem. This routine displays a rectangle on
the screen and tries to arrive at a color as close as possible to the desired
color.

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).

2.4.1 What Do You See?

Let's take a closer look at what happens on the screen.

We defined the basic objects using mathematical equations to make it


easy to calculate points of intersection with a line. The line described
here is the visual ray. This visual ray begins at projection point P and
runs through the actual screen point. A line equation can also be
written in point-direction form:
r ~ rl + 1*r2

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:

Line:r = ~ + l*rR , P1ane:r = r 1 + u*r 2


Intersect point: l*rR - u*r 2 - v*r3 = (r 1

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)

No intersection point exists if the denominator is zero. This means that


the plane and the line are parallel. Instead, 1 is directly calculated and
returned to the called program.

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.

Now on to the intersection points of other basic objects. The preceding


subprogram is identical to that of the triangle except that the additional
parameters u and v must be computed and then tested to see if the
restrictions for the triangle are enough:
SUB IntersectpointTriangle(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b) STATIC~
SHARED Help () , K() ~
• => 1 = exact parameter, a,b = area parameter~
D=Ry*Help(n%,4)-Rx*Help(n%,3)-Rz*Help(n%,5)~
IF 000 THEN~
1=«Px-K(n%,1,0))*Help(n%,3)-(Py-K(n%,1,1))*Help(n%,4)+(Pz-
K(n%,1,2))*Help(n%,5))/D~
IF 1>0 THEN~
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~
b=FN Det(K(n%,2,O),Px-K(n%,1,O),-Rx,K(n%,2,1),Py-
K (n%, 1, 1) ,-Ry, K (n%, 2,2) ,Pz-K (n%, 1,2) ,-Rz) /D~
IF a<O OR b<O OR a>l OR b>l OR a+b>l THEN~
l=-U
END IF~
END IF~
ELSE~
1=-1~
END IF~
END SUB~

The Det function calculates only the value of a determinant. The


intersection point calculation for the parallelogram, circle, circle
section, and circle arc are similar-the only difference being the
restrictions. The name of the SUB program appears in parentheses (see
the complete listing in the appendices):
Parallelogram (IntersectpointRectangle):
IF a<O OR b<O OR a>l OR b>l THEN
1 = -1
END IF

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

Anglelnterval tests to see if the intersection point lies inside of


the defmed angle interval:
SUB AngleIntervall(l,n%,a,b) STATIC~
SHARED Pi,Pm2,Pd2,K()~
IF a~O THEN~
D~Pd2*SGN(b)~
ELSE~
D~ATN(b/a)~
IF a<O THEN~
D ~ D+pa
END IF~
END IF~
IF D<O THEN~
D ~ D+Pm2~
END IF~

And now check if this lies in the defined interval:


IF D<K(n%,5,0) OR D>K(n%,5,1) THEN~
l~-a
END IH
END SUB~

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~

This time we test to see if L1 is greater than T h res hoI d (set at


0.0001), instead of whether it is greater than zero. This Threshold is
used for shades and reflection. Because they work with the same
routine, the test must already exist.

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.

A coordinate system is set up by the three direction vectors. When we


convert the coordinates from P and R into this coordinate system (basis
transformation), we can calculate the intersection point of the line with
the cylinder. 'The cylinder equation is reduced to:

(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

(P xt, Pyt, P z t) is the transformed projection point and (xt ,yt,


zt) is the transformed direction vector. When we insert these in the
cylinder equation, we get:

(Pxt + 1*xt)~2 + (Pyt + 1*yt)~2 =1


o < = (pzt + l*zt) < = 1

Now there is only one unknown and this can be calculated after some
rearranging:

The further calculating of this equation is taken care of by the


following SUB program:
SUB IntersectpointCy1inder(n%,Px,Py,Pz,Rx,Ry,Rz,1,a,b,c,O
rigina1!) STATIC~
SHAREO Thresho1d~
I => l=exact parameter, a,b,c = transform Intersect point
coordinates~
CALL
Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,Origina1!)~
O=Xt*Xt+Yt*Yt'll
IF 0<>0 THEN'll
p=(Pxt*Xt+Pyt*Yt)/D~
q~(Pxt*Pxt+Pyt*Pyt-l)/D~
O=p*p-q~
IF 0>=0 THEN~
l=-p+SQR (D) ~
Ll=-p-SQR{D)'ll
c=Pzt+l*Zt'll
D=Pzt+L1*Zt'll
'two solutions: 1,e and L1,d. Which is right?
IF L1<1 AND L1>Thresho1d AND 0>=0 AND 0<=1 THEN~
SWAP 1,Ll'll

26
ABACUS 2.4 SIMULATI;\,G PERCEPTION

SWAP c, c'lI
END IF'lI

'1 and c contain the correct s:J~llti()n parameter:


IF c<O OR c>1 THEN'lI
1~-1'lI
ELSE'lI
a~Pxt+l*Xt'lI
b~Pyt+l*Yt'lI
END IF'lI
ELSE'lI
~~-1'lI
END IF'lI
ELSE'lI
1~-1'lI
END IF'lI
END SUB'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.

This time an additional parameter comes in the parameter assignment:


Or i gin a l! This is needed for Bas i s T ran s. Bas i s T ran s
converts the vectors P and R in the coordinate system of the cylinder:
SUB Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,
Original ' ) STATIC'lI
SHARED Help () , K () 'lI
• Transform (px,py,zy) ~> (pxt,pyt,pzt), (rx,rY,rz) ~>
(xt,yt,zt)'lI
'lI
IF Original! ~ True THEN'lI
Pxt~Help(n%,10)'lI
Pyt~Help(n%,II)'lI
Pzt~Help(n%,12)'lI
ELSE'lI
Pxt=(Px-K(n%,1,0))*Help(n%,13)-(Py-
K (n%, 1,1) ) *Help (n%, 14) + (pz-K (n%, 1, 2) ) *Help (n%, 15) 'lI
Pyt~(Px-K(n%,1,O))*Help(n%,16)-(Py-
K (n%, 1,1) ) *Help (n%, 17) + (pz-K (n%, 1, 2) ) *He1p (n%, 18) 'lI
Pzt~(Px-K(n%,1,O))*Help(n%,19)-(Py­
K(n%,I,I))*Help(n%,20)+(Pz-K(n%,1,2))*Help(n%,21)'lI
END IF'lI
Xt~ (Px+Rx-K (n%, 1,0) ) *Help (n%, 13) - (PY"Ry-
K(n%,I,I) )*Help(n%,14)+(Pz+Rz-K(n%,1,2))*Help(n%,15)-Pxt'll
Yt=(Px+Rx-K(n%,1,0))*Help(n%,16)-(Py+Ry-
K(n%,I,I))*Help(n%,17)+(Pz+Rz-K(n%,1,2))*Help(n%,18i-Pyt'll
Zt~(Px+Rx-K(n%,1,0))*Help(n%,19)-(Py+Ry­
K(n%,I,I))*Help(n%,20)+(Pz+Rz-K(n%,1,2))*Help(n%,21)-Pzt'll
END SUB'lI

The beauty is that the transfomled coordinates of the projection point


do not change during the entire calculation. We can calculate these
beforehand and save them in our Help array. Because the intersection
point routine is also used for reflection and shade calculation another
point is inserted instead of the projection point (Px,Py,P z). This is

27
2. THE BASICS OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING

why we must write an IF-THEN-ELSE construct. When Original!


is true, (Px,Py,P z) contains the coordinates of the original projection
point.

The basis transformation is the solution of an equation system with


three unknowns. The transformed point is simply inserted in the body
equation, which looks like the following for P:

P - rl + u'r2 + v*r3 + w*r4

or solved in the coordinate equations:

Px r1x + u*r2x + v*r3x t w*r4x


Py rly + u*r2y + v*r3y + w*r1y
pz r1z + u*r2z t v*r3z + w*r4z

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

'Test for solution c,l angle interval

IF c> ~ 0 AND c< = 1 THEN


CALL AngleInterval(1,n%,Pxt+l*Xt,Pyt+1*Yt)
ELSE
1 = -1
END IF

'No'"" for the second solution

IF C1> 0 and Cl<= 1 THEN


c

CALL AngleInterva1(11,n%,Pxt+L1*Xt,Pyt+l1'yt)
ELSE
L1 = -1
END IF

'If the second solution is better: Exchange

IF (1<-.5) OR (L1<1 AND L1>Thresho1d) THEN


SWAP 1,11
SWAP c,C
END IF

'Correct solution in c,l

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).

We can now determine which objects we see in the picture at point


bx ,by. This is done by converting (bx,by) to three dimensional
coordinates and testing for the line that goes through P at point R.
Then we calculate all of the intersection points of this line and all
bodies and find which is next to us. The equivalent SUB program is
called WhichBody, because it establishes which body the line
intersects:
SUB WhichBody (Kp%,Px,Py,Pz,Rx,Ry,Rz,Original!,Shadown!) STATIC~
SHARED True,False,minmax%(),NumberK,minmaxlq(),
Help(),K(),xb%,yb%,Sx,Sy,Sz,Body%,Ac,Bc,Cc,la,Threshold~
, ;> Body% ; Nr the body under coordinates xb%,yb%,
S(sx,sy,sz)=Intersect point, la=intersection line~
, => if Typ>=20: (ac,bc,ce) = transform Intersect point
coordinates~
la=-U
Body %;0'11
~
FOR n%;l TO NumberK'II
~
IF K(n%,O,O);O THEN~
CALL IntersectpointPlane(n%,Px,Py,Pz,Rx,Ry,Rz,l)~
GO TO Wkok~

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 -;-?

Or i gin a l! is set to true when it is established which object is


visible at the current screen position. It is false when reflection is in
effect. Shadown: becomes false when the shadow is calculated.

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.

2.4.2 What You Should See

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

Wc have one simple way of dctermining whether a point of a surface is


in the path of the light source. As a measurement for the brightness of
the surface we take the cosine of the angle. This is convenient, because

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.

In nature, there is no universal function to calculate the brightness of a


surface. Different material can have different brightness under the same
light. Because we cannot cover them all here, we use the cosine because
the cosine of the angle between two vectors can be calculated very
easily.

Now we need to find the normal vector. For planes, triangles,


parallelograms, etc., this remains the same during calculation, so that
we can compute it before the calculation and store it in Help. The
normal vector is the product of vectors r2 and r3, which cross the
plane. The normal vector is easier to compute for the sphere. The
normal vector is the same as the vector from the midpoint of the sphere
to the intersection point.

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.

The normal vector is parallel to the base surface of the cylinder, so we


need only consider vectors r2 and r3. The base surface of the cylinder
is (in the general case) an ellipse, and an equation for this already
exists:

(x'" 2 / + (y'" 2 / J..) L)

Solution for y:

y b * SQR(1-(x"2 I a"2))
y b/a * SQR(a"2 - x"2)

This equation solves y and gives the slope of the ellipse:

y' = -b/a * x/SQR(a"2 - x"2)

When we regard y' a~ the slope of a line, it is perpendicular to our


desired normal vector. We obtain the perpendicular by taking the
negative return value of the slope. The slope of the perpendicular is
equivalent to ny / nx, also the slope of the normal vector:

ny/nx ~ alb * SQR(a"2 - x"2)/x

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:

ny (a*b) *(y*a/b) ~ >


ny (a'2) *y

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:

n ~ Ir31'2 * u*r2 + Ir21A2 * v*r3

Because the quadratic of the length of r2 and r3 does not change, we


place these in our Help array, which saves us a lot of time.

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:

nl ~ n2/ln2 * iu*r2 + v*r31

is the normal vector on the base surface with a length of u * r 2 +v * r 3.


The direction remains the same. The normal vector on the cone surface
is given by:

n = Inll/!r41 * r4 t Ir41/1nll "nl

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:

n = (Ir31'2 + Ir41'2) * u*r2


+ (ir21'2 + Ir41'2) • v*r3
+ (Ir21'2 + ir31 A2) • w*r4

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.

SUB SAtBrightness(fl~_;,P.x,Py_.Pz,~irror,Or.Lgi ;al!) STATIC~qr


SHARED
He lp () , K () ~ ~v~a t () , Ox, Qy, Qz, Ar:" P,e" ee, Sx, Sy, Sz, N:~, t<:i r >1:;: r N1, Spx, Spy,
Spz,Briqht 'TI
• -=>BLight, Brightness, SP---Micc Vector,
LQ-Mirrorung'Jl
'JI
IF K(n%,O,C)<=9 THEN'il
r Determine Mi1'"ror \lektor Sp'i[
Nx~Help(n%,O)'il
Ny=He:" ,-),!]
N z-:-~ He,~ ~~ (q!; f ) "

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~

IF K(n%,O,O»=20 AND K(n%,O,O)<24 THEN~


Nx=Help(n%,4)*Ac+Help(n%,1)*Bc~
Ny=Help(n%,5)*Ac+Help(n%,2)*Bc~
Nz~Help(n%,6)*Ac+Help(n%,3)*Bc~
~
IF K(n%,O,O»~22 THEN~
Nl=SQR(Nx*Nx+Ny*Ny+Nz*Nz)~
IF Nl<>O THEN~
a=(Ac*K(n%,2,O)+Bc*K(n%,3,O))A2~
a~a+(Ac*K(n%,2,1)+Bc*K(n%,3,1))A2~
a=(SQR(a+(Ac*K(n%,2,2)+Bc*K(n%,3,2) )A2))/Nl~
Nx Nx*a~
Ny = Ny*a~
Nz = Nz*a~
b=SQR(Nx*Nx+Ny*Ny+Nz*Nz)/Help(n%, 7)~
Nx=K(n%,4,O)*b+Nx/b~
Ny=K(n%,4,1)*b+Ny/b~
Nz=K(n%,4,2)*b+Nz/b~
ELSE~
, If a cone angle:~
Nx~K(n%,4,O)~
Ny=K(n%,4,1)~
Nz=K(n%,4,2)'II
END IF~
END IF~
END IF~
~
IF K(n%,O,O»~24 THEN~
Nx=Ac*Help(n%,l)+Bc*Help(n%,4)+Cc*Help(n%,7)'II
Ny~Ac*Help(n%,2)+Bc*Help(n%,5)+Cc*Help(n%,8)'II
Nz~Ac*Help(n%.3)+Bc*Help(n%,6)+Cc*Help(n%,9)~
END IF~
'II

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

2.4.3 The Dark Side of the World

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.

The check in our program is very simple because we already have a


SUB program that calculates the intersection point between a line and
all objects. We must call this SUB program again, but this time the
line runs from the intersection point to the light source. When we get
an intersection point as a result, the point lies in the shadows;
otherwise we can assign it a normal color. The program section could
look like the following:
, =>Compute Brightness of the point. c> stack'll
CALL WhichBody (0, Px, Py, Pz, Rx, Ry, Rz, Original' ,False) 'll

IF Body% > 0 THEN'll

CALL SetBrightness(Body%,Px,Py,Pz,Mirror,Orcginal') 'll

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%~

IF Kp%>O AND la<l THEN~


, in shadow:~
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~

, Mirror light source on interface:~


Bright=Bright*(l-RestLght(StackPtr%»~

IF Bright<Mat(K(Body%,O,2) ,3) THEN~


Bright=Mat(K(Body%,O,2),3)~
END IF~

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

As the last feature we should take a look at reflection. We can compute


the reflected visual rays and their intersection point with an object. The
problem remains of combining the different colors of the different
surfaces.

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'

We will proceed as follows: First we'll compute all of the intersection


points and their color as in the above program section. We place this
color on the stack. After the last reflection we take the color and
combine it wIth the h:st color. We combine the result with the color
heforc iast, and so on, until we relum to the first color.
Computepoint: 1l
r =>ComputJ': Sr igh~r,~-:-ss e>f t.he point => stackcn

CA:,L 1j·n:; ,-=":JBody (:; ?x, I Py,~)!; Rx, Ry, 1-(Z, Origi:lal ~ , False'} 91

I~' Body% > 0 THEN'1I


Cl'l~_,L SetIiri.ght.ness (Body%, Px, Py, Pz, Mi rror I Origina 1. ~) 9I
Rest.: .uC:~
(StackPtr%) =Mar (K (Bociy%, C, 2) , 4) 'll
'l[
If Briqht<cO THEN'll
• unlit: 'lI
Br H''''..
r=Ma c (V (Body%, C, 2) ,0) * MOl t (K (Body%, 0,2) , :;) <I[
8riyhL.g=Ma~(K(Body%,O,2),1)*Mat(K(Body%,0,2), 3)'ll
Bright. b=Mat (K iBody%, 0, 2) ,2) *Mat (K (Body%, 0,2) , 3) 'lI
FLSE'lI
Kp%"-"'-B·:)dy%'Ji

CALL WhichBody (Kp%,Sx,Sy,Sz,Qx-Sx,Qy-Sy,Qz-Sz,False, True)'ll


SWAP Body%, Kp%'lI
IF Kp%>O AND 1a<1 THFN'iI
f in shadow:cn
Bright. r-MaL (K (Body%, 0,2) , 0) *Mat (K (Body%, 0, 2) ,3) ']I
Bright. q~Mat (K (Body%, 0,2) , 1) *Mac (K (Body%, 0, 2) ,3) 'iI
Bright.b=Mat (K(Body%,O,2) ,2)*Mat(K(Rody%,O,2) ,3)'lI
ELSFg)
I Mirror light source cn loterface:1
Bright=BrighL* (J -RestLght. (SlackPtr%)) 'lI
IF' Brjght<Mat(K(Body%,O,2) ,3) THEN'll
Hright=Mat(K(Body%,O,2) ,3),
EN!) IF'lI
Brighr.r=Bright·Mat(K(Body%,0,2),O)+Mirr~r·
Rest10ht(StackPtr%)'ll
nr~qht.g:'::l~rJ.yht*MC?L (K (Body%, 0, 2),1) +Mi rror*
:Zc;tLgl-tt_ ( __ dckPtc%) '1
Bright. b=BrigiJt '~lat (K (Body%, 0,2) ,2) +Mirro;:*
Rest LIJht (StacKr:Lr%) 9[
ENl) rz~<{[

END ";."

IF (RestLq'lt (StacKPtr%) >0) AND (StackPtr%<MaxStack%1 TllEN'll


I Determine Mirror inter[ace~
I 'l(~termL[Jp m£rr0t vector P-S:ST
Dq~ ~x'(Px-Sx)tNy*(2y-Sy)+Nz*(Pz-Szl'lI
Hx'--Sx-Px~ :;*Dqe*Nxqj

Ry-"Sy-?y+ 2 'Doe* Ny'll


R;', --:::;- pz +2"1: :)qc ~-NzlI

:;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

GOSUB Computepoint , Recursion !!!!~


'II
Bright.r=Stack(StackPtr%,O)+Stack(StacKPtr%+l,O)*
RestLght(StackPtr%)'ll
Bright.g=Stack(StackPtr%,l)+Stack(StackPtr%+l,l)*
RestLght(StackPtr%)'ll
Bright.b~Stack(StackPtr%,2)+Stack(StackPtr%+1,2)*
RestLght(StackPtr%)'II
END IF'll
ELSE'll
IF StackPtr% = °
Bright.r=-l'll
THEN'II

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.

2.4.5 Bringing Color to the Screen

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.

We aren't done combining colors. We base the displayed color


combination on the pattern defined. The pattern itself is two-color: One
color is established using the foreground color, and the other is

40
ASACCS 2.4 SIMljLA TING PERCEPTION

established using the background color. To get different color


combinations, we define different patterns, some with more pixels from
one color, and some with fewer pixels on one color. The pattern
automatically used by the operating system gives you a rectangle when
you set a pointer to it in the RastPort structure.

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:

A study of the color green appears below. Because we must economize


on memory space, our screen has only four colors: black, red, green,
and yellow. We need red and green because the picture contains red and
green objects. When we display the colors in a coordinate system
(which can be two dimensional in this case), we get the following
picture:

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.

It would be unacceptable if the algorithm went through all of the pos-


sibilities and took the best one. The routine in assembly language
requires five seconds per pixel for 64 colors and 25 patterns. That
means that one 320x200 picture would require more than three days to

41
2. THE BAStes OF RAY TRACING AMIGA 3D GRAPHIC PROGRAMMING

execute. And the time needed [or an equivalent program in


BASIC ... well, let's just s>ay it'll take more time.

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.

Because BASIC is not the fastest language, we programmed the algo-


rithm in assembly language. It would be better if the entire tracer
program was written in assembly language, but assembly language
programs are harder for the average person to read and understand than
BASIC programs. The program length also makes reading hard.

111e assembly routine is written with AssemPro. See the appendices


for the source code (SetPoint.ASM) and a BASIC loader [or those of
you who do not have an assembler. If you want to implement this
yourself, you must create PC-relative coele with AssemPro, You
must also write out the addresses of the three subprograms and the
vill~bks RastPort,Mode,MaxColors,Colors,RasterW,
and RasterH, and these must be adeled to the BASIC subprogranl
InitSetPoint. The created code must be saved as SetPoint. B.
,u1d the the routine can be loaded Wifh Lni tSetPoint. The variables
Rasterlni t and ColorPalet te will be changed. The routine is
called with:
CALL OSSetPoi nt & (x 1, yl , >:2, y 2, ,.ccj~ 1 (j24, q:c'en' l024, bl ue* 1 024)

where (x 1 ,y ~) is the upper left comer and (x 2 ,y 2) is the lower right


corner of the rectangle. The values for red, green, anel blue must be
between 0 and 1024. These va:ues should generally be given as integer
values.

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

contain the height and width of the window/screen because


OSSetPoint takes its own clipping.

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

The algorithm we have been formulating so far works. We should add


some improvements. This algorithm has a built-in feature for com-
puting printout parameters that remain unchanged during calculation.
The SUB program that executes this for us is called InitShadows.
The computed values are stored in the Help array, the elements in this
array have different meanings for different objects. He lp contains the
normal vector for planes, and the denominator detenninate for the basis
transformation for cylinders, cones, and ellipsoids.

The next step encountered is the intersection point calculation. Exam-


ine the following diagram and imagine the objects are displayed on your
screen:

Figure 2.15 l'--------------------------------------J


The objects take up a fairly large section of the screen. We can first
establish a minimal rectangle in which all of the objects lie. Then our
program needs to send out a visual ray for every point that lies inside of
this rectangle.

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.

We can store the rectangle borders in an array, say MinMax. Each


element of MinMax contains the following values:

MinMax(n,O) minimum x coordinate for object n


MinMax (n, 1) minimum y coordinate for object n
MinMax(n,2) maximum x coordinate for object n
Min Max (n, 3) maximum y coordinate for object n

The subroutine which calculates these rectangles is Ini tMinMax. For


"round" objects (circular surfaces, cylinders, spheres, etc.), a rectangle
or square is put around the objcct, and those comer points create the
basis for the rectangle computation. Here you can put an octagon
around an object and the rectangle calculations occur naturally.

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.

Do you understand what is going on? Instead of the cartesi~m coordi-


nates (x,y,z), we can also give a point in polar coordinates as (a,b,d).
a and b are angles and d is the distance from the coordinate origin. We
can give an Amin and an Amax for each object so that for each point of

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.

When we determine in WhichBody whether an object casts a shadow


on a point, you first compute the polar coordinates of the point
(pa,pb,pd). Before you work through the intersection point
calculation, test to see if pa lies between Ami nand Amax and if pb
lies between for Bmax and Bmin for this object. If this is not the case,
this object cannot cast a shadow on the point and you can skip the
intersection point calculation.

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:

MinMaxLq(n,O); increment for angle a


MinMaxLq(n,l): minimum [or angle a
MinMaxLq(n,2): maximum fOT angle d
MinMaxLq(n,3): increment for angle b
MinMaxLq(n,4): ~injmum for angle b
r·1i'-IHaxLq(n,5i; maximum for angle b
HinHaxLq(n,6): minimum distance of object n fro", q

This field is initialized in the subroutine Ini tMinMaxLq. The test


for MinMax and MinMaxLq in WhichBody is:
SUB WhichBody (Kp%,Px,Py,Pz,Rx,Ry,Rz,Original',Shadown!) STATIC~
SHARED Tn]e, Fa l 5e, minmax% () ,Numbe cK, minmaxlq () ,Help () ,K () ,
xb%,yb%,Sx,Sy,Sz,Rody%,Ac,Bc,Cc,la,Thrcshold'!I
, =) Body% ~ Nr the body under coordinates xb%,yb%,
S(sx,sy,sz)=Interscct point, la=inlersection line'!I
, => falls Typ>=20:
'(ac,bc,ee) = transform Intersect points coordinates'
la=-l'II
Body%=O'!I
'If
iF Shadown I = Tcuc ThEN 'l:
CALL Calcablq(Anglea,Angleb,OI,OI,Px,Py,Pz)'lf
Dist=SQR (Rx*P",+Ry*Ry+Rz*Rz) '!I
'::ND IF'll

FOR n%~l TO NumberK'll


IF Original' = True THEN'll
IF minmax%(n%,O»xb% THEN'll
GOTO NxtkS

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

CALL IntersectpointCylinder{n%,Px,Py,Pz, Rx,Ry,Rz, l,a,b,c,


Original') 'II
GOTO Wkok'll
END IF'll
IF K{n%,O,O)~21 THEN'll
CALL
IntersectpointCylinderSegm{n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,
Oriqinal ! ) 'Il
GOTO l'ikok'll
END IF'Il
IF K{n%,O,O)=22 THEN'll
CALL IntersectpointCone{n%,Px,Py,Pz,Rx,Ry,Rz,l,il,b,c,
Oriq'.nal') 'll
Gom Wkok'll
r;,m IF'll
IF K{n%,O,O)=24 THEN'll
CALL IntersectpointEllipsoid (n%, Px, Py, P z, Rx, Ry, Rz, 1, a, b, c,
Ociginal' ) 'il
END IF'!!
Wkok:'il
, Work OK!'11
'II
IF (l>Threshold) AN;) (la<~O OR l<la) AND (n%<>Kp% OR
K{n%,O,O»=lO) TfJEN'II
la=l 'Il
Body%=n%'11
IF K{n%,O,O»=20 AND Kp%=O THEN'll
Ac=a'll
Bc=b'll
Cc=c'll
END IF'll
END IF'i.
Nxtk:'Il
, ~;ext body'll
NEXT n%'11
'll
TF Rnoy%>O AND Kp%=D THEN'll
Sxo·Px , la*Rx'll
Sy=Py+la*Ry'll
Sz=Pz+la*Rz<.IT
END IF 11
END SUB'll

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

3. The Tracer Program


Now that we have discussed the basic algorithms required for three
dimensional graphics, we'd like to show you our results. This chapter
contains our realization of a ray tracing program. Before describing the
routine we'd like to point out that the aim of this book is to teach you
how to program three dimensional graphics. This book is not a
programming tutor in itself. The routines are written in modular form
so they can easily be adapted for use in your own programs. The
optional disk contains the separate modules saved in ASCII format so
they may be easily merged into your own program code.

3.1 Wire Models

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.

To display our objects, we must project all of the three dimensional


points whose X, Y and Z coordinates were given onto thc screen.
Points that make up the room must also be put on thc plane. The
points projected on a plane can then be displayed on the screen.

It must be obvious from the screen display whether an object is placed


in front of or behind another object. We must also create a perspective
effect, so the computer gives the most realistic scene possible.

We first fix a stationary point inside the computer world. We do this by


giving the coordinates of our stationary point with the variables p x,
Py, and Pz. We named the given point Projection point.

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.

We place ourselves at the projection point and look in the direction of


the main point.

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

The line PM (projection point/main point) helps us determine the


iOtation angle around the coordinate axes, around which the projecliull
plane must rotate so that it coincides with the Y Z plane.

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.

The following diagram illustrates how we determine the rotation angle:

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

Sin (beta) = (pz-Hz)/DPH (DPH Distance from projectiC)ll


point to main point)
Cos (beta) = D1/DPH

The angle can be calculated using the A TN (arctangent) function of


AmigaBASIC. This is possible because the tangent of an angle is also
defined as the quotient of the sine and cosine of the angle:

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.

How do you rotate a point? Look at this illustration:

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:

Sin(~) = Qy/r Sin (a-~) = Q' y /r

S4
A HACl:S 3.1 WIRE MODELS

Cos (~) = Qxir Cos(U-~) = (i'xir

Insert this in the addition theorem and you get the formula for the
rotation of a point around Lhe angle alpha.

Addition C0S(~-U) Cosl~)*cos(a)+Sin(~)*Sin(a)


t heoreITI: Sin(~-a) Sin(~)*cos(a)-cos(~)*Sin(a)

Substitlltifln Q'xic CosIU)*Qx*r + Sin(a)*Qy*r


Q'yir Ccs(U)*Qy*r - S~n(U)*Qx*r

C'x Cos(U)*Qx + Sin(u)*Qy


Q'y = Ccs(U)*Cy - Sin(U)*Qx

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.

The rotations arc shown in the following diagram:

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.

Now we can concentrate on perspective. We examine the line through


the projection point and the points that rotate around the coordinate
axes:

55
3. THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING

P
-x

Figure 3.5 Projection plane I


As you can see, the projection point now has the coordinates
(DPH,O,O). We determine the rotation angle around the Z and Y axes
from the projection-main point line so that the projection plane lies on
the YZ plane. Because the line PH is perpendicular to this plane and the
main point again lies on the coordinate origin, this means that the
projection point lies in the range DPH on the X axis.

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.

How do you determine these intersection points? We see the line


equation of the line projection point--displayed point:

x Qx (Px-Qx)
y -- Qy t ,.. (Py-Qy)
z Qz (pz-Qz)

We know that the intersection point must have the X coordinate 0


because the X coordinate of all points on the YZ plane is 0 (we
determined through the rotations that the projection plane lies in the
YZ plane).

Together with the coordinates of the projection points and the X


coordinate of the intersection point we can set up the following
relationships:

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)

These are our screen coordinates. We must now consider the Z


coordinate of the intersection point as the Y screen coordinate, and the
Y coordinate of the intersection point as the X coordinate of the screen.

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!

xl= (x-Hx) *Cosa" (y-Hy) *Sina 'Z-Axis rotatLon!


yl=(y-Hy)*Cosa-(x-Hx)*Sina!
x2=xl*Cosb+(z-Hz)*Sinb ' Y-Axis rotation~
z2=(z-Hz)*Cosb-xl*Sinb!
y3=yl*Cosctz2*Sinc ' X-Axis cotation'
z3=z2*Cosc-yl*Sinc'lI

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:

FN XSclae (x) (x+pictureX) * PicLurewidLh and


FN YScale (y) (PlctureY-y) * Picturc~h"ight

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:;;

Picturewidth and Pictureheight act as the enl:lrgemenl


(magnification) faclors in the X and Y directions. pic t u ..-eX and
P ict ureY give the size of the window section whose contents should
be enlarged:

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:

PictureX RasterW2% I Picturewidt~


PictureY = RasterH2% / Pictureheight

RasterW2 % and RasterH2 % are the screen coordinates of the mid


point (For a 320x200 screen RasterW2% = 160 and RasterH2% =
100).

Picturex and PictureY get larger as Picturewidth and


pi ct ureheight get smaller, and vice versa.

XScale and YScale ensure that the origin of the coordinate system
(= transformed main point) transforms to the midpoint of the screen.

This occurred because the X coordinate of the intersection lX)int is added


[0 PictureX. Remove PictureY from the Y coordmate of the
intersection point because the Y coordinates cross from top to bottom,
not from bottom to top as in Cartesian coordinates.

Multiply the coordinates by the enlargement factors to make the points


correct for the screen.

Until now we have always maintained that a main point and a


projection point would be given. These two points are basically
sufficient to develop a completely functioning 3D/2D routine.

These points can be changed in a program. First the program must be


interrupted and one or more program lines changed, for example, to
give new coordinates for the center point.

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 12, 1'!I


PRINT" Hx --= 11;71
CALL FormInpu~, (Hx,30:,-1E+14,1E"14),[

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 l3, 1'li


PRINT" Py = ";'ll
CALL Formlnput (Py, 3D! , -1E+ 14, 1E+ 14) 'll

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

CALL Forrnlnput (DPH,30',-lE+l1,lE+14)'ll


'II
GOSUB Initial'll
Newone' = True'll
CIS'll
GOSUB ~akeHenu'll
RETlJRN'll
''II
IoputAngle:'ll
Status$ = " Status: Enter angle of rotation"+CHRS(O) 'II
CALL SetWindowTitles&(NWBase&,SAfJD(Status$) ,O)'lI
'II
GOSUB DeleteHerm'll
'II
a=FN Deg(Alpha)'ll
b~FN Dcg(lleta)'ll
c=FN DeC) (Camma) 'II
'II
LOCATE 10,1'll
PRINT " Angle of rotation (a,_,c): "'lI

LOCATF :.2,' 'II


PRINT" Alpha (Z-Axis) = ";'ll
CALL FormInput (a,30!,0',360:)'ll
'II
LOCATE 13,1 'lI
PRINT" Beta (Y-Axis) = ";'l!
CALL Formlnput (b, 30' ,O! ,360' ) 'll
'II
LOCATE 14,1'll
PRINT" Gamma (X-Axis) = ";'ll
CALL FocmInput (c, 30 1 ,O!, 360 1) 'l!
q[
Alpha=FN Rad(a)'ll
Beta·cFN Rad (b) 'lI
Gamma~FN Rad(c)'ll

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.

In Ini t ial, the data of the new projection point is computcd:


************************~

* 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.

3.1.2 Objects and Surfaces

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

'n'. •....••.. ...' ..... ~


K 1, .1
X In'. 2, .1
b ,. J{In', J, .1 '

-..... .......... .......... ........' ..'.'


.......... ..........
..........
..'
.' ..........•.
.....
.,
..... , , ........
" ' .... ,....

"

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

Circle (Ellipse) : K (n%,O,O) 3


o = K(n%, 1, .j
a K(n%, 2, .j
b K(n%, 3, .j

,,,
,

Figure 3.10
7
,/'
~------------------~--~------,~
y

Circle segment: K (n%,O,O) 4


0 ~
K (n%, 1, • j
a K (n%, 2, • j
b K (n%, 3, ·)
K(n%,5,O) starting angle
Z K(n%, 5, 1) ending angle

,,
,,,

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

Circular ring K (n%, 0(0) 5


() = K (n%, ·)
a = K(n%, 2,"
·)
b K (n%, 3, ·)
K(n%,5,O) starting angle
z K(n%,5,1) ~ ending angle
K(n%.4,O) inner radius
K(n%.4.1) outer radius

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

Cylinder segment : K (n%, 0,0) = 21


0 K (n%, 1- ·) K(n%,5,O) st a rt i "g angle
a ~
K (n%, 2, ·) K(n%,5,~) ending angle
b -- K(n%, 3, ·)
Z h K (n%, 4, ·)

x
,, ,

------ --
.
. .... .....~

Figure 3.15 .••."


l
:""
l
"
y

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

The following routines draw the characteristics of the individual objects


and surfaces:

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

FOR wl=-Pd2+D TO Pd2-D/2 STEP D~


Dx=K(n%,l,O)91
Dy=K(n%,1,1)+K(n%,2,0)*COS(wl)~
Dz=K(n%,1,2)+K(n%,2,0)*SIN(wl)~
CALL Pro=ection(Xp%,Yp%,Dx,Dy,Dz)~
CALL ~ove&(Rast?ort&,Xp%,Yp%)f
FOR w2=D TO P~2+D/2 STEP D9I
Dx=K(n%,1,0)+K(n%,2,O)-SIN(w2)*COS(wl)'
Dy=K(n%,1,1)+K(n%,2,0)*COS(w2)*COs(wl)9I
D7-=K(n%,1,2)+K(n%,2,0)*SIN(w1)~
CALI. Projection(Xp%,Yp%,Dx,Dy,Dz)9I
CALL Oraw&(RastPort&,Xp%,Yp%)91
NEXT w291
NEXT w1~
FOR w>-Pd2+D '~O pd2-D/2 STEP D~
Dy=K (n%, 1, 1) ~
Dz=K(n%,1,2)+K(n%,2,O)*COS(w1)9I
Dx=K(n%,1,O)+K(n%,2,0)*SIN(wl)9I
CALL Pro jecti cn (Xp%, Yp%, Dx, Dy, Dz) 91
CALL Move&(RastPort&,Xp%,Yp%)~
FOR w2=0 TO Pm2+D/2 STEP 091
Dy=K(n%,1,1)+K(n%,2,O)*SIN(w2)*COs(wl)9I
Oz=K(n%,1,2)+K(n%,2,O)*COS(w2)*COS(wl)1:
Dx-K(n%,1,O)+K(n%,2,OI*SIN(wl)91
CALL Projection(Xp%,Yp%,Dx,Dy,Dz)~
CALL Draw& (RastPort&,Xp%,Yp%) 91
NEXT w291
NEXT wi'll
Ri::TURN'll
'91
DrawCy~inder:'ll
Dx=K(n%,l,O) +K(n%,2,0)~
Dy=K(n%,i,11+K(n%,2,1)9I
Dz=K(n%,1,21+K(n%,2,2)'ll
CALL Projection(Xua%,Yua%,Dx,Dy,Dz)9I
Dx=K (n%, 1, 0) +K (n%, 2, 0) +:< (n%, 4, 0) 91
Dy=K(n%,:,1)+K(n%,2,1)+K(n%,4,1)9I
Dz=K(n%,1,21+K(n%,2,21+K(n%,4,2)9I
CALL Projection(Xoa%,Yoa%,Dx,Dy,Dz)9I
D=Pm2/NumberScgmcnts~
FOR w=D :'0 Pm2+D/2 STEP D9I
Dx=K(n%,1,C)+K(n%,2,O)*COS(w)+K(n%,3,O)*SIN(w)'
Dy=K(n%,~,11+K(n%,2,1)*COS(w)+K(n%,3,1)*SIN(wl~
Dz=K (n%, 1,2) I K (n%, 2,2) *COS (w) +K (n %, 3,2) *SIN (w) 91
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%,i,0)'
Dy=K(n%,1,11+K(n%,2,1)*COS(wl+K(n%,3, 11*SIN(wl+K(n%,4,1)9I
Dz=K(n%,1,2)+K(n%,2,2)*COS(w)+K(n%,3,2)*SIN(w)+K(n%,4,2)~
CALL P,ojcct'on(Xp%,Yp'o, DX,Dy, DzI'!l
CALL :1ove&(RastPort&,Xua%,Yua%)'f.
CALL Draw&(RastPort&,Xu%,Yu%)'
CALL Draw&(RastPort&,Xp%,Yp%)9I
CALL D,aw&(R~stPort&,Xoa%,Yoa%l~
Xua %--Xu%'!l
Yua%=Yu%'!l
Xoa%=Xp%'!l
Yoa%~Yp%'ll
~1EXT w'j
RETURN"!
"J:
~> clwCyli r.d"rScgm: '11
w=K(n%,5, I'll

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'

P rojecti on (xl %, y1 %, K (n%, 1, 0) +K (n%, 4, 0) , K (n%, 1,1) +K (n %, 4, l) ,K (n %,


1,2)+K(n%,4,2))~
CALL
Projection(Xp%,Yp%,K(n%,1,O)+K{n%,2,O),K(n%,1,1)+K(n%,2,1) ,K(n%,
1,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%,1,O)+K(n%,2,O)*COS(w)+K{n%,3,O)*SIN(w)~
Dy=K(n%,l, 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 Projection{Xp%,Yp%,Dx,Dy,Dz)'
CALL Draw&(RastPort&,Xp%,Yp%)~
CALL Move&{RastPort&,x1%,y1%)~
CALL Draw&(RastPort&,Xp%,Yp%)~
KEXT w~
i\I::,URN~

'~
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).

If none of the parameters (Projection point, Main point, etc.)


are changed in the meantime, the picture is not refreshed.

Our tracer program allows you to choose backgrounds for your


drawings. Should you choose a new background for the picture because
the original background color is too distracting, DrawNew provides for
this by clearing the background. The picture then appears over the
selected background:

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

IF (Newone! = True) OR (Hg True) THEN'll


Newone I = False I Redraw picture 'll
Hg = False I and "paint oVerl!<I[
GOSUB :1akeMenu I background 'll
END IF'ji
RETURN'll
l'lf

73
3. TilE TRACER PROGRAM AMIGA 3D GRAI'IJIC PROGRAMMING

3.2 The Editor

3.2.1 Why an Editor?

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 is also possibile to save the calculated numbers into a separate file


with the help of a word processor. The program then reads these lines
into memory. The disadvantage shown above applies to this case as
we.lL

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

3.2.2 The Tasks Required of the Editor

Once the larger programming objective is established, all of the detail


work is before us. All of the desired values and features of this editor
must also be determined. For this we divide the editor into its
individual, logical, and functional sections, called modules. The main
task of the editor is to read in numerical data. We must add input and
output procedures for this. Since we want this data presented both as
numbers and as a wire model, the corresponding procedures must be
developed. Some additional functions are used; they are not necessary,
but make the program more user friendly. The individual modules are
explained in the following sections.

The graphic The graphic presentation cannot be displayed as a finished three


output dimensonal graphic complete with light, shadows, hidden lines, or
reflections. This would take far too much computation time. On the
other hand, displaying the graphic as a wire model in perspective in the
editor is possible but not to our advantage. The details would be barely
recognizable and perspective would be distorted. We reserve both the
wire model in perspective and the final shadowed graphic for our ray
tracing program.

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.

Additional What most professional Amiga applications have in common is the


features ability to use gadgets (objects on the screen that can be selected with
the mouse, such as sliders, text gadget'>, etc.). Programming gadgets in
AmigaBASIC can be complicated, but it makes the program easier for
the average person to use.

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 abovementioned features have almost completely described our


editor program; only the realization is missing. One possibility for
programming such an editor is listed completely in the appendices. The
following sections describes the most important routines of this editor.
From these routines we can create a relatively simple and fast editor for
creating 3D objects.

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)

3.2.3 Individual Components of the Editor

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.

3.2.3.1 The Input

When a number is entered in a program, an input error may occur if


"onehundred23 ", "la23" or something similar is entered. The input
routine should make sure that the only active key is the one the user
pressed. The <Delete>, <Backspace>, <Cursor left>, <Cursor right>
and <Return> keys function as usual.

The INPUT routine of BASIC is unusable here. The procedure used


instead of the INPUT routine is called getstring. It reads a variable
length string from a certain place on the screen and places this string in
a window. The character string can be scrolled left and right within this
window.

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:

rp&=WINDOW(8) 'take the pointer from RASTPORT


cw%=PEEKW(rp&+60) 'character width
ch%=PEEKW(rp&+S8) 'character height

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"

After this preparation the routine is simply:


SUB setcursor(z,s) STATIC'
'TASK :set cursor at specified position'
'PARAMETER:=>z line'
s column<iI
SHARED cW%,ch%Si
CALL setdrmd& (WINDOW(8) ,2)'
LINE (s*cw%-cw%,z*ch%-ch%-1)-\$*cw%,z*ch%-1),3,bf'
CALL setdrmd&(WINDOW(8) ,1)'
END SUB 'lIB

When setcursor is called twice with the same parameters, the


cursor is erased again and the characters under it are presented normally:
SUB getkey(a$,z,s)STATIC'll
I TJ\SK : l-Zead one character in'll
'PARA"":""i\: '>z line'
s column'
<=a$ presseci key~
CALL setcursor(z,s) ,
a$=""q[
WHILE a$=""'ll
a$=INKEY$'lI
WEND'
CALL setcursor(z,s)'
,
END SUB'

These two procedures are used in the procedure ge t s t ring. This


routine requires the old contents of the string, the keypress, lhe
allowable characters, window position, and window length. Passing the
routine the old string contents allows changes to an existing character
string without re-entering the string's contcnLS.

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

CALL getkey (a$, z, s+?ositiCl:l-J.) Igt:::' nex~_ kE'y~


WEND 'lI
END IF'll
IF i ><pos l t~on ',fIEN'iI
CALL p~tstring (old$, Z, s, inplen ) 'iI
END IF 'll
END SUB'lI
'lI
Next we examine if the length is equal to one or not. If so, it waits for
a valid key and returns this, and in the other case the characters arc read
until the user presses the <Return> key. Each character is checked to
see if one of the following five cases occurs:

1.) Valid characters (in z $), then INS1R(z $, a $) is unequal to zero


and the characters are inserted in the corresponding place In
old$, Then i and posi tion must be increased to ine

2.) <Cursor right>, then i and posi t ion are increased by olle

3.) <Cursor left>, i and po sit ion arc lowered by one. I is


important to make sure that these two varaibles do not take all
an invalid value

4.) <Delete>, here the ith chamcters arc removed [rom old$

5.) <Backspace>, a combination of <Cursor left> and <Delete>

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

The routine for reading an integer value is identical to the above


routine, the only difference appearing in the call of get st ring ("." is
allowed in getreal but not 10 getint). The statement of the value
range is necessary for the parameters already known, as well as the
upper and lower limits of all valid numbers (un t ! ,ob !). Both
procedures use two routines that have not been mentioned till now: the
conversion routines conrealstr and constrreal:
SUB conrealstr(i', l$)STATIC~
'TASK :convert real value into string~
rounded to 3 decimal placcs~
'PARAMETER:~>i! the ceal Vd;l1e~
<~i$ the string'li
i$=STRSli! )~
j!=FIX(1000' *j! +.5*SGN (i')) /lOClO' 'ul(,,,d'll
i$~STR$(j!)~
IF ABS(j'»O AND ABS(j!)<l THEN 'if O<~'<l 0 inserted'll
i $=MID$ (i $,1,1) +" O"+MID$ (i S, 2, SEN (i $) ) 'll
END IF~
IF j!>~O THEN 'if O<~j! truncate first place~
i$=RIGHT$(i$,LEN(jS)-l)~
END IF~
END SUB'l[
'lI
SUB constrreal (i$, i ') STATIC~
'TASK :convert string into real vaL,(~'ll
'PARAMETER:~>i$ the string'll
<-j' the real value~
i$ if conversion er:or i$.:::IIII<Ii
i ' =VAL ( i $ ) 'll
IF i! >~O THEN~
LF i! >0 !-\ND i! <1 THEl\ll
i$=" "+RIGflT$ (is, LEN (i$) -1) 'insen space and cdtoff 0,1
ELSE ~
i$~l' ·'+~S 'insert space~
END IF'll
END IF'll
j'~i '-FIX(i'*lOOO')/lOOO' 'r",,,d 'll
IF is><STRS(i') OJ, j!><O THEN 'Feror ?'IT
i$="'''ll
END IF 'l!
,~ND S·;:l'l!
'li

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

mouse position emerges, because mouse input is allowed. This only


works when reading room coordinate vectors and not angle vectors. An
additional parameter tells the procedure whether mouse input is allowed
or not. The mouse position is stored in the global variables called
mox ! , moy! and mo z ! . To let the procedure know that the keyboard
input doesn't count, we press <Return> and no other keys. And now
the routine:
SUB get3::::-ea~ (il ~ I i2 ~, i3! I as, Z, 5, inplen ,Lnt.!, ob! ~modlJs)
STATIC'll
'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 if~O no mouse entry'll
if~-l mouse input (position vector)'ll
if>O mouse inout (Difference vector)'ll
<~il',i2' ,i3' specified value'll
SHARED mox', moy', moz' ,k' () 'I!
CALL con3realstr(il:,i2!,i3',j$)'ll
IF a$~"" THEN'll
CALL gel key (a$,z,s)'ll
END IF 'I!
IF ASC(a$)~13 AND modus><O THEN'll
IF modus~-l THEN'll
il' ~mox! 'I!
i2!~moy''ll
i3!=moz''ll
ELSE'll
il! =mox '-k! (modus, 1, 0) 'I!
i2'~moy!-k! (modus,l,l)'ll
i3'~moz!-k' (modus,1,2) 'I!
END IF'll
CALL put3real(il',i2',i3',z,s,26)'ll
ELSE'll
loop2:'ll
i$=j$ 'I!
CALL getstring(i$,a$,"1234567890-.,",z,s,inplen )~
j$=i$'Il
CALL constr3real(i$,il!,i2!,i3')'ll
IF i$~"" OR il'<unt' OR i2'<unt' OR i3'<unt' OR il'>ob' OR
i2'>ob' OR i3'>ob: THEN'll
a$=" 1Iq{
GOTO loop2'll
END IF'll
END IF'll
END SUB 'I!
'I!

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

As before, we use the conversion routines (con3realstr and


constr3real):

SUB constr3real(i$,i1!,i2!,i3!) STATIC'


'TASK :convert one string into 3 real values'
'PARAMETER:=>i$ the string'
<=i1!,i2!,i3! the real values'
i$ if conversion error i$=""'
Problc,"=O'll
i$=i$+",'"
FOR i=l TO 3'll
comma=INSTR(j $,",") 'Mark comma position'
IF comma<=l THEN 'Problem ?,
Problem=l'l!
ELSE'j[
a$=MID$ (i$, 1, comma-1) 'tn;ncate string to be converted'
i$=RIGHT$(i$,LEN(i$)-comma) 'mark the rest'j[
Cl,LL constrreal (a$, i' (i) ) 'converL 'lI
IF a$="" THEN 'Problem?'j[
?roblem=l'j[
END IF 'l!
END IE'q
NPXT is
IF Problem=l THEN'
i $='''' <[
ELSE<TI
i$=" nen
11!=i! (1)'ll
i2! =i! (2)'
i3!=i! (3)'
END IF'
END SUB •
'j[
'l!
SUB con3realstr(il!,i2!,i3!,i$) STATIC'
'tASK :convert 3 real values into vector sLrinq'li
'PARAMETEE:~>il!,i2!,i3! the 3 Real values'll
<=i$ the string'll
CALL conrealstr (il!, il$) 'II
Cl,J L conrealstr (i2!, i2$) 'II
CALL cClnrealstr (i3!, 13$) 'j[
i$=-cil$+","+i2$+","+i3$<JI
END SUBqI
'II

Both routines support the conversion procedures and operate in the


same way. The constr3real procedure is a little complicated
because the beginning position of the coordinates in the character string
must be determined by using the INS T R function. After all this
preparation, we want to program a menu for our editor. As an example,
we use the menu for a circle section because it uses all of input
procedures discussed so far. Next the location and length of the screen
must be determined. These positions are arbitrary. To simplify the
following program, these values are stored in an array (tabs).

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

As you see, implementation in BASIC is easy with this procedure. The


read procedure for the rest of the objects uses similar programming, and
should present no difficulty. If you have problems you should look at
the finished editor in the appendices and on the optional disK.

3.2.3.2 The Output

The output routines display the value of a variable, with a certain


length, on the screen. The simplest case is the output of a character
string that uses the MID$ function to extract the correct section.
SUB putstring(s$,z,s,inplen ) STATIC'll
'TASK :output of a string of a certain length'll
'PARAMETER:=>s$ the string'll
, z line'll
s column'll
inplen Lenght of output window'll
LOCATE z,s 'clear specified range'll
PRINT SPACE$(inplen )'ll
LOCATE z,S 'display the string'll
PRINT MID$(s$,l,inplen )'ll
END SUB'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

CALL putreal (k' (ptr, 2, 0),4,4,8) 'll


E'SE'li
LQC]\TE 3,1'3I
PR.INT HM :1I'lJ
?f:Z:::;\,T HA : "SI

Cl,LL put3real(k! (ptr,l,O),k! (ptr,J.,:),k! (p:.r,1,2),3,4,26)'ll


c:J',L!. put3real(k!(ptr,2,O),k! (ptr,2,1),k' (pcr,2,2),4,4,26)'ll
CA;L put3real(k' (pU,3,O),k' (ptr,J, 1),1<' (ptr,J,2),5,4,26)'ll
IF typ>cc4 THEN'll
IF typ>~20 THEN'll
LOCATiO 6,19;
PET NT !Ie : "il
CALL
putJreal(k' (pt",4,O),i<' (ptr,4,1),k! (ptr,4,2),6,4,26)'ll
IF typ~21 THEN'lI
LOCATE 7,1'l!
PRINT "sw:"'11
LOCATE 7, 13'll
PRINT "ew:"'ll
CALL put real (grad! *k' (()t r, .5, 0) ,7,4,8) 'II
C!,LL putreal(grad'*k! (pc.t,S, 1),7,16,8)'11
END IF'll
FLSE<JI
LOCATE 6,1 'I!
PRINT tl sw : "q{
LOCATE 6,13'l1
PRINT Ilew: nq[
C!\LL putre,,] (gr«d'*k' (ptr,5,O),6,4,8)'ll
CALL putreLl] (grad' *k' (ptr, 5, 1),6,16,8) 'I!
IF typ ,5 lfEN1[
LOCATE 7,191
PR=N'l' " r i: 11~
LOCATE 7,1391
PRINT Hrd: u ll
CALL putr",,] (1<' (ptr,4,n), !,~,8)'lI
CALL putreal (k! (ptr, 4,lj, 7, J 6, 8) 1:
"N[) IF'll
IF'll
END :F'll

SUH91

This procedure is easy, but it must be remembered that the C L S


statement, used for erasing the screen in BASIC, cannot be used in this
program because a section of the screen must remain intact. To delete
this section, every line is overwritten with a certain number of empty
fields stored in empty$. Another critical point is the array typ$ into
which the object names for the individual type numbers are stored. The
array typS is installed as follows:
\.·'iP$ (O)="Plane tl 'arrange by type dilO na::1c'l!
typ$(l}="Triangl,el'~
typS (2) ~"Parallelograrn"'11
typ') { -.-,uCircle"~

':-,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

3.2.3.3 The Graphics

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.

Because there are an infinite set of numbers between 0 and 360, it is


impossible for every angle of the ellipse points to be calculated. For
every circle or ellipSe We approach a Certain number of lines
(maxlines). The larger the number, the more accurately the ellipse
appears, but the more computation time needed. This number should be
chosen later in the program so the user has some control over the
drawing speed. Arcs (partial ellipses) can be calculated as well as
complete ellipses-start and end angles act a'> additional parameters:
SUB drawellipse lax', ay! ,bx' ,by' ,mx' ,my' ,sw! ,ew') STATIC'll
'TASK :draw ellipse in current output window'!!
'PARAHETER:c>ax!,ay',bx!,by' span of ellipse'!!
mx',my! center point of ellipse'll
sW!,ew' the start angle and end angle'll
to be used'll
SHf,RED m~xlines,pi2!~
alpha! "sw' 'I!
numlines~l\BS(sw'-cw')*maxlines/pi2' 'Compute number of lines'll
IF numl ines"O THEN'll
numlines~maxlines 'if sw'=ew', draw full ellipse'!!
beta!=pi2'/maxlines'll
ELSE 'II
beta'=ABS(sw!-ew!)/numlines 'compute increment angle'll
END IF'll
X',ci'!X~*COS(alpha!)+bx'*SIN(alpha!)+mx! 'compute start point'!!
y! =ay! *COS (al phi'! ~ ) +by! *S IN (alpha ~ ) +my ''II

90
ABACUS 3.2 TilE E DITO R

CALL setpoi.nc (x' , y! ) 'Start point output 'h


FOR i=l TO numlines~
alpha'=alpha'+beta! 'compute new angle'll
x!=ax!*COS(alpha!)+bx"S~N(alpha')+mx' 'compul.c cc"w po C"C

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

The beginning of this routine calculates the number of lines. When a


full ellipse is displayed, this number is the maximum; when only a
half ellipse is desired, this number is halved, and so on. Whcn this
number is set, the step value, which increases the angle from the start
value to the end value, can be found. The actual rotation of the vectors
uses both the sine and cosine functions.

For an example of the above three routines, let's develop a display


routine for a cone. This procedure should draw the cone in three
windows then place the numeric output in the fourth window, which is
used for text input and output. The base must be given first and then
four lines drawn from this base to the cone peak. The beginning point
of these lines runs through the base vectors:

SUB drawcone(ptr) STATIC'll


SHARED k' (),pi2!'ll
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)'ll
az'=k' (ptr,2,2)'ll
bx'=k! (ptr,3,O)'ll
by!=k! (ptr,J,l)'ll
bz!=k' (ptr,3,2)'1l
cx!=k! (ptr,4,O)'!]
cy '~k! (ptr, 4,1) 'll
cz'=k! (ptr,4,2)'ll
WINDOW OUTPUT I'll
CALL drawellipse (ax!, ay', bx' ,by' , roc!, my' ,0' ,pi2' ) 'lI
CALL setpoint (ax!+mx! ,ay!+my!)'ll
CALL drawline(cx!+mx!,cy!+my')'ll
CALL drawline(mx'-ax!,my'-ay!) 'IT
CALL setpoint(bx'+mx!,by'+my')'ll
CALL drawline(cx!+mx!,cy!+my!)'ll
CALL drawline (mx! -bx', my! -by!) 91
WINDOW OUTPUT 2'll
CALL drawellipse(ax!,az! bx!,bz:,mx!,mz!,G:,pi2!)
CALL setpoint(ax!+mx',az +mz')'ll
CALL drawline(cx!+rr~!,cz +mz')'ll
CALL drawline(mx:-ax',mz -az!) 91
CALL set point (bx' +mx! , bz +mz') 91
CALL drawline(cx'+rrx',cz +mz')'ll
CALL drawline(mx'-bx',mz -bz') 91
WINDOW OUTPUT 391
CALL drawellipse (ay!, az! by!, bz: ,my', mz! ,0' ,pi2' ) 'lI
CALL setpoint(ay!+my!,az +mz')91
CALL drawline(cy!+my',cz +mz')'lI
CALL drawline(my'-ay',Mz -az!) 'lI
CALL setpoint(by'+my!,bz 'mz')'lI

91
3. THE TRACER PROGRA:\1 AMIGA 3D GRAPHIC PROGRAM:\1ING

CALL drawline (cy! +my I, cz' Tmz! ) 'll


CALL drawEne (my' -by!, mz! -bz!) 'll
WINDOW OUTPUT t,'ll
END SUB'll
'IT

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.

3.2.3.4 Data Operations

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.

Let's begin with deleting elements in our array. We have several


options. The first would be to move all objects that lie to the right of
the one to be erased in array k! one position to the left. This method
can take a large amount of time for very large arrays. Another method
is to give each object a number which states whether it is active or
deleted. Now we can mark the deleted e!emenl, as free. Then when the
program is running the input routine can search for a free spot in array
k! and the new element can be inserted in the free position. How can
our program find the next frcc s{X)t quickly?

There is a simple solution. You create a global variable (k free)


whieh points to a free position. When an object is deleted, the index of
this object is stored in k f r e e. What if an clement was erased
previously? Then this information goes into this free position. You
keep track of this pointer to build a list of free positions of
k! (kfree, .. ,.. ), for example in k! (kfree,O,l). When more objects
are erased while the program is running, a list of the free clement is
built. This is shown in the diagram below:

Figure 3.22

'<free Ele~ents 1,4,5 and 7 are free

92
ABACUS 3.2 THE EDITOR

This task, building a list of the free elements, is taken on by the


following procedure, which clears the non-zero elements because these
have a special meaning as initializing elements:
SUB deleter(ptr) STATIC~
'TASK :delete one body~
'PARAMETER:~>ptr points to the bodyTt
SHARED k' () ,kfreeTt
IF ptr><O THEN 'not the starting element~
FOR i~O TO 5 'Delete~
FOR j~O TO 2~
k! (pt r, i, j) ~O~
NEXT j~
NEXT i ~
k! (ptr,O,O)~-l 'Add body to free list~
k' (ptr, 0, 1) ~kfree~
kfree~ptr~
CALL lefts(ptr)~
END IF 'll
END SUB~

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.

To copy an element in the array, we need a pointer to a free memory


area, and then we write data from one element to another, value for
value:
SUB copy (ptr) STATIC~
'TASK :copy one body~
'PARAMETER:~>ptr points to the body~
SHARED k' () 'll
IF ptr><O THEN 'not the starting element'll
old~ptr 'save pointer'll
CALL newelem(ptr) 'create new space'll
FOR i=O TO 5 'copy'll
FOR j=O TO 2~
k! (ptr,i,j)4' (old,i,j)~
NEXT j~
NEXT i'll
END IF'll

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!

Now we want to describe data manipulation and the enlarging, moving


and rotation of a shape.

When the individual coordinates of a vector are multiplied by the same


constant, the named vector is increased by this factor. When the
coordinates are multiplied by different factors, the vector is unevenly
stretched in the three basic directions, an effect that we shall add to our
program.

To move our shape we must move its reference point. The new
reference point can be entered either with the keyboard or the mouse.

It is more complicated with the rotation. The reference point stays in


place and the difference vectors are changed. These vectors are rotated
around three angles in the room according to the following formula:

94
ABACUS 3.2 THE EDITOR

(X, y, z) is the original vector

(alpha,beta,gamma) are the three angles around which the


vector should be rotated

(X, Y , Z) is the rotation vector given with the three


help variables

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

With a few changes this procedure handles enlargement and movements:

1.) Eliminate the conversion from the different angle systems

2.) get3real is called in mode -1 for the movement, the check is


made to see if k! Cpt r,O ,0»=2 0 and the FOR loops are set
with:

k I (ptr, 1,0) =vx'


k! (ptr,l,l)=vy'
k! (ptr,1,2)=vz!

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.

3.2.3.5 Disk Operations

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

SUB lc)adlist STATIC~


'TASK :Load list 'll
SHAK~:) k' (), knum, pt.!:, ;egchar$, File$'ll
WINDOW '),"Load ['st", (O,129)-(314,150),O,1'll
PRINT "NdIT"" "91
CALL getst.rinqWile$," ",legchar$,1,6,IO)'ll
1~ Filc$><"" THEN'll
OPEN File$+" .list" 1"0',
INPUT II,quantity'll
vJHI LE NOT (EOF (1 ) ) 'l!
CALL newelem(ptr)'l!
FOR i~O TO SI
INPUT #l,k ' (ptr,i ,0), k' (ptr, j, 1), k I (ptr,i,2)'IT
NEXT i'll
V[1"ND 'IT
CLOSE ~91
END IF9[
WIND(Y"; CLOSE 5'
WINDO~"J OUTPUT 4S]
CALL cc"Clwelem(ntr)S
END SUE'IT
'l!

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:

< ;,E NOT FOUND

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

3.2.3.6 Mouse and Gadgets

Before we examine the gadgets that will be used in our program, we


want to show you the mouse check routine we talked about earlier. Our
mouse check routine executes by pressing the left mouse button and
reading the coordinates of the mouse position. This should only happen
when the chosen window is a projection window. It should not happen
for our input and output window. In another case MOUSE(3) and
MOUSE(4) che(~k the X or Y coordinates of the mouse position. These
coordinates represent the screen coordinates and not the room
coordinates which interest us. You must also calculate if section,
enlargement factor, and X correction factor should be considered. To
mark the position clicked on, the program draws a small cross OIl the
screen. Then the mouse coordinates arc read:
I*~**~*~***********~

I*"/(" KEAD ~·~O::';SE **S


f~*****************~

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 ~
~

This subroutine is incorporated into our program with ON MOUSE


GOSUB click.

If you have carefully examined the subroutine, the call from


checkgadget should attract your attention. This is where we
implement the gadgets. We have chosen the following route:

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[

As an example for using this procedure we want to present two routines


from the editor. Five real values must be read into this editor (a red
value, green value and blue value, a value that tests for the brightness
in the shadows and a reflection factor). All of these values must be
between zero and one. Because a color should be established using the
red, green, and blues values, it is very helpful if the user can see this
color on the screen, which is built using the PALETTE 2, .. , .. , ..
instruction. The routine to indicate a material clement is here also (the
opposite of showelem):
SUB show",at (matpL r) STATIC'lI
'TASK :See corresponding routine for the body list 'lI
SHARED mat' () ,n:l%,nr2%,nr3%,nr4%,nr5%,nr6%'!!
CLS'JI
PRINT "Material:"'lI
CALL plltreal(matptr'l: ,1,10,10)'1[
=1" matptr ><0 THEN'I[
LOCATE 1,20'lI
PRINT "R+G+B="'lI
PALETTE 2,mat! (matptr,O),mal' (matptr,l),mat' (matptr,2)'!!
LINE (250,0)-(260,7) ,2,bf'jj
?RINT "Red :"'lI
PRINT 'lI
PRINT "Green : 119I
PRINT 'JI
PJUNT "Blue :"'11

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

mat! (m,-,tpl r, 3) ~gadqe:% (nr4%, 4) /lOn


mat.! (re.alper, 4) ~g"dget% (nrS%, 4) /lUl'll
CALL deleLegadget(nr1%)'ll
CALL deletegadget(nr2%1'll
CALL de'etegadget (c,3%)'
CALL deletegadget(nr~%)S
CALL de:~tegadget(nrS%I'iI
CALI. deletegadqet(nr6%)'II
END SUB 'II

This was the la'>t important routine for creating our ray tracer editor.

3.2.4 Tips on Writing an Editor

What we have presented so far is a collection of procedures. To get a


complete program, additional functions must be inserted. One problem,
for example, is how these functions should be accessed by the user.

102
An,\CLS 3.2 THE EDITOR

Should there be individual commands that only run in the material


editor, reconstruct the screen, or move the section? So that the user is
spared a lot of unnecessary typing, it may be better to have all
functions in a menu and combine this so some important functions can
be activated by pressing a key. The important procedures for this arc
very easy and are basically a row of IF statements.

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.

It is useful to be able to change from the actual object element to any


other. The show function displays the object in the projection
windows (that means with another color). This is so you don't lose the
overview of the picture with large data sections.

It is also important to be able to leave the program without having to


execute a reset. A Quit procedure which checks if the user would
actually like to quit the program is needed, perhaps using a requester.

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

3.3 The Main Program

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.

The complete listing of the tracer program IS In Appendix B. 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. Formatting the program listings to fit into this
book has caused some long BASIC lines to be split into two lines. To
show where a BASIC line is actually encIed a ~ will appear. This
character only shows when the <Return> key should be pressed in the
BASIC editor. For example, the following line is split into two lines
in this book, but must be entered as one line in AmigaBASIC:

WinDef NWindow, 100, 50, 460, 150, 32+641512&, 15&+4096&,


0&, Title$'lf

The ~ shows the actual end of the BASIC line.

3.3.1 The Remaining Tracer Routines

Now we come to the routines that are important to the completion to


our main ray tracing program.

First we want to describe the Rasterlni t routine. The user and


display screens are constructed in this routine. All input takes place on
the user screen. The wire model and shadowed picture appear on the
display screen. The tracer program functions in all screen modes, and
works in either user mode (with 60/80 characters per line):
Rasterlnit:'lf
, Sel ect resolution ar.d displ ay mode 11
WINDOW CLOSE 2 ' delete any windows and'lf
SCREEN CLOSE 1 ' screens 'ii

WINDOW 1,1111, (O,O)-(6~31,185),6 'ne".' ....'_indo ...., v.'i'=-n St2~us-lineS


'If
'PALETTE 0,0,0,0 I Colour for user screen~
'PALETTE 1,1,:,1 'IT
'PALETTE 2, .4, .4,1'lf

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)~

DisplayM$ (0) n Normal nen


DisplayM$ (1) " Hold and Modify"'ll
DisplayM$ (2) " Extra Hillfbrite"~
~
XResl$ (0) 11 Normalllqr
XResl$ (1) " HIRES "~
~
YResl $ (0) " Normal ,,~
YResl$(l) "Interlaced"~
~
x (0) " O:x (1) ~ O:x (2) ~ O:x (3) ~ 4'll
, Which values or strings at which position ?~
~
y ~ O~
, topmost line Start line~
~
Modulo (0) 3'ji
Modulo (1) 2'll
Modulo (2) 2'll
Modulo(3) 6'I1
I How many values for each select jon line ?~
'II
COLOR l~

Colours (0) 1 '!l


Colours (1) 2 'II
Colours (2) 2~
Colours (3) 2~
, First line ~> white rest of the lines => blue~
'lI
Outg:~
LOCATE 10,21'lI
COLOR Colours(O)~
PRINT "Display mode ";DisplayM$(x(O))~
LOCATE 12, n ~
COLOR Colo~'rs (1) 'lI
PRINT "X-Resolution ";XResl$(x(l))~
LOCATE 14,21'lI
COLOR Colnurs(2)~
PRINT "Y-Resolution ";YResl$(x(2))~
LOCATE 16,24~
COLOR Colours(3)~
PRINT "BitPlanes: ";x(3)+l~
~
Waiter: a$ = INKEY$~
IF a$ THEN Waiter'li
'lI
IF as CHR$(30) THEN x(y) (x(y)+1) MOD Modulo(y)~
IF as = CHR$(31) THEN x(y) = x(y)-l ~
, CRSR I~ft/Rjqht'll

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

CALL Printlt ("Insufficent memory for bitmap


" ''',lOO,False)'ll
CALL PrintIt ("Please try a lower resoluiton or: number of
bitmaps '!!",130,False)'11
'll
CALL DialogBox("Ok",1,True,xlb%,ylb%,x2b%,y2b%,False)'ll
CALL DoDialog(n%,1,-1,-1,-1,-1,x1b%,y1b%,x2b%,y?b%,-1,-1,-
1, -1) 'll
CLS'II
GO TO Outg'll
END IF'll
'II
SCREEN 1,RasterW%,RasterH%,RasterT%,x(1)+(x(2)*2) >I'll
Width ,Height ,Depth, Mode'll
'II
WINDOW 2,"", (0,0) - (RasterW%-9, RasterH%-15) , 0, 1 'II
, Window layer'll
'll
RasterT% ~ x(3)+l'll
I old RasterT value'll
'II
WBase& ~ WINDOW(7)9c
WScreen& ~ PEEKL(WBase&+46)'11
, Extract address of the new screen from window addrress'll
'lI
POKEL WBilse&+24,&H100 OF &H800 O!{ 6~S36&'11
I Window F~ags chanCje: Borderless, RBMTrap, NoCareRefresfl'lI
'll
Viewport& PEEKL(WBase&+46) +44'11
ColorMap& PEEKL(Viewport&+4)'ll
RastPort& Viewport&+40'll
BitMap& ~ WScreen&+l84'l[
'll
Adr ~ PEEKL(RastPort&+4)+8 I BitPlanes for loading'll
FOR i~O TO RaslerT%-l I and saving'll
BitPlanes&(i) ~ PEEKL(Adr+4*i)'ll
NEXT i'll
'lI
BitPlane6& BitMap&+28'll
, Where do you want the sixth bitplane address plilced ?'ll
'll
Dcpth& ~ BitMilp&+59c
, Where do you want the new depth placed "'II
'II
CALL SetRast&(RastPort&,O)'II
CALL SetRGB4&(Viewport&,l,IS,lS,lS)'11
CALL SetRGB4&(Viewport&,O,0,O,0)'11
I Clear new screen and set backgL)c:nd 'II

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

WHILE MOUSE (G) = G'll


WEND'll
'II
x = MOUSE (1)'l[
Y MOUSE (2) 'l[
'l[
IF (x < 2G) OR (x > RasterW%-20) THEN'll
GOTO LoopA:'ll
END IF 'II
IF (y < 1) OR (y > RasterH%/lG) THEN'll
GOTO LoopA:'l[
END IF'll

Colr% = INT «x-20) /Widthe) • which colors was clicked'll


CALL Scroff'll
Ied=INT(Colour(Colr%+l,l)*15.5)'ll
green=INT(Colour(Colr%+1,2)*15.5)'ll
blue=INT(Colour(Colr%+l,3)*15.5)'ll
'll
LOCATE 10,1'll
PRINT" red-component (G • • 15) : ";'l[
CALL FormInputInt (red,3G!,G!,15!)'ll
'II
LOCATE 11,1'll
PRINT" green-component (G • • 15) : ";'ll
CALL FormInputInt (green,3G',G',15!)'ll
'l[
LOCATE 12,1'll
PRINT" blue-component (G • • 15) : ";'ll
CALL FormInpu~Int (blue,3G!,O',15')'ll
~l
Colour(Colr%f",l)=red/1S'll
Colour(Colr%+l,2) -green/IS'll
Colour (Colr%+I,3)-blue/1s'll
'II
POKEW OSColour&+Colr%*8+2,red!ls*lG24'll
POKEW OSColour&+Colr%*8+4,green/15*IG24'l[
POKEW OSColour&+Colr%*8+6,blue/1s*lG24'll
\1
IF MaxColour%=64 THEN 'ExtraHalfBrite'll
Colour(Colr%+33,l)=(red\2) /1 5 'II
Colour(Colr%+33,2)=(green\2)/lS'Il
Colour(Colr%+33,3)=(blue\2)/ls'll

POKEW OSColour&+Colr%*8+2s8, (red\2) /1s*I024'll


POKEW OSColour&+Colr%*8+26G, (green\2) /15*1024'!1
POKEW 05Colour&+Col r%*8+262, (bl uo\2) I1S*1024'!1
li
ENu IF'll
'll
CALL
SetRGB4& (Viewport&,Colr%,CINT(red),CINT(green),CINT(blue»'ll
'll
CALL DialogBox ("End",O,True,x1a%,yla%,x2a%,y2a%,False)'l[
CALL DialogBox ("Next
color",2,False,x!b%,y1b%,x2b%,y2b%,False)'Il

lIO
ABACUS 3.3 THE MAIN PROGRAM

CALL DoDialog (n%,O,xla%,yla%,x2a%,y2a%,-1,-1,-1,-


1,xlb%,ylb%,x2b%,y2b%)~
CLS'lI
'II
IF n% ~ 2 THEN 'lI
CALL Scron'll
GOTO LoopA'lI
END IF'll
Newone! ~ True~
Hg = False~
GOSUB MakeMenu'l[
RETURN'I[
"I[

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

Status$ = " Status: Object Saver"+CHR$(O)'lI


CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'lI
'I[
LOCATE 3, I'll
PRINT" Under what name do you want the object saved?"'lI
PRINT 'lI
PRINT " Filename: ";'lI
00$ = 1111~

CALL FormInputString (dn$, 30!) '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

CALL SetWindow~,-'itJ.es& C\\\~asc&, SADD (Str1~usS), 0) qr

LOCATE 3,1'i:
PRINT" Which ob'~ecL would yO'-.J :i ke to ~.e~q«;]1
PRINT'll
dnS = 1111 ~:

PRINT " Filename : II; I}T


CA~L Fo:-:-ml:lpulStri ng (dn$, 3C ~ ) ~;

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]

IF x<num THEN num x'li


IF MaxNumber-NumberK<num THEN num
'Ii
lr num>..,...1 THEN'1I
FOR TO NumberK+num'll
n%~NumberKtl
TO 5'll
FO,( p%=Q
INPUT #1,K(n%,p%,O),K(n%,p%,1),K(n%,p%,21'1i
NEXT p%'ll
N;::XT n%S
NumberK = NumberK+num'll
Newone! ~ True'll
Start% = I'll
END IF'fc
CLOSE #I'll
END Ir'll
END IF'll
CLS'l[
GOSUll MakeMenu'll
RETURNS
"iT

When merging objects, array K ( ) , where the objects are stored


internally, must be large enough to accommodate these obj'.3cts. The
number of array elements is set in A r ray In it. Any object
definitions stored previously here arc lost:
T\rrayInit: qr
, Create new array K() 'll
S~atus$ ::- " Status: New array cr'c2'-_on +CllR$ (0) q[ ll

CALL SetWindowTitles& (W"BaSe&,SADD(Status$), )<IT


91
GOSUB DeleteMenu'
'll
LOCATE lO,j'!j
PRlNT " Maxl~um ~1~~o>r of objects U;S
a = MaxNurnbec-'ll

1 13
3. TIlE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMIl'iG

CA~L Formlnputlnt (a,3C:,O!,lOOO:)T


'lI
IF MaxNumber <> a THEN'll
MaxNurrber ~ a'll
NUfl'berK"
ERASE l<'ll
DIM K(MaxNumber,5,2)'lI
Start% ~ O'll
END IF'll

CLS'II
GOSUB Ma%eMenu'II
RETURN'll
''ll
IS

In addition to object definitions, you can also load new material


constants created in the editor from disk into the tracer:

'"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

Status$ "Status: Screer. save:-"+CHR$ (0) 'l[


CALL SetWindcwTitles&(NWBase&,SADD(Status$) ,C)~

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

BODYSize& (Faste rW%/ 8) *Raste rH%* Ra slerT%'ll


, FORMsize& = Chunk-Length + 8 Bytes per Ch'~nK-Headcr +
Bytes ("ILBM")'ll
FORMSize& = BMHDSize&+CMAPSize&+CAMGSize&+13CDYSi 20&+36':
'll
, FORM-Header 'll
ChunkS = "FORM"'ll
Length& = xWrite& (Handle&,SADD (Chunk$) ,4)'ll

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) ,

FOR i%=O TU MaxColour%-l'II


Colours% = GetRGB4%(ColorMap&,i%)'II
bl~e = Colours% AND 15~
Colours% = Colours% - blue'II
green = (Colours%/16) AND 15'11
Colours% = Colours%-green*16~
red = (Colours%/256) AND 15'11
POKE(ColorBuffer&+(i%*3)) ,red*16~
POKE(ColorBuffer&+(i%*3)+1),green*16 'II
POKE (ColorBuffer&+ (i%*3)+2),blue*16'II
NEXT'II
'II
Length& = xWri te& (Handle&, ColorB'Jffer&, CMAPSi ze&) ~
'll
IF Leng~h& <.:- 0 THENq[
DialogS ~ "Write error on CMAP-Chunk I " "q'
GOTO EndSilVe'll
END IF 'll

, 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,,\\

IF Length& <= 0 THEN'll


Dialog$ = "Write error on CAMG-Crn'::iK !!! ncr;
GOTO EndSave'll
END IF :J
'll
, BODY-Chunk (BitMaps)'I!
Chu",kS = "BODY"'ll
Length& ~ xWrite&(Hand~e&,SADD(Ch"nkS),1)']l
Length& = xWrite& (Handle&,VARPTR(BODYSize&) ,4)'11
BytesPerRow% = RasterW%/8'11
FOR y1 = 0 TO RasterH%-l'll
FOR b=O TO RaslerT%-l'l!
Adress& = BitPlanes& (b)+ (yl*BytesPerRow%)'ll
Length& - xWrite& (Handle&,Adress&,BytesPerRow%) '!i
IF Length& <= 0 THEN'I!
Dialog$ = "Write error on BODY-Chunk!! '"'II
GOTO EndSave'll
END IF 'II
NEXT'll
NEXT'll
'II
DialogS "Saving OK"'11
'll
EndSdve:'ll
IF Handle& <> 0 THEN CALL xClose&(Handle&)~
IF Buffer& <> 0 THEN CALL FreeMem& (Buffer&,BufferSize&) 'TI
CALL DialogBox (Dial og$, 1, True, xlb%, ylb%, x2b%, y2b%, Fal se) 9!
CALL DoDialog(n%, 1, -1, -1, -1, -1,x1b%,y1b%,x2b%,y2b%, --1, -1,-
1, -1) 'll
END IF'll
CLS 'll
GOSUB MakeMenu'll
RETURN'll
''ll

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.

We also thought about printed output. The following hardcopy routine


sends the graphic on a printer. It uses the printer driver that was chosen
from Preferences:
HardCopy: 'II
Status$ = " Status: Screen hardcopy"tCHR$(O)'ll
CALL SetWindowTi tles& (NWBase&, SAUD (Status$) ,0) ~[
'll
GOSUB DeleteMenu~
'll
CALL Di~logBox(I'No Printer",O,True,x~a%,yla%,x2d%,y2d%,False)

CALL DialogBox ("Printer


OK",2,False,x1c%,ylc%,x2c%,y2c%,Falsc)'i
CA:.c. Dolli a: og (n%, 0, xl a%, yla%, x2a%, Y22%, -: ,-1, _.j , -
1,xlc%,ylc%,x2c%,y2c%) 'II
C'SS
IF n% <> 0 THEN'll
Modes% PEEKW(Viewport& + 32)'ll
'II

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 ~

We included a routine to create a new background for the picture created


by the tracer routine. This can give more realism to the picture than the
usual background color does. This is done using the routines
Background, Sky, Fhg (floating colors) and ScreenLoader.

These routines allow you to choose between a simple pattern, a starry


sky, a floating background that consists of a color and brightness
change between colors, or an IFF picture that was created with a
drawing program.

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 •

ChLL PrintIt(IIBackground = t'attc;n",'~~:,F'a,_.s(')r;_

'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

LOCATE 11,1 'lI


PRINT " Foregcound pc" (APen) : "; 'll
a"APer'%'11
Cl\~_l, Formlnputlnt (a,30~,O!/CS~~G(Ma.xCo our%-l))
'\?An% = a)I

: .C>::1\"'E ]).1 'IT


PRINT" Background pen (3P,'') : "; 'll
a dPen%<JI
ClUJ, FormInput Int (cl_, 3D!, O! I CSN'_~ (t'-ldy.Col (1- ~)) 9l
BPerc% =' a'll

Xpattern% = Xpattcrn% MOD


(NumberPatternS% +NumberPat. lernX%' 2+ 1) 'II
'II
IF Xpattern% > N~mberPiltteI'nS% THEN'll
CALL
Extend(~dFil 1 {O, 0, Ras:.:.erWl %, RasLe r-HI %, Pat ternHX (Xpat Le rn %-
NumbecPatte-:-'i1S%), 0:, -1!, AI'Ien%, HFen%) q(
ELSE'll
CALL

Xpallcc~.'i,),l\Pen%.8Pen%) 91
[Fen

fif) Truc9I
i·:ND
"
iF n% = 1 THf'NSI
LOCATE J ,1 ~
PRINT Sky type: "'II
II

PRINT" 0 Stars (srat. t.", n,d) "'l!


PRINT " Strlrs (centered) "'l!
PRINT " 2 ;_,i nes (seilt te red) "'II
PHI NT " 3 :--,i nes (centered) "'II
PRINT " - Lines (midd] " centered)" 'II
'II
: ,CJC,',,;"E 10, 1 'll
FRiNT "Type : ";'II
,1 :\rt%ll
en.!. FormlnputInt (a.30!,O:,~')'i:
An ~ a'IT

l,OCA';'E 11, 1 'll


Pi~~1 II Color : 1f;<JI
a ~ 1 'l!
CALL FormInputTnt (a, 30' ,0' ,CS>JG (MaxColour%-]) ) 'l!

120
ABAClJS 3.3 TilE MAIN PROGRA;\I

HCol r'i; = a'll


'll
LOCATE l2,1'll
PRINT " Number : "; 'll
a = 100'll
CALL Formlnputlnt (a,30',0!,SOO!)'ll
num% = a'll

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

SUB Fhg(Colours1%,Colours2%) STATIC'll


SHARED RasterW1%, RaslerHl %, Colour () ,MaxColour%, WSereen&1,
SHARED NWBase&,RastPort&,OSSetPoint&,OSModus&,OSMilxColou;c&'ll
, Produce floating passage between Colours1 ilnd ColouLs 'II
CALL SeLon'II
'll
Led.s=Colour(Coloursl%+l,l)'ll
green.s=Colour(Coloursl%+1.2)'ll
blue.s=Colour(Coloursl%+1.3)'ll
red.e=Colour(Colours2%+1.1)'ll
green.e=Colour(Colours2%+1,2)'l!
blue.e=Colour(Colours2%+1,3)'l!
'II
IF (PEEKW(OSModus&) AND &H800) = &H888 Te:EN 'HAM'll
'll
'Background limited to 16 Colors, or else Objects disturbed.'ll
'lI
POKEW OSMaxColour&.16'll
fOR y%=O TO RasterHl%S
red=red.s+ (y%/RasterHl%) * (red.e-red.s)'ll
green=green.s+(y%/RasterHl%)* (green.e-green.s)'lI
blue=blue. s+ (y%/RasterHl%) * (blue.e-blue.sl'lI
CALL Set Point (0. y%. RasterWl%. y%. red, green, bJ 'lei 'lI

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

ChunkS ChunkS + CHR$(PEEK(InputBuffer&+n%))'ll


NEXT'll

IF ChunkS <> "ILBM" THEN 'll


Dialog$ = "Not IFF-Format! !!"'ll
GOTO EndLoad'll
END IF'll

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

IFF-Picture adapted to Display-Screen ?'ll


IF (RWidth% <> RasterW%) OR (RHeight% <> RasterH%) THEN'll
Dialog$ = "Format error: "+STR$(RWidth%)+"
x"+STR$(RHeight%)'ll
GOTO EndLoad'll
END IF'll
'll
ELSE IF ChunkS = "CMAP" THEN • Color-Palette'll
Length& = xRead&(Handle&,ColorBuffer&,Chunkwinlen&)'ll
CMAP = True'll
• Color-Palette set up'll
FOR n% = 0 TO RMaxColors% - I'll
red% PEEK(ColorBuffer&+(n%*3))/16'll
green% PEEK (ColorBuffer&+ (n%*3)+1)/16'll
blue% PEEK (ColorBuffer&+ (n%*3) +2)/16'll
dummy = SetRGB4(Viewport&,n%,red%,green%,blue%)'ll
'll
POKEW OSColour&+n%*S+2,red%/15*1024'll
POKEW OSColour&+n%*S+4,green%/15*1024'll
POKEW OSColour&+n%*S+6,blue%/15*1024'll
NEXT'll

ELSEIF ChunkS "BODY" THEN 'BitMap Loader'll


CALL Scron'll
Body = True'll
IF Compression% = 0 THEN 'No compression'll
FOR yl = 0 TO RHeight% -I'll
FOR b = 0 TO RDepth% -I'll
IF b<RasterT% THEN'll
Adress& = BitPlanes& (b)+(yI*BytesPerRow%)'ll
ELSE'll
Adress& = Buffer&'ll
END IF'll
Length& xRead&(Handle&,Adress&,BytesPerRow%) 'll
NEXT'll
NEXT'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

CALL PrintIt("JD - CAD",60,False)'ll


CALL Printlt("Original-Version: Peter Schulz (c)
1986",75,False)'ll
CALL Print It ("Amiga-Version: Bruno Jennrich (c)
1987",90,False)'ll
'lI
a$ ~ "Maximum number of objects "+STR$(MaxNumber)'ll
CALL PrintIt(a$,10S,False)'lI
'lI
a$ ~ "Actual number of objects "+STR$ (NumberK) 'll
CALL Print It (a$,120,False)'lI
'II
GOSUB Pause'll
'lI
CLS'lI
GOSUB MakeMenu'lI
RETURN'll
''ll
Help:'ll
, Which key press for which action'll
Status$ ~ " Status: Help"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'lI
'll
GOSUB DeleteMenu'll
'lI
LOCATE 2,1'll
'lI
PRINT" Projections point"'ll
PRINT" H Main point"'11
'll
PRINT " W enter angle"'ll

126
AIIA CUS 3.3 TilE MAI N PR O GRA:'>l

PR! N'[ I' Cur s o r keys => ro t ate l' ~


?P.IN~~ " H eta te (Sl~IFT , CO?-JTROi.. ) II ~

PRI NT II D: spa c inq fo r main po i nt " ~


PRINT " -1- 1_ 1* \ / Fnla rge/r edt..:ce s pac'~ ng (SHIF T +l -) tl
91

PRI NT II \/ En .l.a r."genqr

PRIN T 11 Load Obj ect ll <!!


PR I. NT " S 3 VE: Ob j ect. 11 l1

PRINT ' I M er ge Gb ject " ~


PRINT New , clear all objects " 91
II

PRl r,r : .. B Screen sdve r" q!


PRINT II Q => Prog;'a m end (Quit ) 11 en

PRINT " r'9 =' > ~: ; : d do ws :r:itia.liza tion " <TI


PP. .LNj.' II F J 0 -c::.> Sha dc,ws 1I ~1
PRI NT ,. <SPACE> : .) Show pic tur"e " 91
PRIN T ,. C lear scrpen" ; ~

GOS UB Pa~lse C{!


C:LS'lj
C;OSUB t1akeMenu'll
RETURNS!
'<JI

Nexl is the routine used for enlargemenl or magn ification of the screen
image:

II St.atus : Erd arge s cree n ~;egmen t " +CHRS ( 0) 91


CAL:. Se~ , v.Li. nd()wTi I I e.s & ( N\-J8a se & , S ADD ( S lat us$) , J ) q[

'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

PHT NT ::,nl ar1'~>'1"1c~ nt Factor:


II " ;q[
d=.l ("j;
CA I_ l Po r mlnput (~ , 3Q ~ , . 1 , lOC! ) ~
1:
CLS '"
Pi~tl;:- ewidt h = a* Fact o~X~
Pic t u rehe i g~ t=a* F d c to rY ~
?icture x=Rasl erW 2%/Picturewidth,
Pict. ur 2 y ~Ras L erH7%/ Pictu~ eh c iqht ~
'OJ.S C'l1
Wa it Flq! = Fa15e~
GO~~~}[-3 !)raw~;'?~'1i
CALI.. Rubber-box (S x %, Sy%,1'l idt.he %, He i ghte% , t .l1 se ) ql
rictlJ : ewiJ tt1 - · Ra~~c ~ W % ! Wj d th e % * Fa c torX~

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~

pic t u re X and Pic t u re Y are recalculated for every enlargement


(either proportional or distorted).

Menu control of programs is the norm for Amiga applications. Almost


every program in existence uses menus, so ours will too. This routine
constructs and reads menus:
MakeMenu:'Il
Status$ ~ " St.at.us: B'Ji Iding mer:c"'C!IR$ (D)~
CALL SetWindowTitles&(~~8ase&,SADD(Slat.us$) ,O)'Il
'l!
t"';ENU I, 0, I, II Amiga"r::
MENU 1,1,1," 3D-Ca(i-'~-:lfo 1"9
'll
V£NU 2,O,l,"File"q[
MENU 2,1,1, " LOrlO L"'Il
MENU 2,2,St.art.%, " Save S"'Il
MENU 2,3,1, " Merge M"'ll
MENU 2,4,1, " New N"~
11 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 1 '
V~~NU 2,5,0,
MENU 2,6,1, .. Load mat.erial "'Ii
MENU 2,7,0, II _ _ _ _ _ _ -----------"~

r-rlENU 2,8,St.art%, II Background !lqj


MENU ?,9,Start.%, II Sa.ve screen P"9I
MENU 2,10, St.art%, fI Hardcopy "9}
~·1ENU L') , '1 "
J..1.., V, "-----------------"'iI
MENU 2,12,St.art%, " Color pajct~c; C"~
MENU 2,13,0, 1I-------------.~--_II9I

MENU 2,14, I, " Program end Q"~


91
MENU 3,0,1, "Editor"~
MENU 3,1,1, .. Load Editor
~
MENU 4,O,Start%,"Parameter"~
MENU 4,l,Start%, " Projection point P"~
MENU 4,2, Start %, " Main point H"~
MENU 4,3,Start.%, .. a, , c J\"<f[
MENU 4,4,Start%, " Distance D"'ll
MENU 4,5,0, "--------------------"'ll
MENC 4,6, Start%, " Enlarge V"'ll
MENU 4,7,Start%, Number corner
II E"<J.I

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 <> 0 THENo/,

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).

In addition to menu control, the program can accept keyboard shortcIIL".


Most menu items list these shortcuts in the right margin of the menu
list. Because some functions can only be executed from the keyboard,
we list the important shortcuts in the Help routine. You can access
this routine by either pressing the <Hclp> kcy or the <?> key, Here is
U1C rouline which checks for a keypress:

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

IF KeyS Ok KeyS ~ II!'. ~JR ~cy$

'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

~:PH ~)rH +- lJlj1


GOSl,'3 J;titia}q
f~e . . .'onc' = True9I
Wact-i":q' ~ True'll
GOSUH DrawNew<JI
END IF'll

IF KeyS ~ IIV" THEN GOSUB En} argement,'Il


[F KeyS "pI! ~~EN GOSUH ~r.p~~Fqr
~ 1·' Key$ "hit ~'l-lE:J L:;O::;U~~ nputll<{I
It, r:ey$ "a II TrF:N GO,~l~;E In:,)' . ·,Jl.:".g~ eS;
F' Y(~yS GriST;? H l\;,rA J : "'eY-
~

-- "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

IF (Key$ = CHR$(28)) OR (Key$ = CHR$(29)) OR (Key$


CHR$(30)) OR (Key$ = CHR$(3l)) THENi
IF Key$ = CHR$(28) THENi
Beta = Beta + Pi/lSi
END IF i
IF Key$ = CHR$(29) THENi
Beta = Beta - Pi/lSi
END IF i
IF Key$ = CHR$(30) THENi
Alpha = Alpha + Pi/lSi
END IF i
IF Key$ = CHR$(3l) THENi
Alpha = Alpha - Pi/lSi
END IFi
GOSUB Ini tiaU
Newone! = Truei
WaitFlg! = Truei
GOSUB DrawNewi
END IFi
i
IF (Key$ = CHR$(18)) OR (Key$ = "R") THENi
IF Key$ = CHR$(18) THEN 'ARi
Gamma = Gamma + Pi/lSi
END IF i
IF Key$ = "R" THEN'l[
Gamma = Gamma - Pi/lSi
END IF'l[
GOSUB Initial'l[
Newone! = Truei
WaitFlg! = True'l[
GOSUB DrawNew'l[
END IF 'l[
END IF'l[
IF Key$ "rn" THEN GOSUB Merger'l[
IF Key$ "n" THEN GOSUB ArrayInit 'l[
IF Key$ "1" THEN GOSUB Loader 'l[
IF Key$ "?" OR KeyS = CHR$(139) THEN GOSUB Help'l[
IF Key$ "q" THEN Quit'l
IF Key$ = "i" THEN GOSUB Info'l[
i
IF Key$ = CHR$(l) THEN GOSUB LoadEditor'l[
END IF 'l[
RETURN'l[
''l[

No operations are performed when the program is waiting for user


input, or when it isn't executing any shadow calculations. This is
known as NOP (No Operation) status. This status appears in the top
window line through the NOOP routine:
NOOP: 'l[
Status$ = " Status: NOP"+CHR$(O)'l[
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'l[
RETURN'l[
''l[

The following routines allow the creation and control of requesters.


These are contained in DialogBox, which draws the requester, and
DoDialog, which waits for you to select a requester gadget:

131
3. THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

SUB DialogBox(Dialog$,Position%,Ret,x1%,y1%,x2%,y2%,Scr) STATIC~


SHARED RastPort&,NRastPort&,True,RasterW1%,RasterW2%~
, Create your ownrequ requester~
, Dialog$ = Text in Dialog Box~
, Position% 'II
o right'll
1 center'll
2 left'll
'Ret% can you press <Return>?~
True = Yes'll
False = No~
, x1%,y1%,x2%,y1% = Size of 'click'-Field (word returned)'11
Scr = In which screen output ?~
True = Display-Screen'll
False = User-Screen'll
'II
IF Scr = True THEN~
rp& = RastPort&'11
Middle& = RasterW2%~
SEnd& = RasterW1%'11
, Write to Display-Screen'll
ELSE'll
rp& = NRastPort&'11
Middle& = 320'11
SEnd& = 640'11
, RastPort des Basic Windows~
END IF'll
'II
y1% 150'11
y2% 150 + 6 + 10'11
'II
Length& = TextLength&(rp&,SADD(Dialog$),LEN(Dialog$))'11
'II
IF Position% = 0 THEN'll
xl% = 70'11
x2% = xl% + Length& + 20'11
END IF'll
'II
IF Position% = 1 THEN'll
x1% = Middle&-Length&/2-10'll
x2% = Middle&+Length&/2+10~
END IF'll
'II
IF Position% = 2 THEN 'II
xl% SEnd&-70-20-10-Length&~
x2% = SEnd&-70-10'll
END IF'll
~
CALL Move&(rp&,x1%+10,y1%+10)~
CALL Text&(rp&,SADD(Dialog$),LEN(Dialog$)) 'II
'II
IF Scr = True THEN'll
CALL Box(rp&,x1%,y1%,x2%,y2%)'11
CALL Box(rp&,x1%-4,y1%-2,x2%+4,y2%+2)'II
IF Ret = True THEN CALL Box (rp&,x1%-2,y1%-1,x2%+2,y2%+1)'11
ELSE'll
LINE (x1%,y1%)-(x2%,y2%)"b~
LINE (x1%-2,y1%-2)-(x2%+2,y2%+2)"b'll
IF Ret = True THEN LINE (x1%-1,y1%-1)-(x2%+1,y2%+1)"b'll
END IF'll
END SUB'll
''II

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 P dnt I t routine displays centered text:


SUB PrintIt (OUt$,y%, Scr) STATIC'll
SHARED RastPort&,NRastPort&,RasterW2%,True,Length&'ll
I Centered text output on one of the two screens 'll
I OutS: Printed string'll
I y%: verticle Position ?'ll
I Scr: User or Display Screen?'ll
IF Scr = True THEN'll
rp& = RastPort&~
Middle& = RasterW2%'ll
I write to new (Display) Screen'll
ELSE~
rp& = NRastPort&'ll
Middle& = 320 I User-Screen (NO OP Window)'ll
END IF'll
Length& = TextLength&(rp&,SADD(Out$),LEN(Out$))'ll
Middle& = Middle& - Length&/2'll
CALL Move& (rp&,Middle&,CLNG(y%))'ll
CALL Text& (rp&,SADD(Out$),LEN(Out$))'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)~

IF (x% <> Oldx%) OR (y%<>OldY%) THEN~


IF Flag! = 1 THEN ~
CALL Move&(RastPort&,Oldx%,O)~
CALL Draw&(RastPort&,Oldx%,RasterHl%)~
CALL Move&(RastPort&,O,OldY%)~
CALL Draw& (R~stPort&,RasterWl%,OldY%)~
END IF~

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

IF MOUSE(O) 8 GOTO mousel~


~
CALL Move&(RastPort&,x%,O)~
CALL Draw&(RastPort&,x%,RasterHl%)'ll
CALL Move&(RastPort&,O,y%)'l[
CALL Draw&(RastPort&,RasterWl%,y%)~
~
Oldx% -l'll
OldY% -H
Flag' om
"
<J[
WHILE MOUSE (0) <> O'll
'l[
w% = PEEKW(WScreen&+18)~
h% = PEEKW(WScreen&+16)~
IF (w% <> Oldx%) OR (h% <> OldO'%) THEN~
S

134
ABACUS 3.3 Tm: MAIN PROGRA:I1

IF Flag' ~ 1 :'HEN CALL Box(RascPort&,x%,y%,:Jldx%,OldY%)'ll


Flag' = I'll
'll
IF (w% < x%+6) THEN w% x%+6'll
F (h% < y%' 3) THEN '1% y%+3'll
'!I
IF (w% > xl; AND (hi > yl) T'iEN'll
IF ''''%>Ras~erWl% THEN . . .J% - RasterW1%'II
IF h%>Rast.erH1% THEN h% - KasterHl%'II
01 dx% w%'ll
OldY% = hi:
'II
CALL Box(Ras:.Port&,x%,y%,w%,h%) 'll
END IF 'll
END IF'll
w'END 'll

IF Flag = 1 THEN CALL Box(P.astPort&,x%,y%,w%,h%)'!I


'll
CALL PrintIt("Seotion Ok ?",130,True) '!I
'II
Flag' O'll
Oldx% 'c -I'll
OldY% -1 '!I
'll
CALL Dialoy30x("OK'I,1,Truc(xla%,yla%,x2a%,y)a%,1'rue)~

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

CALL SetDrt.-:d& (!\dstPort&,:) ! ,-~l\)vj)tJ!


CALL SetDrMd& (Nf\dstPort&,l)'ll
'll
:~ Back! = TrlJe T~EN CALL Sc~o[fS
END SUB'll
''!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

and changing the display screen using Rastport, which allows us to


access the entire bitmap. We can also use the points that normally draw
the border around a window or screen. This allows us to draw on the
full screen.

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'
"!!

SUB EmptyEluffers STATIC'!!


I clear r',ouse and keyboard buffe~c •
WHILE MOeSf', (0) <> O'll
WEND'li
WHILE (I1,KEYS<>"")'ll
WEND'll
END SUB'll
"IT

The following routines implement a completely different kind of input:


SUB FormInpet (i,winlen,unt',ob') STATIC'll
'Enter i ndi veda 1 real val ues'il
t i => nUTTlber '.'2riables to be rCc3.1 (C),ld value
displayedl'll
'winlcn,unt!,ob! => see above.~
z~CSRLIN'
s-POS(O)'lI
a$ ~ " "'ll
CALL PutRcal (i,z,s,winlen)'lI
CALL GetReal (i,a$,z,s,winlen,unt',ob!I'll
i:ND SUB'll
''ll
SUB FormlnputInL (i,winlen,unt',ob!) STATIC'li
'En:er an indivudal integer value'll
'i -> number variavles to be read (old value
displayedl'll
'winlen,unt!,ob! => see above.'
z=CSRLIN'll
s=POS (0) 'll
as = " "t)l
CALL PutReal (i,z,s,winlen)qr
CALL GetInt (i,a$,z,s,winlen,unt!,ob')'ll
END SUB'll
''ll
SUB FormlnputString (sS,winlen) STATIC'll
I String read (z.B. Filename)'ll
as = II "9]
s = POS(G) 'il

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.

Illegal characters (e.g .. letters entered when numbers should be entered)


are ignored. When we enter a value smaller than the given lower limit
or larger than the upper limit, the screen flashes, to indicate an error.

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

Selecting a new disk directory makes it possible to w;e other disks.


You may know the dilemma of suddenly having to make a disk swap
(maybe because of a read error), but a chdi r Of cd can't be executed
from the program. Sometimes data loss can occur. Not with our
program: You can use a new disk by calling Di rectory without
quitting the 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

;F SetPointAdr& <> C THEN CALL


f'! eeMem& (SetPointJ-\dL'&,SetPcl.:tcn;}ii'l&) 7.
IF Pat ternS& <> 0 THEN CAL1,
~'l eeMem& {PaC ter nS& I (NurrLoerP at :_0 Y nS% +<L) "K 2* 16) ~I
IF Pat ternX& <> C THEN CAI.'"
;..~ ;. eeMem& (Pat:. te rr,X&, (Numb(; rPa t teL ;-,X %'" 2-t-1 ) +.-) * 16) s;
I ~av(~ pattern and r ....::::~c3Sf~ ASSEM-KGULi
LIBRARY C:LOSE9I
RETURN'!!
'lI
9':
;'~Ji t: 'lI
CALL Scroft'l!
Status$ = " -;.:; rog.::-am eild ?" .!.CHP~ ) {;
CALL SetWindowTj, tlt~s& {NWBase&, SA~JD {St2t us$) , G) 11
'lI
GOSUB DeleteMenu'lI
'!!
CALL Printlt (liDo you r-eally wish to exi.t the
program?",lGO, ;se)lI
'l!
CALL Dialog:30x ("Noll, 0, TriJerX-=-~J:'i" ;l%,x2a%, y)a%, 1- se) ~
CALL Dialog30x ("New sta ~~:-", ~ ,Fdl se, xlb%, ylb%, x2t/~, y2b%, Fal 58) S
CALL D-La logBox (IIYes'l ,2, F,:-il se, xl c%, yl c%; x2~%; y )c%, Fed SF') <IT
'lI
CALL
DODialog(rl%,O,xla%,yla%,x?a%,y2a%,xlb%,ylb%,x2b%,y2b%,xlc%,ylc%,
x2c%, y2c%) 91
'l!
C:LS'Il
IF n% > 0 THE1,'ll
GOSUB C~cscltc::.
IF n% 1 THEN'![
RUN <If
E:,sE'lI
Et\Dq[
SND TF'lI
END IF'll
<';OSU8 Make''ic:lu'l!

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:

SUB Scroff STATIC'lI


SHARED NWBase&,NWScreen&'lI
, Display Screen off, User Screen on'lI
CALL ScreenToFront&(NWScreen&)'lI
WINDOW OUTPUT 1'lI
WINDOW I'll
CALL ActivateWindow&(NWBase&)'lI
END SUB'lI
''lI
SUB Scron STATIC'lI
SHARED WScreen&,WBase&'lI
, Display Screen on, User Screen off'lI
CALL ScreenToFront&(WScreen&)'lI
WINDOW OUTPUT 2'lI
WINDOW 2'lI
CALL ActivateWindow&(WBase&)'ll
END SUB'll
"1I

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

CALL DialogBox("not called",O,True,xla%,yla%,x2a%,y2a%,False)


'lI
CALL DialogBox("callec",2,False,xlc%,ylc%,x2c%,y2c%,False)'ll
CALL DoDialog(n%,O,xla%,yla%,x2a%,ya2%,-1,-1,-1,-
1,xlc%,ylc%,x2c%,y2c%) 'lI
CLS'lI
IF n% = 2 THEN'll
CHDIR "Tracer:" 'lI
GOSUB CloseIt'ji
CHAIN "Editor"'ll
END IF'IT
GOSUB MakeMenu 'IT

139
3. TilE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

END'll

ErrorHandling keeps you infonned of errors encounlered. These


can only be I/O (input/oulput) errors (e.g., a read/wrile error on the
disk). If another error is encountered in your program, the editor
displays the error number (e.g., 2 [Syntax error]). See Appendix B of
your AmigaBASIC manual, or Appendix A of Abacus'
AmigaBASIC Inside and Out for a list of error messages and
numbers:

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

3.3.2 Merging Tracer Modules into one 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.

Do not type the seven tracer modules in as one program. These


seven modules must be entered separately and merged together as
explained below. This method allows easy incorporation of these
codes into other programs later on.

Enter each module from AmigaBASIC and save each module in


ASCII format under the exact name given in the appendices, in a
directory named modules. For example, the first module must
be saved as follows:

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.

Run AmigaBASIC and enter the following in the BASIC window:

clear ,140000

This reserves the necessary program memory (this command must be


executed before each start of the tracer). This release only works on
Amigas with at least 512K of RAM.

The optional disk (named t rae e r) has all of the modules in a


directory called mod u 1 e s, so set the current directory to
tracer: modules using the following AmigaBASIC command
sequence:

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.

Now we will combine the tracer modules found in the modules


directory. Merge them using the following commands in direct mode
(enter them in the BASIC window):

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"

Then the completed program should be saved as described below:

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

4• Using the Program


In our exploration of the program modules in Chapter Three, we didn't
talk at all about operating the finished product. This chapter is a set of
operating instructions for the tracer and editor programs.

4.1 Editor Documentation

4.1.1 Input-General Information

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:

a) integer values: 0-9,-

b) real values: 0,1, .. ,9,-,.

c) vectors: 0,\, .. ,9'-'0''''''

d) character strings: all characters

e) single characters:
for visible input: y,n
for enlargement, rotation, movement: q,c,d
for the Show function: d,m,f

Each input can be ended by pressing the <Return> key, regardless of


the cursor location. You must press <Return> after characters because
the program waits for the first valid key. For values greater than zero
and less than one, a zero must precede the decimal point (e.g., 0.6 is
acceptable, while .6 resulL~ in an error). If the user enters an input in an
invalid form, or if the value entered lies outside the specified value
range, the program ignores the input and returns the cursor to the
beginning of the line for correction. Valid values are in the range [-
10000 .. + 10000]' with the follov. ing four exceptions:

145
~. lJSl:'\G TilE PROGRAM

a) material type: 1..10000

b) inner or outer radius: 0 .. 1

c) enlargement factor: 1/64 .. 64

d) line view: 1..50

When a coordinate vector is required in an input po~itlon, which is


always the case for us, you have two input options: conventional
keyboard input or mouse input. When you use the mouse. the cursor
must be at the beginning of the corresponding line--no valid keys can
be pressed for this input. When using the mouse. the desired position
in the window can be clicked on where the coordinates will be displayed
in the input and output windows. When it is in the position you want.
ail you need to do i, press <Return>. Then the mou~e position in the
input line takes charge, either directly or as the difference between the
mouse vector and the direction vector.

There are some speciaJ cases to be aware of in menu input. For


example, if you decide that there i~ an input error in the fifth input
position, you don't need to start again. Instead you can return to the
incorrect line. This is done with the <Cursor up> key. This is only
active when no keys are pressed in the input line. You don't have to
enter the entire line. Simply move the cursor to the error, correct it and
press the <Return> key. Then move down to the old input line with
the <Cursor down> key.

4. i.2 Entering Object Data

When the above program specifications for input are considered,


entering object data is no longer ;j problem. You know which data is
actually checked and how the input of a certain object IS started. The
information about the first point can be taken from the drawings below.

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

4.1.3 The Operations Menu

These functions make a number of operations available for working on


object data. The most important ones can be called by pressing a key.
With Left operations can be performed on the previous object. For
example, when the data of the sixth object is visible, selecting the
Left item displays the data for the fifth object. Right functions in
the same manner, moving in the opposite direction. If no further
objecL<; exist, the current object is redisplayed.

By using Segrnen t the visible section can be chosen in the graphic


window (see the program description of the editor for detailed
information on this). The next three menu items (F act 0 1: ,
Factor*2 and Factor/2) change the enlargement factor. Factor
increases or decreases the enlargement factor.Factor*2 doubles tlle
enlargement factor, while Factor / 2 halves the enlargement factor.
The factor is doubled with the first, the s(X;ond halves it, and the third
can be chosen in intervals between [1/64 .. 64 J. The more the
enlargement factor, the smaller the visible section, but the more
recognizable the details. When the enlargement factor changes, the
screen contents arc unchanged because the display of large pictures takes
too much time. A new drawing of the screen appears when you select
the Refresh item.

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.

4.1.4 The Material Editor

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

material editor. It assigns a number to each material so that you know


each object has the color which you assigned to it.

All input in the material editor is done through mouse-controlled


sliders. When you want to insert a value with these sliders, you must
click the position inside of the corresponding slider, where the position
on the left border means the value 0 and the position on the right border
means the value 1. Here we cannot insert an exact value such as 0.765.
A value like this means nothing to the materials. Besides, you wouldn't
be able to see a visible difference between a reflection factor of 0.7 and
0.63.

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.

4.1.5 The Transform Menu

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.

4.1.6 The Disk Menu

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.

'When data is to be saved. select Save 1 i s t from the Disk menu.


Enter the filename without an extension~ just as in loading data-the
program automatically adds the file extension . 1 is t.

Load mat and Save mat handle the loading and saving of the
materials lists from and to disk.

154
ABACUS 4.2 TRACER DOCUMENTATION

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).

4.2.1 After Starting

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

4.2.2 Amiga Menu

The 3D-Cad-Info menu item tells you the maximum number of


objects in memory. The objccts (surfaces and bodies) are saved in array
KO. Furthermore, array KO shows how many objects already exist. The
program variables MaxNurnber and NurnberK contain these values.

4.2.3 File Menu

The File menu contains items for controlling printer and disk access.

4.2.3.1 Loading and Saving Objects

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>.

A default gadget is a gadget surrounded by a bold rectangle. Either click


on the default gadget or press <Return> to accept this gadget.

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.

4.2.3.2 Loading Materials

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

By selecting the Background item you can brighten the background


of the graphic to be shadowed. Usually when shadowing only the
background color or a plane is presented. But you can change this: You
are given the option of loading an IFF graphic from the disk or creating
a pattern.

When you select Load Screen, a screen similar to the Load


object screen appears. You can change directories, load an IFF
graphic or view the files in the current directory. When you click on the
Continue gadget the program asks for the name of the IFF file that
contains the picture to be loaded. An IFF picture can be taken from any
drawing program that supports Interchange File Format (IFF). Try this
with pictures from Graphicraft® or DeluxePaint®.

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.

4.2.3.4 Saving Graphics

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.

4.2.3.5 Printing Graphics

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
~---- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -.......

ABACUS 4.2 TRACER DOCUMENTATION

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.

4.2.3.6 Setting New Colors

Selecting the Color palette item displays all of the available


colors on the display screen. Move the mouse pointer on the color to
be changed and press the left mouse button to select the color. You can
then set the new red, green, and blue components of the foreground and
background colors. After that you can either leave the color palette
screen or change the next color.

Note: Selecting Color palette deletes the current graphic from the
display screen, replacing the graphic with the palette screen. Save
graphics often.

4.2.3.7 Leaving the Program

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.

4.2.4 The Editor Menu

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

4.2.5 The Parameter Menu

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.

As you know, the body of an object appears as a wire model. This is an


alternative to the very slow shadow process. When you enlarge the wire
model, the object also appears larger when it is shadowed. You have
two options of enlargement:

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.

The default proportional enlargement factor is one, which returns you


to the original screen. In some cases you may see anything on the
display screen after the enlargement. This can be remedied by choosing
En 1 a rge again and this time entering a proportional factor of 1 to
restore the original picture. Then select the En 1 a rge item and click
on the Distort gadget to enlarge the appropriate section.

Number of lines should also be explained. Remember: the


number here (numbersegments) gives the number of lines used to
draw a circle in the wire model. Only numbers are given in the ahove
menu items and no requesters are used.

160
ABACUS 4.2 TRACER DOCUMENTATION

4.2.6 The Draw Menu

This menu lists items for controlling the shadowing as well as drawing
wire models.

4.2.6.1 Shadows

Select the Shadows item to start the shadowing process.

You must first determine the parameters used by the shadowing process
first (Shadow window, etc.).

This is done by choosing In i t i ali z at ion. First you are asked


about the actual shadow window. Click on the All gadget to shade the
entire screen. Section gives you the option of choosing a particular
screen section.

Y A· YE gives you the option of specifying a vertical area (a stripe) to


shade. This stripe covers the whole width of the screen; you can set its
position and height. First move the mouse to the beginning position of
the stripe to be shaded. A line drawn at the current mouse position
helps with the positioning. When you have found the correct position,
press and hold the left mouse button while moving the pointer to the
desired end position. Release the mouse button to select the stripe.

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

Because the shading can take many days or weeks on complicated


pictures, the pixel sizes can be changed. This has the advantage that
you can calculate a large picture within a few hours. All of the points
of the shade window can be shaded by setting the pixel width and pixel
height at 1. When an unpleasant result occurs, this can be changed by
resetting some of the parameters.

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.

4.2.6.2 The Wire Model

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.

This happens if no parameters (projection point, main point, distance


to projection surface, rotation angle) have changed since the last
selection of the Wire model item. When one of these parameters is
changed, or the display screen is erased using the Clear screen
item, or a background is chosen, the picture is redrawn.

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.

4.2.7 Keyboard Program Control

We included keyboard shortcuts for some menu items to make the


program easier to use. For example, pressing <Space> creates a wire
model.

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.

One of these is Help. By pressing the <Help> key a list of keyboard


codes and their actions appears on the screen.

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.

Object Object rotations present another simplification of the input of objects.


rotation These can be done with cylinders, cones, and circle surfaces. You must
write an editor that lets you enter the profile of a rotation body. From
that profile the data of the object can be generated and saved to disk.
You can create a section from a rotation body, but the cone section
must also be implemented.

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.

We define the relief function in relation to both parameters of the


direction vectors u and v for planes. For spheres and ellipsoids we take
the angle of the polar coordinates of the intersection point, and for
cones we take the polar coordinate angle, which is responsible for the
rotation around the r4 axis, and the w parameter for the r4 axis. We
leave writing the relief function up to you and your imagination.

A pattern affects more changes in the surface. It's up to you to decide


whether the pattern will be a chessboard pattern, stripes or small hearts.

Patterns do not change the normal vectors of a surface, but change


colors or the entire material constant. The pattern should be defined
periodically, in relation to the parameters or the polar coordinates. It is
best if the pattern is defined in the Ma t array. For example, take

168
ABACUS 5. PROGRAM ENHANCEMENTS

Ma t (n, 6) , which is unoccupied. When this element is zero, this is


valuable for the other elements we have defined. Otherwise Ma t (n, 6)
gives the number of the pattern. For example:

1: Chessboard

2: Dotted

3: Lined

4: ...

Ma t (n, 0) through Ma t (n, 5) contain the material numbers for the


different materials of the pattern. We can assign different materials for
the black fields and the white fields of the chessboard pattern. The
hearts could be multicolored, or you could define a red-and-blue
Commodore symbol. We can define the pattern using parameters and
polar coordinates like the relief. We could also usc different methods,
for example in relation to the Z coordinate so tllat you get high lines.

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.

Calculating transparency is not quite as easy as reflection, and both


things together make it even more complicated. For the definition of
the materials the sum of the reflection and transparency coefficients
should not exceed one because the brightness of the surface can
eventually be greater than one, which would produce a realistic
impression.

As a last feature we make it possible to define multiple light sources.


We must execute all calculations for each light source and the colo'-s we
get. The addition of the brightnesses of all of the light sources should
not give a value over one, because our graphic could get too bright. To
be able to use the optimization, a MinMaxLq array must be calculated
for each light source, or we enlarge the MinMaxLq array around one
dimension which gives the number of the light source:
DIM MinMaxLq{NumberLq,Numberlk,6)

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

6. 3D Tricks and Tips


Now that you have read through most of this book, we'd like to give
you some practical hints. These tricks and tips will help you design
graphics for your current 3D system more easily, and help eliminate
most errors.

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:

calculation time * pixel_width * pixel_height

The result of this multiplication gives you a rough idea of the


calculation time.

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.

Calculating in If the computer needs days to compute, which happens in more


sections elaborate graphics, you can calculate the picture in sections and save the
screen. You can then calculate further by loading the graphic, setting
the necessary parameters and selecting the sections not yet shadowed.

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.

Before we go any fl.Hther, let's remind you of a ...ord yOtl've seen


repeated throughout this book. We first defined it in Chapter One, but
it can't hurt to describe it again:

Algorithms An algorithm is a step-by-step plan for problem solving, usually


through computer programming. Often a computer book explains the
algorithm needed for the particular task, then lists the program used to
perform that task. We chose to do it the other way around. This book
vicws algorithms as working programs instead of as formal "statements
of intent." Therefore, we showed a segment of a program listing first,
then we discussed the algorithms used by the program. In short, you
saw the program code itself, then the reasoning behind the way the
program code works. The programs were written as modules so you
could incorporate the routines in your own programs. The completed
program listings for the tracer and editor are listed in the appendices.

7.1 Vectors

First we should look at vectors. A vector acts as It connection between


geometry and standard arithmetic. Vectors are graphically represented as
arrows. Each vector arrow has a starting point and an end point; the
arrow's "head" lies at the end point. Vectors with the same length and
direction are equal. regardless of \heir location. 'The following iIlustrll-
bon soows a set of equal vector~ and a set of different vectors:

Equal vectors Different vectors

Figure 7.1
ill geometry there arc two ways to differentiate vectors:

179
7. MATHEMATICAL BASICS AMIGA 3D GRAPHIC PROGRAMMING

1. position or equal vectors and


2. direction or difference vectors

Position vectors begin at the origin of the coordinate system (0,0,0).


Position vectors require that you only give the end point-the beginning
point is already set at 0,0,0. Parts of the space can also be assigned as
position vectors.

Direction or difference vectors start at locations other than the origin


and are usually the difference between two position vectors. The start-
ing point of a direction vector is usually the end point of a position
vector.

Direc ion
Figure 7.2 vecto

The difference vectors bring up an important subject: Computing with


vectors. You can add and subtract vectors:

-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)

When multiplying a vector with a scalar (a real number), multiply each


component by this number:

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

7.2 Using Vectors

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

The above equation looks like the following in graphic form:

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

'This diagram makes it somewhat clearer:

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.

Why is it squared? Because squaring must occur when a vector is


equated with a scalar. By squaring, the scalar product becomes a real
number:
xA2
yA2 = x*x+y*y+z*z = a
zA 2

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

7.3 Angles Between Two Vectors

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

One of the vectors (6) can be extended by S-muItiplication until it is


exactly as long as the other vector (a). Examine the coordinates or
components of the vectors, then note that the following apply:

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

By solving k and inserting and transforming the equation, you get:

ax*ox+ay*oy = 0

This is also a form of the scalar product placed between two vectors.

Consider two non-perpendicular 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):

ax Cos(Ct.) * lal ox Cos (~) * 161


ay sin (a) * I aI oy Sin(~) * 161

If you place these in the equation of the scalar product:

Cos(a) * 'al * Cos(~) * 161


~ Sin(a) * 031 * Sin(~) * 161 ~ ax*ox +ay*oy

<-> (cos(a)*cos(~) ~ Sin(Ct.)*Sin(~)) * laj * loi


ax*ox+ay*oy

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

Where the angle ~-a is enclosed by the vectors.

For the value of a vector (Ial) use the Pythagorean theorem:

185
7. MATHEMATICAL BASICS AMIGA 3D GRAPIDC PROGRAMMING

y2

y2-yl dy

yl

x
Figure 7.10 xl x2
x2-xl ~ dx

dax represents the difference of the X-end-component minus the X-


starting-component of a vector. day and da z stand for the difference
between the Y and Z components, respectively.

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

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

Take the x component, for example:

(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.

Intersection point factors look more complicated still when considering


a line and a plane. Here the line and the plane equations must be set to
equality:

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:

l*rx a*rlx b*r2x ax-ox


l*ry a*rly b*r2y ay-oy
l*rz a*rlz b*r2z iiz-oz

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

You can now begin constructing the determinant:


D ~ det A ~ all a12 al3 I
a21 a22 a231
a3l a32 a331

all a22 a33 + a12 a23 a31 + a13 a2l a32


- a13 a22 a31 - all a23 a32 - a33 a12 a21

Besides this denominator determinant you must create three more


number determinants:
Ibl a12 a13!
01 det Al Ib2 a22 a231
Ib3 a32 a331

bl a22 a33 + a12 a23 b3 + aU b2 a32


- al3 a22 b3 - a23 a32 bl - a33 a12 b2

I all bl a131
02 det A2 I a2l b2 a231
la3l b3 a331

all b2 a33 + bl a23 a31 + al3 a2l b3


- a13 b2 a3l -
a23 b3 all - a33 bl a2l

I all a12 bll


D3 det Al la21 a22 b21
la3l a32 b31

all a22 b3 + a12 b2 a3l + bl a2l a32


- bl a22 a3l - b2 a32 all - b3 a12 a2l

188
ABACUS 7.4 INTERSECTING LINES AND PLANES

Why these determinants are called numerator determinants and


denominator determinants is something we'll discuss now. To solve the
equation system you must get the quotient from a numerator and
denominator determinant.

This depends on the positions of the variables in the equation system,


which are used by the numerator determinant. In our example 1 stands
in the ftrst place. The quotient Dl/D is made for this variable to test for
the 1 of D.

The solution for a and b follows in the same way:

a=D2/D
b=D3/D

That functions only when the denominator determinant isn't equal to


zero because division by zero is undefined. When D=O the equation
system has no solution, or, in other words: the plane and line have no
point in common.

We have addressed some basics of three dimensional math, and hope


you have been able to understand them.

189
8.
The Optional Disk
ABAClJS 8. THE OPTIONAL DISK

8. The Optional Disk


The tracer program modules contained in this book are found on the
optional disk in the modules subdirectory. The screens directory
contains some ILBM format files generated with the tracer program that
show the fantastic capabilities of this program.

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)).

The C language routine that reads and displays IFF screens


(ShowILBM in directory c) reads any IFF graphic once compiled. The
routine's source listing appears in the modules directory.

We couldn't include more than two demonstration graphics on the disk


due to memory restrictions. An executable tracer/editor disk requires the
following files and directories:

editor program (either edi tor. bas or edi tor. run)

libs directory (contains the necessary. bmap files)

complete tracer program (either your merged BASIC tracer or


tracer. run)

SetPoint . B program (see Appendix D)

AmigaBASIC (if you're running uncompiled programs)

Objects directory (see description below)

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

compiled using AC/BASIC V1.3. The programs required a few


modifications to compile successfully. The next section explains these
modifications in detail. We strongly recommend compiling these
programs, since they run about 50 times faster than the original BASIC
versions. For example, a graphic that the original BASIC version of
the tracer needed three weeks to compute was finished in about six
hours using the compiled tracer program.

8.1 Compiling the Programs

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.

Naturally you can use any compiler which is compatible with


AmigaBASIC. At the time this book went to press, we only had one
compiler available-the AC/BASIC Compiler from Absoft. The
following description applies to Version 1.3 of t.his compiler, released
April 10,1988.

The first item of business is to make a backup copy of your disk.


You'll use this backup disk for compiling: Remove any unnecessary
files from the disk-kccp only the uncompiled sources for the ray tracer
and editor (do not copy the compiled versions of the tracer and editor).

Note: Never use an original disk for compiling. Always use a copy!

8.1.1 Compiling the Editor

First let's compile the editor. This is easy-load AmigaBASIC and


enter the following in the BASIC window:

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.

Search for the CHAIN command. You'll find it in the Ende


subroutine. Replace this command with END. The reason for doing this
is that the compiled version will not recall the tracer properly. If you
have a later version of the AC/BASIC Compiler (or another brand of
compiler) which correctly accesses the CHAIN command, replace the
CHAIN command with:

CHAIN "Tracer. run"

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

Replace the CALL f ini sh (qui t) with the following:

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.

If your sortsubs program is still straight BASIC code, compile it


before you do anything else. Double-click the sort subs icon. When
sortsubs requests the filename, enter edi tor. cmp and press the

195
8. THE OPTIONAL DISK AMIGA 3D GRAPHIC PROGRAMMING

<Return> key. When sortsubs requests the location of temporary


files, press the <Return> key (Yes). This program moves all the SUB
programs to the end of the source text.

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

R: Link in the runtime library (the compiled editor won't do anything


without looking for this first)

T: Keep temporary files on the RAM disk, which speeds up compilation


(you can do this only if you have enough RAM-at least 1 megabyte)

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.

If you tryout the compiled editor, you'll discover a big difference in


speed from the uncompiled AmigaBASIC version.

Compiling the Tracer

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.

Load AmigaBASIC. Enter the following in the BASIC window and


press <Return> at the end of each line:

elear,140000
ehdir "modules"

Enter the following commands in the BASIC window:

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.

Search for the Ra s t e r I nit: routine. Delete or REM out the


Screen and two Window commands if your want to be able to size
the window for multitasking. Deletion of these commands is
optional.

Search for the CHAIN command in the LoadEdi to r: routine and


change it to END. Or change it to the following:

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

Many compilers have trouble compiling larger program code such as


the tracer (129K of BASIC source code). The following directions apply
to the AC/BASIC Compiler, Version 1.3. If you have a newer version
of this compiler, test compile the original version of the merged
program to sec whether the original command sequences work.

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

CALL RectFill& (RastPort&,xl%,yl%,x2%,y2%)


END SUB

Here are two ways of changing this routine---commenting and deleting:


, NOTE--all lines commented except label and END SUB
SUB SetPoi nt (xl%, yl%, x2%, y2%, Bright. r, Bright. g, Bright. b) STATIC
'SHARED MaxCclour%,Colour(),RastcrHl%,RasterWl%,RastPort&
'SHARED NumberPatternX%, Pat ternX&, Pat ternHX ()
IF x2%>]{asterWl% THEN x2%~RasterWl%
' ... more code follows ...
CALL RectFill&(RastPorL&,xl%,yl%,x2%,y2%)
END SUB

, NOTE--lines deleted except label and END SUB


SUB SetPoi nt (xl%, yl%, x2%, y2%, Bright. r, Bright. g, Bright. b) STATIC
END SUB

The following routines must be deleted or commented out from the


source text you intend to compile. If you try compiling the program
without removing the contents of these routines, the program will
probably crash.

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.

Configure the original BASIC program to add a default


background of some sort of solid color, then compile it.

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)

rp& represents the RastPort passed as the first argument of the


TextLength function. " . $" represents the string from which the
length is calculated and passed on the to program as the string's address
and length. Both commands work identically, provided you avoid
proportional fonts.

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).

If the so r t s ub s program on the is still straight BASIC code,


compile it before you do anything else. Double-click the sortsubs
icon. When sortsubs requests the filename, enter tracer. crop and
press the <Return> key. When sortsubs requests the location of
temporary files, press the <Return> key (Yes). This program moves all
the SUB programs to the end of the source text.

Once sortsubs ends, double-click the compiler icon. Select the


following compiler options:

A: Long addressing enabled

N: Tracer uses ON MENU GOSUB and ON MOUSE GOSUB

R: Link in the runtime library

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.

If everything compiled according to plan, you can now tryout the


tracer. Amiga users with only 512K should open only one screen at a
time. Now when you load objects and calculate them, the difference
between compiled and uncompiled programs is like night and day.

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

A. Modules of the Tracer


1. Initial Routines in I NIT. AS C

DECLARE FUNCTIONs
InitMat
InitPatternS
InitPatternX
InitSetPoint
Rasterlnit

2. Trace system routines in SYSTEM. ASC

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

3. Wire model routines in WIREMODEL-DRAW. ASC

Projection

DrawPlane
DrawTriangle
DrawRectangle
DrawCircle
DrawCircleSector
DrawCircleRing
DrawSphere
DrawCylinder
DrawCylinderSegm
DrawCone
DrawEllipsoid

DrawAll
DrawNew

HowManyCorners
Enlargment

4. Input routines in WIREMODEL-INPUT. ASC

Initial
InitialP

InputP
InputH
InputDPH
InputAngle

5. Shadow initialization in SHADOW-INIT. ASC

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

6. Shadows in SHADOWING. ASC

IntersectionPointPlane
IntersectionPointTriangle
IntersectionPointRectangle
IntersectionPointCircle
AngleIntervall

IntersectionPointCircleSector
IntersectionPointCircleRing
IntersectionPointSphere
BasisTrans

IntersectionPointCylinder
IntersectionPointCylinderSegm
IntersectionPointCone
IntersectionPointEllipsoid

WhichBody
Set Brightness

StandardFill
ExtendedFill
SetPoint

Reprojection
ComputePoint

Shadows

7. Service module in SERVICE. ASC

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

B. The Tracer Program


The complete tracer program is presented in this appendix as seven
separate modules. These modules are on the optional diskette in the
modul es directory. If you type in the modules from this appendix,
type them in one module at a time; you cannOl enter the seven modules
as one unit in AmigaBASIC. Save each module by the specified
filename and in ASCII format. ASCII files can be easily merged to
form the final BASIC tracer program, or as a single ASCII file for
compiling. In addition, each module can be merged into your own
program code.

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 programs and modules in these appendices contain some BASIC


lines that must be entered as one line in AmigaBASIC, even though
they appear on two lines in this book. Formatting the program listings
to fit into this book has caused some long BASIC lines to be split into
two lines. To show where a BASIC line actually ends we'll insert an
end of paragraph (~) character. This marker is not to be entered by you:
It simply shows when the <Return> key should be pressed in the
BASIC editor when entering a line. For example, the following line is
split into two lines in the paragraph below, but must be entered as one
line in AmigaBASIC, as shown by the ~ character:

WinDef M"iindow, :CO, 50, ~60, ~SO, 32+64+512&, L~&+4096&,


0&, TitleS'll

The ~ shows the actual end of the BASIC line.

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

The INIT.ASC module

'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 1,1,1, .1, .2'll


DATA O,l,l,O,O'll
DATA 1,1,1,.05,0'll
DATA .3,.3,.3,.05,.5't
DATA 1,O,O,.2,.3'l1
DATA 0,0,1, .2, .3'll
''lI
PatternS:'!!
, Nurr.ber patterns -I'll
DATA Ie 'lI
''lI
DATA °
DATA &HFFFF'lI
'll

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,!!

, Value of detL'rminante with the vectors a,b and c:'!!


DEl" FN Oct (Al,Bl,C,A?,B2,C2,A3,B3,C3) =Al* (B?*C3-C2*B3) -81* (A2*C3-
C2*A3)+Cl* (1I2*B3-B2*A3)'!!
'!!
, Cosine of the angle between vector a and Vector b:'!!
DEF FN
CosinAngle(ax,ay,az,bx,by,bz)=(ax*bx+ay*by+az*bz)/SQR( (ax*ax+ay*aytaz*az)* (bx*bx+by
*by+bz*bz))'!!
'!!
, Radiant Lo Degree:'

,
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

I :cfa ~~t-Cbjcc~ load:~


<jj
'RESTOFE demo'l[
'READ MaxNurr~er'l[
'Nu~erK~MaxNumber'l[
'FOR n%=1 TO ~;c;mberK'lI
FOR p%~O TO S'l[
FOR q%~O TO 2'li
RE1,D K(n%,p%,q%)'iI
NE:XT q%'l[
N:::X'i' F~'[
''''~X',' ,,%'l[

I How' ~,ar.y 1i:c]lcs needed to compute in a ci:o::'c .. c -?<il


Numbc'rSc(:::;:c:'""~: s -.:;: 4~

'li

Qx~l

Oy ~(;:

Qie-l

I Liqh:-. sc~rce colo!:"": ',.;hite9I


Qb. r:.-:.1 <Jl
Qh.g~l'l[
Qh.b~l'l[

'f
, Fill patlern = Standard'l[
, Only need in case of SetPoint. OSSetPoint has its own pattern''iI
PalternAt-t%~O'IT

8-:) x'v',:{; c-;- ~


B,x::% '

1 VCli
t'\c :COY-: liS
;(

caSUB Cpcn~Ex~
COSlJn ;;;'ast.e:-Ir:i ~:l

I S~adow window (Defaull)~


XSta~~: 1,...:O~1
YStart{::;:O<I
XEnd %c-:O;{d ster1'-J 1 %~
Yend%~RAsterHl%S

'., =-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

REM ON ERROR GOTO ErrorHandling~


~
ok: , Main loop~
MENU ON~
WHILE l~
ON MENU GOSUB MessageEvent~
GOSUB KeyEvent'll
WEND~
''lI
InitMat: 'lI
, Initial material brightness~
'mat(n,O) Red material brightness~
'mat(n,l) Green material brightness~
'mat(n,2) Blue material brightness~
'mat(n,3) Factor for unlit/shadow,!!
, mat (n, 4) Factor for mirroring'!!
'mat(n,5) Factor for Transparecy, not implemented~
'mat(n,6) reserved~
RESTORE Material~
READ NumberMat~
DIM Mat(NumberMat,6)~
FOR n%~l TO NumberMat'li
FOR m%=O TO 4~
READ Mat(n%,m%)~
NEXT m%'lI
NEXT n%'!!
Rc:TlJRN'lI
'~
InitPatternS:,!!
, Initialize fill pattern (Standard)~
RESTORE PatternS~
READ NumberPattcrnS% 'lI

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

REM read binary data:'ll


'll
OPEN "I",#l,"Tracer:SetPoint.B"'ll
SetPointNum&=LOF(l)'ll
SetPointAdr& = AllocMem& (SetPointNum&,6SS36&+2)'ll
'll
IF SetPointAdr&=O THEN'll
CLOSE #l'll
GOSUB CloseIt'll
END'll
END IF'lI
'll
FOR n%=O TO SetPointNum&\2-1'll
h%=CVI(INPUT$(2,#1))'ll
POKEW SetPointAdr&+2*n%,h%'l[
NEXT n% 'll
'll
CLOSE #l'lI
'll
REM subroutine call addresses:'ll
'll
LET OSOpenGfx&=SetPointAdr&'ll
LET OSCloseGfx&=SetPointAdr&+&H1E'll
LET OSSetPoint&=SetPointAdr&+&H38'll
'll
REM Addresses of the variables:'lI
'l!
LET OSColour&=SetPointAdr&+&H3F8'lI
LET OSMaxColour&=SetPointAdr&+&H27A'lI
LET OSModus&=SetPointAdr&+&H27C'll
LET OSRastPort&=SetPointAdr&+&H276'll
LET OSRasterWi&=SetPointAdr&+&H27E'l[
LET OSRasterHl&=SetPointAdr&+&H280'l[
RETURN'lI
''lI
OpenGfx:'ll
CALL OSOpenGfx&'lI
RETURN'll
''lI
CloseGfx:'l!

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

Display~1$ (0) "9i


DisplayM$ (l) 'I ~lo1d and Moai~y"~
DisplayM$(2) II Extra H~lfb~jtE~"9

XResl$(O) " Nor-mai 'll l1

XResl$ (1) II HIHES IIqr


'll
YResl$ (0) ~~o rrra 1
II " ~[
YResl$ (l) ~.nLc~rlacl3d"'1l
II

'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

I How rrany values fer each selection line '11


'fl
COLOR 1 'll
'If
Colours (0) I'll
Colours (1) 2'll
Colours (2) 2'11
Colours (3 ) ?9i
, FiT st l~ne ,~> 'o'J~"l.: te
11
OiJlg:'1I
LOCATE: lO,211I
COLOR Colours(8)'ll
PRINT "Display mods ";~i spi.-)yMS (x (C)) en
LOC1,TE 12, 2i.'1I
COLOR Colm;rs(l)'ll

221
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

PRINT "X-Resolution ";XResl$ (x (1))'lf


LOCATE 14,21']f
COLOR Colours (2)']f
PRINT "Y-Resolution ";YResl$(x(2))'lf
LOCATE 16,24']f
COLOR Colcurs(3)']f
PRINT "BitPlanes: ";x(3)+1']f
']f
Waiter: as ~ INKEY$']f
IF a$ THEN Waiter'lf
'If
IF a$ CHR$(30) THEN x(y) = (x(y)+l) MOD Modulo (y) 'If
IF a$ CHR$(31) THEN xlv) x(y)-l 'If
, CRSR Left/Right'lf
'lI
IF xlv) < 0 THEN xlV) Modulo(y)-l'lI
IF a$ = CP.R$(78) THEN'lf
Colours (y) 2'lI
y = y-l'lf
END IF'lf
, CRSR Up'lf
'If
IF a$ = CHR$(29) THEN'lf
Colours(y) = 7 'If
y = (y+l) MOD 4'lf
END IF'lf
, CRSR Down'lI
'If
IF y<O THEN y=3'lf
'If
Colours(y) = l'lf
'If
IF (x(O) > 0) AND (y=O) THEN'lf
x(l) = 0 ' Select ~M or Halfbrite 'If
x(3) = 5 ' 5+1 BilPlanes'lf
Modulo (3) 6'lf
END IF'lI
'If
IF x(O»O THEN x(3) 5 ' Number of BitPlanes unchanged by HAM or'lf
, Halfbrite mode~

IF (x(O) - 0) AND (x(l)<>l) ~'HEN 'If


Modulo(3) 5'lf
IF x(J) > 4 THEN x(3) = 4 'Maximum 4+1 BitPlanes'lf
END IF ' in Normal Mode'lf
'If
IF (x(l) = 1) AND (y = 1) THEN'lf
x (0) = 0 ' HIRES and Normal'lI
IF x(3»3 THEN x(3) = 3 ' Maximum 3+1 BitPlanes 91
Modulo (3) = 4'lf
END IF'lf
'If
IF a$<> CIIR$('3) THEN GOTO Outg'lf
'If
COWR 1'lI
'lI
RasterW%=(x(1)+1)*320'lf
RasterH%=(x(2)+1)*200 '256 for PAL-cesolution'lI
'If
IF x(O) = 1 THEN Modus% = &H800 'HAM'll

222
ABACUS ApPENDIX B- TilE TRACER PROGRAM

IFx(C) ~ 2 THEN MOGus% = &H8D 'Ha~ f3ri te'll


IF x(l) = 1 THEN Modus% = &H8DOD 'HIRES'll
(HAM, Halfbrite) and Hl'<ES close the same way'll
'll
IF x (2) 1 THEN Modus% = Modus% OR 4 'LACE'll
'll
CLS'll
RasterT% = x(3)+1~
'll
IF RasterT% = 6 THEN RasterT% = S'lI
, If HAM, open a normal screen'll
(max. 5 Bl~Planes)'ll
'll
IF FRE(-I) < (RasterW%/8*RasterH%*RasterT%I+5CCC THEN'll
CLS'lI
CALL "rinUt ("Insl:fficent memory for bitmap" ''', 100,False)'ll
CALL Prjnt.TL ("P:ease try a lower resolL:tion or nllrrbcr of bitmaps
! ! ! II, 1 3 G, Fa 1 se) 91
'll
CALL Dia-LcgBox ("Ok", 1, True, xlb%, ylb%, x2b%, y2b 90{ F a1 sc) <J[
CALL DoDialog(n%,l,-1,-1,-l,-1,xlb%,ylb%,x2b%,y2b%,-1,-1,-1,-II 'll
CLS'll
GOTO Outg'll
END IF'll
'll
SCREEN 1,RasterW%,RastcrH%,RasterT%,x(11+(x(2)*2)+l'll
Width ,Height ,Depth ,Mode'll
'll
WINDOW 2, '''', (0,0) - (RasterW%- 9, RasterB%-l5) ,D, 1 'll
I Wirldow laycrq{
'lI
RasterT% = x(3)+1'll
I old RasterT value~
'll
WBase& = WINDOW(7)'ll
WScreen& = FEEKL(WBase&+46)'ll
, Extract address of the new screen from window addrress'll
'll
POKEL l'iBase&+21, &HIOO OR &H8DO OR 65536&'lI
, Window Flags change: Borderi",;s, RBMTrap, NoCareRefresh'll
'll
Viewport& PEEKL(WBase&+46)+44S
ColorMap& PEEKL(Viewport&,4)'ll
RastPort& Viewport&+40,
BilMap& = WScreen&+184'll
'll
Adr = PEEKL(RastPort&+4) +8 , Bit2lanes for loading'll
FOR i=O TO RasterT%-l , and saving'lI
BitPlanes& (i) ~ pr,EKL(Adr+4*i)'ll
NEXT i11
'lI
BitPlaneE& llitMap&+28'll
, weoere do YOel Wi'lnt the sixth bitplane add1Cess placed ?'ll
'll
Depth& 8itMap&~5S
1 Where do Y01J Waj1'- the new depth placed -?9)
'll
CALL SetFast& (?astPort&, 0) 'll
CALL SetRGB4&(Viewport&, 1, IS,lS,IS)'ll
CALL SetRGB4&(Viewport&,O,O,a,O)'ll

223
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

1 Clear new screen and set background ~

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~

POKEW OS~axColoGr&,2ARascer1'% 'If HAM: 6 11 Colou,~"[


OIM Colour (MaxColour%. 3) 'lI

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

The SYSTEM.ASC module

'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

IF Scr ~ True THEN'll


rp& ~ RastPort&'11
Middle& ~ RasterW2%'ll
SEnd& ~ RasterWl%'ll
, Write to Display-Screen'll
ELSE'll
rp& = NRastPort&'ll
Middle& = 320'11
SEnd& = 640'11
, RastPort of Basic Windows'll
END IF'll
'II
yl% 150Q;
y2% 150 + 6 + 10'11
'II
Length& = TextLength& (rp&,SADD(DialogS) ,LEN(DialogS))'ll
'II
IF Position% ~ 0 THEN'll
xl% 70'11
x2% = xl% + Length& + 20'11
END IF'll
'II
IF Position% ~ 1 THEN'll
x1% Middle&-Length&/2-10'll
x2% ~ MiddJe&+Length&/2+10'll
END IF'll
'II
IF Position% ~ 2 THEN'll
x1% SEnd&-70-20-10-Length&'ll
x2% = SEnd&-70-10'll
END IF'll
'II

228
ABACUS ApPENDIX B- THE TRACER PROGRAM

CALL Move& (rp&,xl%+lO,yl%+lO)~


CALL Text& (rp&, SADD (Dialog$), ,>EN (Dialog$)) 'll

IF Scr = True THEN~


CALL Box(rp&,xl%,yl%,x2%,y2%)'ll
CALL Box(rp&,xl%-4,yl%-2,x2%+4,y2%+2)'ll
IF Ret = Trlle THEN CALL Box(rp&,xl%-2,yl%-1,x2%+2,y2%+l)'IT
ELSE~
LINE (xl%,yl%)-(x2%,y2%)"b'll
LINE (xl%-2,yl%-2)-(x2%+2,y2%+2) "b'IT
IF Ret = True THEN LINE (xl%-1,yl%-1)-(x2%+1,y2%+1) "b~
END IF'll
END SUB'll
' IT
SUB DoDialog(n%,Ret%,xla%,yla%,x2a%,y2a%,xlb%,ylb%,x2b%,y2b%,xlc%,ylc%,x2c%,y2c%)
STATIC~
, Dialog box read'll
, n%: which gadget clicked ?'ll
, Ret%: which gadget specified by pressing <Return>?'ll
, xl.,yl.,x2.,y2. coordinates of the box~
CALL EmptyBuffers'IT
n% = -l~
WHILE (n% = -l)'ll
IF MOUSE (0) <> 0 THEN'll
x MOUSE (l)'ll
y = MOUSE(2)'ll

IF (xla%<x) AND (x2a%>x) AND (yla%<y) AND (y2a%>y) THEN n% O'll


IF (xlb%<x) AND (x2b%>x) AND (yl b%<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$ = CHR$ (13) THEN n% = Ret %'IT
WEND'll
END SUB~
''ll
SUB Rubberbox( x%, y%, w%, h%, Back') STATIC'll
SHARED
RasterWl %, Raste rH 1 %, WScreen &, NRastPort &, RastPort &, NWScrccn& r NT~\'~~ -'.::;c &, \fIJ~~asc& , Length&,
True,False'IT
, Make rectangle with mousc'IT
, x%,y%: upper left corner'll
, w%,h%: Width, Height'll
, Back': Return to user window ?'lI
CALL Scron'll
CALL SetDrMd& (RastPort&,2) 'COMPLEMENT 'lI
'll
CALL SetAPen&(RastPort&,l)'ll

Repiti tion: 'll


Oldx% I'll
OldY% I'll
Flag! O'll
'IT
CALL EmptyBuffers'IT

mousel: 'IT
x% PEEKW(WScreen&~18)'lI
y% = PEEKW(WScrecn&~16)'IT

IF (x% <> Oldx%) OR (y%<>OldY%) THEN'll

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

CALL Move& (RastPort&,x%,Ol'


CALL Draw& (RastPort&,x%,RastcrHI%)'li
CALL Move& (RastPort&,O,y%)'
CALL Draw&(RastPor~&,RasterWl%,y%)'ll
Oldx% xl,
OldY% - y%'
END 1 F ,
'll
, IF MOUSE (0) o GOTO mousel'

CALL Move& (RastPort&,x%,O)'


CALL Draw&(RastPor~&,x%,RasterHI%)'ll
CALL Move&(RastPort&,O,y%)'
CALL Draw& (RastPort&,Ras~crWl%,y%)'
'll
Oldx% -I'll
OldY% -I'll
Flag! O'll
'll
WHILE MOOSE(O) <> O'll
'll
\-1% - PEEKW(WScrceenHl8) 'li
h% = I'EEKW(WScreen&+16)'ll
IF (w% <> Oldx%) OR (h% <> OldY%) THEN'll

IF Fla9~ = 1 THEN CI\LL 3ux(RasLPorL&,x%,Yll,Clux%,OldY%)1l


Flag! = I'll
'll
IF (w% < x%+6) THEN w% x%+6'll
IF (h% < y%+3) THEN h% y%+3'll
'll
IF (w% > xl) AND (h% > y%) THEN'
IF w%>RasterWI % THE" ,,,% RasterWl I'll
:F h%>RasterHl% THE~ tl% = RasterHl%~
Oldx% - w%'ll

, OldY% = h%'ll

CALL Box(RastPorct&,x%,y%,w%,h%) 'll


END IF 'll
END IF'll
WEND 'h
'li
IF Flag = 1 THEN CALL Box(RaslPort&,x%,y%,w%,h%)'ll
'll
CALL PrintIt("Section Ok ?",130,True) 'll
'll
Flag' O'll
Oldx% -I'll
OldY' -1 'It
'll
CALL DialogBox("OK",1,True,xla%,yla%,x2a%,y2a%,True)'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[

MENU 2,8,Start%, " Background "'II


MENU 2,9, Start%, 11 Save screen P"<j[
MENU 2,10, Start%, " Hardcopy "'II
MENU 2,11,0, 1' _________________ 11'
MEKlJ 2,12,Start%, " Color palette C"'II
11 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "q[
~ENU 2,13, 0,
MENU 2,14,1, " Program end Q"'II
'll
MENU 3,0, i,"Editor"q]

231
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMIl\G

MENU 3,1,1, " Load Edi tor

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 MPoint ~ 1 THEN COSUB LoadEdi tor'lI


CCTO MessageEnde'lI
END IF'lI
'll
Ie MTitle 4 THEN'll
IF MPoinc 1 THEN GOSUB Input?'lI
IF MPcint 2 THEN GOSUB Input2'll
IF !>Ii?oint 3 THEN COSUB InputAngle'lI
IF MPcint ,THEN COSUB :nputDPH'll
, MPoint ~5: "-----------"'ll
IF MPoint ~, 6 THEN COSUll Enlargement'lI
IF MPoint ~ 7 THEN COSUB HowManyC8rners~
GOTO MessageEndo'l!
END IF'lI

Ir' MTitle 5 THEN'lI


IF MPoint 1 THE" COSUS Shadows'll
IF MPoint 2 TilEN COSUB Ini tPar ameters1!l
IF MPoint 4 THEN GOSUB Dra'..;New'll
IF :.Ip" int 5 THEN COSUS ClearScreen'll
END IF'll
END Ir''ll
MessageC:nde: 'll
RETURN'lI
''ll
KeyEvent:'ll
Key$=INKEY$'lI
IF Key$ <> "" THEN'll
LOCl'.TE 1, L'lI
'lI
IF Scart% 1 THEN'll
IE- Key$ c
" " THEN GOSUB JrawNew'lI
IF Key$ "dO THEN COSUi3 InplltD?H'lI

IF Key$ - "e" THEN COSUB ColorPalette'lI

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

DPH = DPH + D'lI


COSUB lnitial'lI
Newonc' = True'lI
WaitFlg: = True'lI
GOSUB Drav"XcwS
END IF'lI
<C

IF Key$ lIVIITHEN COSUS Enia rgement 'll


IF Key$ lip II
T2EN COSUE3 InputP':I[
IF Key$ "h" T'iEN GCSUB InputH'lI
IF Key$ !Ia" THEN COSUE3 InplltAngle'II
IF Key$ - lie TIlEN
II
COSUB HowManyCorners'l!
'I!
IF Key$ "::" THEN COSUS ClearScreen'lI

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

IF KeyS = CHRS(138) THEN GOSUB Shadows'll


'II
IF (Key$ = CHRS(28)) OR (KeyS = CHR$(29)) OR (KeyS CHR$(30)) OR (Key$
CHR$(31)) THEN'll
IF KeyS = CHR$(28) THEN'll
Beta = Beta + Pi/IS'll
END IF 'II
IF Key$ = CHRS(29) THEN'll
Beta = Beta - Pi/iS'll
END IF 'II
IF Key$ = CHR$(30) THEN'll
Alpha Alpha + pi/IS'll
END IF 'II
IF KeyS CHR$(31) THEN'll
Alpha Alpha - Pi/IS'll
END IF'll
GOSUB lrcitial'll
Newone! = True'll
WaitFlgl = True'll
GOSUB DrawNew'll
END IF'll
'II
IF (KeyS = CHR$ (18)) OR (KeyS - "i{") THEN'll
IF Key $ ~ CHR$ (18) '['MEN ' 'R'll
Gamma ~ Gamma + Pi/IS'll
END IF 'll
IF KeyS "R" THEN'll
Gamma = Gamma - Pi/15~
END IF'll
GOSUB Initial'll
Newone! = True'll
WaitFlg' = True'll
GOSUB DrawNew'II
END IF 'II
END IF<Jr
IF KeyS "m" THEN GOSUB v,crger'II
IF Key$ "n" THEN GOSUB Arr ayIr,i t 'II
IF KeyS "111 THEN GOSUB Loader 'II
IF KeyS " ?II OR KeyS = CHRS (139) THEN GOSUB Help'll
IF KeyS "q" THEN Quit'll
IF KeyS "ill THEN GOS:JB Info'll
'II
IF KeyS CHR$(l) THEN GOSUB LoadEditor'iI
END IF 'II
RETURN'll
''II
''II
ColorPalctte:'II
StatusS = " Status: Color changc"+CHRS(O)'II
CALL SetWircdowTitles&(NWBase&,SADO(StatusS),O)'iI
'II
C;OSUB DeleteMcnu'll
'II
CALL SetRast& (RascPortc &,0) 'II
CALL Scron'II
CALL PrintIt("Which color to change ?",IOO,True)~
'll
NumCol = MaxColour%'II
IF NumCol = 64 THEN NumCol = 32 ' Halfbrite ?'ll
Widthe = (RasterW%-40)/NumCol'II

234
ABACUS ApPDIDIX B - THE TRACER PROGRA~1

LINE ((20+1),1) - (20+Widthe-1,Ras'cerH%!:C-l), 1,b 'iI


FOR i=l TO NumCol-1~
LINE ((20+i*Widthe+1),1)-((20+(i+:)*WidLhe)-1,RasterH%/10-:),i,HFT
IF MaxCo1our% ~ 64 THEN 'Halfbrite Colour outpuL'll
LINE ((20+i*Widthc+l),RasterH%!lC)-( (20+(i·l)-WidLhc)-1,Ra, ~erH%/S-
1),i+32,BF'lI
END IF~
NEXn
'lI
LoopA:'ll
CALL EmptyBuffers'lI
~
WHILE MOUSE(O) ~ O'll
WEND~
'll
x = MOUSE (1) ~
Y MOUSE (2)'ll
'll
IF (x < 20) OR (x > RasterW%-20) THEN 'iI
GOTO LoopA:~
END IF ~
IF (y < 1) OR (y > RasterH%/10) THEN~
GOTO LoopA:'ll
END IF~
~
Co1r% = TNT ((x-20) /Widthe) 'which coler was cl i cked'lI
CALL Scroff~
red=INT(Colour(Colr%+1,1)*15.S)~
green=INT(Colour(Colr%+1,2)*1S.S)'ll
blue=INT(Colour(Colr%+1,3)*1S.S)'lI
'lI
LOCATE 10,1~
PRINT" red-component (0 .. 15): ";'lI
CALL FormInputTnt (red, 30' ,0' , 15' ) 'lI
'1
LOCATE ll, 1 ~
PRINT" green-component (0 .. 15) : ";~
CALL FormInputTnt (gree~,30',0',lS')~
'lI
LOCATE 12,1'll
PRINT " blue-component (0 .. :5) : "; S
CALL FormInputlnt (blue,30!,O',lS!)'lI
'll
Colour(Colr%+1,1)=red/15'lI
Colour(Colr%+1,2)=green/15'lI
Colour(Colr%+1,3)=blue/15'lI
'lI
POKEW OSColour&+Colr%*8+7, red/15*1024~
POKEW OSColour&+Colr%*8+4,green/15*1024'lI
POKEW OSColour&+Colr%*8+6,blue/15*1024~

IF MaxColour%=64 THEN , Ext raHalfflr i te'lI


Colour(Colr%+33,1)=(red\2)/15~
Colour(Colr%+33,2)=(green\2)/15~
Colotl r (Colrl+ 3 3,3) = (bl ue \2) /15'11

POKEW OSColour&+Colr%*8+2S8, (red\2) I1S-1024'lI


POKEW OSColour&+Colr%*8+260, (green\2) IlS*1024'll
POKEW OSColour&+Colr%*8+262, (b1ue\2) !15*l024'l1
'lI

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

CALL Dialog30x (IIEnd",C,':'rucfx~a%/yJ ,:<2a%, ::'):


CALL Dialog3cx (l1Next color",~~,?alsc/x=b%,J'l
'II
CALL DoDialog (n%,O,xla%,yla%,x2a%,y2a%,-l,-i,-i,-i,xlb%,,/ll)%,x2b%,y2b%)<TI
CLS'ii
'II
IF n% = 2 THEN 'II
CALL Scron'll
GOTO LoopA'll
END IF'll
Newone! = True'll
Hg = False'1l
GaSUS MakeMeflu<![
RETURc:'j)

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

Dialog$ = "L)(':vice ~/~) Errc[ ! ~ ! liqr


END IF'iI
'11
IF NumErr 68 TIIEN I DI?',': icc 1;~(lb ~c1,

Dial :)g$ co- "~~evicc fC\jr::j 'I C]


END Il:'ll
'll
IF NumErr 61 THEN I Dis:': Ful19!
Dialug$ "D: sket: c ~ oS f LJ.: I! 1 II

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

Dialog$ liFe rmi 5:::; ~ " uS;


END If'IT
<j[
It Dia1og$ ~ "" TiicN'1I
Dia~c-)g$ --:: "~~ror ~~,,;~be~ ="+STH$(~L~:r'F,;r)lI
END IF'l[
'l[
CALL Dia1ogBox (Dj al og$, } ,True, xl a%. yla%, x2a %, y2a%, Fal se) <l]
'l[
CALL DoDialog (c%, 1 , -1 , -1, -1, --1, x1a %, / J a %, x2a %, y/~a %, - ~ , -~; , - 1 , ~~ ) Q"

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

CALL DialogBox(IINew start l1 ,1,False,xlb%,yJb%,x2b%,y2L%,Fa' se)'!l


CALL DialogBox( Yes",2,False,xlc%,ylc%,x2c%,y2c%,Falsc)9
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

CALL PutReal (i,z,s,winlen)'ll


CALL GetRoal (i,a$,z,s,winlen,unt!,ob!)'lI
END SU8'll
''ll
SUB FormlnputInt (i,winlen,unt!,ob!) STATIC'll
'Enter an indivudal integer value'll
cc> number variav;cs Lo be read (old value displayed) 'j]
'winlen,unt!,ob! => see above.S:
zoCSRLIN'j]
s~POS(O)'j]
a$ ~ ,. "'ll
CALL PuLReal (i,z,s,winlen)'j]
CALL GetInt (i,a$,z,s,winlen,unt!,ob!)'lI
END SUB'j]

SUB FormInputSLring (s$, w).nlen) STATl C'j]


, SLring read (e.g. Filename)'ll
as = " "q[
s = POS(O) 'll
z ~ CSRI.IN'j]
CALL PuLString (s$,z,s,winlen)'ll
CALL GetString
(s$,aS, "abcdcofghijklmnopqrstuvwxyzdvi ABCDEFGHIJKLMNOPQRSTUV'IIXYZDV\1234567890.-
: /11, 2, Sf winle;l) en
c ~;D SUB'll
''ij
Directory:'ll
I Directory read, or change drive'll
Status$ = " Status: Directory"+CHR$(O)'j]
CALL SetWindowTitles&(NWBaso&,SADD(StaLus$),O)'lI
'lI
GOSUB DeleteMenu'll
a$ ~ "Active Directory: n+ActDrive$'lI
CALL PrintI~ (a$,50,~alse)'j]
CHOIR ActDrivc$'j]
'j]
RepeaLD:'lI
CALL DialogBox("Files",0,False,xla%,yla%,x2a%,y2a%,False)'j]
CALL DialogBox("Continue",1,True,xlb%,ylb%,x2b%,y2b%,False)'j]
CALL DialogBox("Chdir",~,False,xlc%,ylc%,x2c%,y2c%,Faise)'j]
'Il
CALL DoDL1~ og (n%, 1, xIa%, yIa%, x2a%, y2a%, xIb%, ylb%, x2b%, y2b%, xlc%, ylc%, x2c%, y2c%)
'II

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

The WIREMODEL-DRA W.ASC module

'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;\(;

FOR w2=D TO pm2+D/2 STEP D'lI

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

IF (Newone! = True) OR (Hg True) THEN , Background and New drawing'!!


GOSUB DeleteMenu'll
RetRast& = RastPort& , reserve RastPort 'll
RastPort& = WINDOW(8) , In Window-RastPort (GIMMEZERO Window I) 'it
CALL SetAPen&(RastPort&,l) , the new Screens'll
GOSUB DrawAll , draw (because of Clipping)'!!
RastPort& = RetRast&'ll
BEEP'll
END IF'll
'll
IF WaitFlg! = True THEN , wait for mouse or key press'!!
GOSUfl Pause '!!
CALL Seroff,!!
END IF'!!

IF (Newone l c Tcue) OP (Hg True) THEN'll


Newo!le~ = False , Redraw picture ~
Hq ?alse I and "paint over"11
GCSUIl MakeMenu , background '!!
END IF'll
EETUHN'll
"1l
HowManyCorners:'ll
Status$ = " Status: Draw angles at n-eorners"+CHR$(O)'ll
CALL SetWindowTitles&(NWRase&,SADD(Status$),O)'ll
11
GOSUB DeleteMenu,!!
'!!
LOCATE 10,lSI
PRINT" How many corners: ";1I
CALL FormTnp\ltlnt (Nu~erSegments,30!,OI,2001),!!
Newone: -:;-; Trlle91
CLS'll
GOSUB i'-1,jkc~1cnu~
RETUEN'll
''ll
Enlargcmcnt:<ir
StaLls$"" Status: Enlarge screen segment"+CHR$(O)'l:
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
'll
COSUB DeleteMenu'll

CALL DialogBox("Proportional",O,True,xla%,yla%,x2a%,y2a%,False)'ll
CALL DialogBox("Distort",2,Falsc,xlb%,ylb%,x2b%,y2b%,False)'ll
r;;

CALL DoDialog(n%,O,xla%,yla%,x2a%,y2a%,xlb%,ylb%,x2b%,y2b%,-1,-1,-1, -11'il


CLS'll
'll
IF n%= 0 TlIE~; 'll
LOCATE 10, 'i '!!
PRINT " ~nlc1rqcmcnL Factor: ";'jl
d' 1 'll
C1\LL Formc~.pu'- (a,lO!, .1,IOO')'ll
'l:
CJ,s 'll
Pict~rew'dth-a'FactorX'
Pict~reheighL'a*FacLorY'
Picturex=RasterW2%/PicturewidLh'll
Picturey=RasterH2%/Picturcheight'

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

The WIREMODEL-INPUT.ASC module

'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)~

Px=Hx+DPH*Cosa*Cosb , Projection point based on the ~


Py=Hy+DPH*Sina*Cosb , main point and the spacings~
Pz=Hz+DPH*Sinb , DPH and Alpha, Beta and Gam~a~
RETURN ~
'~
InitialP:~
D1=SQR ( (Px-flx) A2+ (Py-Hy) A2) ~
DPH=SQR ( (Px-Hx) A2+ (Py-Hy) A2+ (Pz-Hz) A2) ~
~
IF 01=0 THEN~
Sina=O~
Cosa=l~
ELSE'll
Sina=(Py-fly)/D1'll
Cosa=(Px-Hx)/D1'll
END IF'll
'!I
IF DPH=O THEN~
Sinb=O'll
Cosb=l'll
ELSE'll
Sinb=(Pz-Hz)/OPH'll

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

IF' Cosb--C' TWFNqf


Bet.a -;>j:)
ELSE'li
Beta f,.c,',

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

LOCATE 13, l'IT


PRINT " Py ~ ";'ll
CALL Forrr.l nput (Py,JO!,-lEtl~,lE>14)'lI

: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

The SHADOW-INIT.ASC module

'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

CALL Printl =. ("s[-:(lCluw window?",130,False)':l1


i

CALl.., DialogBox ("Alllt, C, Tcue,xla%,yla%,x2a%,y2a%,False) qr


CALL DialogB~)x ("Sect_! ",1_,Faise,xlb%,ylb%,x)b%,y2b%,False)'l[
CA~L Dialog30x(I'YA - YE",2,False,xlc%,ylc%,x2c%,y2c%,Falsc)~
'll
CALL DoDialcg(n%,O,xla%,yla%,x7a%,y2a%,xlb%,ylb%,x2b%,y2c%,xlc%,ylc%,x2c%,y2c%)'ll
CLS'lI
'll
IF n% ~ 0 THEN'll
XStacC% ~ O'll
YSt.:lrt% = O~
XEnd% Rastc~W:%!
Yend%
END IF'iC
'll
IT n % ~ ] ~'H!~N'll
CALL Rl.:r.bc:rbcx (Sx%, Sy%, Widthe%, f-:leig;-~te%, 'I'rue) <)!
'JI
XStart%=Sx-%qi
YStart.%~Sy%lI
XEnd%=Sx%+Widthe%1
Yend%:Sy%+~leighte%~
ND IF'JI

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

, IF YStart% > Yend% THEN SWAP YStart%,Yend%'ll

CALL Movce& (RastPort&,O,YStdrl%)'ll

, CALL Draw&(RastPorl&,RaslerW1%,YStart%)'lI

CALL Move& (RastPorl&,O,Yend%)'l!


CALL Draw&(RdstPort&,PasterWl%,Yend%)'ll
'lI
CALL SelDrMd& (RastPort& ,1) 'lI
'lI
CALL Sc;ofCqr
i::ND IF'lI
'lI
LOCATE 2,1'll
PPINT " Xstart ";XStart%;", X"nd ";XEnd%'lI
PRINT " Ystart ";YStart%;", Y"nd ";Yend%'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~

Help (n%, 0) -Nx'll


Help(n%,l)=Ny'll
Help(n%,2)=Nz'll
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,0)*K(n%,2,2)~
Help(n%,5)~K(n%,2,0)*K(n%,3,1)-K(n%,3,0)*K(n%,2,1)~
END IF~
IF K(n%,0,0»=20 THEN~
I Help(n,O)=Names determinant, 1-6=for Normal vector cylinder, 7=length
(n, 4,x)~
, 10-12=transform Projection point~
, 13-21=2*2-Determinantes for P/R-Transformation~
Help(n%,O)=FN
Det (K (n%, 2,0) ,K (n%, 3, 0) ,K (n%, 4, 0) ,K (n%, 2,1) ,K (n%, 3, 1) ,K (n%, 4,1) ,K (n%, 2,2) ,K (n%, 3,2
),K(n%,4,2))'lI
IF Help(n%,O)=O THEN~
a$="The basis of object "+STR$(n%)+" is no basis"~
CALL PrintIt(a$,130,False)~
CALL DialogBox("Pitch",1,True,xla%,yla%,x2a%,y2a%,False)~
~
CALL DoDialog(n%.1.-1.-I.-I.-I.xIa%.yla%.x2a%.y2a%.-1.-I,-I,-I)'ll
COSUS CloseIt~
RUN ~
END IF~
a=K(n%,2,0)A2+K(n%,2,I)A2+K(n%,2,2)A2~
b=K(n%,3,O)A2+K(n%,3,1)A2+K(n%,3,2)A2~
IF K(n%,0,O»=24 THEN~
c=K(n%,4,0) A2+K(n%,4,I)A2+K(n%,4,2)A2~
Help(n%,I)=b*c*K(n%,2,0)~
Help(n%,2)=b*c*K(n%,2,1)~
Help(n%,3)=b*c*K(n%,2,2)~
Help(n%,4)=a*c*K(n%,3,O)~
Help(n%,5)=a*c*K(n%,3,1)~
Help(n%,6)=a*c*K(n%,3,2)~
Help(n%, 7)=a*b*K(n%,4,O)~
Help(n%,8)=a*b*K(n%,4,1)~
Help(n%,9)=a*b*K(n%,4,2)'lI
ELSE~
Help(n%,l)=a*K(n%,3,O)~
Help(n%,2)=a*K(n%,3,1)~
Help(n%,3)=a*K(n%,3,2)~
Help(n%,4)=b*K(n%,2,0)~
Help(n%,5)=b*K(n%,2,l)~
Help(n%,6)=b*K(n%,2,2)~
Help(n%, 7)=SQR(K(n%,4,O)A2+K(n%,4,1)A2+K(n%,4,2)A2)~
END IF~

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 (;":Txyz 1'1 (x, y, z, n%, x2%, y2%, z2%) 'll


CALL ,;;ltest(x,y,z)'ll
CALL CalcabiqU\2, B/,Ainc,Blnc, x, Y, z) <Jj
'll
CALL G~Txyzlq (x, y, z, n%, x3%, y3%, z3%) 'II
CALL Disltest(x,y,z)'ll
CALL Calcablq(A3,n3,Ainc,Binc,x,y,z)'ll

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 Disttest (x,y,z)~


CALL Calcablq(A3,B3,Ainc,Binc,x,y,Z)~
'lI
CALL GETxyzlqk(x,y,z,n%,x4%,y4%,z4%)'ll
CALL Disttest(x,y,z)'ll
, CALL Calcablq(A4,B4,Ainc,Binc,x,y,z),

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~

CALL Deltasum4 (b,Bl,B2,B3,B4)'ll


'll
IF b>Pi THEN'll
, => Light source 'within' triangle'll
BMin~-Pi'll
BMax=Pi'lI
Binc=Pi'J[
ELSE'l[
IF Bl<BMin THEN BMin BI'll
IF B2<BMin THEN BMin B2'll
IF B3<BMin THEN BMin B3'J[
IF B4<BMin THEN BMin B4'll
'l[
IF Bl>BMax THEN BMax Bl'll
IF B2>BMax THEN BMax B2'll
IF B3>BMax THEN BMax B3'll
IF B4>BMax THEN BMax B4'll
'll
IF (BMax-BMin>=Pi) AND (Binc=O) THEN'
Binc=Pi'll
ok'=False'll
END IF'
END IF'll
IF ok'<>True THEN GOTO RepeatC'll
END SUB'
''ll

267
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMMING

SUB MmlqShpere(n%) STATIC~


CALL MmlqKTest (n%, -1, -1, -1, -1,1, -1,1,1, -1,1, -1, -1) 'II
CALL MmlqKTest(n%,-1,-1,-I,-I,1,-I,-1,I,I,-1,-1,1)~
CALL MmlqKTest(n%,-I,I,-I,I,I,-I,l,I,I,-l,l,l)'11
CALL MmlqKTest(n%,1,I,-1,1,-1,-1,1,-1,1,1,1,1)"
CALL MmlqKTest(n%,1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,1)~
CALL Mm1qKTest(n%,-1,-1,1,-1,1,1,1,1,1,1,-1,1)'11
END SUB"
'~
SUB MmlqCylinder(n%) STATIC'll
CALL Mmlq4Test(n%,-1,-1,O,-1,1,0,1,1,O,1,-1,0)"
CALL Mmlq4Test(n%,-1,-1,O,-1,1,O,-1,1,1,-1,-1,1)"
CALL Mrnlq4Test(n%,-1,1,O,1,1,O,1,1,1,-1,1,1)~
CALL Mmlq4Test(n%,1,1,0,I,-I,0,1,-1,1,1,1,1)~
CALL Mmlq4Test(n%,1,-1,O,-1,-1,O,-I,-I,I,1,-1,1)"
CALL Mrnlq4Test(n%,-1,-1,1,-I,1,1,1,1,1,1,-I,I)'lI
END SUB"
'~
SUB MmlqCone(n%) STATIC~
CALL Mrnlq4Test(n%,-1,-1,O,-1,1,O,1,1,O,1,-1,O)~
CALL Mmlq3Test (n%, -1, -1,0,-1,1,0,0,0,1) 'II
CALL Mmlq3Test(n%,-I,I,0,1,1,O,0,0,I)'11
CALL Mrnlq3Test(n%,1,1,O,I,-1,0,0,O,1)~
CALL Mmlq3Test(n%,1,-1,O,-1,-1,0,0,C,1)"
END SUB~

'"
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

FOR n%=l TO NumberK'lI


AMin=Pi~
A1V,ax~-Pi~
Bt1in~Pi 'II
BMax=-Pi~
Ainc~O"
Binc=O~
Min::Jist=-l'll
~
IF K(n%,O,O)=O THEN'll
AMin=-Pi~
BMin=-Pi'll
AMax=Pi'll
BMax-Pi ~
Min::Jist~ABS(Help(n%,O)*(Qx-K(n%,:,O))+Help(n%,I)' (Qy-
K(n%,I,l) )+Help(n%,2)*(Qz-K(n%,1,2»)~
END IF"

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

The SHADOWING.ASC module

'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

, Transform (px,py,zy) => (pxt,pyt,pzt), (rx,!:"y,rz) => (xt,yt,zt)'ll


IF Original! = True THEN'll
Pxt=Help(n%,lO)'ll
Pyt=Help(n%,ll)'ll
Pzt=Help(n%,12)'ll
ELSE'll
Pxt=(Px-K(n%,1,0))*Help(n%,13)-(Py-K(n%,1,1))*Help(n%,14)+ (pz-
K(n%,1,2) )*He1p(n%,15)'ll
Pyt=(Px-K(n%, 1,0))*Help(n%,16)-(Py-K(n%, 1,1))*Help(n%,17)+(Pz-
K (n %, 1 , 2) ) * He 1 p (n %, 18) 'll
Pzt=(Px-K(n%,1,0))*Help(n%,19)-(Py-K(n%,1,1))*Help(n%,20)+(Pz-
K(n%,1,2) ) *l1elp(n%,21) 'II
END IF'll
Xt=(Px+Rx-K(n%,1,0) )*Help(n%,13)-(Py+Ry-K(n%,1, 1) )*Help(n%,14)+(Pz+Rz-
K(n%,1,2))*Hclp(n%,15)-Pxt'll
Yt~(Px+Rx-K(n%,1,0))*Help(n%,16)-(Py+Ry-K(n%,1,1) )*Help(n%,17)+(Pz+Rz-
K(n%,1,2))*Help(n%,18)-Pyt'll
Zt=(Px+Rx-K(n%,l,O) )*Help(n%,19)-(Py+Ry-K(n%, 1, 1) )*Help(n%,20)+(Pz+Rz-
K(n%,1,2))*Help(n%,21)-Pzt'll
END SUB'll
''I[
''I[
SUB IntersectpointCylinder(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Original!) STATIC'I[
SHARED Threshold'll
, => 1=exact parameter, a,b,c = transform Intersect point coordinates'll
CALL Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,Original!)'11
D=Xt*Xt+Yt*Yt'll
IF' D<>O THEN'll
p~(Pxt*Xt+Pyt*Yt)/D'II
q=(Pxt*Pxt+Pyt*Pyt-1)/D'II
D=p*p-q'll
E' 0>=0 THEN'll
l=-p+SQR(D)'ll
Ll=-p-SQR (D) 'll
c=Pzt+l*Zt'll
D=PzULl*Zt'll
IF Ll <1 AND Ll>Threshold AND D>=O AND 0<=1 THEN'll
SWAP l,Ll'l[
SWAP c,D'II
END IF'll
IF c<O OR c>1 THEN'll
l=-l'll
ELSE'll
a=Pxt+l*Xt'l[
b=Pyt+1*Yt'll
END IF'll
ELSE'll
1=-1 'll
END IE''ll
ELSE'll
l=-l'll
END IF'll
END SUB'll
"1I
SUB IntersectpointCylinderSegm(n%,Px,Py,Pz,Rx,Ry,Rz,l,a,b,c,Original') STATIC'lI
SHARED Threshold 'll
, => l=exact parameter, a,b,c = transform Intersect point coordinates'll
CALI. Basistrans(n%,Pxt,Pyt,Pzt,Xt,Yt,Zt,Px,Py,Pz,Rx,Ry,Rz,Original!)'
D=Xt*Xt+Yt*Yt'l!
IF 0<>0 T!-lEN'll

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~
'~
.~

SUB StandardFill (xl%,yl%,x2%,y2%,Bright,Coll%,Co12%) STATIC~


SHARED PatternHS(),PatternS&,NumberPatternS%,RastPort&~
, draw rectangle in standard fill pattern~
Min=lE+35~
Nr%=O~
n%=O~
~
WHILE ABS (Bright-PatternHS (n%)) <f(cnq[
I sort in ascending ord{~rq{
Min=ABS (Bright-PatternHS (~,%) ) ~
Nr%=n%~
n% = n% +l~
IF n%>=NumberPatternS% GOTO ContinueA~
WEND~
~
ContinueA:~
CALL SetAPen&(RastPort&,Coll%)~
CALL SetBPen&(RastPort&,Col2%)~
~
POKEL RastPort&+8, (PatternS&+Nr%*32)~
• RastPort->AreaPtrn = &(PatternS%(O,Nr%)~

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

POKEL RastPort&+8, (PatternX&+NrM%*32) 'Address of PatternS'll


,'OKE RastPort&+29,1'll

CALL RectFil 1& (RascPort&,xl%,yl%,x2%,y2%)'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'(;

yl=y*Cosc-z*Sinc ' Rota:ion X-Axis'


zl=z*Cosc+y*Sinc'lI
x2=x*Cosb-zl*Sinb I Rotation Y-Axis'
zr=zl*Cosb+x*Sinb+Hz'lI
xr=x2*Cosa-yl*Sina+Hx 'Rotation Z-Axis'
yr=yl*Cosa+x2*Sina+Hy'lI
END SlJB'l[
l(/f

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

Rest. (,;tack," c%) ccMat (X (Body%, 0, 2),4) 'lI


'lI
~~' B~' i <= () ~~E~rJ9[
, unj 'lI
BrighL.r=Mat(X(BoJy%,O,2),O)*Mat(K(Boay%,O,2),3)i
Bright.g=Mat(K(Body%,O,2), ;)*Mat(K(Body%,O,2),3)'l[
Bright. b··M,3t (K (Body%, 0,2) ,2) *Mat (K (Body%, 0, 2) ,3) 'l[
ELSE'l[
Xp%=Body%'l[
'Shadow ?<iI
CALL WhichBody (Xr't, Sx, Sy, 5z, Qx-Sx, Qy-Sy, Qz-Sz, False, True) 'lI
SWAP Body%,Kp%'l[
IF' Kp%>O AND la<l THEN'lI
, in shadow:'lI
Brigh:.. c=Mac. (K (Body%, 0, 2) ,0) *Mat (X (Body%, 0, 2) , 3) 9i
igh:.q~M~t (K(Body%,0,2),1)*Mat(X(8ody%,O,2), 3)'lI
tlrcqhc. o-M"t (X (Clody%, 0, 2) ,2) *Mat (X (Body%, (], 2) , 3) 'lI
EI s:,~qi

I t'-Lrror _~ ~ght source on interface:<:!l


Ilrig~:. (l-RestLght (StackPtr%l)qr
Ilrig~~*
IF Rright<Mac(K(Body%,O,2),3) THENS
Bric;hL'Mdt(K(Body%,O,2),3)'ll
IFqt
Sc~ghl.[~Bright*Mat(K(Body%,O,2),O)+Mirror*RestLght(StackPtr%)'lI
Bright.g=Bright*Mat(X(Body%,O,2) ,1)+Mirror*RestLght (St ackPtr%)':!
Bright. b=Bright *Mat (K (Body%, 0,2) ,2) +Mirror*RestLght (S"ackPtr%) q!
END IF'll
END IF'l[
':!
IF (HestLght (StaciocDtr%1 >0) AND (StackPtr%<MaxStack%) THE[\;S
I Determine Mirror i.nterfaccq[
• Determine mirror vecLor to P-S:,
:)qe"Nx* (Px-Sxl +Ny* (Py-Sy) +Nz* (Pz~Sz) 'lI
~·=Sx-Px+2*Dqe*Nx'
!-Sy-Py+2*Oq(~*Ny~
Sz-P%. ... 2"1<::::::qc":"Nzqj
1!
2r~(Sta~kPtr%,O)=Brjght.r!
Stac~(SLackPtr%,l)=Bright.g'll
Stack (StackPrr%,2)=Bright.b'lI
'l[
[)x Sx(;~

Py Sy~
pz Sz'lI
Origir:cl J.! False'll

282
ABACUS ApPENDIX B- TilE TRACER PROGRAM

GOSUB Computepoint , Recursion'!!!'ll


'II
Bright.r~Stack(StackPtr%,O)+Stack(StackPtr%+l,O)*Res:Lqht(StackPt ,%)'ll
Bright.g=Stack(StackPtr%,l)+Stack(StackPtr%+l,:)*Rest~ght(StackPtr%)'ll
Bright.b=Stack(StackPtr%,2)+Stack(StackPtr%+1,2)*RestLght(StackPtr%)'ll
END IF'll
ELSE'll
IF StackPtr%
Bright.r=-I'll
°THEN'll

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

Status$ ~ " Status: InitMinMax"+CHR$(O)'II


CALL SetWindowTitlcs& (NWBase&,SADD(Status$), 0)'lI
GOSUB InitMinMax'll

Status$ ~ " Status: InitMinMaxLq"+CHR$(O)'ll


CALL SetWindowTitles& (NWBase&,SADD(Status$) ,0) 'II
GOSUB InitMinmilxLq'll

CALL Scron'll

Status$ = " Status: Shadows"+CHR$(O)'ll


CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'II

XAOff (BoxW% AND 1)*.5'II


YAOff (BoxH% AND 1)*.5'll
'll
, Offsets to guarantee correct point size'II
IF XAOff = .5 THEN'll
XBOff .5'll
ELSE'll
XBOff 1 'II
END IF'II
IF YAOff ~ .5 THEN'll
YBOff = .5'II

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

CALL ReProjeclion(Rx,Ry,Rz,O',FN Xresc(xb%),FN Yresc(yb%))'Il


'Il
Rx Rx-Px'll
Ry Ry-Py'll
Rz Rz-Pz'll
91
St.ackPtr% ~-I'll

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

The SERVICE.ASC module

SERVICE.ASC'll
****************~***************~

* 'SERVICE' - Module *'lI


****************************~***~
''ll
Saver: 'll
, Save array K() to disk'll
GOSUB Directory'll

Status$ = " StaLls: Objcc~. Saver"'~:lii\$ (0) 'll


CALL SetWindowTitlcs& (N'd!3']se&, SAGU (Scatus$), 0) 'll
'll
LOCATE 3,1'll
PRINT" Under what name do you want tr:c object sav.,d?"'ll
PRINT 'll
PRINT " Filename : "; Sl
dn$ = ""'ll
CALL ForrnInputString (dnS,30')'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~

Status$ = " Status: Object L'Jader"+CHH$ (0) 'll


CALL SetWindowTitles& (NWBasc&,SADD(Status$) ,O)'ll

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

IF dn$ <> "" THEN'll


dn$ = 00$+". LIST"'ll
OPEN "I",#1,dn$,~024'll
INPUT #l,NumberK'll
LOCATE. IO,lO'll
PRINT "Total u;NumberK;1I Object ("+dn$+").1I1j[
PRINT'll
PRINT" Maximum number of objects? ";'ll
MaxNumber NumberK'll
CALL FormInputlnt (MaxNumber, 30! ,I!, NumberK) 'll
'll
IF NumberK > MaxNumber THEN NumberK = Max Number'll
'll
ERASE K'll
DIM K(MaxNumber,5,2)'ll
'lI
FOR n%=l TO Nun~rK'lI
FOR p%=O TO 5'll
INPUT #1,K(n%,p%,O),K(n%,p%,1),K(n%,p%,2)'ll
NEXT pI'll
NEXT n%'ll
CLOSE #l'll
Newone! = True'll
Start% = I'll
END IF'll
CLS'll
GOSUB MakeMenu'll
RETURN'll
''ll
Merger:'ll
Elerrents appended to available array K()'ll
°
I

IF (MaxNumber-NumberK) <= THEN'll


Status$ = " Status: Object Merger"+CHR$(O)'ll
CALL SetWindowTitles&(NWBase&,SADD(Status$),O)'ll
'll
a$ = "Insufficent !Ternary for more objects!!! "'ll
CALL PrintIt (a$,IOO,False)'ll
a$ = "Please select New to create a cleared array K () ! "'ll
CALL PrintIt (a$,130,False)'ll
CALL DialoqBox("OK",1,True,xla%,yla%,x2a%,y2a%,False)'ll
'll
CALL DoDialog(n%,I,-1,-1,-I,-1,xla%,yla%,x2a%,y2a%,-1,-1,-1,-I)'ll
ELSE 'll
GOSUB Directory'll
'll
Status$ = " Status: Object Merger"+CHR$(O)'ll
CALL SetWindo«Titles&(NWBase&,SADD(Status$),O)'ll
'lI
LOCATE 3,1 'll
PRINT" Which object would you like to merge?"'ll
PRINT'll
dn$ = "" 'll
PRINT" Filename: ";'ll
CALL FormlnputString (OO$,30')'ll
'll
CLS'll
IF dn$ <> "n THEN'il
dn$ = dn$ + ".LIST"'ll
OPEN "I",#1,OO$,1024'il
INPUT #1, x'll

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 x<num THEN num ~ x'll


IF MaxNumber-NumberK<num THEN num MaxNumber-NumberK'll

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

Flags& = 65537& I MEMF PUBLIC I MEMF CLEAR'I[


BufferSize& = 360'll
Buffer& ~ AllocMem& (BufferSize&,Flags&) 'I[
IF Buffer& = ° TfiEN'I[
DialogS - "No more memory!! !II~
GOTO EndSave'll
END IF'll
'll
ColorBuffer& Buffer&'ll

Null& = O'll
PadRyte% O'll
'll

289
ApPE:'>DIX B- Tm: TRACER PROGRAM AMIGA 3D GRAPIIIC PROGRAMl\lI:\G

IF RasterW% = 320 THE;\'ll


IF RasterH% = 200 THEN'
Aspect% &HAOB~
ELSEql
Aspect% &1l1 ~OB'll
END IF'lI
ELSE'
IF Raste~R% = )80 THEN~
Aspecl% c &'iS03'll
ELSE'll
Aspect% &PJ\OB'll
END ::T'll
END IF'll

IFFFile$ ~ IFFFde$ + CRR$ (0) 'II


Handle& = xOpen& (SADD (IFFFile$), 1006) ,
IF Handle& 0 TliEN'll
Dialog$ - HeHn! t open the fi lc you wanted!! ! liS!
GOTO EndSave'll
END IFq[
'll
'II
, How many byles contain IFF-Chunks ?'II
BMHDSi ze& - 20';i
C~APSizc& MC\xC()~our%*3 + ((>laxColcur%*3) AND l)'ii
CAMGSize& 4S
BGDYSize& (I,,,
sterl,% /8) *Ra:c;Ler !'% 'f1dste r-1'%'ll
, FORMsize& ~-, Chunk-Length + 8 Bytes per Chunk-Header + By:-.es (IIII,BM") en
FORMS' zc& = BMHDS.i ze&+CMl·.PSize&+CAMGSj ze&+BODYSize&+36'll
'II
, ,OHM-Header 'll
ChunkS -~ IIFOR~-111fIT

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

Length& = xWrite& (Ha:odle&, SADD(ChunkS) , 4) 'II


'll
IF Length& <" 0 THEN'll
Dialog$ = "Write er-ror on FORM-Header!! ~ulI
C;01'O EndSa'JeS
END IF 'i1

, 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

IF Length& <= 0 THE~~


DialogS "Write error on BMHD-Chunk !!!"~
GOTO EndSave~
END IF ~
~
• CMAP-Chunk 'li
ChunkS = "Cf'AP"~
Length& xWrite& (Handlc&,SADD(Chunk$),4)~
Length& = xWrite& (Handle&, VARPTR (Cf'APSize&), 4) ~
~
FOR i%=O TO MaxColour%-l~
Colours% = GetRGB4%(ColorMap&,i%)f'
blue = Colours% AND 15'li
Colours% = Colours% - blue~
green = (Colours%/16) AND l5~
Colours% = Colours%-green*16~
red ~ (Colours%/256) AND 15~
POKE (ColorBuffer&+ (i%*3) ),red*16~
POKE (ColorBuffer&+ (i%*3)+1),green*16 ~
POKE(ColorBuffer&+(i%*3)+2),blue*16~
NEXT~
~
Length& = xWri te& (!landle&, ColorBuffer&, CMAPSize&) 'II
'II
IF Length& <= 0 THEN'!I
Dialog$ = "Write error on CMAP-Chunk I I ! "'II
GOTO EndSave'!l
END IF 'II
'II
, CAMG-Chunk 'II
ChunkS = "CAMG"'II
Length& = xWrite&(Handle&,SADD(Chunk$),4)~
Length& = xWrite&(Handle&,VAIWTR(CAMGSize&) ,4)'11
Modes& = PEEi<W(Viewport& + 32)'!I
Lengtr:& - xWrite& (Handle&,VARPTR(Modes&) ,4) 'II
~
IF Length& <= 0 THEN'!I
Dialog$ = "Write error on CAMG-Chunk !! !"'II
GOTO EndSave~
END IF '!I
'!I
, BODY-Chunk (BitMaps)'li
ChunkS = "BODY"~
Length& = xWrite&(Handle&,SADD(ChunkS),4)'!I
Length& = xWrite&(Handle&,VARPTR(BODYSize&) ,4)'11
BytesPerRow% = RasterW%/8'11
FOR yl = 0 TO RasterH%-l~
FOR b=O TO RasterT%-l'll
Adress& = BitPlanes&(b) + (yl*BytesPerRow%) 'II
Length& = xWrite&(Handle&,Adress&,BytesPerRow%) ~
IF Length& <= D THE~'!I
Dialog$ = "Write error on BODY-Chunk '!! "'II
GOTO EndSave'll
END IF 'II
NEXT'I
NEXT'll
'II
DialogS "SelVing OK"'II
'II
EndSave:'II

291
ApPENUlX B - THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

IF Har.dle& <> 0 THEN CALL xClose& (Handle&) 'll


IF Buffer& <> 0 THEN CALL FreeMem&(Buffer&,BufferSize&)'ll
CALL DialogBox(Dialog$,1,True,xlb%,y1b%,x2b%;y2b%,False)'ll
CALL DoDialog(n%,1,-1,-1,-:,-1,xlb%,ylb%,x2b%,y2b%,-1,-1,-1,-1) 'll
END IF'll
CLS 'll
GOSUB Make~l;enu'll
RFTURN'll

''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

InputBuffer& flu ffer&'ll


ColorBuffer& fluffer& + 120'll
'll
'I!
;FFFile$ ~ IFFFile$ + CHR$(O)'ll
Handle& ~ xOpen& (SADD (IFFFileS), 1005) 'll
IF Handle& ~ 0 THEN'll
Dialog$ ~ "IFF-File can not be opened!! !"'ll
GOTO EndLoad'lI
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\!

IF ChunkS <> "ILBM" THEN'll


Dialog$ = "Not IFF-formal!! !'I~
GOTO EndLoad'll
END IF'll
'II
ReadLoop:'ll
Length& ~ xRead&(Handle&,InputBuffer&,8)'ll
Chunkwinlen& = PEEKL(InputRuffer& + 4)'ll
ChunkS = ""S
FOR n% = 0 TO 3'll
ChunkS = ChunkS + CHR$(PEEK(InputBuffer&+n%))'ll
NEXT '!I
'!I
IF ChunkS = "BMHD" THEN , BitMap-Header 'II
BMHD = True'll
Length& = xRead&(Handle&,InputBuffer&,Chunkwinlen&)'ll
RDepth% P£EK(InputBuffer& + 8) '!I
Compression% PEEK (InpuLIlc:ffer& + lO)'ll
RWidth% PEEKW(InputBuffer& + 16)'ll
RHeight% PEEKW (InputBuffer& + 18) 'II
BytesPerRow% RWidth%/8'II
RMaxColors% 2 (RDepth%)'ll
A

'!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

FOR yl ~ 0 TO Rneight% -l~


FOR b ~ 0 TO RDepth% -l~
IF b<RasterT% THEN~
Adress& BitPlanes&(b)+(y1*BytesPerRow%)~
ELSE~
Adress& Buffer&~
END IF'll
NumBytes% O'll
'll
WHILE (NumBytes% < BytesPerRow%)~
Length& = xRead&(Handle&,InputBuffer&,l)~
Code% ~ PEEK(InputBuffer&)'ll
IF Code% < 128 THEN ' Code%-Bytes ta~e over'll
Length& ~ xRead&(Handle&,Adress& + NumBytes%, Code%+l)'ll
NumBytes% ~ NumBytes% + Code% + 1'll
ELSEIF Code% > 128 THEN ' Byte replicates'll
Length& ~ xRead& (Handle&,InputBuffer&,l) 'll
Byte% ~ PEEK(InputBu~fer&)~
FOR n% ~ NumBytcs% TO NumBytes% + 257 - Code%'ll
POKE (Adress&+r;%) ,Byte%'ll
NEXT 'll
NumBytes% ~ NumRytes% + 257 - Code%'ll
END IF~
WEND'll
NEXT'll
NEXT'iI
'iI
ELSE~
Dialog$ - "Unknown compression proccdure~! ~11<Jl
GOTO EndLoad'll
END IF'll
CALL Scroff'll
ELSE 'll
, "Unknown" Chunk-Typ'll
FOR n ~ 1 TO ChunkwJ.nlen&'i1
Lenqth& = xRead&(Handle&,InputBuffer&,l)'ll
NEXT'll
, Chunks have even numnber of bytes~
IF (Chunkwinlen& AND 1) ~ 1 THEN ~
Length& = xRead&(Handle&,InputBuffer&,l)'ll
END IF'll
END n'll
'll
, All Chunks read?'ll
IF (BMHD = True) AND (CMAP True) AND (Body .c True) THEN'll
GOTO LoadOK'll
END IF'll
'll
, Read ok, get next Chunk~
IF Length& > 0 THEN GOTO ReadLoop'll
~
IF Length& < 0 THEN 'll
Dialog$ = "Read error' '! "'ll
GOTO EndLoad'll
END IF 'll
'l!
IF (RMHD~Valse) OR (CM1U'=False) OR (Body~O) THEN'll
Dialog$ = "Not a 1l necessary ILBM-Chunks fOllnd I ! ! "'ll
GOTO EndLoad'll
END IF'll

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

CALL DialogBox("No Pr~nter",O,Truc,x1a%,yla%,x2a%,y2a%,False) 'lI


CALL DialogBox("Printer OK",2,False,xlc%,ylc%,x2c%,y2c%,False)'ll
CALL DoDialog (n%, 0, xla%, yl a%, x2a%, ya2%, -1, -1, -1, -1, xlc%, ylc%, x2c%, y2c%) 'II
CLS<JI
IF n% <> a THEN'll
Modes% PEEKW(Viewport& + 32)'lI

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

Cl,LL AddPort (MsgPort&) 'lsit Port'Jl

ioRequest& = AllocMem&(6 4 ,Fldgs&)i


IF ioRequest& =. 0 THEN'TI
Dia~og$ = I'No ioRequest !! !II~
GOTO EndPrinter3'II
E~D IF'li
'11
POKE(ioRequest& + 8),5 'l!
POKE(ioRequest& + 9),0 'll
POKEL(ioRequest& + 14), 11sgPort&'l!

NamS = "pr inter.device"+CHR$(CJ)S1


P ri nterE ,ror& = OpenDevice& (SADD (Nam$) ,0, ioRequest.&, 0) 'll

295
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

~F PrinterError& <> 0 THEN'll


Dialog$ "No Printer ?!?n~
~

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

PrinterError& ~ DoIO& (ioRequest&) 'll


IF PrinterError& <> THEN'll°
IJj a logS ~ "DumpRPort Error ~"+STR$ (PrinterError&) +" !! f "'ll
GOTO EndPrinter'll
END IF'if
'll
CS'lI
DialogS = "Hardcopy done"'ll
'lI
FCldPrin:er: 'll
CALL Clos€Device(ioRequest&)'ll
'it
El'""ldPri ntJ'::L2: ~
POKF(ioRequest& + 8), &HFF'll
POKE'.. (ioRequest& + 20), -I'll
POKEL(ioRequest& + 24), -I'll
CALL FreeMem&(ioRequest&,64)'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

CALL DialogBox("Cancel,0,True,xla%,yla%,x2a%,y2a%,False) 'll


CALL DialogBox("Load",2,False,xlc%,ylc%,x2c%,y2c%,False)'ll

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)'![

as ~ "Actual number ot objects "+STR$(NumberK)'II


CALL Prl.nLIt (a$, 120, False) 'IT
'IT
GOSUB Pallsc'IT
'IT
CLS'![
GOSDB MakeMenu'![
I~ETU;ZN<JI

''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

PRINT" Projection point"'![


PRINT '1 H Main pointll<j'[

PRINT" W enter angJe"'![


PRINT " Cursor keys => rotate"'![
P'UNT " Rotate (SHIFT, CONTROL) '''ll
'![

297
ApPENDIX B- THE TRACER PROGRAM AMIGA 3D GRAPHIC PROGRAM:'vUNG

PRINT " D: spacing for mClin point "'IT


PRINT" +I-I*!/ Enlarge/reduce spacing (SHIFT'i-)"'
'IT
PRINT " V Enlarge"'iI

PRIN':' " Load Objecc"'!!


PRINT" S ave Object"'!!
l-':~INT II M erge ()bject"~

PRINT" New, clear all oblect:s"'!!


PRIN~ I, B Screen saverl'~

PRIN':' " Q "> ProgriL~ end (Quit)" '!!


'!!
PRINT" Fc => Editor l02d"T
'!!
PRINT "F9 ~> Shadows initLlliza~ion"'!!
PRINT" FlO -> Shadows"'ll
PRINe;' .. <SPACE> => Show picture"'ll
PRINr~' " C lear screen II; <Jl

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

=F RND<. 'l THEN'il


CALL WritePixel&(RastPort&,x%,y%)'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

LOCATE 11,1 'II


PRINT" Foreground pen (]I.Pen) : ";'11
a~l\Pen%'lf
CALL Formlnputlnt (a,JO!,O:,CSNG(MaxColour%-I))'ll
]I,Pen% = a'll

LOCATE 12,1 'lI


PRINT" Background pen (BPen) : ";'11
a ~ BPen%'1l
CALL Formlnputlnt (a,30!,O',CSNG(MaxColour%-1))'ll
BPen% = a'll
'll
Xpattern% = Xpattern% MOD (NumberPatternS%+NumberPatternX%*2+1)'ll
'll
IF Xpattern% > NumberPatternS% THEN'll
CALL ExtendedFill (0,0, RasterWI%, RasterHI %, PatternHX (Xpal tern%-
NumberPatternS%) ,0' , I' ,APen% ,BPen%) 'll
El.SE'll
CALL Standardfill(O,O,RasterWl%,Rast<?rHl%,PatternHS(NumocrPa~ternS%-
Xpattern%) ,APen%,BPen%) 'lI
END IF'!'
CLS'll
Hg = True'll
END IF'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

c. The Editor Program


The following is the complete listing of the editor program found on
the optional diskette. The example program that follows contain some
BASIC lines that must be entered on one line in AmigaBASIC even
though they appear on two lines in this book. Formatting the program
listings to fit into this book has caused some long BASIC lines to be
split into two lines. To show where a BASIC line is actually ended, an
end of paragraph character (~) will be used. This is not to be entered, it
only shows when the <Return> key should be pressed in the BASIC
editor. For example, the following line is split into two lines in this
book but must be entered as one line in AmigaBASIC:

WinDef NWindow, 100, :0O, 460, :50, 32+64+512&, 15&+1096&,


0&, Title$'ll

The ~ shows the actual end of the BASIC line.

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

qrJ~iT ~5).295T! 1 C{)r~vc;-s: anLs -


r ad ! - . 01 -; ~ 5 J 1 COflvpr SiOIl cunst a;~ts - dc.'qrQe Lu

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]

quitO 'Initialize end flag~


max ~ =--Oc:rr
moy:=O'll
mOL ~:--CSI
kfn,c-1 .c
'Set free pointer to st~r· , "
matfree=l'll
rp&=WINDOW (8) 'Detc,minc cc;'~s()r width and height'll
cw%=PEEKW(rp&+60),
ch%=PEEKW(rp&+58),

,
file$="objects/" 'contains all t'ileClames, used by disk oper at i or:s":

DECLARE FUNCTION all ormem& ! .TBRJlYY , addi lion 0 f allocmem Clnd f


LIBRARY dir$+"exec.library" 'al :DC- and freemem added'll
LIBRARY dir$+"intuition.! ibrary" 'sct- and clear~pointer <loGed'l

,
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

,CALL in.i tmdus~[

CALL actlwi th4 'Menu with 4 active'II


CALL deacti v5 'Menu 5 deactivat.edS

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

CALL refresh 'redraw screen'll


END IF'll
IF a=109 AND mat=l THE\'j!
CALL matinp.ct (matpt,) 'Mater lcl i inp ;:, C
END IF 'll
MENU ON'll
RETURN'li
qr

1*******************~

'** READ MENU **'ll


I**************k****~

'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

,** OUTPUT '*'11


'*** *** ** * * * -I< *~l

SUB showel,,", (pi:, 0) STATIC'l[


'TA,;K : data output of '2"ement prr'll
'FARAMETER:=>ptr pointer to the specit:ed clementCJI
SHARED k! (), typ$ () ,emptyS, grad!, rad I 'll
LOCATE i,l'll
FOR i=l TO 7'll
PRINT empL.yS?:
NEXT i'l[
LOCATE 1, 1 'J:
PRINT "bCldy : "S"
CALL putreal (ptr'l', 1,8, ,J) 'll
lyp~INT (k! (ptr, 0,0) ) 'IT
IF ptr><O THEN'll
LOCl,TE 1. I4'll
PRINT typ$(typl'll
LOCATE 2,"']1
PRINT Hvis~<::lc :";Sl

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

LOCATE Z,s 'clear specified range~


PRINT SPACE$(inplen ) ~
LOCATE z,s 'display the string~
PRINT MIDS(s$,l,inplen )~
END SUB~
~
~
SUB putreal(i',z,s,inplen )STATIC~
'TASK : Di splay real value of predetermined lengLh,[
'PARAMETER:;>i! the real value~
Z line~
s column'lI
inplen Length of output window~
CALL conrealstr(i!,s$)~
CALL putstring(s$,z,s,inplen )'J[
END SlJB'lI
~
SUB put3real(il!,i2!,i3!,z,s,inplen )STATIC~
'TASK :display 3 Real values of certain length'lI
'PARAMETER:=>il!,i2!,i3' the real values~
Z line~
s column~
inplen Length of the output window~
CALL con3realstr(il',i2',i3',i$)~
CALL putstring(i$,z,s,inplen )~
END SUB~
~
I*******************~
'** CONVERSIONS **~
I*******************~
~
SUB conrealstr (i!, is) STATIC'I[
'TASK :convert real value into string~
rounded to 3 decimal placesQ[
'PAFp~~TER:=>i! the real value~
<=i$ thp string'
i$=STR$ (i ! ) 1[
j!=FIX(1000!*i!+.5*SGN(i!) I/lOOO! 'round~
i $ =STRS ( j , I ~
IF ABS(j'I>O AND ABS(j'l<l THEN 'if O<j!<l 0 insertcd~
i$;MID$(i$,1,11+"0"+MIDS(iS,2,LEN(i$) )'lI
END IF'lI
IF j' >=0 THEN 'i f O<=j' truncate first place~
i$;RIGHT$(i$,LEN(i$)-l)'I[
END IF~
END SUB'J[
'lI
SUB constrreal(i$,i!) STATIC'J[
'TASK : convert string into real value'lI
'PARAMETER:;>i$ the string~
<=i! the real value~
i$ if conversion error i$;""~
i!=VAL(i$)~
IF i'>~O THEN'I1
IF i'>D AND i'<l ThEN'lI
is='' "tRIGHTS (is, LEN (is) -1) 'insert space and cutoff ~q;
ELSE ~
i$=" "ti$ I insert space<JI
END IF~
END IF~
j!=i!-FIX(i!*1000!)/I000! 'round 'lI
IF i$><STR$(i!) OR j!><O THEN 'Error ?~

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**************~

,** GRAPHICS **'


I**************~

'Routines to display graphics in the projection windows'll


'the following routines are virtually identical'll
'to one another, hence the lack of comments'll
'll
SUB drawplane(ptr) S7ATIC'll
SHAPJ,D k! () 'IT
mx!=k! (ptr,l,O)'IT
my!=k' (ptr,l,l)'IT
mz'=k' (ptr,l,2)'IT
ax'=k! (ptr,2,O)'IT
ay'"k! (ptr,2,1)'ll
az!=k! (ptr,2,2)'ll
bx!=k! (ptr,3,O)'ll

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

CALl, drawl.im: (bx! -trnx', b7' +mz!) 1!


CALL dr~wll~e(rnx',mz')
WINDOW ClJT?UT 3'll
CALL sCLpoint(my',mz:I'
CALI drawlir,(' (ay' +my', ac' +mz I) 'll
CALL drawl ine (by 1 +rny!, bz 1 +mz I) 'll
CALL drawl i ne (my I , mz!)
WINDCW OUTPUT ~'lI
END Slid'l!

SHARED 1(1 ()'l!


mx!=k' (ptr,l,O)'il
rny'=k! (plr,l,l)'ll
mz:::::k! {ptr,1,2)<[l
ax!~k! Ipt_r,2,~)'ll

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

CALL drawl ine (bx; +mx!, by' +my! ) 'lI


CALL drawl ine (mx' ,my' )
WINDOW OUTPUT 2'lI
CALL setpoint(mx',mz')'lI
CALL drawline (ax!+mx', az!+mz') S
CALL drawline (ax !+bx! +mx', az'+bz I +rC,L ' ) 'li
CALL drawline(bx'+mx',bz'+mz')'lI
CALL drawline(rnx!,mz!) ~[
WINDOW OUTPUT 3'lI
CALL set~':lint (my' ,mz! ) 'lI
CALL drawline(ay:+my',az'+mz!)'lI
CALL drawline(ay!+by'+my:,az'+bz!+mz!)'lI
CALL drawline (by! +my!, bz! +mz' I 'lI
CALL drawline(my',mz!) 'IT
WINDOW OUTPUT 4'IT
END SUB 'lI
'IT
'lI
SUB drawc~rcle(ptr) STATIC'lI
SHARED k' () ,pi2''li
mx'~k! (ptr,I,O)'ll
my'~k' (ptr,l,I)'lI
mz ,~!-! (pt r , 1,2) 'll
ax!~k! (ptr, 2, 0) 'lI
ay!~k! (ptr, 2, 1) 'll
az!4! (ptr,2,2)'ll
bx!~k! (ptr,3,O)'lI
by!~k! (ptr, 3, 1) 'll
bz '"k! (ptr, 3, 2) 'll
WII'DOW OUTPUT I'll
CA;~L drcwellipse(ax!,ay',bx',by',lTJ(!,my',O',pi2')'ll
WI N[)OW OU~'P UT 2 'll
CALL drawellipse (ax! ,az: ,ox! ,bz~ ,mx~ ,mz!, 0; ,pi2!) 11:
WINDOi,/ OUTPUT :J'lI
CALL drawellipse(ay!,az!,by',bz!,my',mz!,O!,pi2')'ll
WINDOW OUTPUT 4q[
END SUB '1!
'll
'll
SUB drawcrseg(ptr) STATIC'll
SHARED k I () 'll
mx'~k! (ptr,I,O)'ll
my'~k! (ptr, 1, 1) 'll
mz!~k! (ptr,I,2)'ll
ax!=k! (ptr, 2, 01 'Ii
ay!~k! (ptr,2,1)'ll
az!~k! (ptr,2,2)'ll
bx'~k' (ptr,3,0)'ll
by!~k! (ptr,3,1)'lI
bz'=k' (pLr,3,2)'ll
sw:=k' (ptr,5,0)'lI
ew;=k! (ptr,S,I)'il
WINDOW OUTPUT l'll
CALL drawell ipse (ax! lay: ,DX! ,by! ,~: ,my!, 5''';: ,ew!) 11
CALL setpoint (ax! *COS (sw') +bx' 'SIN (sw: ) tmx', ay' 'COS (sw: ) +by: *S:N (sw' ) ~rIY: ; 11
CALL drawli:1e (rnx' ,my') 'il
CALL drawcine (ax' *COS (ew') +bx! *S I N (ew') Imx', "1" *C-)C; (e'N: ) 1 by' '';IN (ew' j ':ny:) "
WINDOW OUTPUT 2'1i
CALL drawe:lipse (ax: ,az' ,bx!, bz! ,mx' ,mz I, sw', ew:) 'lI
CALL setpoint (ax' *COS (sw!) +bx' *SIN(sw' )+mx! ,az' *COS(sw:) ,loz' *STN ,,;w: I'm,'.:) '!!
CALL draw~ine (rnx' ,mz!) 'll
CALL draw:ine(ax!*COS(ew!)+bx!*SI~(cw!)+ITx!,az!*COS(cw!) i

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

CALL dr awell ipse (ax! * r i ! , d Z ! * r i ! , bx! * ri ~ , DZ ! * ri ! , rnx : , mz ! , sw ! r ew! ) q:


CALL
setpoint (ax' * r a! *COS (sw! ) t bx' * ra ! *SIN (sw ' ) +mx ' , a L ! * ra! 'COS (sw ' ) +bz ' * ra ' * SIN (sw! ) tm
z!) 'll
CALL
drawline(ax'*ri !*COS (sw!) +bx' *ri '*SIN(sw') +mx', az' *ri' *COS (sw') tbz '*ri! *SIN (sw! )+mz
! )~
CALL
setpoint (ax' * ra' *COS (ew!) tbx! *ra' 'SlN (ew') +mx', az' *ra' *COS (ew' ) +bz' * ra' *SIN (ew' ) +mz
!) 'll
CALL
drawline(ax!*ri'*COS(ew!)+bx!*ri!*SIN(ew')t~x',az'*ri'*COS(ew')tbz'*ri'*SIN(ew')+mz
')'ll
WINDOW OUTPUT 3'll
CALL drawellipse (ay! * ra! I az! * ra! I by! * ra! , bz! * ra! , my! ,mz! , SW! , e'w! ) <JJ
CAL:"" drawell ipse (ay! * ri ! , az ! * ri ! , by! * ri ! , bz ! *:-i ! , my! , mz ! , sw! , e',..' ! ) 'il
CALL
setpoint(ay!*ra!*COS(sw!)+by!*ra!*S:N(sw!)+my!,az!wra!*COS(sw~ )+bz!-ra!*SIN(sw! )+mz
!) 'l!
CALL
drawl ine (ay! * ri ! *COS (sw ! ) +by' * ri ! * SI N (sw! ) +C1y , , az' * r i ' *COS (sw! ) tbz ! * r j ! * SIN (sw: ) +mz
')'ll

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

CALL drawl ine (my' -by', mz' -bz') 'll


WINDOW OUTPUT 4'lI
END SUB 'lI
'lI
SUB draweyl(ptr) STATIC'll
SHARED k! (),pi2!'lI
mx!=k! (ptr,l,O)'ll
my'=k' (ptr,l,l)'ll
mz!=k' (ptr,1,2)'lI
ax!=k' (ptr, 2, 0) 'll
ay'=k! (ptr,2,1)'lI
az!~k! (ptr,2,2)'lI
bx!=k! (ptr, 3, 0) 'll
by'=k! (ptr,3,1)'ll
bz'=k! (ptr,3,2)'lI
ex!=k' (ptr,4,0)'ll
cy!=k! (ptr, 4, 1) 'll
ez!=k! (ptr,4,2)'II
WINDOW OUTPUT 1'lI
CALL drawellipse (ax!, ay! ,bx! ,by' ,mx! ,my! ,O!, pi2!) 'lI
CALL drawellipse (ax!, ay! ,bx' ,by! ,mx! +-ex! ,r'y!+ey', 0' ,pi2') 'lI
CALL setpoinl(ax'+mx!,ay'+my')'lI
CALL drawline (ax! +ex! +mx' , ay' +ey' +my! ) 9J
CALL selpoint(-ax!+mx',-ay!+my!)'lI
CALL drawline (ex' -ax! +mx! , cy! -ay !+my! I 'lI
CALL setpoint (bx! +mx! , by' +my') 'lI
CALL drdwline (ex'+bx' +mx! ,ey' +by!+my' I 'lI
CALL setpoint(-bx'+mx',-by'tr'Y')'lI
CALL drawline (ex! -bx' +mx' , ey! -by' +my! ) 'lI
WINDOW OUTPUT 2'II
CALL drawellipse (ax!, az! ,bx' ,bz' ,mx! ,mz', 0' ,pi2') 'lI
CALL drawellipse(ax',az',bx!,bz',mx!+ex',mz'tez',O',pi2!1'lI
CALl. setpoint (ax! +mx! , az' +mz' I 'lI
CALL dra·..,line (ax! +ex! +rnx!, az' +-ez' tmz' I 'lI
CALL seLpoint (-ax! +mx! f -az! +mz!) 'TI
CALL drawline(cx!-ax!+rnx:,cz!-dz:+mz!)1i
CALL setpoint(bx'+mx',bz'+mz!I'lI
CALL drawline(ex!+bx!+~~!,ez!tbz!+mz!)'lI
CALL setpoint(-bx'+mx!,-bz'+mz')~
CALL dra,;l ine (ex' -bx' +:nx' , ez' -bz' +m:o' I 'll
WINDOW OUTPUT 3'lI
CALL drawellipse(ay' ,az' ,by' ,bz' ,my' ,mz' ,0!,pi2'1'lI
CALL drawellipse (ay' ,a7' ,by' ,bz! ,my' + ey' ,mz 'tez' , 0' , pP' I ~l
CALL setpDint (ay! +my' , ilZ' tmz' ) 'II
CALL drawline(ay'+cy!+my',az!+ez'+mz!I'lI
CALL setpoint (-ay' +my!, -az! +mz' 1'lI
CALL drawline(cy!-ay!+my!,cz!-az!+mz!)i
CALL setpoint(by!+my!,bz'+mz!I'lI
CALL drawline(ey!+by!+my',cz!+bz'+rnz!I'll
CALL setpoint (-by' +my' ,-bz' 1m2! ) 'll
CALL drawline(ey!-by! tmy',ez!-bz'+mz!I'll
WINDOW OUTPUT 4'll
END SUB 'll
'll
SUB draweylseg(ptr) STATIC'll
SHARED k' () 'lI
mx'=k' (ptr,l,O)'ll
my!=k' (ptr, 1, II 'll
rnz!=k' (ptr,1,21'll
ilx'=k! (ptr,2,OI'lI
ay!=k' (ptr,2,11'll
az!=k' (ptr,2,21'lI

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

x:C"ax:*cOS(a:pha!)+bx!*SIN(alpha!)+mx' 'compute new point'l1


y! =ay! *COS (dpi,a') +by! *SIN (alpha') +rry; '1'
CALL drawl ine (x' ,y' ) 'draw line from old point to new~
N"EXT i'll
lO:;\JD SUB'll
'II
SUB set point (x' ,y: ) STATIC'll
I TASK : set point in current output windowcn
'PARAMETER:=>x:,y! Point coordinate'll
SHARED mx!, my!, mz!, factor! ,xcor::'fac!, colour'lI
sw i ndow=\rJ 1 NDOW ( 1 ) <j[
IF swindow=l THEN~
LINE ((x!-mx!) *xcorrfac; *far'::'c:.or!, (my! -y! )*facto['!) - ((x!-
!nX!) *xcorrfac! *factor!, (cry! -y') *factor!) ,coloer'!!
ELSE'll
IF swindow=2 THEN'll
LINE ((x'-cex') *xcorrf"';'*factor', (mz '-y') *factor') - ((x'-
rnx! ) 11 xcorrfac! * f dc,,,or!, (rnz! -y: ) * factor! ) , col DurcrI
ELSE'll
IF swindow c=3 TEEN~
LINE ((my! -x: ) *xconfac' * factor!, (mz' -y' ) * factor ') - ( (my!-
x! ) *xcorrfac' *factor! , (mz I -y') *f actor') ,colour'll
END IF'll
EN::: IF'll
END IF'll
END SUB'll

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

IF File$><llll THEN 'if file$=l1" then cancellfl


OPEN File$+".MAT" FOR OUlb~ AS I'll
WHILE mfrom!<mto! AND mat' (mto',8)~-lS
mto!~mto!-l'll

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

FOR ptr=mfrom! TO mto!~


IF K! (ptr, 0, 0) ><-1 TP.F:1\ 'forget blank elements'll
FOR i=O TO 5'li
PRINT #1,k' (ptr,i,O);",";k' (ptr,i,l);",";k' (,J>c,i,2)11
NEXT i ~
END [F'li
NEXT I'tr'li
CLOSE I'll
KILL File$+".LIST.info"'ll
END IF'll
WINDOW CLOSE 5'll
WINDOW OUTPUT 4~
END SUB
~
'li
l**********************~
'** TRANSFORMATION **'ll
I**********************~
'll
SUB rotation (ptr) STAT[C'li
'TASK :rotate body by three angles'll
'PARAMETER:=>I'tr I'oi.nts Lo the body'll
SHARED k' (),grad',rad',min',max''ll
IF ptr><O THEN'll
WINDOW 5, "Rotation", (0, :29) - (314, 1701,4, I'll
vx!=grad!*vx''li
vy! =grad! *vy! 'll
vz' =grad! *vz! 'li
LOCATE 2,n
PRINT"V :"~
PRINT"q<uit,d<o,e<opy&do :"'li
CALL put3real(vx!,vy!,vz!,2,4,26)'ll
CALL get3real (vx! ,vy' ,vz!," ",2,4, 26,min' ,max', ~I 'lI
CALL getstring (a$," ", "qed", 3,21,1) 'li
vx!=rad!*vx!~
vy!=rad! *vy' 'll
vz! =rad' *vz' ~
WINDOW CLOSE 5'll
WINDOW OUTPUT 4'll
IF a$><"q" THEN'll
IF a$="e" THEN'll
CALL eopy(I'tr)'ll
END IF'll
IF k' (ptr,0,0»=20 THEN'll
til=4~
ELSE'll
til=3'll
END IF'll
FOR i=2 TO til'll
a' =k! (ptr, i, 0) *COS (vz ' ) - k' (I't r, 1, 1 I * 51 N (vz ' I 'll
b!=k! (I'tr, i, 0) *SIN (vz!) ik' (ptr, i, 11 *cc)S (vz') 'll
e!=a!*SIN (vy!) -k! (ptr, i, 2) *COS (vy') 'II
k! (ptr,i,O)=a'*CC)S(vy~)+k' (I'tr,i,2)*SIN(vy'l':i
k! (I'tr, i, l)=c' *SI1\ (vx') +b! *COS (vx') 'li
k' (I'tr, i, 2) =b' 'SIN (vx') -c' *COS (vx') 'll
NEXT i'll
CALL showe1em(I'tr) 'll
IF k' (I'tr,5,2)< THEN':i
CALL drawelem(I'tr)'ll
END IF 'll
ELSE 'il
WINDOW CLOSE 5'11

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~

0] rl=pt 1:" pcinter:9i


C!",1 -::~'w'el".,.'-' (rr'.:-) 'credtf' (lew space~

'~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

'PAR}\'lliTi::J,:~>ptr pOlnl" '.-


Sl-iA"ED k' () , k t ree'/i
IF ptr><O THEN 'not the 51 ~r~jng
FOE i=O TO S 'Delete'll
FOE j=O TO 2'll
k! (ptr,i, j)eD'll
NEXT j'll
tiEXT i 'll
k I (ptr, 0, 0) e._]
k' (~'~-.rr::I,l) -<~:

r~\JS SUB<jf
<IT

I TASK : (J« 1C','T'(_'~:: 7,_0

'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

SUB set factor (f!) STATIc91


'TASK : read the new si zing factor'll
'PARAMETER:=>f! old factor'li
<=[! new factor'll
CALL getreal(f!," ",1i,B,8, .015625,64')S
END SUB'll
'li
SUB factor7([')STATIC'll
'TASK :C':;] tiply [actor' /\~
'PARAMETER:->i' old factcr~
<=f! new factor'li
IF f~<=32 THEN91
['=f'*291
CALL putreal(f!,ll,8,8)'i1
END IF 91
'.'ND SUB91
91
SUB fact orhalf (f ~ ) STATIC'll
'TASK :multiply factor! with O.:''ll
'PARAI--:ET'.'R:=>f' old factor'll
<=f' new factor'
IF 1/f' <~32 THEN91
f!=f'*.S'll
CALL p"tre31([~,ll,8,8i":
END IF'll

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

WINDOW CLOSE. ~)q;


WINDOvl OUTPUT 4'11
IF k' (p',O,O»<-l THEN'I1
IF p'><ptr THEN'J[
ptrcp''J[
C!\;"~ showelem (ptr) g
E~,;~'; IF qr

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

CALL dral"elem (pt [) 'TI


a $=" flSi
WHILF 2$--=:11 nqr
a$-- IN':{LY:,~:
WENDS
cclour=i<fI
CA1~L drawelem{ptr)~
END IF'll
END IF'll
END IF 'll
~,NDIF (j!
t~ND SUB'1I
'!l
,;UB refresh STAT I:::'ll
1 TASK :Ref-resh screcn~l
SHARED k' () ,knum'J[
FOR i=l TO 3'J[
,,1:NDOI'; OUTPUT i'll
CLS~
NC:XT i'J[
POR i=l TO k:)lJffi~

335
ApPENDIX C- THE EDITOR PROGRAM AMIGA 3D GRAPHIC PROGRAMMING

IF k! (L,5,2)=1 AND k! (i,O,O»<-l THEN'll


CALL drawcle'l1(i)'II
END IF'll
NEXT i 'lI
WINDOW OUTPUT 4 'II
END SUB'll
'll
SUB drawelem(ptr) STATIC'll
'TASK :draw current body'll
'PARAMETFR:=>ptr points to the body'll
SHARED k! (),mx',my!,mz"ll
IF ptr><O THEN'lI
CALL busymouse'lI
typ=k! (ptr,O,O)'lI
IF typ=O TfI:::N'll
CALL drawplane(ptr)~
END IF'll
I t typc-cl THEN'll
CAI.L drawtrianglelpt~)'ll
END IF'll
IF typ~2 THEN'll
CALL drawparnll (ptr) 'Il
END IF'll
IF typ=3 TH"N'll
CALL drawcircle(ptr)'l!
END IF'II
IF typ=~ THFN'll
CI\LL drawcccseg (ptr) 'll
END IF'll
IF tyV'S THEN'll
CALL drawcrarc(ptr)'ll
END IF'll
IF typ=10 T;,EN'll
CALL drawsphere(ptr)'ll
END IF'll
IF typ=20 Tm:N'Il
C.l\LI. dra\·!:::,_yl (ptr) qr
END IF'll
IF typ=21 THEN'lI
CALL drawcylseg(pLr)'ll
END IF'n
IF typ=22 THEN'lI
CALL drawcone(ptr)'ll
END TF'lI
IF tYF=24 THEN'll
CALL d~awspheriod(ptr)'lI
END IF'Il
CM~L lazymo\lse'l!
END T;<J;
;·:;;D SUIl 'll
'lI
SUB getelem (pt r) STATIC'll
'TASK : Read the neceSS,l[Y body data'll
't'ARAW,TER:pt.r POlrlts tD the specified body'!!
SHARED k' () 'lI
typ=k! (ptr,O,O)'lI
IF tYD<~3 AND ptr>O THEN'll
CALL getpldne (ptr)'ll
END IF 'll
IF typ=4 THEN'll
CA~L getcrseg(ptr)'ll
END j_~-'~

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

MENU 2,0,1, "Body 1l<JI

MENU 2,1,1, "Plane "'ll


MENU 2,2,1,"Triangle "'ll
MENU 2,3,1,"Parallelogram "'ll
MENU 2,4,1,"Circle "'ll
MENU 2,5,1,"Circle segmentllCJ[
MENU 2,6,1,"Arc "'ll
MENU 2,7,1, "Sphere "91
MENU 2,8,l,IICylinder "91
MENU 2,9,1, "Cylinder seg. '''i!
MENU 2,10,1,"Cone "'ll
MENU 2,11,1,"Spheroid "'ll
'll
MENU 3,O,1,"Disk "'ll
MENU 3,1,1,"Load List"qr
MENU 3,2,1,"Load Mat "'ll
MENU 3,3,1,"S;)vc List"ljI
MENU 3,4,1, "Save Mat "'ll
'll
MENU 4,O,1,"Operations "'ll
MENU 4,1,1,"Left L"'lI
MENU 4,2,1,"Right R"'lI
MENU 4,3,1,"Segment "'lI
MENU 4,4,1, "Factor "en
MENU 4,5, 1,"Factor*2 *"'lI
MENU 4,6,1,"Factor/2 /"'ll
MENU 4,7,1,"Mat.cditor "'ll
MENU 4,8,1,"Refresh AR"'lI
MENU 4,9,1,"Show s"'lI
MENU 4,lO,1,"Lines "'lI
MENU 4,11,1,"Quit "'lI
CALL lazymouse'll
END SUB'll
'lI
SUB entactl!.>;i th4 STATIC<n
I TASK :de."1ct- iV,J_~f-=- MENU
CALL busymouse 'IT
'lI
MENU 1,O,O,"Transform "'lI
MENU 1,1,1,"Rotation "'lI
MENU 1,2,1,"Translation "'lI
MENU 1,3,1,"Enlargc "'lI
MENU 1,4,:,"Copy "'1'
MENU 1,5,1,"Delete n AD"'ll
MENU 1,6,1, "Correction "K"ll
'll
MENU 2,0,0, IIHody "<jI
t'1ENU 2,l,1,"Plane II'll
MENU 2,2,1,"Triangle "'ll
MENU 2,3,1,"Parallelogram "'lI
MENU 2,4,1,"Circle "'ll
MENU 2,5,1,"Ci:ccle segment"'lI
MENU 2,6, J, "Arc "'lI
MENU 2,7,1,"Sphere
MENU 2,8,1, Cylinder
Ii
"'ll
~NU 2,9,1,"Cylinder seg. "'ll
HENU 2,lO,1,ncone "'lI
r1ENU 2,11,1,"Spheroid "'II
'll
MENU 3,O,O,"Disk "'ll
MENU 3,1,1, "Load List"'ll
MENU 3,2,1, "Load Mat "<[[

338
ABACUS ApPENDIX C - TilE EDITOR PROGRAM

MENU 3,3,1,"Save List"'ll


MENU 3,4,1,"Save Mat '''lI
'll
Mt~NU 4,O,C,1I0perations liT;
MENU 4,1,1,"~ft L"'11
MENU 4,;/,1,"Right R"'ll
MENU 4,3,1, "Segment 1191
MENU 4,4,1,HFactor lie!
MENU 4,5,1,"Factor'*? '/<:lIqr
MENU 4,6,1, "Factor/,' /"'li
MENU 4, 7,1,"Mat.editor "<]I
MENU 4,8,l,"Refresh AR"'ll
MENU 4,9,:,"Show S"'ll
MENU 4,10,1, "Lines "'ll
MENU 1J,11,l,"Quit lien
CALL lazymollse'll
ENO SUB'll
'IT
SUB akt5 STATIC'
'C'ASK :activate Menll 5'11
CALL busyrnollse 'II
MENU 5,0, l,"Mal.editor "'ll
MENU 5,1,1, "Left L"'ll
MENU 5,2, ~,"Right R"'ll
MENU 5,3,l,"Oelete 'O'''ll
ME:NU 5,4,1, "Correct ion~""'ll
MENU 5,5,1,"Material M"'ll
MENU 5,6,1, "Quit "91
CALL lazymcllse'll
END SUB 'll
'll
S';3 deacti v5 STATIC'll
'TASK :deactivate Me~u j'll
CALL bllsymOlJSe qj
MENU 5,0, D, "Mat.edi "'!i
MENU 5,l,O,"Left L"'lI
MENU 5,2,O,"Right E"'ll
MENU 5, 3, ,,~,', "DeleLe AO"'ll
MENU S,4,O,"Corr-ection"'K"qr
MENU 5,S,';:,"Material M"CJI
MENU 5,6, D, "Quj t "qj
CALL lazyrnollse'II
,',NO SUB 'iI
(IT
r********~***~'t:**'t:****~

I ** ~:A rEP IAt-ED 1 TOP "*<JI


I.'t:**********'t:********~

SUB mdt,.eddy STATTCq[


'Tl\SK fiqurc window for rTkJ.Lerial ~~or91
SHl\I~.~=!.~ rra:_ptr, mat., nrl%,nr2%, nr3%, nr4%, ::::S%, nr6%(TI
CALL e~~t~c~lwlt.h4~
CALL akt5'lT
Clat=l'II
WINDOW 5, "Material-;-'~d'..~or", (J, 85) - (314,1 ,~6, -!.Si
CALL shm.;rnat ('1'.at,p:_ c) 'i:
CALL deleteqadget (n: :.%) 'act 1 rn',Jst be deactivateu'Si
CldJ, deletegadget (nrn) q[
cr,LL deleteqddget (nr3%) 'lI
CALL deletegadget(nr4%)'lI
CALL deletegadqet(~r5%)'II
CALL de let.egiJ(jqr:t (n~6%) 'II
:~~:JD SUB<f{

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

SUB matinput(matptr) STATIC'll


'TASK :See corresponding rc;utine for the body 1ist~
SHARED mdt' () 'II
CALL ne'.-Jmat (matpLr) 'II
CALL getmat(malptr)'ll
END SUB'll
'I!
SUB getmat(matptrl STATIC'ii
'TASK :SE-?'2 correspondin'J routine :or the l:;.ndy .lls:-.1[
SHlIRE;) mat' () ,gadg"t% () ,nrl %, nr2%, n d%, nr4%, nr5%, nr6%~1
CALL showmaL(matptr)'ii
WHILE gadget%(nr6%,4»<8~
P~~LFTT~;~ 2/gaGgc~.%(nr~%,'1)/lO:),CJ,dget%(i.I/%,4)/~ ,qadqet {nr-:3~i,/])/lOOqr

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

Sf-lAREC mat! () ,r:rl%,nr2%,r.r3%,nr~%f'lr5%,n.':E'>Sl


CLSqr
PRINT "Material:"'Il
CALL pell:ceal (l".aLpec.r*l', 1,10,10) 'j!
IF matptr ><0 THEN'!]

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****~*****~**~~

,~* GADGETS **'ll


'***************~
SUB checkqadqe~ STATlCS
, TASK :test whc~her a g2dget has bQer1 clic~(!d
SHARED gadset% () ,g3dqet.s% () S'.
dummy~MOUSE(O)'ll
dx--:v1()US2(3) ![vj()'~se F'osiLiongj
c1.y~MOUSC(4)1l
i= O'lI
WHILE 'search entire array'll
l<~lO
x%~gadget%(i,O) 'get values from array!
y%=gildget%(i,l)'ll
h%~qadget%(i,2)'li
1%=gadget%(i,3)'lI
valu%~gadget%(i,4)'II
wind%~gadqet%(i,5)~
yes%=gadget%(i,6)'ll
nonc%=qadget% (i, 7) 'Mouse ever ,!adgeL ?'ii
IF x%<ax AND x%+l%>ax AND y%<ay A~JD y%+h%>ay Al~i.J x%.->--,·Q AhD hlNDOW (0) ::-·wind% THEN1t
old~WINDOW (1) 'reserve output wi ndow'll
WINDOW OUTPUT \.;j nd% Idel etC' old slider cir , ..; :-;~",..'
IF yes%=-l THEN'll
=--'INE: (val~%+x%+l,y%+l)-(vall~%+x%j.:,y%j~%-'l) rO~:

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

LINE (x%,y%)-(x%+l%,y%+h%) ,O,bf~


PUT (x%,y%),gadgets%(yes%)~
END IF~
ELSE ~
IF valu%~l THEN 'first time, display no o~tput'lI
gadget%(i,4)~O~
LINE (x%,y%)-(x%+l%,y%+h%),O,bt'lI
PUT (x%,y%),gadgets%(none%)~
ELSE ~
gadget%(i,4)~1 'else yes output~
LINE (x%,y%)-(x%+l%,y'<h%) ,O,bf~
PUT (x%,y%),gadgets%(yes%)'IT
END IF'll
END IF~
END IF'll
WINDOW OUTPUT old 'old output window active'll
i~lO 'll
END IF'll
i~i +1 'll
WEND~
END SUB ~
'll
SUB ini tgadget (x%, y%, h%, 1 %, valu%, wind%, nr%, yes%, none%) STI\T1C'j:
'TASK :place a new gadget in the gadget array gadget%()'ll
'PARAMETER:~>x%,y% Position of upper left corner'll
h%,l% border height and lenght'll
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 display another gadget~
yes% and none% supply the indices for graphic information'll
of the array gadgets'll
<=nr% Position of the gadgets in array 'IT
SHARED gadget%(),gadgets%()'ll
IF x%>=O AND y%>=O I\ND h%>o~2 AND 1%>=3 AND valu%>C I\ND valu%<l% r,ND Vi' :~i%>O
THEN'll
MOUSE OFF'll
old=W1NDOW (1) '!I
WINDOW OUTPUT wind%'ll
IF yes%=-l THEN'll
LINE (x%,y%)-(x%,y%+h%)'ll
LINE -(x%+l%,y%+h%)'!I
LINE -(x%+l%,y%)~
LINE -(x%,y%)'ll
LINE (valu%+x%+l,y%+l)-(valu%Tx%+l,y%+h%-l) ,3'll
ELSE'll
IF valu%=l THEN'll
PUT (x%,y%),gadgets%(yes%)'ll
ELSE'll
PUT (x%,y%),gadgets%(none%)'lI
END IF'll
END IF'll
nr%=O'll
WHILE gadget%(nr%,O»<-l AND nr%(~9 ~
nr%=nr%+l'll
IN'END'll
IF gadget%(nr%,O)=-l THEN ~
gadget%(nr%,O)=x%'ll
gadget%(nr%,l)=y%'ll
gadget%(nr%,2)=h%'ll
gadget%(nr%,3)=I%~

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

D. The SetPoint Program


The SetPoint machine language program usee! by the tracer program
is listed here. The program appears here in machine language source
code and as a BASIC loader, for those of you who do not have the
AssemPro assembler.
;SetPoint.ASM
;Output one rectangle in oDe Rastport (screen)

;Calculate from the existing colour word the desired combination


; for the desired color word.

_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

; Offsets for the parameter of the stack: All longwords

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:

;output one rectangle. Parameter:

; (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 :

HOVEM~L xl(SP) ,DO/D1


SUBQ #1,DO
Dec: . oS \ Hl'Jvil
MOVEQ #O,DO ;If Pixel = first in line => backgr0l1~d color
SRA.S \HAM2
\HAM1:
MOVE.L RastPort,A1
CALLSYS ReadPixel
1'ST DO
BMI \R
\HAM2 : ;00= Color number

;Copy ndditiona} HAM-Colo!:"s in array:

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

MOVEQ #$10,D1 ;ColorNr: blue


MOVEQ #16, DO ;16 Steps
MOVEQ #0,D5 ;blue-Intensity <)
BRA.S \StUB
\SHLB:
MOVE 01, (AO) +
ADDQ #1,01
MOVEM 03-D5, (AD)

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

MOVEQ #0,D3 ; red-li1t.ensi ty=O


MOVEQ #16,00
BRA.S \SHIR
\SHLR:
MOVE 01, (1\0) +
ADOQ #1,01
MOVEM D3-05, (AD)
AOOQ.L #6,1\0
AOO #64,03 ; 64~1024!l6
\SHIR:
OBRA OO,\SHLR
MOVE (A1)+,D3

MOVEQ #16,00 ; ColorNr=$30! : Green


MOVEQ #0,04
BRA.S \SHIG
\SHLG:
MOVE DJ, (AD) +
AOOQ #1,01
MOVEM 03-05, (AD)
ADOQ.L #6,AO
AOO #64,04
\SHIG:
DBRA DO,\SHLG

;Now all 64 possib~e co~ors are calculated => all normal


;additionaJ.

\I'ORMAL:

;Seacrh first for the color, in one pass:

LEA Colour,AO
MOVE MaxColour,OO
MOVEQ #-1,07 ;Minimum
MOVE. LAO, Al
BRA.S \INl
\LP1:

MOVE 2 (AD) ,Dl


SUB red (SP) ,01
MULS 01,01
MOVE 4 (AD), D2
SUB green(SP),D2
MULS D2,D2
AOO.L 02,01
MOVE 6 (AD) , 02
SUB blue(SP),02
MULS 02,02
AOO. L, 02, OJ

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

Sea rch now t~he color, in the second Fas::~

LEA Colour,AO
MOVE MaxColour, DC
MOVEQ #-1, D7 ;Mini"num
MOVE.L AC,A2
BRA.S \IN2
\LP2:

8SR \COMPARE Colour


BEQ.S \NXT2

MOVE 2 (AD) ,Dl


SUR red (SI') ,fJl
MULS Dl,Dl
r~CJ'JE t, (AD) , D?
SUB green (SI') ,82
MlLS !:I?, D2
I\DD. L D2, D1
MOVE 6(AC),D2
SUB blue(SI'),D2
MULS [;2,02
ADI).L 1)2,Dl

CMP.L D1,J7
I3LS.S \NXT?
MOVE.L U:,D'/
MOVE.L AO,A2

\NXT2:
ADDO.I. #fJ,AO
'"IN:? :
DBRA 00,\]'P2

BSR.S \SEARCH PATTERN


MOVE.;, D7,03
MOVL. L 1\3, 114

EXC; ld, A2 llSR. S \SEARCH PATTER};


CKE'. L D3,Di
BLO.S \RECT
EXG Al,A2 MOVE.I. A4,A3
'RECT:

; Al A ColorNrl, A2' ColorNr2, AY Patten;

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

MOVE.L (S2) ,A1


MOVE 07, DO
CALLSYS SetBPen
MOVE.L (SP)+,A1

;Clipping:

MOVEM.L xl (SP) ,00-03


MOVEM RasterWl,04/05
eMP 04, DO
BHI.S \R
CMP 05,0:
BHI.S \R
CMP 04,02
BLS.S \R1
MOVE 04,02
\Rl:
CMP 05,03
IlLS.S \R2
MOVE 05,03
\H2:
CALLSYS RectFi.l 1

\c,:
MOVSM.L (SP)+,00-1\6
RTS

\SEARCH PATTERN:

;A1 A Colorl, A2 A Color2. ~> 1\3 A 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

MOVE 6 (AI) ,04


BEQ.S \E5
MULU 02,J4 ;Colorl.blL:C' (i-Bkg"Pattem)
JrVU #1024,04
\E5:
MOVE 6 (A2) , 05
REQ.S \E6
MULU C1,~5 ;Color2.bluc·?<gnPa~ter~
OIVU #1024,05
\E6:
ADD 05,04 ;Color.b1ue
SUB hiuc+4(SP) ,D4
MULS ;;1,:';4
ADD.L D4,06 ;distance between desired and current C01ur

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:

;Al~ Colorl, AO~ Color2

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

The following program is the BASIC loader used to create


SetPoint. B on a disk named Tracer. The example program that
follows contain some BASIC lines that must be entered on one line in
AmigaBASIC, even though they appear on two lines in this book.
Formatting the program listings to fit into this book has caused some
long BASIC lines to be split into two lines. To show where a BASIC
line is actually ended, a ~ will be used. This is not to be entered, it
only shows when the <Return> key should be pressed in the BASIC
editor.
'SetPoinl.BAS'l[
OPEN "tracer:SelPo.'nt.S" FOR cJl}';'t'UT AS I'll
FOR i~l TO 1528'l[
READ a$'l[
a% VAL("&H"+aS)\l
PRINT #~,C~!P,$(~l%);gr
NEXT91
CLOSE 1 S~
l<ILL "Tracer:SetPoint.B.:Lnfo"q{
<1[
datilS:'I[
DAT'/\. 48,E7,cO,C~, '), D, 113,Fl\, ;', 58,2C, 78, C, 4, 4E,AE,FD, CS, l;l,FATl
DATA 2,5£,20,80, [)?,43,3,~~,75,48,E7,CO,C2,20,3A,2,4E, 67,A~
DATA 22,40,2C, 78,0,4,~E,rlE,FE,62,4C,DF,43,3,4E, 75,4B,E7,FF,FE91
DATA 20,3A,2,34,67,O,1,68,2C,40,30,3A,2,34,2,40,8,O,67,0'
DATA 0,BO,1C,EF,O,3,O,40,53,40,64,4,70,O,60,E,22,7A,2,14'
DATA 4E, l>E, FE, C?, ~lI, '10, 68, 0, I, 3E, E7, 48, 41, FA, 3, 86,43, FO, 0,2'
DATA 4C,?I,O,38,DO,FC,O,80,72,lO,70,10,7A,O,60,E,30,Cl,S2,4l'
DATA 48, 90, 0, 38, ::C, 88, Dl>" 7C, 0, 40,51, C8, ?F, FO, 3A, 29, 0, 4, 76, a'll
DATA )O,10,60,E,30,Cl,57,41,48,90,O,38,5C,88,D6,7C,O,40,51,C8'll
DATA FF,FO,36,19,70,10,78,0,60,E,30,C1,52,41,48,90,O,3B,5C,88'll
DATA 08, 7C, 0,4 0, 52 , C8, F'F, FO, 4', FA, 3,26,30, 3A, 1, A4, 7E, FF, 22,4 8'll
DATA 60,2C,32,2R,O,2,92,6F,O,52,C3,Cl,34,28,O,4,94,6F/O,56~
DATA C5,C2/D2,82,j4,28,O,6,9~,6E·(O,5A,C5,C2,D2,82,BE,81,63,4i
iJATA 2E,l,22,48,50,88,51,CS,FF,D2,41,FA,2,EB,30,3A,1,66, 7E,FF'll
DP.~TA 24,48, 60,32, 61 f 0 1, 20, 67, 2A, 32, 28 r 0, 2, 92, 6F, 0 152, C3, C1 'lI
I

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

DATA 36,5,4;:::-.,P..E,t-"S,C['I'iC:,DF, 7F,Fr,lj~,7S,4~ ~'f<, C: :)0 14'l!


I

DATA 7E,FF,'7~;rI1,,32,~~,,34/3C/4,Of94,41,3C,/ , C,:? r 67 16,


DATA 8C, Fe, L, 0, 31'1, 2il, 0, -;,67,6, CA, C1, 8A, FC, 'C:f~X=r45,9 Ii::,:~
DATA Cl,'::6,CD,CC,J:3,29,C,4,6 i ,c-,C8,C7, ,1" t;S
DATA ,b,Cl1"C, FC,,1,C, ,r,~,98,b['
GATA 0, G, 6'-),6, I ':_:~'I 88, Fe, Lt ='1 :~j"~, 2P." :', -::, L-',
j ~,::~:~-,:~, .r'

;:)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

,GI,7:!, ,'9,C,O,C,O,C,J,C,O,O,:.:, t':', ::,,1,/~


t)ATA 0,C8, 0, 8, 0, u, G, C, 0, C), 0, 0, 0, L!, C, 0, 0, G, ~~', ,:'Iqr
JATA 0,0, ,:,0, C, 0, 0, 0, 0, 0, 0, 0, 8, J, 0, U,~, 8"', :~"'1l
[)AT;'~ O,O,O,C,O,0,O,(),O,C,O,O,O,O,0,:~,OfO,C,0S
DATA ,O,O,C,C,O,C,O,O,O,C,fl,nO,O,c,'J,' ; ~,C:'lI
DATA 0,0,0,0,C,O,O,0,0,80,0, O,C,O,:;, ,C,O,ilq]
DATA G, 0, 0, 0, 0, 10, [) Cl, 80, 0, CI ::;, 'J, 0, 0, ~~, , 0, 0, n, G91
DATA O,O,80,UJ,O,O,O,O,O,O,O,O,O,O,O,O,C,O,O,'::Oq[
DATA 80,BO,O,O,O,O,0,C,8,8,O,O,G,O,J,O,80,8C,::',091
DATA C, 0 , 0 , 0 , B , 8, 8, 0, 0, 0, 0, ere, 4 C, B8 r 3 S , C, Q, 0 I 0 IJl
DATlI, 0,0,88,8P,0, ,O,o,C,O,SE,88,O,O,O,'.,O,O,88,;'
DA~A 0,O,O,O,O,J,],80,88,(38,C,C,22,2?,O,C,88,88,J,=~
[lATA 22,:U,O,O,88,88,C,:J,22,22,:),C,E8,88,O,C,L',22,O,
Dl1TA 1.,0, AA, AA, 0,0, M, p..1\, 0, a,
M, ll}'. . , D(0, AA, ,r:,.A, 0, J, r\A, A/\~l
DATA 0, 0, I,ll, N>" 0,0, N" 'lA, 0,0, N\, M\, (;,0,1, 8e ,/\A, lIP" : 1, ' 1 'll
DATli .n....t..,AA, 44, 1;<1, l\/\, AA, 1-1,11, " ('I, AA, 4,-1,11·1, l\A,tlA.,.! ~ ,: ,1\,1\, Ai~,
DATI-'\, {J\.,AA, 1.:, 11,tJ\.,AA, ''l:4/4~;, l,eO,PA !-J-".,5':), :,5, Al\,;\J" 'il;, _~_n
I

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

OAT/\. J,O,C,C;,L~,O, (O'CfO,~:,0, ,o,o,o,e, ,:i,Cqr


!)l,TA o,o,o,C,o,O,O,Cl,0,C,O,O,O,O,C,Il,O,G,O,09:
DATA O/O,~J,O/D,O,O,C,CI,U,O,O,O,C,Vf~~,O,O,O,C7t
DATA 0, 0 ( C, C, 0, 0, 0, 0, C, ] fe, 0, 0, 0, :::; , C, 0, 0, C, 0 'lI
OAT!,. C), C, 0, 0, [., :=,
,C, 0, 0, C, '), \", () r D, 0, C, (), CJ, Cq]
DAt~)\ O,O,l;,U,,:,CJ,D,O':)'~~f ,0,0,0, '~~'/JrOqr
DAfi'A J,G, 0, \", G, G, G, 0, 0, 0 , ~, J, G 0, 0 (j, C, J, G'IT
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.

ScreenLoad and ScreenSave use the library commands to access


the disk. Errors such as a full disk arc trapped in thcse routines that (for
example, .. -Chunk cannot be saved I I I ) allow you to returIl
to the program.

Error messages when starting the program (N 0 free Chi P


mem! ! !) are caused by insufficient memory. Here little tricks, like
working with a very small AmigaDOS window help. You mllst also
close or delete less important programs running in the background.
Unfurlunatciy it can also happen that the computer or AmigaBASIC
wiii ignore the jack of memory. This can OCCllr with a large K array
(200+ clements) on a 5I2K machine.

Errors can also be encountered during the initilization of the shadowing


process: When the basis of an object is not a basis at all, you arc
informed. (A basis consists of three independent, linear vectors. A
vector i~: not presented as a multiple of the other two vectors). These
errors occur when the vectors a, b, and c span no space of an ellipsoid,
cone, or cylinder or when they arc coplanar or colinear.

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.

The optional diskette for Amiga 3D Graphic Programming in BASIC includes


BASIC source code for the editor program, ASCII sources of the tracer program modules,
and compiled, ready to run versions of the tracer and editor programs. Also included are a set
of 3D wire model graphics and their matching materials, ready for calculation.

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

Or for fast service (credit card orders only)


call 616-698-0330 (orders within Michigan)
or 1-800-451-4319 (orders outside of Michigan).
One Good Book deserves another
and another, and anoth (~r
tle w! - --_._--
Amiga 'c' Amiga C for Advanced Programmers AmigaDOS Inside and Out AmigaDOS
lo r Advanced
Programmers conlalns a wealth of informalion from Ihe pros: how compil· ·covers Ihe insides of AmigaDOS from Ihe inlernal design up Inside & Out
ers. assemblers and linkers work. designing and program - 10 praclical applications. Includes delailed reference sec -
mmg user friendly interfaces using Intuition. combining lion, lasks and handling. DOS edilors ED and EDIT, how 10
ass embly language and C codes, and more. Includes com· creale and use scripl files , mullilasking. and much more.
plele source code for lexl edilOr. ISBN 1-55755-041-7 $19.95
Abacusllli!
ISBN 1-55755-046-8 $24.95 Includes Workbench 1.3

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

Amiga 3-D Graphic Programming in BASIC Amiga System Programmer's Guide


Amiga System
·shows you how 10 use the powertul graphic capabililies of ·compreh ensive guide 10 whal goes on inside Ihe Amiga in Programmer's Gui(to
Ihe Amlga Delalls Ihe techniques and algorilhms for wrili ng a single volume, Only a few ollhe many subjecls covered
three -dimensional graphiC programs: ray tracing in all reso- Include Ihe EXEC struclure. 1/0 requesls, inlerrupls and
lulions. Irghl sources and shading. saving graphics in IFF resource management, multitasking functions and much,
tormat and more much more.
ISBN 1-55755-044-1 $19.95 ISBN 1-55755-034-4 $34.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

Amigalor Amiga For Beginners' Computer Viruses : a high-tech disease' c om pUTER


-the first volume in our Am iga series. introduces you to -describes what a computer virus is, how viruses work .
Beginners
I n ~ UI!IOn (Amiga's graphic interlace), the mouse, windows, viruses and batch files. protecting your co mputer, designing VIR£fJ67
IE.m Ihe eLi and Amlga BAS IC and explains every praclical
aspecl ollhe Amiga In plain English
virus proal systems and more.
ISBN 1-55755-043-3 $18.95
~ tSBN 1-55755-021-2 $16.95 " /' ,-"h,lhll ,/,,' /1, ' \/ tlild Ilh' I / ' 1//1<"11/

/,,, ,,( tlh'T\" ' / " ,""\I' IIIIIt"//!1"' I,IIIII' 1


Includes Wo rkbench 1.3
PC ",,' ak /I·21·t~8

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

" . . ... .,.


~ ,,' ,., and delalled. TopiCS include charts, Windows, pulldown
,
Optional in Ihe books are on each respechve disk and will save you
' menus , fiies, mouse and speech commands.
.. ..

ISBN 0-916439-87-9 $24.95 Disk countiess hours of Iypingl $14.95


Abacus~ (. Opllonal Diskette Nol Available for Ihese Tilles)
Includes Workbench 1.3

Arniga Amiga Tricks and Tips


Tricks & TIps -jollows our tradition of other Tricks and Tips books for CBM
users Presents dozens of tips on accessing libraries from
BASIC, cuslom characler sels, AmlgaDOS. sound, impor·
la nl 68000 memory localions. and much morel
ISBN 0-916439-88-7 $19.95
Abacus. Dept. L2, 5370 52nd Street SE
Grand Rapids, MI 49508

See your local Dealer or Call Toll Free 1·800·451·4319


Add $4 .00 Shipping per O rder
Foreign add $1? OO per item
- - - I

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

TextPro More than word processing ...

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.

Suggested retail price: $79.95 Suggested retail price: $99.95


l

ROFESSIONAL

File your other databases away!


Professional DataRetrieve, for the Amiga 500/ 1000/2000, is a friendly easy -to-operate
profession al level data management package with the features of a relational data base system.

Professional DataRetrieve has complete relational data management capabilities. Define


relationships between dilferent files (one to one, one to many, many to many). Change
relations without file reorganization.

Professional OataRetrieve includes an extensive programming language which includes


more than 200 BASIC-like commands and functions and integrated program editor. Design
custom user interfaces with pulldown menus, icon selection, window activation and more .

Professional DataRetrieve can perform calcul ations and searches using complex
mathematical comparisons using over 80 functions and con stants .

Professional DataRetrieve's features:


Up to 8 files can be edited simultaneou sly
Maximum siz e of a data field 32,000 characters (te xt fields only)
Maximum number of data fields limiled by RAM
Maximum record size of 64,000 characters
Maximum number
(2 ,000,000,000 of records disk dependa•.~~t~iE~~~~~~~~:l
maximum)
Up to 80 index fields per file
Up to 6 field types - Text, Dal e, Time,
Numeric, IFF, Choice
Unlimit ed number of seal'ches and sub -
rilng e crit eria
Integrated li st editor and full ·page printer
ma sk editor
Ind ex accuracy selectable from 1-999
chilracters
Multiple file masks on -screen
Easily cre ate/edit on -screen masks for one
or many file s
Use r-prog rammable pulldown menus
Operate the program from the mouse or from
th e keyboard
Calculation fi elds , Date fields
IFF Graphics supported
• Mass·storage -oriented fil e organizati on
Not Copy Pro tected, no dongle : can be installed on your hard drive

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. •

._-------------------------------------_.

You might also like