Author Topic: Gear Wheels  (Read 17890 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Gear Wheels
« on: August 12, 2007 »
Always wanted to do some of these but I kept forgetting to make them :)

Code: [Select]

'-------------------------------------------------------------------------------
' Cogs By Shockwave
'
' An intro featuring gear wheels :-)
'-------------------------------------------------------------------------------

        OPTION STATIC
        OPTION EXPLICIT
       
        CONST   XRES = 800
        CONST   YRES = 600

        DIM SHARED AS DOUBLE RAD2DEG
        DIM SHARED AS INTEGER HALFX = (XRES/2)
        DIM SHARED AS INTEGER HALFY = (YRES/2)
        DIM SHARED AS DOUBLE ROLL1,ROLL2,SMV

        RAD2DEG = ((4*ATN(1)) / 180 )
       
        #INCLUDE "TINYPTC_EXT.BI"
        #INCLUDE "WINDOWS.BI"
       
        DIM SHARED AS UINTEGER  BUFFER ( XRES * YRES )
        DECLARE SUB DRAW_WHEEL(BYVAL CX AS INTEGER ,BYVAL CY AS INTEGER,  BYVAL RADIUS AS DOUBLE , BYVAL STEPSIZE AS DOUBLE, BYVAL TOOTHSIZE AS DOUBLE, BYVAL ANGLE AS DOUBLE , BYVAL COLOUR AS UINTEGER )
        DECLARE SUB FLAT_TRIANGLE(BYVAL X1 AS INTEGER , BYVAL Y1 AS INTEGER, BYVAL X2 AS INTEGER , BYVAL Y2 AS INTEGER , BYVAL X3 AS INTEGER, BYVAL Y3 AS INTEGER , BYVAL TC AS INTEGER)
       
'-------------------------------------------------------------------------------

        PTC_ALLOWCLOSE(0)
        PTC_SETDIALOG(0,"",0,0)   
       
        IF (PTC_OPEN("<( - DBF - )>",XRES,YRES)=0) THEN
        END-1
    END IF     
   
'-------------------------------------------------------------------------------   

    WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<>-32767) 
        SMV=1.5*SIN(TIMER/3)
    ROLL1=ROLL1+SMV
    ROLL2=ROLL2-SMV
    IF ROLL1>360 THEN ROLL1=ROLL1-360
   
    DRAW_WHEEL ( 460 , 115 , 50 , 20 , 6 , (ROLL1*2),&H778899 )
    DRAW_WHEEL ( 460 , 395 , 50 , 20 , 6 , (ROLL1*2),&H778899 )

    DRAW_WHEEL ( 198 , 140 , 100 , 10 , 10 , ROLL1,&H8899AA )
    DRAW_WHEEL ( 379 , 255 , 100 , 10 , 10 , (ROLL2-5) ,&H667788)

    DRAW_WHEEL ( 617 , 433 , 100 , 10 , 10 , (ROLL2-5) ,&H667788)

    PTC_UPDATE@BUFFER(0)
   
    ERASE BUFFER
    WEND

'-------------------------------------------------------------------------------

'
' USAGE : DRAW_WHEEL ( XPOS , YPOS , RADIUS , STEPSIZE , TOOTH SIZE , ROTATION )
'

SUB DRAW_WHEEL(BYVAL CX AS INTEGER ,BYVAL CY AS INTEGER,  BYVAL RADIUS AS DOUBLE , BYVAL STEPSIZE AS DOUBLE, BYVAL TOOTHSIZE AS DOUBLE, BYVAL ANGLE AS DOUBLE , BYVAL COLOUR AS UINTEGER )

    DIM AS DOUBLE RADIUS2
    DIM AS INTEGER STORE
    DIM AS INTEGER CNT
   
    STORE = (360/STEPSIZE)+1
    DIM AS DOUBLE X1(STORE),Y1(STORE),X2(STORE),Y2(STORE)
    DIM AS INTEGER L


'-------------------------------------------------------------------------------
' First create the gearwheel object;
'-------------------------------------------------------------------------------

    RADIUS2 = TOOTHSIZE+RADIUS
   
    FOR L=0 TO 360 STEP STEPSIZE
       
        X1(CNT) = (RADIUS * SIN ((L+ANGLE) * RAD2DEG)) + CX
        Y1(CNT) = (RADIUS * COS ((L+ANGLE) * RAD2DEG)) + CY

        X2(CNT) = (RADIUS2* SIN ((L+ANGLE) * RAD2DEG)) + CX
        Y2(CNT) = (RADIUS2* COS ((L+ANGLE) * RAD2DEG)) + CY
       
'        BUFFER (INT(X1(CNT))+(INT(Y1(CNT))*XRES)) = &HFFFFFF
'        BUFFER (INT(X2(CNT))+(INT(Y2(CNT))*XRES)) = &HFFFFFF       
       
        CNT=CNT+1
    NEXT

'-------------------------------------------------------------------------------
' Now we can draw it.
'-------------------------------------------------------------------------------

' INSIDE FIRST;

FOR L=0 TO CNT-2
   
    FLAT_TRIANGLE(CX,CY,X1(L),Y1(L),X1(L+1),Y1(L+1),COLOUR)
   
NEXT

' NOW THE TEETH;

FOR L=0 TO CNT-2 STEP 2
   
    FLAT_TRIANGLE(X2(L),Y2(L),X1(L),Y1(L),X1(L+1),Y1(L+1),COLOUR)
    FLAT_TRIANGLE(X2(L),Y2(L),X2(L+1),Y2(L+1),X1(L+1),Y1(L+1),COLOUR)
   
NEXT


END SUB


SUB FLAT_TRIANGLE(BYVAL X1 AS INTEGER , BYVAL Y1 AS INTEGER, BYVAL X2 AS INTEGER , BYVAL Y2 AS INTEGER , BYVAL X3 AS INTEGER, BYVAL Y3 AS INTEGER , BYVAL TC AS INTEGER)
'-------------------------------------------------------------------------
' FLAT TRIANGLE RENDERER WITH ASSEMBLY LANGUAGE RASTERISING BY SHOCKWAVE ^ DBF ^ S!P 2006.
'-------------------------------------------------------------------------
'-------------------------------------------------------------------------
' WE NEED TO SORT THESE POINTS INTO ORDER FROM TOP TO BOTTOM, AN EXCHANGE SORT IS OK.
' AS WE ONLY HAVE GOT 3 POINTS TO ARRANGE.
'-------------------------------------------------------------------------
DIM AS INTEGER TEMPX,TEMPY,LO,LI
                DIM AS INTEGER PX(3)
                DIM AS INTEGER PY(3)
                DIM TFLAG AS INTEGER
                dim pp as uinteger PTR
                DIM AS INTEGER IL1,IL2,SLICE
                TFLAG=0
        PX(1)= X1
        PX(2)= X2
        PX(3)= X3
       
        PY(1)= Y1
        PY(2)= Y2
        PY(3)= Y3

FOR LO = 1 TO 2
    FOR LI =1 TO 2     
        IF PY(LI+1) <= PY(LI) THEN
        TEMPX = PX(LI) : TEMPY = PY(LI)
        PX(LI) = PX(LI+1)
        PY(LI) = PY(LI+1)
        PX(LI+1) = TEMPX
        PY(LI+1) = TEMPY
        END IF   
    NEXT LI
NEXT LO

'   BOOT OUT INVISIBLE TRIANGLES!

    IF PX(1)<0 AND PX(2)<0  AND PX(3)< 0 THEN TFLAG=1
    IF PX(1)>XRES AND PX(2)>XRES  AND PX(3)>XRES THEN TFLAG=1
    IF PY(1)>YRES AND PY(2)>YRES  AND PY(3)>YRES THEN TFLAG=1
   
        DIM AS DOUBLE XP1,XP2:' SCREEN POSITIONS.
        DIM AS DOUBLE XI1,XI2:' INTERPOLATIONS.
       
'***
'*** REGULAR TRIANGLE (Y1<Y2 Y2<Y3)
'***

IF PY(1)<PY(2) AND PY(2)<PY(3) or (PY(2) = PY(3)) THEN
    TFLAG=1
XP1 = PX(1)
XP2 = PX(1)
XI1 = (PX(1)-PX(2)) / (PY(2) - PY(1))
XI2 = (PX(1)-PX(3)) / (PY(3) - PY(1))

FOR LO = PY(1) TO PY(2)-1
   
IF LO>=0 AND LO<YRES THEN

    IF XP1<=XP2 THEN
        IL1=XP1
        IL2=XP2
    ELSE
        IL1=XP2
        IL2=XP1
    END IF
   
    IF IL2>XRES THEN IL2=XRES
    IF IL1<0 THEN IL1=0

    SLICE = IL2-IL1
    IF SLICE>0 THEN
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    end asm   
    END IF
   

END IF

XP1=XP1-XI1
XP2=XP2-XI2
NEXT

XI1 = (PX(2)-PX(3)) / (PY(3) - PY(2))
XP1 = PX(2)

FOR LO = PY(2) TO PY(3)
IF LO>=0 AND LO<YRES THEN
    IF XP1<=XP2 THEN
        IL1=XP1
        IL2=XP2
    ELSE
        IL1=XP2
        IL2=XP1
    END IF

    IF IL2>XRES THEN IL2=XRES
    IF IL1<0 THEN IL1=0

    SLICE = IL2-IL1
    IF SLICE>0 THEN
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    end asm   
    END IF
END IF
XP1=XP1-XI1
XP2=XP2-XI2
NEXT

END IF


'***
'*** FLAT TOPPED TRIANGLE Y1=Y2
'***

IF TFLAG=0 AND PY(1) = PY(2) THEN
   
        TFLAG=1
        XP1 = PX(1)
        XP2 = PX(2)
        XI1 = (PX(1)-PX(3)) / (PY(3) - PY(1))
        XI2 = (PX(2)-PX(3)) / (PY(3) - PY(2))
FOR LO = PY(1) TO PY(3)
 IF LO>=0 AND LO<YRES THEN
    IF XP1<=XP2 THEN
        IL1=XP1
        IL2=XP2
    ELSE
        IL1=XP2
        IL2=XP1
    END IF
   
    IF IL2>XRES THEN IL2=XRES
    IF IL1<0 THEN IL1=0
   
    SLICE = IL2-IL1
    IF SLICE>0 THEN
    PP = @BUFFER(IL1+(LO*XRES))   
    asm
        mov eax,dword ptr[TC]
        mov ecx, [slice]
        mov edi, [PP]
        rep stosd
    end asm   
    END IF
END IF
    XP1=XP1-XI1
    XP2=XP2-XI2

NEXT
END IF
END SUB
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Gear Wheels
« Reply #1 on: August 12, 2007 »
I like to see gears in intros too   :goodpost:
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Gear Wheels
« Reply #2 on: August 12, 2007 »
That just screams tutorial :-)
Nice little demo.

Chris
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Gear Wheels
« Reply #3 on: August 13, 2007 »
really love them, too. look very industrial - love that !!!
cool fx, shocky. thx for sharing. k++
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Gear Wheels
« Reply #4 on: August 13, 2007 »
Nice!  I'd like to know the logic behind the gear ratios/sizes/teeth sizes and how to work out where the gears are placed :)

Jim
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Gear Wheels
« Reply #5 on: August 13, 2007 »
fook me!

Reminds me of Vanish WOC demo!!!! Karma +

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #6 on: August 13, 2007 »
Nice!  I'd like to know the logic behind the gear ratios/sizes/teeth sizes and how to work out where the gears are placed :)

Actually it's just trial and error for now, however every time you halve the size of a cog, you have to double the rotation speed and double the distance between the teeth. I'm sure it could be done more elegantly than this but hey, it's early days :)

Thanks for the comments and the Karma guys :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Gear Wheels
« Reply #7 on: August 14, 2007 »
looking good,
but could evolve to something way much better if you give it some time shocky
 ;)
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #8 on: August 14, 2007 »
looking good,
but could evolve to something way much better if you give it some time shocky
 ;)


I am working on it.. :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Gear Wheels
« Reply #9 on: August 15, 2007 »
How about having some cogs break. So it alters the cycle, or is that too much of a pain in the rectum.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #10 on: August 15, 2007 »
How about having some cogs break. So it alters the cycle, or is that too much of a pain in the rectum.

Feel free to change it if you like Clyde. :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Gear Wheels
« Reply #11 on: August 15, 2007 »
Very nice work Shockwave!  :goodpost:
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #12 on: August 15, 2007 »
After showing it to some of my friends it is going to be an intro for the group; Ravebusters, I joined them a couple of weeks ago (I am still in S!P as well).

Anyway, here is a preview and a pic.
Then the next time you will see it it will be finished.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Gear Wheels
« Reply #13 on: August 15, 2007 »
Cool idea and looks pretty good although sometimes the shadows of the cogs nearest the edges of the screen kind of go the wrong way. If you're drawing with filled triangles (I don't know if you are or not) it would be possible to project your points from the light source coordinates.

Tell me to shut up if you want.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #14 on: August 15, 2007 »
Ah yes. Cheers for that I'd missed it!

I'll fix it up so that the shadows all point the right way (it is rendered with triangles but I will cheat my way around it for speed, because I want to add some more effects)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Gear Wheels
« Reply #15 on: August 15, 2007 »
Looks great Shocky - as always.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Gear Wheels
« Reply #16 on: August 15, 2007 »
No need for any cheating, maybe only needs something like:

Code: [Select]
shadow_x=light_x+(point_x-light_x)*1.1
shadow_y=light_y+(point_y-light_y)*1.1

for each point.

or whatever value looks better instead of 1.1

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Gear Wheels
« Reply #17 on: August 15, 2007 »
Well jazzy and smart. Congrats in your new group too dude.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Gear Wheels
« Reply #18 on: August 16, 2007 »
Can we have an icon for not worthy? please? Looking really smart Shockwave.
Keep up the fantastic work!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Gear Wheels
« Reply #19 on: August 16, 2007 »
Ah cheers Stonemonkey :) I will add that later on tonight after I have assembled the patio furniture.

Thanks for all the positive comments.
Shockwave ^ Codigos
Challenge Trophies Won: