GENTUT24.TXT
General Tutorial for Lisa GJ2 Fic3
-- the f3 language explained as a series
of tiny essays
Written by Aristo Tacoma with L.A.H.
Date: 2011:3:3
Numbers 01..99 in this series of gentutNN
are circulated as needed, when more recently
written articles make earlier ones unnecessary.
Each article: copyright author, further distribution
license the usual www.yoga4d.org/cfdl.txt.
Kids: there are other tutorials for you.
But you should find pieces here and there
which are easy to read. In B9, use the
search function, CTR-F or F4 within each.
Beware ;-) This is written as a flow, quickly,
and wherever there is a reference to concrete
f3 syntax, it may have been written from memory
and so not every word is guaranteed to be
written here exactly correct. Search up with the
CTR-F and repeated search CTR-L in the F3DOCS
manual or in example programs if things here
are not clear enough or precise enough for your
present purposes. Good luck!!!
***A BIT ABOUT TRIGONOMETRY AND LIGHT3D
Trigonometry is all about doing numbers about triangles
-- their sides, their angles, such stuff. These
triangles we can then use to create things on the
screen, once we know how to twirl and swirl them around
on our fingertips.
By convention, trigonometry speaks of triangles that
we organise around a vertical line, Y, and a horisontal
line, X, so that we draw a circle around the center
(sometimes called "origo").
Let me just have it said that something of this was
invented by the french philosopher Rene Descartes, but
he was building on earlier work; and that, as far as
history goes, there were apparently independent lines od
development much earlier such as by the Mayans in
America, the Indo-Aryans in India, and the Egyptians,
sometimes with -- relative to their neighbours --
spectacular buildings as a result, with some level of
scientific credibility relative to such as star
movements.
As we see it here, this is not part of a larger box
called 'mathematics' at all. Trigonometry stands on its
own as a branch of calculation. It is the plus (ADD),
minus (SUB), multiplication (MUL) and division (DIV) of
ordinary lovely numbers taken one step further, to the
area of imagined flat -- 2D -- two-dimensional --
triangles, their sides and angles.
Let us also note that a lot of religious hogwash
around triangles was done, according to history, by a
certain self-centered man called Pytagoras, to whom one
ascribes such as the formula for getting the long line
of a triangle when one has got hold of the two shorter
lines, in such cases as it has a corner which is
perfectly square.
By convention, such a straight normal corner is said
to have 90 degrees, while when we imagine that an angle
opens up to spread all around in a full circle, it is
said to have 360 degrees. In LIGHT3D, a phrase like
; $3.141592654 => TWICER => *R ;
is found. When we have a circle which, if you cut it
straight across the center, has length 2, then it can be
said to have radius (from the center) 1. If you put a
thread or wire around the circle, it will have about the
length as given it the number above -- twice 3.14,
about. [[[The science aspect of this is that in general
circumstances there is a flood of confirming instances
for this and no serious disconfirming instances, enough
that we can apply it in daily life and regard it as a
feature of the manifest world and more, without saying
that this form of dimensional organisation is entirely
essential -- see my 8-sphere theory for that.]]]
In the FIC3.TXT there is the LL or LogoLike mode,
named after an experimentative language for children
called Logo, which uses a similar number (not quite as
accurate, for the context is more playful) to give
startling and fun views of star-like drawings on
screen. There is (soon) a KIDPOPnn about LL.
In any case, then, since it is more psychologically
fun and easy and natural to talk of 90 degrees, 360
degrees (which also can be said to be basis, or 'zero'
degrees), and other angles such as half 90 or 45, a
straight line or 180, two-thirds a circle or 270, or a
third of a square corner or 30 degrees, a friendly
program, a first-hand program, typically works with such
degrees, and converts these only in the last moment
before throwing them into what is called the
trigonometric functions to the accurate measurement.
This accurate measurement (by some called 'radians')
is then nothing but that given in the line above, more
or less: two times ca 3.14 is used as factor. When you
have an angle like 30, you take the decimal number you
get by looking at 30 divided at 360, and multiplies it
by that factor. Dividing it by that factor gives you the
original number back.
When you take 30 divided by 360 you get a very small
number, with lots of decimals. You've got to retain some
of these decimals, at least, so that you get some
accuracy when doing these things.
In LIGHT3D, when you start it up, it says what X is --
your coordinate -- then what Y is -- then what Z, or the
third mysterious depth coordinate is -- on top left of
the screen. As you click around with SHIFT CTRL arrows
and such, you modify these (ESC gives a little more
info). At the bottom of the screen, if the view is
rotated somehow, it gives an angle for this. No rotation
is technically 0 degrees, but it is more pleasant to
view the number 360, besides it reminds on what type of
number we are thinking about. So you can rotate sideways
and upways. These are two rotations. Combining them is
also possible. In that way we can in principle move in
any direction, although LIGHT3D is made on the simple
premise of focussing much on straight lines and cubicles
(small cubes, and also large) built out of triangles in
a fairly visible way. This is so as to stimulate the
person interacting with it to think, rather than be
seduced by an appearance of reality, for such seductions
by the PC is not contributing to human intelligence.
In LIGHT3D, I wanted to say, the X and Y and Z
coordinates are given as whole numbers. However they
have a couple of more digits than on display, these are
cropped off so as to make the reading of the coordinates
easier. These little extra digits mean that when we
rotate a whole lot of structure, it won't get screwed so
that e.g. the sharpness of the corners become blurred.
In LIGHT3D, every thing, then, is made of three sets
of X, Y, Z coordinates, giving a triangle; and to this
triangle of nine whole big numbers, we add a number for
green tone, 128..191 going from black to bright green
191, and we add a couple of more numbers, as a kind of
street address or what we can call it, in order to group
triangles together (group number and record number).
This then gives a matrix of nine plus one plus two
numbers in each row, or 12 in width.
When you want to rotate a cube, you want to know its
center: that can be calculated, if you run through all
the coordinates, adding them up, dividing each on the
amount of them. Then you look at each triangle
independently -- or rather program the PC to do so --
and turn each triangle the amount of angles you want.
This you do, when it is 3D, for two times 2D, -- in
LIGHT3D, you do it with the triangles as they appear at
the flat view of XZ, and as they appear at the flat view
of YZ (a vertical plane, whereas XZ is a horisontal
plane), then you combine the results, to obtain depth
appearance, with both rotations applied.
So the record number (usually) is used to make sure
that only the cube coordinates are calculated on. As an
alternative, we can rotate a larger set of things, in
which we take a different point of rotation than the
centre of one cube as the central point.
Since you may want to move through a LIGHT3D situation
in several ways, without leaving a debris, as it were,
in the sense of slightly changed objects after you have
done a bit of rotation and such on them, the approach we
took in LIGHT3D is that all the coordinates is copied
over to a blank matrix, a so-called VIEW matrix, and the
claculations are done there instead. The PC does copying
fast. The living mind excells in original good impulses,
but the PC excells in copying stuff. Having a good day
for a PC is to be allowed to copy much stuff; quite the
contrary for human beings!
The calculations are a bit tougher work for the PC,
and for that reason the numbers -- stored on the RICH
stack, which can have decimals -- are not moved from the
stack but rather rotated around on the stack, copied up
and so forth, even though the code got like this:
(LET TURN-XZ-THIS-AMOUNT-ANGLES BE (( >N8 >N5 >N3 ))
((
(( $1000000 ; ))
(( ; N8 => STKTORICH ; $3.141592654 =>
TWICER => *R ; $360 => \R ; ; ))
(( ; ; VIEW-X >>> => STKTORICH =>
TANTRAR => \R => SWITCHR ; ; ; ))
(( ; ; ; VIEW-Z >>> => STKTORICH =>
YANTRAR => \R => SWITCHR ; ; ; ; ))
(( ; ; ; ; N3 => STKTORICH ; MANTRAR => \R ; ; ; ; ; ))
(( ; ; ; ; ; => YANTRAR =>
SUBR ; ; ; ; ; ))
(( ; ; ; ; ; N5 => STKTORICH ; DHYANAR =>
\R ; ; ; ; ; ; ))
(( ; ; ; ; ; ; => YANTRAR =>
SUBR ; ; ; ; ; ; ))
(( ; ; ; ; ; ; => BRIDGER => SQUARER =>
BRIDGER => SQUARER => ADDR =>
SQRTR ; ; ; ; ; ; ; ))
(( ; ; ; ; ; ; ; => BRIDGER =>
YANTRAR => ARCTAN2R ; ; ; ; ; ; ; ; ))
(( ; ; ; ; ; ; ; ; => MANTRAR =>
ADDR ; ; ; ; ; ; ; ; ))
(( ; ; ; ; ; ; ; ; => ONER =>
COSR => TANTRAR => *R ; ; ; ; ; ; ; ; ; ))
(( ; ; ; ; ; ; ; ; ; => BRIDGER =>
SINR => YANTRAR => *R ; ; ; ; ; ; ; ; ; ; ))
(( ; ; ; ; ; ; ; ; ; ; => ANGELR => RMR =>
ANGELR => RMR => ANGELR => RMR =>
ANGELR => RMR ; ; ; ; ; ; ))
(( ; ; ; ; ; ; => YANTRAR => ADDR ; ; ; ; ; ; ))
(( ; ; ; ; ; ; => DHYANAR => *R => RICHTOSTK =>
HEAL => >N5 ; ; ; ; ; ))
(( ; ; ; ; ; => YANTRAR => ADDR ; ; ; ; ; ))
(( ; ; ; ; ; => MANTRAR => *R => RICHTOSTK =>
HEAL => >N3 ; ; ; ; ))
(( ; ; ; ; => RMR ; RMR ; RMR ; RMR ))
(( N3 ; N5 => => ))
)) OK)
Let us be clear that however the PC doesn't do all those
semicolons, and each YANTRA MANTRA and so on, with an R
added to indicate which stack, the RICH stack, are just
copying instructions (see F3DOCS). They are very very
simple. The work is done by *R, SQRTR, ARCTAN2R, \R,
SINR and COSR, and the rest is just copying and the
semicolons are all for helping the feller who tries to
make sense of the whole thing afterwards. So if you look
at the points in the above where it says *R or multiply,
SQRTR or take square root, ARCTAN2R or find angle of
this triangle, \R or divide, and SINR or find Y position
of this triangle, and COSR or find X position of this
triangle, you see the core of what is done, and the rest
is but entirely trivial stuff altogether. Once the
routine is made, it is remade by very slight changes
only to do all the other things in LIGHT3D which has to
do with rotations, whether of all or of just something,
whether along one plane or along another plane.
However, when you have the XY and YZ set both to 360,
and you move just straight forward, or left, or back, or
up, or beneath, then we have NO USE for anything of this
AT ALL! For then we only add by normal addition to the
coordinates, or substract, and there is no having to
loop about with rotation, unless, that is, there is an
automatic rotation having been programmed in as a warp
in addition, or such.
But then, you might perhaps ask, how do you get the
apperance of depth, such as when you have the
coordinates of a cube, but only a flat monitor to show
them on? The answer lies in the beauty of the division
function. When you watch both your hands but you have
one arm extended far ahead you, and the other nearer,
then the eyes report, if you focus on the sensory
impressions, the hands being of different size: which
you naturally, by your perceptive mind, at once
understand to be but appearance.
If you have a hand first fairly near, compared to the
nearest, then double the distance, it halves in
appearant size. So by the \R function, you get room
depth simply by taking each Z coordinate and using it to
divide on the X as well as the Y so as to reduce size
when Z gets larger, in our room/depth view. So the
letter R is also used to indicate room/depth.
This is easy to do when the view orientation is ahead,
but once things are rotated, there is a whole lot of
recalculation, where we use the VIEW matrix, to find out
just what is now supposed to be ahead in the monitor
view. THEN, having done the recalculations, we apply
afresh the R\ to get it.
Note also that in order to get the effect of a thing
near being able to block view of a thing further away,
we should display the stuff we've got not just in any
sequence, but in a sorted sequence. That's why LIGHT3D
uses MATRIXSORT, which uses nothing but exactly the same
sorting routine which we have used everywhere else, the
fairly well-documented QSORT2 or 'quick sort', as it is
also called. Actually, for good measure, it sorts all
three coordinates, so MATRIXSORT3 is used. Note that
since Z is most important by far in order to get this
sort of thing straightened out, Z must be first in the
matrix row for MATRIXSORT3 to regard it as the key
sorting number.
The things which are to show -- the triangles -- are
to be ahead of view, not entirely on the side, and
certainly not behind. And so there is some amount of
checking and the use of (MATCHED .. MATCHED) whether the
position of a triangle indeed is so that it is within
the view ahead. If it is even with one corner of it not
entirely ahead, it is clipped away from the presentation
at that particular instant. This accounts for the
sometimes (or often) funny corners of cubes shown at the
edges of the view. Each cube, then, has obviously six
square sides, and each square side is but two touching
triangles, meaning that a cube involves twelve triangles
and as such, twelve times three points to be calculated
on. A good first-hand 3D approach must then not try to
conceal all this by performing compression techniques on
size and calculation, so as to give the appearance of
the 32-bit computer not being a 32-bit computer at all;
nor does it make sense to squeeze in extra bits just for
the sake of perpetrating such illusions. Rather, we must
love the limits that the 32-bit perfect programming
language f3 gives and only in high level functions,
doing obvious and explainable things, without reckless
computational seductive tricks, find out what it means
to create mind-stimulating games and models and such.
Play with these functions and look at the logolike LL
mode in FIC3.TXT to work them out, do drawings in WT to
think about the circles with radius 1 to which sinus
refer to Y and cosine to X, when the triangle is drawn
so as to have one vertical line which touches the X
axis, with its angle given relative to the right-hand
side of the X axis.
Note that to get the angle of a triangle which is in
the upper right quarter, ARCCOS and ARCSIN or something
like that these do give the answer -- how long is the
'arc' given such a coordinate for X or for Y, but if you
have an angle of something which is going above 90
degrees, you need a slightly more complicated function
which takes in two coordinates, both X and Y, not just
one of them. It is here ARCTAN2 comes to the rescue.
This is technically related to the TAN function which
has a vague not-quite-working definition in terms of one
of the SIN COS pair being 'divided on the other', but
this is entirely unworking in praxis as division on zero
is to be avoided and SIN as well as COS frequently gets
zero values.
As for triangles having a different length than 1 as
for their longest lines: which indeed is the typical
case in LIGHT3D -- all we need to do is get to know the
factor with which we can divide the triangle coordinates
on to get it to become a triangle with longest line 1 or
dance. Then we can work on the normalised triangle, and
multiply the results back with this factor when done. It
is here the SQRTR comes in. SQRT and, for the rich
stack, SQRTR, gives what is called the square root of a
number. For 4, that is 2, for the so-called square of 2,
which is what we get when we multiply this number with
itself, is 4. So the square root of 9 is 3. The square
root of something like 8 involves then a number less
than 3, greater than 2, presumably with lots of
decimals. To check the result, doubling the number --
ONE doubles one number, TWO doubles two, THREE doubles
three, -- then multiplying with the *R -- should give
the result back (use ONER on the RICH stack, ONE on the
main stack).
In any case, the formula is: the square root of the
squares of the two shorter lines is the size of the
longest line -- as for any triangle who has such a
normal, straight corner as we use with the COS and SIN
functions.
Take then two points hovering about in XY plane, what
are their distance? Substract X1 from X2, and Y1 from
Y2, and you get a triangle of the ordinary kind, with
these two points nearer the center of the XY plane. Then
you can use the formula of square root of the square of
each of the two short sides.
Only by applying excessive much extra calculation can
you get a reproduction when doing full rotations of all
appearancies of the points when laid out in 3D: but the
whole point about first-hand RD is to retain the sharp
contrast between that which is a modelling on the
computer to stimulate the mind, and the surroundings.
Once you realise that limits is what programming on a
single 32-bit computer is all about, then you see also
that LIGHT3D is the way it is by the sweet powers of
necessity. Even so, it has within itself so much
additional potential than this, that it is required that
the initial and also completing messages are retained
when work is done which is founded on it, to constrain
temptations to overuse this the truest 3d engine ever
made.
Metaphysically, in order to the Berkeleyan mind
holding everything to have effortlessness in doing so,
it naturally invokes -- as thought about elsewhere --
the notion of the digital -- and then LIGHT3D comes
easily to mind.
Good luck with your LIGHT3D programming!!!