Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Shockwave on August 12, 2007
-
Always wanted to do some of these but I kept forgetting to make them :)
'-------------------------------------------------------------------------------
' 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
-
I like to see gears in intros too :goodpost:
-
That just screams tutorial :-)
Nice little demo.
Chris
-
really love them, too. look very industrial - love that !!!
cool fx, shocky. thx for sharing. k++
-
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
-
fook me!
Reminds me of Vanish WOC demo!!!! Karma +
Drew
-
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 :)
-
looking good,
but could evolve to something way much better if you give it some time shocky
;)
-
looking good,
but could evolve to something way much better if you give it some time shocky
;)
I am working on it.. :)
-
How about having some cogs break. So it alters the cycle, or is that too much of a pain in the rectum.
-
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. :)
-
Very nice work Shockwave! :goodpost:
-
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.
-
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.
-
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)
-
Looks great Shocky - as always.
-
No need for any cheating, maybe only needs something like:
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
-
Well jazzy and smart. Congrats in your new group too dude.
-
Can we have an icon for not worthy? please? Looking really smart Shockwave.
Keep up the fantastic work!
Drew
-
Ah cheers Stonemonkey :) I will add that later on tonight after I have assembled the patio furniture.
Thanks for all the positive comments.
-
Added more stuff now.
Thanks for noticing that the shadows looked wrong Stonemonkey, they are fixed now :)
-
Looks cool but I'm going to be really annoying here, I take it you're using the calc i gave to find the centre of the shadow cogs which if you only draw the shadows and not the cogs themselves will look a bit strange, what I was meaning was when drawing the shadow cogs you do that calc for each vertex of each triangle before you draw the triangle.
-
I ended up changing that calc a bit to get the result I wanted, I took the gear wheels out and left the shadows and it looks ok to me. If I applied the same calc to each vertex then I'd get more stretchy shadows I guess, I'll try it out soon but it means calculating each cog twice so I will need to do a fair bit of re-coding.
Other cheaper methods could be used to make the shadows stretch too... I will need to look at both. Thanks for the feedback :)
-
but it means calculating each cog twice
not necessarily, you could make use of the alpha channel in the screen buffer, when filling a pixel do the test:
if (screen(x,y) and &hff000000)=0 then screen(x,y)=fill_colour
using whatever method it is to access and fill the pixels
and add some alpha value to the colour that you fill the actual cogs with fill_colour=&hff00ff00 (for green)
then you can draw the cog triangle,do the shadow calcs,fill the shadow triangle
have the alpha part of the shadow colour set to 0 though so that other parts of cogs can be drawn over the shadows.
-
I'll certainly take some of that on board.
Thank you. :) K+
-
I just realised that I probably won't be able to render it with alpha like that because all colour palettes are precalculated.
There are palettes for each element, 2 for the cogs, one for the shadow, one for the border line and two more for the twisters.
Each palette contains 1000 colours.
The pallettes are laid out sequentially in one array and start on 1000 +
The lighting works by having a gigantic 600 * 600 metablob which is rendered over the top after all the other things have been drawn. it looks a little like the light model you'd use in a bump map only here there is no height map.
This produces the nice gradient shading, very easy to do at this speed in gl or directx I think but harder to get running quickly in software.
I have used this method before in other intros, frequently in fact.
Anyway the upshot of it is that each pixel is actually physically copied over to the screen buffer like this;
SUB COPYOVER()
DIM L AS INTEGER
DIM AS UINTEGER PTR PP1,PP2
PP1=@BUFFER (0)
PP2=@BUFFER2(0)
FOR L=0 TO (XRES*YRES)-1
*PP1 = PAL(*PP2)
PP1+=1
PP2+=1
NEXT
END SUB
As you can see, the actual colour value of each pixel is retrieved from the palette array.
I want to give your method a try though as it would be interesting so what I'll probably do is re-code it in the near future to work with proper colours.
In all fairness to you you are a big inspiration as usual, my programming methods are unorthadox though and a little hard to second guess, especially when I had not posted the source for a while.
(I will post the full code for this when it's released).
-
Still possible I think, if you had the shadow palette before the cog palettes then you could use
if screen(x,y)<1000 then screen(x,y)=colour_index
or whatever the index is of the first entry in the cog palette.
no need for using the alpha channel but you'd be able to use the same drawing sequence, draw the cog triangle, do the shadow offset calcs,draw the shadow triangle.
-
I must say that this is looking very good, i think the shadows look right, even if they aren't. the twisters though look a little unnatural, i don't know why but it just does.
Keep up the good work!
-
Yes it could be done actually, you are right.
I'd have to double the amount of stored colours though because of the light model.
The shadows could be stored on 0-999 and the light could be stored on 10000-10999.
Thanks.
And Paul, yep, the twisters are a bit freakish and liquidy... It will probably change a little bit before I release it.
-
Other cheaper methods could be used to make the shadows stretch too...
I'm intrigued by that. When shadowing first started being used in games and things and done with some sort of offset mask on the background it added a little to the dimension of the image and usually assumed a directional lightsource but if you introduce a lightsource with position (or evidence of one) just an offset masked image isn't enough to fool the eye.
With a little work (and tbh if you're already drawing the shadows as triangles i can't think of anything cheaper, even any 'cheats') you can add a whole new dimension to the image, and if it's possible to alter the lighting effect so as to look like the lightsource is getting closer (smaller but brighter light point) /further(larger not so bright) (z distance) you could adjust the shadowing convincingly too.
-
Or I could just stretch one radius of a shadow as it moves away.
The way that the shadows were at first was wrong, they looked stupid. I hadn't noticed, then thanks to your help they move in a much more natural way now.
The thing is, in my experience it can be too counter productive to get really bogged down in the intricacies of something. More positive gain can be made sometimes by diverting the effort into doing something else like tweaking the colours, adjusting the movement of the lights etc..
Like I said, I will do something along the lines of what you suggested, but not this time. For those who are interested, I have almost run out of time to work on this, I am working on the S!P intro now, this RBS one is finished save for the tune and the logo, but have a look, it's not bad considering I spent less than a week on it.
-
Looks cool, still think you should fix the shadows though. I like the scoll too.
Or I could just stretch one radius of a shadow as it moves away.
I really hope I've just missed some sarcasm in that and you're not being serious.
-
wwwwooooooowwwww! the shadowed version is really kick'n ass shockwave! fucking great! i love it! very nice! K++
-
With very little modification to the original code you posted:
'-------------------------------------------------------------------------------
' 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 )
''#define PTC_WIN
#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 ,_
byval light_x as single=320.0,_
byval light_y as single=240.0,_
byval offset as single=1.1)
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
'-------------------------------------------------------------------------------
dim as single la,shadow_offset,light_x,light_y
dim as integer i,c0,c1,c2
WHILE(GETASYNCKEYSTATE(VK_ESCAPE)<>-32767)
SMV=1.5*SIN(TIMER/3)
ROLL1=ROLL1+SMV
ROLL2=ROLL2-SMV
'rotate light around centre of screen
la+=0.01
IF ROLL1>360 THEN ROLL1=ROLL1-360
for i=0 to 1
if i=0 then
'change this value slightly for more/less depth
shadow_offset=1.08
'shadow colour
c0=&h300030
c1=c0
c2=c0
else
shadow_offset=1.0
c0=&H778899
c1=&H8899AA
c2=&H667788
end if
light_x=400.0+350.0*sin(la)
light_y=300.0+250.0*cos(la)
DRAW_WHEEL ( 460 , 115 , 50 , 20 , 6 , (ROLL1*2),c0, light_x,light_y,shadow_offset )
DRAW_WHEEL ( 460 , 395 , 50 , 20 , 6 , (ROLL1*2),c0, light_x,light_y,shadow_offset )
DRAW_WHEEL ( 198 , 140 , 100 , 10 , 10 , ROLL1,c1, light_x,light_y,shadow_offset )
DRAW_WHEEL ( 379 , 255 , 100 , 10 , 10 , (ROLL2-5) ,c2, light_x,light_y,shadow_offset )
DRAW_WHEEL ( 617 , 433 , 100 , 10 , 10 , (ROLL2-5) ,c2, light_x,light_y,shadow_offset )
next
'draw the light position
draw_wheel(400.0+350.0*sin(la),300.0+250.0*cos(la),20,1,1,0,&hffffff)
PTC_UPDATE@BUFFER(0)
for i=0 to (800*600-1)
buffer(i)=&h600060
next
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 ,byval light_x as single=320.0,byval light_y as single=240.0, byval offset as single=1.1)
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(light_x+(CX-light_x)*offset,light_y+(CY-light_y)*offset,_
light_x+(X1(L)-light_x)*offset,light_y+(Y1(L)-light_y)*offset,_
light_x+(X1(L+1)-light_x)*offset,light_y+(Y1(L+1)-light_y)*offset,_
COLOUR)
NEXT
' NOW THE TEETH;
FOR L=0 TO CNT-2 STEP 2
FLAT_TRIANGLE(light_x+(X2(L)-light_x)*offset,light_y+(Y2(L)-light_y)*offset,_
light_x+(X1(L)-light_x)*offset,light_y+(Y1(L)-light_y)*offset,_
light_x+(X1(L+1)-light_x)*offset,light_y+(Y1(L+1)-light_y)*offset,_
COLOUR)
FLAT_TRIANGLE(light_x+(X2(L)-light_x)*offset,light_y+(Y2(L)-light_y)*offset,_
light_x+(X2(L+1)-light_x)*offset,light_y+(Y2(L+1)-light_y)*offset,_
light_x+(X1(L+1)-light_x)*offset,light_y+(Y1(L+1)-light_y)*offset,_
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
-
How the hell did I miss this? Shockie thats bloody brilliant. I'll go on a limb and say thats going to be the best cracktro/intro you have ever done. If you could work out a way to make that a machine that creates the scroller, dont do a cheap scroller over the top, I think it could be truly great. I'm amazed - I want your frickin coding skills.
Chris
karma++++++++ (but will take me a few days)
-
Thanks everyone for the comments, cheers Stonemonkey for the example too, by the way I wasn't being sarcastic, I just had a thought that I had hoped would have worked. :-\
You should know by now that I bodge my way around most things anyhow, some things work out, some don't. None of my things are mathematically perfect, I assure you, and thanks a lot for the help too, you've definately made a big difference to this intro.
And Chris, I also really like the idea also of using the gear wheels as some sort of machine to make the scroller appear, I just hope there is time for me to do it. I have so much stuff unfinished you wouldn't believe it Chris, and as it happens I'd like your coding skill I'll swap you :)
Va!n, glad you like it mate.
-
You should know by now that I bodge my way around most things anyhow, some things work out, some don't. None of my things are mathematically perfect, I assure you, and thanks a lot for the help too, you've definately made a big difference to this intro.
Most things are some sort of bodge and sorry for sounding a bit pushy about it all but this was something that I felt would really be much simpler to be done that way rather than hacking around trying to get it to look right. And if you're going to post the code for others to learn by example, hmmmm.
Also, I take no credit for any of this other than for being a pushy c***.
EDIT:
And I'm not going to change, if I can see something that's not quite right or whatever (although I have no idea on the design aspect) then so can a lot of others and I'm not going to sit back and say nothing or go 'great work'.
-
That's ok, I'd rather you said what you thought.
-
If you could work out a way to make that a machine that creates the scroller, dont do a cheap scroller over the top, I think it could be truly great.
I think I have done this :) I would have definately done a cop-out over the top job if it wasn't for you Chris.
I am waiting for some graphics and a song now but this should be finished shortly with luck. I will send you a preview later once it's a bit more stable.
-
Screenie for everyone else.
Nb, the shadows stretch now too.
-
Looks awesome man :D
-
Shockwave,
What started out as gears now is almost a machine - excellent work as usual man!
Drew
-
Well it is working as a machine now, but as it's so close to completion I will wait the few days to release it properly, I only need a few files to finish it :)
I will probably post the source too, there's just one thing I am wrestling with at the moment that would prevent this.
-
Ah well, I tried.
-
Ah well, I tried.
The shadows work exactly the way you suggested thank you for your help.
-
Quote from: Stonemonkey on Today at 02:37:27 PM
Ah well, I tried.
The shadows work exactly the way you suggested thank you for your help.
Sorry, I'm not sure why then but from your screenshot something about the shadows still looks a little bit off to me.
-
They probably aren't as exagerated, I didn't use your code so it's not as easy to see in the screenshot, but they do stretch. It looks better for it too.
Congratulations for penetrating my stubborn nature :) I owe you a pint for that.
-
Btw, before you think I cheated, I did not use a workaround. I compared all the points to the lightsource and calculated it like you suggested.
-
ok, I can't figure out what it is then.
Cool idea with the scroll.
-
I'll release it soon.
Perhaps it's just the shot that makes it look skew whiff to you. :)
-
Shockwave, your productions are always amazing!
Can't wait to see this released!
SoldierBoy
-
Just waiting for gfx and music now Soldierboy :)
-
What a fine release Shockwave!
I'm amazed that you release your source for everyone to see.
Thanks for sharing! This is truly the only place on the internet to learn Demo coding
And get help from such knowledgeable people!
k++
SoldierBoy/ICC2007
Infinity 1987-2007
-
Thanks for the Karma :) Posting the source is always a pleasure, I've learned a lot from others here and indeed use some of thier code in my things too so it would be wrong of me not to post it I think.