tunnel - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

tunnel

brewskibrewski Posts: 18Member
@texture

calcTunnel:

mov di,64000-1
mov cx,100
@capl
dec cx
cmp cx,-100
jne @finish:

mov ax,0003h
int 10h
ret

constant1 dw 8192
constant2 dw 128
i dw ?
j dw ?
z dw ?
temp dw ?

mup db ?

displace db ?
offscreen dw ?

END START

Comments

  • espydudeespydude Posts: 7Member
    Thank you for being the first person to add some code. I'am hoping that this type of message board works. Any body with comments please feel free to post or send a message to me.


    Thanks!



    [blue][size=3]Question [b][italic]everything![/italic][/b][/size][/blue]

    Espydude

  • blipblip Posts: 756Member
    @texture

    calcTunnel:
    mov di,64000-1
    mov cx,100
    @capl
    dec cx
    cmp cx,-100
    jne @finish:

    mov ax,0003h
    int 10h
    ret

    constant1 dw 8192
    constant2 dw 128
    i dw ?
    j dw ?
    z dw ?
    temp dw ?

    mup db ?

    displace db ?
    offscreen dw ?

    code ends
    END START[/code]
  • brewskibrewski Posts: 18Member
    Nice! =)
  • angelusMortisangelusMortis Posts: 141Member
    coud anyone explain the effect to me, please ????
  • blipblip Posts: 756Member
    I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).
  • angelusMortisangelusMortis Posts: 141Member
    i mean source code sharing is a very good idea. but what do i need it
    for if i cant undestand the source?
    so if there is someone who can explain the effect to me, please reply.





    : I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).
    :

  • brewskibrewski Posts: 18Member
    [b][red]This message was edited by the brewski at 2002-6-23 0:7:8[/red][/b][hr]
    [b][red]This message was edited by the brewski at 2002-6-23 0:4:59[/red][/b][hr]
    [b][red]This message was edited by the brewski at 2002-6-23 0:2:14[/red][/b][hr]
    : i mean source code sharing is a very good idea. but what do i need it
    : for if i cant undestand the source?
    : so if there is someone who can explain the effect to me, please reply.
    :
    :
    :
    :
    :
    : : I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).
    : :
    :
    :
    Hi AngelusMortis!

    I can explain what I remember of how this kind of effect is working, with some c-code, hope
    that's ok.
    Lots of look up tables:

    One that precalculates a texture which is 256x256 pixels large.
    In this case, by xor'ing in a loop, produces an image with squares.
    This texture is where pixels or texels will be fetched from later.
    In c code would be:

    int index=0;
    for(int y=0;y<256;y++){
    for(int x=0;x<256;x++){
    texture[y+x*256]=(char)(x^y);
    index++;
    }}

    Next, precalculate the u and v buffers.
    In the source there's one 64k segment for the u's, and another one for the v's.
    These buffers contains memory offsets which points to the texture-segment.
    For every coordinate position on screen there's a corresponding offset where to
    fetch the texel in the texture-buffer.
    So these buffers equals the size of the screen, 320x200.
    The u's contains offsets for the x-coordinates.
    The v's contains offsets for the y-coordinates.
    So in the render loop, ( tAnimate-label in the asm-source) something like:

    int index=0;
    for(int y=0;y<200;y++){
    for(int x=0;x<320;x++){
    PixelOnScreen[index]=texture[ uvBuffer [x+(y *256 )] ];
    index++;
    }}

    ( But in the asm-src there's separate buffers for u and v so it's more like:
    u=uBuffer[index];
    v=vBuffer[index];
    PixelOnScreen[index]=texture[u+v<<8]

    But this would produce a static picture, to get motion, add another dynamic variable and
    add it to the offsets, and the tunnel will move:

    u=uBuffer[index]+displace;
    v=vBuffer[index]+displace;
    PixelOnScreen[index]=texture[u+v<<8]



    ( And once every frame increase displace-variable )

    The 'calcTunnel' label in the source, is where these uv offsets are calculated, with
    some trigonometry-function.
    In c would be somewhat like:

    int index=0;
    for(int y=0;y<200;y++){
    for(int x=0;x<320;x++){
    int i=x-160; // (SCREENWIDTH/2)
    int j=y-100; // (SCREENHEIGHT/2)
    v [index] = (int) ( atan2 (i,j) * 128/ 3.14159265 ); // the angle
    u [index] = (int) ( 8192 / sqrt (i*i+j*j) ); // distance from origin
    index++;
    }}

    (Varying the constant 8192 will produce different perspective.
    Constant 128 is half of size of the textureBuffer width or height.)

    I just converted this to assembler, and tried optimize a bit for size.
    So the asm-code is messier than these c-snippets.

    Hope this help.
    (I wrote this off memory, so if someone spots error, please
    forgive...)

    To Blip: Could you please explain about pipeline, what is it? and how to prevent bad pipelining! )







  • blipblip Posts: 756Member
    Pipelining is like having a few mini-processors in one that do jobs in parallel to speed up the whole machine considerably. There is one catch, though: they must do jobs that don't require the result of another that's in another pipeline or else you'll have a pipeline stall and lose some speed in the process. There are many ways to prevent pipeline stalls and they can differ between processors. I'd rather not explain it because this guide does much better than I would be able to and more: http://www.programmersheaven.com/file.asp?FileID=6344
Sign In or Register to comment.