Scenergy #02
31 декабря 1999

Coding - Texture Mapping - Implementation of SaiR00S/EI.

<b>Coding</b> - Texture Mapping - Implementation of SaiR00S/EI.
TEXTURE MAPPING-ESPECIALLY 4 SCENERGY


(C) 1999 SaiR00S/EI


   The essence of the linear texture mapping
is a linear interpolation
coordinates of the polygon and their corresponding
texture coordinates.

   As the landfill is most often
selected triangle, although described
following algorithm is suitable for any
landfill.

   Thus, the polygon is a triangle,
all of whose vertices have a pair of coordinates
(X, Y) and related textural
coordinates (U, V). By polygon, we
move from top to bottom and from left to right,
ie when moving from top to bottom we
increase at each vertical step
Y coordinate of the triangle at
simultaneous linear interpolation
X coordinate and texture coordinates (in
That will have the contour of the polygon and
corresponding contour triangle
texture), and when moving from left to right,
increasing coordinate of the X-coordinate of
the left border of the contour to the right to
unit, perform linear interpolation
texture and set the coordinates Xi, Yj
color value from the texture coordinates
Up, Vq.

   The first thing to do - it
sort the coordinates of the triangle
vmeste with texture coordinates in
ascending order of the coordinates of Y, ie


   If vert1.y> vert2.y then

          swap (vert1, vert2);

   If vert2.y> vert3.y then

          swap (vert2, vert3);

   If vert3.y> vert1.y then

          swap (vert3, vert1);


   Or (Lexis STORM'a):


        LD HL, (VERT1); Take X, Y coordinates
        LD DE, (VERT2); you have a triangle

        LD BC, (VERT3);

        EXX

        LD HL, (VERT1 +2); Take textural

        LD DE, (VERT2 +2); coordinates U, V

        LD BC, (VERT3 +2);

        EXX

        LD A, D

        CP H

        JR NC, NOSWAP1

        EX DE, HL

        EXX

        EX DE, HL

        EXX
NOSWAP1 LD A, B

        CP H

        JR NC, NOSWAP2

        LD A, L, L, C, C, A

        LD A, H, H, B, B, A

        EXX

        LD A, L, L, C, C, A

        LD A, H, H, B, B, A

        EXX
NOSWAP2 LD A, B

        CP D

        JR NC, NOSWAP3

        LD A, E, E, C, C, A

        LD A, D, D, B, B, A

        EXX

        LD A, E, E, C, C, A

        LD A, D, D, B, B, A

        EXX
NOSWAP3 LD (VERT1), HL

        LD (VERT2), DE

        LD (VERT3), BC

        EXX

        LD (VERT1 +2), HL

        LD (VERT2 +2), DE

        LD (VERT3 +2), BC

        EXX



   The result is a picture
shown in the figure. In this case,
inflection point is on the left
respectively, in the left half
triangle have 2 faces, and the right -
one.


                vert1
,,

              ,,

             ,,

            ,,

           ,,
H1,,

         ,,

        ,,

       ,, H

      ,,
 vert2,

       'U,

           'U,

               'U,
H2 'u,

                        'U,

                              u,

       <W> 'u
'' U

                                     vert3
Ha below:

     H - Maximum height of the triangle

     H1 - the height of ribs (vert1, vert2);

     H2 - the height of ribs (vert2, vert3);

     W - maximum width of the triangle

          triangle of X. Determined

          it follows:


   t = (vert2.y-vert1.y) / (vert3.y-vert1.y)

   w = (vert1.x + t * (vert3.x-vert1.x))-vert2.x


   If H and / or W are zero, then
Draw a triangle is not necessary.

   Next, we determine which side
is an inflection point in the triangle.
This is done checking the sign of W.
If this value is positive, then the point
inflection - the left is negative - on the right.


   If w> 0 then "point" on left

          else "point" on right


   Then perform a linear interpolation
X coordinate of the triangle and texture
coordinates U, V. Interpolation can be
conduct the formula below, or
by Brezenhemu - as you like, but
the second option more quickly (although, for small
number of polygons that we have to
Spectrum, it's almost not noticeable).


   So, if the inflection point on the left (W> 0);
then you need to draw two faces to the left and one
on the right:

Building a left-hand side of the triangle:


   h1 = vert2.y-vert1.y

   DeltaLeftX1 = (vert2.x-vert1.x) / h1

   DeltaLeftU1 = (vert2.u-vert1.u) / h1

   DeltaLeftV1 = (vert2.v-vert1.v) / h1

   h2 = vert3.y-vert2.y

   DeltaLeftX2 = (vert3.x-vert2.x) / h2

   DeltaLeftU2 = (vert3.u-vert2.u) / h2

   DeltaLeftV2 = (vert3.v-vert2.v) / h2

   X: = vert1.x;

   For i = 0 to h1 do

    Begin

      TableLeftX [i]: = X;

      TableU [i]: = U;

      TableV [i]: = V;

      X: = X + DeltaLeftX;

      U: = U + DeltaLeftU;

      V: = V + DeltaLeftV;

     End;

    For i = h1 to h2 do

     Begin

      TableLeftX [i]: = X;

      TableU [i]: = U;

      TableV [i]: = V;

      X: = X + DeltaLeftX2;

      U: = U + DeltaLeftU2;

      V: = V + DeltaLeftV2;

     End;

Construct the right-hand side of the triangle:


    h = vert3.y-vert1.y;

    DeltaRightX = (vert3.x-vert1.x) / h;

    For i = 0 to h do

     Begin

      TableRightX [i]: = X;

      X: = X + DeltaRightX;

     End;


   Here:

     TableLeftX [] - the table containing the X

                    coordinates of the left half
                    guilty of a triangle;

     TableRightX [] - the same for the right position
                    guilt;

     TableU [] - the table containing the U

                    coordinates of the left half
                    treuglnika guilt;

     TableV [] - the same for V-coordinates

     DeltaLeftX - constant interpolation

                    (On the ZX should be considered
                    Camping with the fixed point 8.8);

     DeltaRightX - same thing.


   If the inflection point is on the right
(W <0), then all the same, only the left
Draw one edge of the triangle, and
right - two.


   Next we define the steps in texture,
which are constant for all
landfill (to ZX assume them fixed
point 8.8, and with the sign!):


   DeltaU = (t * (u3-u1) + (u1-u2)) / w

   DeltaV = (t * (v3-v1) + (v1-v2)) / w



  Further, immediately draw a polygon:

 i: = 0;
 For Y: = vert1.y to (vert1.y + H) do
 Begin

  U: = TableU [i];

  V: = TableV [i];

  For X: = TableLeftX [i] to TableRigtX [i] do

  Begin

    {Puts an end to the coordinate (X, Y) color

     from the texture coordinate (U, V)}

   PutPixel (X, Y, Texture [U, V])

   X: = X +1;

   U: = U + DeltaU;

   V: = V + DeltaV

  End;

  i: = i +1
 End;



   The inner loop would look like
follows (by the way, perhaps
faster ...):


        LD A, H; V-coordinate in the texture

        ADD HL, DE; to calculate the following
                 ; Ordinate V

        EXX

        LD B, A

        LD C, H; U-coordinate in the texture

        ADD HL, DE; to calculate the following
                 ; Ordinate U

        LD A, (BC); take texel

        EXX

        LD (BC), A; put texel in bu
                 , Fer

        INC C; increasing X-coordinates
                 ; That



   It is recalled that all (almost)
calculations are performed with the fixed point 8.8,
For example:

       HL = HL, ie, H contains an integer part
number, and L - fractional.


    Well, like all good luck in the coding.





Other articles:

AOSS - "The scene is sick" experiences Random'a.

AOSS - Raver discusses stsenovoy journalism.

AOSS - an analytical article on the music scene from Andy Fer.

AOSS - how easy is it to be the organizer of the group?

AOSS - On journals (thinking aloud).

AOSS - on the example of the canons of demoscene magazine Deja Vu # 9.

AOSS - Today and Tomorrow domestic demoscene.

AOSS - Spectrum banner network.

Charts - all time favorites.

Charts - current rules (fall edition 1999).

Charts - indexed.

Charts - voting rules.

Coding - 16-bit procedure is fast exponentiation.

Coding - Flying is makrobiblioteku: Memory Management Library.

Coding - Texture Mapping - Implementation of SaiR00S/EI.

Coding - Texture mapping + Phong shading implementation of the Senat / Eternity Industry.

Coding - ZXA library: a library for creating and playing animations.

Coding - A bug in the STS?

Coding - Comments to the sources, published in Scenergy # 1

Coding - the libraries of programming on the Spectrum.

Coding - The principle of packing animations in the demo JAM.

Coding - procedure for rapid multiplication.

Coding - parsing intro Daingy from Cryss / Razzlers.

Demo Party - Cafe'2000: Official invitation

Demo Party - CC999.999 information (eng).

Demo Party - D-Man/EI: Report on Di: Halt: 99.

Demo Party - Hartman: report CC'999.

Demo Party - Maxwell and Mr. John: report CC'999.

Demo Party - Merlin / CC: Report CC'999.

Demo Party - Paradox'99 - as it was, but it would be better if he mUst dIe!!!

Demo Party - PHAT'9: list of visitors.

Demo Party - POL / PHT: report Doxycon '99.

Demo Party - Random / CC: volumetric report CC'999.

Demo Party - SerzhSoft: Legend of the CC'999.

Demo Party - Zlincon 2e3 party: minireportazh.

Demo Party - information about the upcoming party PHAT'0.

Demo Party - Information on demoparti CC999.999.

Demo Party - unofficial results Di: Halt'99 with comments Diver'a.

Demo Party - an overview of demoscene 1999.

Demo Party - report the organizers CAFe'99.

Demo Party - Press release Latvian demopati PHAT'9.

Demo Party - an invitation to Latvia demopati PHAT'9.

Demo Party - a story about a trip to Kazan on Antares CAFe'99

Demo Party - Results CC.999.999

Demo Party - Results CC999.999.

Demo Party - the results of Chaos Construction 999.

Demo Party - Results Computer Art Festival 1999.

Demo Party - Results Doxycon'99.

Demo Party - Results Millenium Party.

Demo Party - Results Paradox'2k demoparty.

Demo Party - Results of the Latvian demopati PHAT'9.

Demo Party - the results of the Rostov party Paradox'99.

Demo Party - reportage Gasman'a with Forever 2e3.

Demo Party - a report from Minsk demopati Millennium'2000.

Demo Party - final results Forever 2E3.

Editorial - Opening remarks by Arty.

Editorial - vystupitelnoe word from Random.

Editorial - pens Raver'a entitled "Scenes."

Groups - survey of operating groups: Amaltiya Incoropration Software.

Groups - survey of operating groups: Antares.

Groups - survey of operating groups: Ascendancy Creative Labs.

Groups - survey of operating groups: Crushers.

Groups - survey of operating groups: E-mage.

Groups - survey of operating groups: Eternity Industry.

Groups - survey of operating groups: Excess team.

Groups - survey of operating groups: Extreme Entertainment.

Groups - survey of operating groups: Fatality.

Groups - survey of operating groups: Jupiter 77.

Groups - survey of operating groups: Proxima Centauri.

Groups - survey of operating groups: RaZZLeRs.

Groups - survey of operating groups: RUSH.

Groups - survey of operating groups: Smash Hackers Band.

Illegal Corner - Razzlers justified for the release of the demo First Association.

Illegal Corner - Scenergy Release Charts - Competition crack.

Illegal Corner - Welcome to Scenergy Release Charts (SRC).

Illegal Corner - softografiya Fatality Group.

Lits - Pussy: the history of creation of the famous game from the Fatality.

Lits - Scenergized beyond the belief.

Lits - speed.

Lits - History of Education Association Rostov PartyZans.

Lits - the story of the game "White Eagle - Comrade known."

Lits - the story of how Fatality produces toys.

Mail Box - letter: Ellvis and Fatality happy Scenergy # 1, Ulterior defy Antares and BrainWave, Realtimer disappointed.

News - Doom'a will not!

News - Virtual pati Millennium, X-Raizor returned to the stage, Andrew Fer organized a new group, the failure of the German party Spectrology, news from 3SC, Zero Team, Extreme.

News - The view of Megus'a dentro compo SS'2000.

News - News from the OHG, Delta Hackers Group, Die Crupps, Volgodonsk spektrumisto and from a group SpeedWay.

Scenergy - addresses to communicate with the editors.

Scenergy - thanks to the sponsors of the magazine.

Scenergy - new in the shell of the journal.

Scenergy - the promised video articles will not ...

VIP - Random interviews Unbel! Ever / Sage / XTM.

VIP - The most noble tale of the scene.

VIP - an interview with Arny and Mythos, the creators of Elite clone game Awaken.

VIP - An interview with Fatality, widely known and crackers Game Maker

VIP - an interview with one of the authors of the game Elite.

VIP - an interview with one of the most progressive artists in the Spectrum Diver/4D.

VIP - interviews with Random'a some PC-magazine

Warez Pack - description of Inertia Player.

Warez Pack - description of the demo 1140.

Warez Pack - description of the import demo 'no work'.


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

Similar articles:
Book - Secrets ZX-Spectrum: Editor.
Ottyag - Why did the sheep better than women.

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