ZX Power #03
31 декабря 1997

Likbez - a new algorithm for fast 3D graphics on SPECCY.

<b>Likbez</b> - a new algorithm for fast 3D graphics on SPECCY.
Fast 3D-graphics for SPECCY, realnoli this? Perhaps, the 
following statyaraskroet you previously unknown possibilities 
SPECCY and will be useful prirabote with three-dimensional 
objects. Statyaraschitana more or less 
podgotovlennyhchitateley, but may be poleznoydazhe novice users 
... (C) 1997 BY RUFF OF AVALON / RUSH / ASM 
_________________________________________ I read both articles 
in the "ECHO 1" output of 3-D objects. There is described of 
traditional method, which all (who znaet) use. This is 
certainly a very interesting turning point around the axes X, Y 
and Zpo special formulas. For povorotavokrug axis X: Y '= COS 
(N) * Y-SIN (N) * Z 

          Z '= SIN (N) * Y + COS (N) * Z

around the axis Y:


          X '= SIN (N) * Z + COS (N) * X

          Z '= COS (N) * Z-SIN (N) * X

around the axis Z:


          X '= COS (N) * X-SIN (N) * Y

          Y '= SIN (N) * X + COS (N) * T

(N - Angle)


   This method has drawbacks. And more precisely, one very big 
disadvantage - Takes a long time! On the operations of 
multiplication (b what they were not fast) and calculate the 
COS and SIN (even on the table) takes a long time.


   If we consider the problem with the signs and then
which is usually the object rotates once around
three axes (some even use
BASIC calculator), then there's nothing
choice but to first count
coordinates, and then withdraw graphix. Some even loads 
separately calculated on BASIC'e coordinates. The same 
lamer'stvo! (In some cases) 

   True, sometimes there are programs from
with REAL-TIME 3D CALCULATING'om. But how do they
retard!


   ... This was the entry. Now closer to
case. I invented a new way to display 3D
objects. Here are his virtues:

 - It is much faster than the above (!!!)
   of ways. To calculate the coordinates

   one point to about 200

   cycles (if desired can be done

   faster)

 - 3D object can not only rotating the
   vat, but also to deform (stretch,

   compress, etc.)


   In short, will soon be ours (AVALON'ovskaya) demo (or may 
not come (And probably already out)), in which

3D will effektik with ROTATING'om man.

   Man consists of 175 points (if
More specifically, the 175 vectors, however, to
little man is not very noticeable, as
hands and his feet were relatively flat).
If he was out of line, the effect is not
climbed to a one interrupt (set point
faster). This, of course, my REALTIME
3-D ROTATOR.

   I can not fully bring here
listing of this effect, so here
all in pieces, which you can build and
supplement who needs what. Here's the first piece of
- The procedure of printing 3D objects:

PRINT

    LD (SAV +1), SP; save SP

    LD SP, ...

; ... - This is the start address of origin that; check the 3D 
object. At one point 4 bytes (3 ; Bytes - coordinates X, Y, Z; 
1 byte Senior ; Byte table axes (about it a bit later)

, Who, incidentally, further denoted by label
; TABAX).


    EXX

    LD HL, BUFER; special buffer for

            ; Clear the screen (see

            , Below)

    LD B, 175; number of points

LP1

; Goes beyond how to print a single point


    EXX

    POP BC; In BC - Y, X

    POP HL; In HL - or older. B table

             ; Axes, Z


    LDA, (HL)

    LDE, L

    LDL, B

    INC H

    ADD A, (HL)

    INC H

    LDL, C

    ADD A, (HL)

    ADD A, HX

    LDC, A

    INC H

    LDA, (HL)

    LDL, E

    INC H

    ADD A, (HL)

    LDL, B

    INC H

    ADD A, (HL)

    ADD A, LX

    LDL, A

And now the coordinates of points (X and Y on the screen, not) 
are computed and stored in registers C and ; L. Next comes how 
to print the point of ; Coordinates in these registers (69 bars)

, For it needs a special table, so
; That, who is protsedurki not know model, Jette use his.

PLOT

    LDH, TABLE_P

    LDD, (HL)

    INC H

    LDA, (HL)

    INC H

    LDL, C

    ADD A, (HL)

    INC H

    LDE, A

    LDA, (DE)

    OR (HL)

    LD (DE), A

, Well, here. Point printed, we can now
; (If desired) in a special buffer hybrids; tit address this 
point in the screen (for that; first, then to quickly clear the 
screen ; By POP HL: LD (HL), 0: POP HL: LD

; (HL), 0: POP HL ...)


    LDA, D

    EXX

    DEC HL; address buffer grows up

            ; Feet (for convenience)

    LD (HL), A

    EXX

    LDA, E

    EXX

    DEC HL

    LD (HL), A


    DJNZ LP1; next point
SAV

    LDSP, 0

    RET


   One unusual look team
LD SP, 0: RET. But saves memory.


   I hope you guessed that the procedure itself will fail. More
need to write a routine cleaning screen
(Look up) and how to create tables
axes. Here I do not cite due to
large volume (length, mass), which
they occupy. Clear the screen of course, I
could write only about that of
Everyone has their own principles (who would write
installer, who would put everything in dup'y and
etc., etc.), in short, write themselves.

   And as for creating tables with coordinates axes, it is 
better first I'll tell the principle. 


       Y Figure 1

        ________________

      / "^!

     / "*!

    /> 48. Ah!

   / "*!

   ! ! *!

   ! ! *!

   ! ! *!

   ! ! *!

   ! ! *!

   ! ! *!

   ! "* 32!

   ! !*______^________!

   ! 30 /****************>/ X

   ! ^ / * /

   ! / * /

   !/<________________/

  Z


   See Figure 1.

   You guessed it, (or maybe not), this
cu. Imagine that inside of it is 3D object. Each point of this 
object has three coordinates of the axes Y, X and Z. Here the 
axis is not endless. For example, in my effect, they consist of 
64 points (coordinates). That is, the point can be set three 
numbers from 0 to 64. 

   And now the fun part.


   Take, for example, a point with coordinates Y = 48, X = 32, 
Z = 30. How do I know its coordinates in the screen, when you 
consider that the Z axis rotated as in the picture?


   On each axis is labeled with the appropriate point 
coordinate. Importantly, we must learn the Y and X of these 
points and center (point of intersection of axes) on the 
screen. Suppose we know them: the coordinates of upper left 
corner of Y, X 


             ON THE AXIS Y-70, 1946

             ON THE AXIS X-172, 140

             ON THE AXIS Z-180, 1940

             CENTER -172.46


   To calculate the coordinates on the screen
point "A" I came up (they can and to me
someone came up), two simple formulas:


   Denote coordinates on the screen (the same
above, only the letters instead of numbers):


             ON THE AXIS Y-Yy, Xy

             ON THE AXIS X-Yx, Xx

             ON THE AXIS Z-Yz, Xz

             CENTRE-Yc, Xc

Thus, the formula:


      Y = (Yy-Yc) + (Yx-Yc) + (Yz-Yc) + Yc

      X = (Xy-Xc) + (Xx-Xc) + (Xz-Xc) + Xc

Substitute values:

 Y = (70-172) + (172-172) + (180-172) +172 = 1978
 X = (46-46) + (140-46) + (40-46) +46 = 134

Coordinates of the point "A" in the screen 78.134.


   The above programm printing 3D
object does exactly that - Computes the amount of (admittedly, 
a bit differently (look down)), printed the point and 
remembered address on the screen. And what should be done

program rasschityvaniya coordinate axes?
Of course, calculate the coordinates of the axes.

   But let's first understand with formulas. You probably have 
long poraskryvali brackets posokraschali redundant coordinates 
center and believe that I have not noticed. So you can do, but 
this makes little sense. Here's the thing: here the coordinates 
of each points deducted axis coordinate of the center.

We return to the coordinates of the points axis. As you
surmised, would have to calculate the coordinates of all 64 
points of the axes. And these coordinates We will not count as 
they is in the screen, and the center coordinates

to screen 0.0. And then there will be only
add the coordinates of the center.

    The procedure itself rasschityvaniya coordinate axes does 
not take much time. I, for example, (if the procedure put in 
early termination) Frame Scan not have time to get even before 
the first line of the screen, that is, is entirely on the curb.

But for the coordinate axes needed buffer.

   Calculate its length: one axis - 64
point, it has 128 coordinates. all axes
3, therefore, all coordinates 128 * 3 = 384 coordinates. One 
component - one byte Coordinates 384 - 384 bytes.


   But in order to accelerate the withdrawal 3D sprite
better coordinates of one axis to keep the 512
bytes (the coordinates of Y-256 bytes, the coordinates
X-256 bytes. Of the 256 bytes used
only 64). Total buffer will 512 * 3 = 1536
(B). Is not very much.

   Well, now the program itself. Principle
Work will be explained as we go.
As already stated above, we calculate the coordinates of the 
axes so that if the center has coordinates 0, 0. And then, in 
the derivation, we add the coordinates of the center. This will 
save time. By the way, the center coordinates in my programmke 
be stored in a register pair IX, so that its contents do not 
change or save, and then restore (my program rasschityvaniya 
coordinate axes associated with the program Print 3D sprite 
pair IX and content buffer coordinate axes).


AX

    ; Procedure rasschityvaniya coordinates

    ; Axes. Coordinates (in screen), the extreme

    ; Points of the axes (Figure 2 these points are denoted
    ; Nacheny letters Ky, Kz and Kx) are given by

    ; To register HL ', BC, HL. coordinates

    ; Center in DE. Incidentally, for those who do not

    , Wants the 3D object is compressed and

    ; Stretched, it can turn to

    ; These 4 points to use the formula

    3-D rotation (look up).

TABAX EQU 250 (64000 = 250 * 256)


    ; High byte buffer, which is located
    ; Read coordinate axes. Address

    ; Buffer 256 times (!!!)


    LDA, E

    SUB 32

    LDE, A

    LDA, L

    SUB 32

    LDL, A

    LDA, C

    SUB 32

    LDC, A

    EXX

    LDA, L

    SUB 32

    LDL, A

    EXX

    LD HX, D; refers st.bayt IX.

    LD LX, E; Byte IX.

             ; (Undocumented to
             ; Manda CPU Z-80. 6

             ; Cycles)

    LDA, L

    PUSH AF

    LDA, C

    PUSH AF

    EXX

    LDA, L

    PUSH AF

    EXX

    LDA, H

    PUSH AF

    LDA, B

    PUSH AF

    EXX

    LDA, TABAX

    LD (VAR), A

    LDA, H

    LDB, HX

    CALL K64

    POP AF

    LDB, HX

    CALL K64

    POP AF

    LDB, HX

    CALL K64

    POP AF

    LDB, LX

    CALL K64

    POP AF

    LDB, LX

    CALL K64

    POP AF

    LDB, LX

    CALL K64

    RET

K64

; K64 - the most basic procedure. Vyzy; program is called AX 6 
times. Calculates ; Intermediate 64 koordinaty.Koordinata -

; Goal in the register A, and the source of B. Sources; 
nickname we Centre, then to B is always the coordinates, the 
coordinate of the center (Y or X). But in general here And she 
only needed to get the difference ; (AB or BA) and to determine 
the direction; leniya (positive or negative) , As coordinates 
of the center here, 0, 0 ; (Look up).

; Address table in 64 bytes (which crosses; tit all numbers) 
times 256. His older ; Bytes specified at VAR. This byte

By the way, at the end of programm itself increases; cates 1.
; So, I figured at first the coordinates
; Y, calling this procedure, and then X-s,
; Calling her again. We have three axes,
, So the procedure is called K64 6 times.


    CPB

    JPC, LOOP1

    SUB B

    LDL, A

    LDH, 0

    ADD HL, HL

    ADD HL, HL

    EXDE, HL

    LDHL, 0

LOOP2


    EXX

    LDA, (VAR)

    LDH, A

    INC A

    LD (VAR), A

    LDL, 0

    EXX


    DUP 64; Or any cycle type

            ; LD B, 64 :...: DJNZ ...

    LDA, H

    ADD HL, DE

    EXX

    LD (HL), A

    INC L

    EXX


    EDUP


    RET

LOOP1


    LDC, A

    LDA, B

    SUB C

    LDL, A

    LDH, 0

    ADD HL, HL

    ADD HL, HL

    EXDE, HL

    LDHL, 0

LOOP3


    EXX

    LDA, (VAR)

    LDH, A

    INC A

    LD (VAR), A

    LDL, 0

    EXX


    DUP 1964


    SBC HL, DE

    LDA, H

    EXX

    LD (HL), A

    INC L

    EXX


    EDUP


    RET


    CPB

    JPC, LOOP4

    SUB B

    LDL, A

    LDH, 0

    ADD HL, HL

    ADD HL, HL

    EXDE, HL

    LDH, B

    LDL, 0

    JPLOOP2

LOOP4


    LDC, A

    LDA, B

    SUB C

    LDL, A

    LDH, 0

    ADD HL, HL

    ADD HL, HL

    EXDE, HL

    ADD A, C

    LDH, A

    LDL, 0

    JPLOOP3

VAR


    NOP

    NOP


   Well, that's all. For those who are not going into
all these things, or do not want to add (to change, improve) my 
idea of ​​3D, a wants to write such an effect, as my:



   1. Do not forget about the format for storing the 
coordinates of 3D Objects. Do not forget the buffers 
(coordinate axes, delete buffer). 


   2. Coordinates of extreme points of the axes (Kz,
Kx, Ky, and center), consider the formulas of rotation or by a 
sine plate (I have, incidentally, is a cool way to generate 
syn. Plaques. Plaques are calculated much faster and more 
convenient than BASIC and is compressed somewhere in the 20

times. My plate of kilobytes occupied
less than 50 bytes. And decompress it
You can go along. It takes about
100-200 cycles per interrupt. In the near future
while I'm talking about all this, too, something I'll write).


  3. Algorithm of the program output should
to be somewhere like this:


   EI

   HALT

   DI

   CALL PRINT


   Record in the hl ', bc, hl, de following
values ​​of sin.tablitsy (need more
note that they are not too large, and then the sprite can get 
out of the screen and climb on the other hand (Fig. 3)).



   CALL AX


   Clear the screen using the delete
buffer'a (look up). It is desirable to adapt to work with two 
screens (from whom 128K, of course).



   JP BEGIN



    THAT WERE ALL I WANTED TO TELL U.

       I WISH U SUCCESS. SO LONG!


                  . . .


   After reading this article of our encoder
RUFF'a I (VIATOR), decided to make some adjustments to the text 
to clarify certain nuances ...


   Firstly, I must say that here
described a truly remarkable way
work with 3D objects in real time.
For those who do not understand this expression, I say - 
REALTIME-program and the effects of - Those which are 
calculated on a course program, and are not computed in 
advance. Often by that expression wrong imply that the program 
works for one interrupt that has nothing to do with the 
REALTIME and called ONE INT, or ONE FRAME (one interrupt / one 
frame). The advantage of programs in real time

lies in the economical use of memory and flexibility of 
structures, such as can be force to move a three-dimensional 
object is not on a pre-fixed trajectory, and on

trajectory given by the keyboard.

  Described here is remarkable that works very quickly.
Take for example the second part of the whole
well-known Slovak demos "ECHOLOGY",
vector objects there are also rotating in
real-time. Ponazhimat keys, you can remove the line and leave 
alone vector. Make sure the speed of the effects. On my 
Pentagon'e in one interrupt fit figure with the number of 
vectors, not exceeding 28, the figure with the number of 
vectors 29 and longer brake. 

   This same method allows you to rotate on
all three axes + zoom / delete / stretch, etc. much as 175 
vectors, and more! 

   The main essence of this method is
that rotates each point not in isolation, but once the whole 
plane. 

   This method may be useful not only
to create cool vector effects
but for the writing of new toys. And how
rulez'no will look old vector game, reworked, taking into 
account the latest technology? Imagine, for example, ELITE, 
running 2-3 times faster, or smoothly!



      So go for it, GOOD LUCK!

Comments (C) BY VIATOR / AVALON / RUSH / ASM




Other articles:

Authors - The authors of the journal and editorial contacts.

Entry - Welcome and opening remarks.

Entry - Describes the features of the shell.

Entry - Content.

Entry - Announcement of articles the next issue.

Likbez - Recovery programs by address search start-up, with perevzloma.

Likbez - Automatic creation of masks for sprites.

Likbez - a new algorithm for fast 3D graphics on SPECCY.

Likbez - CHEATS POKES and in game programs: the history of methods of cheating, corporate CHEAT, using published POKES, address search of immortality.

Miscellaneous - Fake editors for musical co-processor.

Miscellaneous - Trouble with AY (wrong clock frequency).

Miscellaneous - The virus in the IS-DOS.

Miscellaneous - Prulevka - strange people.

Miscellaneous - The editor of shipment for ELITE-3.

Miscellaneous - the results of an opinion poll Spektrumistov.

Miscellaneous - Competition special correspondent for the magazine.

Miscellaneous - Development Project Spectrum market.

Miscellaneous - FUNTOP-98 - the outcome of the festival.

Room with laughter - Computer Dictionary for Dummies.

Room with laughter - Chemical History.

Room with laughter - The second nasshestvie Martians.

Room with laughter - Jokes about Internet users.

Room with laughter - Vindoza - Source Code of Windows.

Web - How does a modem.

Web - Command HAYES-modem.

Web - What is MNP in HAYES-modems.

Web - Modems on the Spectrum.

Interview - An Interview with Ticklish Jim-ohm, Rom / Progress, BRAIN WAVE CORP, RST # 7, KGS INC.

Perspective - The presentation of the game "Mirror".

Perspective - CSC: DEJA VU - rumors and reality.

News - News from the scene: Phantom Family, Smash, OHG, Avalon, Spark, K3L, TGM, First Association, Discovery Group, BrainWave, etc.

News - News from the Chelyabinsk spektrumistov.

News - News from Cherkassy.

Around the World - APPLE presented a clear project PC.

Around the World - IA-64: An informal chronicle of the revolution.

Around the World - Bill Gates: ON WINDOWS - only the good.

Around the World - Everything you wanted to know about "silicone".

Fiction - The story EG Nesterenko, "The Crown and the Ring (part 2)

Fiction - Bloody Shadow.

Fiction - Terminator 3.

Scrap - BRIGHT + FLASH = NEW SPECCY.

Scrap - Wiring HAYES-modem.

Review - Magazines that we choose: ADVENTURER-6, AMAZING-2, AMIGA NEWS-1, CHAOS-1, DEJA VU-4, DEPTH-1, FLASH TIME-1, MIRACLE -1, OBERON-4, ODYSSEY-2, SPECCY-7, SPECTROPHOBY-, SPECTROFON-1923, SPECTRUM PROGRESS-2, ZX-FORMAT-7, ZX-NEWS-3, ZX-POWER-3, ZX-REVIEW.

Review - Overview of new products ON: TWILIGHT, BOOVIE, TOWDIE, ORION, SHERWOOD, WACKY RACES, MYSTICAL, JMENO, RUZE, SUPER CARS, LAST NINJA2, CHACK YEAGER-S, ADVANCED FLIGHT TRAINER, THE RAVERS PARADISE, TRITON MIX, TWIN WORLD, DUCK MANIA.

Mail - Letters from readers.

Mail - Letters: what they are ...

Desktop - Shadow mnogotekstovy assembler debugger ALASM 4.1 (Short description of functionality).

melomania - melomania Issue 1.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Problem - On the issue of the newspaper # z80 in English.
Iron - fix incorrect wiring diagrams musical coprocessor AY.

В этот день...   21 November