### Author Topic: 640x480 vec balls[BB2D]  (Read 1121 times)

0 Members and 1 Guest are viewing this topic.

#### nawitus

• C= 64
• Posts: 50
• Karma: 1
##### 640x480 vec balls[BB2D]
« on: September 18, 2006 »

Here is my vector balls. It runs about the same speed as Thygrions blue vector ball demo. . Oh and its true 640x480 and not using "320x240 optimisations". Peace

No media needed
Code: [Select]
`Graphics 640,480,32,0SetBuffer BackBuffer()Const bScreenWidth = 640Const bScreenHeight = 480Const bScreenDepth = 32Const bScreenWidthM1 = bScreenWidth-1Const bScreenHeightM1 = bScreenHeight-1Const bCenterX = bScreenWidth/2Const bCenterY = bScreenHeight/2Dim bScreenArray(bScreenWidth*bScreenHeight)Const bImgWidth = 29Const bImgHeight = 29Const bHalfImgWidth = bImgWidth/2Const bHalfImgHeight = bImgHeight/2Const bImgWidthM1 = bImgWidth - 1Const bImgHeightM1 = bImgHeight - 1Dim bImgArray(bImgWidth*bImgHeight)For bX = 0 To bImgWidthM1 For bY = 0 To bImgHeightM1 Read bpixel If ( ((bpixel Shr 16) And 255) + ((bpixel Shr 8) And 255) + (bpixel And 255) ) = 0 Then bImgArray(bX*bImgHeightM1+bY) = -1 Else bImgArray(bX*bImgHeightM1+bY) = bpixel EndIf NextNextDim bDrawX1(bScreenHeightM1)Dim bDrawX2(bScreenHeightM1)Dim bDrawNewX1(bScreenHeightM1)Dim bDrawNewX2(bScreenHeightM1)For bY = 0 To bScreenHeightM1 bDrawX1(bY) = bScreenWidthM1 bDrawNewX1(bY) = bScreenWidthM1NextDim bBallX#(124)Dim bBallY#(124)Dim bBallZ#(124);Set vector ballsFor btX# = -1.0 To 1.0 Step 0.5 For btY# = -1.0 To 1.0 Step 0.5 For btZ# = -1.0 To 1.0 Step 0.5 bBallX#(bBall) = btX# bBallY#(bBall) = btY# bBallZ#(bBall) = btZ# bBall = bBall + 1 Next NextNextConst bcy#=0.999847695156Const bsy#=0.017452406437Repeat Cls bpXAngle# = Sin(bphase) * 1 ;bpYAngle# = 1 bpZAngle# = Sin(bphase) * 4 bphase = bphase + 1 bcx#=Cos(bpXAngle#) bsx#=Sin(bpXAngle#) ;bcy#=0.999847695156 ;Cos(bpYAngle#) ;bsy#=0.017452406437 ;Sin(bpYAngle#) bcz#=Cos(bpZAngle#) bsz#=Sin(bpZAngle#) ;Update balls For bBall = 0 To 124 ;Rotation bx3d# = bBallX#(bBall) by3d# = bBallY#(bBall) bz3d# = bBallZ#(bBall) bty# = (by3d * bcx) - (bz3d * bsx) btz# = (by3d * bsx) + (bz3d * bcx) btx# = (bx3d * bcy) - (btz# * bsy) bBallZ#(bBall) = (bx3d * bsy) + (btz# * bcy) bBallX#(bBall) = (btx# * bcz) - (bty# * bsz) bBallY#(bBall) = (btx# * bsz) + (bty# * bcz) ;Projection bOneOverZ#=128/(bz3d#+2) bdX = bx3d# * bOneOverZ# + bCenterX bdY = bCenterY - by3d# * bOneOverZ# ;Writing pixel bStartX = bdX-bHalfImgWidth bStartY = bdY-bHalfImgHeight bEndX = bStartX + bImgWidthM1 bEndY = bStartY + bImgHeightM1 For bX = bStartX To bEndX For bY = bStartY To bEndY bimgpixel = bImgArray((bX-bStartX)*bImgHeightM1+bY-bStartY) If bimgpixel <> -1 Then offset = bX * bScreenHeight + bY bpixel = bScreenArray(offset) br = ((bpixel Shr 16) And 255) + ((bimgpixel Shr 16) And 255) bg = ((bpixel Shr 8) And 255) + ((bimgpixel Shr 8) And 255) ;bb = ((bpixel And 255) + (bimgpixel And 255)) If br > 255 Then br = 255 If bg > 255 Then bg = 255 ;If bb > 255 Then bb = 255 bScreenArray(offset) = (br Shl 16) + (bg Shl 8) ;+ bb ;If bX < bMinX Then bMinX = bX If bY < bNewMinY Then bNewMinY = bY ;If bX > bMaxX Then bMaxX = bX If bY > bNewMaxY Then bNewMaxY = bY If bX < bDrawNewX1(bY) Then bDrawNewX1(bY) = bX If bX > bDrawNewX2(bY) Then bDrawNewX2(bY) = bX EndIf Next Next Next For bY = bNewMinY To bNewMaxY bDrawX1(bY) = bDrawNewX1(bY) bDrawX2(bY) = bDrawNewX2(bY) bDrawNewX1(bY) = bScreenWidth bDrawNewX2(bY) = 0 Next bMinY = bNewMinY bMaxY = bNewMaxY bNewMinY = bScreenHeight bNewMaxY = 0 LockBuffer For bY = bMinY To bMaxY bX1 = bDrawX1(bY) bX2 = bDrawX2(bY) If bX1 <> bScreenWidth Then For bX = bX1 To bX2 offset = bX * bScreenHeight + bY bpixel1 = bScreenArray(offset) bpixel2 = bScreenArray(offset+2) bpixel3 = bScreenArray(offset-2) bpixel4 = bScreenArray(offset+1) bpixel5 = bScreenArray(offset-1) br = ( ((bpixel1 Shr 16) And 255) + ((bpixel2 Shr 16) And 255) + ((bpixel3 Shr 16) And 255) + ((bpixel4 Shr 16) And 255) + ((bpixel5 Shr 16) And 255) ) * 0.16667 bg = ( ((bpixel1 Shr 8) And 255) + ((bpixel2 Shr 8) And 255) + ((bpixel3 Shr 8) And 255) + ((bpixel4 Shr 8) And 255) + ((bpixel5 Shr 8) And 255) ) * 0.16667 ;bb = ( (bpixel1 And 255) + (bpixel2 And 255) + (bpixel3 And 255) + (bpixel4 And 255) + (bpixel5 And 255) ) * 0.166667 If br+bg+bb < 5 Then br = 0 : bg = 0 ;: bb = 0 bcol = (br Shl 16) + (bg Shl 8); + bb bScreenArray(offset) = bcol If br+bg+bb Then WritePixelFast bX,bY,bcol ;If bX < bNewMinX Then bNewMinX = bX If bY < bNewMinY Then bNewMinY = bY ;If bX > bNewMaxX Then bNewMaxX = bX If bY > bNewMaxY Then bNewMaxY = bY If bX < bDrawNewX1(bY) Then bDrawNewX1(bY) = bX If bX > bDrawNewX2(bY) Then bDrawNewX2(bY) = bX EndIf Next EndIf Next UnlockBuffer ;bMinX = bNewMinX ;bMinY = bNewMinY ;bMaxX = bNewMaxX ;bMaxY = bNewMaxY ;If MouseDown(1) ;this may show you a little secret  ;); For bY = bMinY To bMaxY; Line bDrawX1(bY),bY,bDrawX2(bY),bY; Next; EndIf fps = fps + 1 ms = MilliSecs() If ms > fpstimer + 999 Then cfps = fps fps = 0 fpstimer = ms EndIf Text 0,0,"FPS: " + cfps Flip FalseUntil KeyHit(1).bImageData -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16252928,-15990784,-15663104,-15597568,-15597568,-15859712,-16056320,-16711680,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16252928,-15532032,-14876672,-14417920,-14155776,-13893632,-13828096,-13959168,-14024704,-14286848,-14811136,-15269888,-16056320,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16646144,-15400960,-14548992,-13959168,-13500416,-13172736,-12845056,-12779520,-12648448,-12713984,-12845056,-12976128,-13434880,-13828096,-14286848,-15204352,-16252928,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-15990784,-14876672,-14024704,-13303808,-12779520,-12320768,-12058624,-11796480,-11730944,-11599872,-11730944,-11862016,-11993088,-12255232,-12648448,-13172736,-13762560,-14614528,-15663104,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-15925248,-14548992,-13697024,-12976128,-12320768,-11862016,-11534336,-11272192,-11140864,-11009536,-10943744,-10878208,-11075328,-11206656,-11468800,-11796480,-12189696,-12713984,-13500416,-14286848,-15532032,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-15925248,-14614528,-13500416,-12713984,-12124160,-11599872,-11141120,-10812416,-10549504,-10417664,-10286080,-10286080,-10286336,-10351872,-10483712,-10746624,-11075072,-11468800,-11927552,-12582912,-13303808,-14286848,-15597568,-16777216,-16777216,-16777216Data -16777216,-16777216,-16515072,-14811136,-13697024,-12779520,-11927552,-11468800,-10943744,-10483968,-10220288,-9957632,-9826048,-9760000,-9694464,-9760000,-9825792,-9891840,-10154496,-10417920,-10746368,-11272192,-11862016,-12451840,-13434880,-14417920,-15925248,-16777216,-16777216Data -16777216,-16777216,-15335424,-13828096,-12845056,-12058624,-11403264,-10878208,-10417664,-10023424,-9760000,-9562624,-9299712,-9299456,-9299456,-9299456,-9299712,-9496832,-9694208,-9891840,-10286336,-10746624,-11206656,-11796480,-12648448,-13697024,-14876672,-16711680,-16777216Data -16777216,-16187392,-14483456,-13238272,-12320768,-11599872,-10944000,-10417664,-9957632,-9628416,-9299712,-9102336,-8904960,-8904704,-8904448,-8904448,-8904960,-9036288,-9299456,-9497088,-9891584,-10286336,-10746368,-11403264,-12124160,-12910592,-14024704,-15663104,-16777216Data -16777216,-15335424,-13828096,-12713984,-11862016,-11075328,-10549504,-10023424,-9562880,-9299456,-8970752,-8773120,-8641536,-8575488,-8509952,-8509952,-8575744,-8773120,-8904704,-9167872,-9431296,-9891584,-10352128,-10878208,-11599872,-12451840,-13500416,-14942208,-16777216Data -16711680,-14745600,-13434880,-12320768,-11534336,-10812160,-10220288,-9760256,-9299712,-9036288,-8773120,-8509952,-8443904,-8312576,-8312320,-8312320,-8378112,-8444160,-8707328,-8904704,-9233664,-9562880,-10088960,-10549504,-11272192,-11993088,-12976128,-14352384,-15925248Data -16187392,-14286848,-13041664,-11993088,-11272192,-10483712,-9957632,-9497088,-9102080,-8773120,-8509952,-8312576,-8180736,-8115200,-8114688,-8114944,-8115200,-8312320,-8444160,-8707328,-9036288,-9299712,-9891584,-10352128,-11009536,-11730944,-12713984,-13893632,-15400960Data -15728640,-14024704,-12779520,-11730944,-11075072,-10352128,-9825792,-9299712,-8970496,-8641536,-8378112,-8180736,-8114944,-7983360,-7983360,-7917568,-8049152,-8114944,-8312576,-8509952,-8904448,-9233664,-9628416,-10154496,-10746624,-11599872,-12386304,-13631488,-15073280Data -15532032,-13828096,-12648448,-11599872,-10944000,-10286080,-9760000,-9233664,-8904704,-8509952,-8312576,-8114944,-7983360,-7851776,-7851776,-7851776,-7983360,-8114944,-8246784,-8444160,-8707328,-9102080,-9562880,-10088960,-10615040,-11468800,-12255232,-13500416,-14811136Data -15400960,-13697024,-12582912,-11599872,-10877952,-10154752,-9628672,-9233664,-8773120,-8444160,-8312320,-8114944,-7917568,-7851776,-7851520,-7851776,-7851776,-8049152,-8246528,-8443904,-8772864,-9102080,-9497088,-10023424,-10615040,-11403264,-12189696,-13369344,-14745600Data -15400960,-13828096,-12582912,-11599872,-10878208,-10220544,-9694208,-9233664,-8838912,-8509952,-8312320,-8114944,-7917568,-7851776,-7851520,-7851520,-7917568,-8049152,-8246528,-8443904,-8707328,-9102080,-9562624,-10023424,-10615040,-11403264,-12255232,-13434880,-14745600Data -15597568,-13893632,-12648448,-11730944,-11009536,-10286080,-9760000,-9299712,-8904704,-8575744,-8378368,-8180736,-8049152,-7917568,-7917568,-7917568,-8048896,-8114944,-8246528,-8509952,-8838656,-9167872,-9562880,-10088960,-10680832,-11468800,-12386304,-13500416,-14942208Data -15990784,-14221312,-12910592,-11927552,-11206656,-10483456,-9891584,-9365504,-8970752,-8707328,-8444160,-8246784,-8115200,-8049152,-8049152,-8049152,-8114944,-8180992,-8443904,-8641536,-8904704,-9299456,-9760256,-10286080,-10878208,-11599872,-12582912,-13762560,-15269888Data -16449536,-14548992,-13303808,-12124160,-11468800,-10680832,-10088960,-9628672,-9233664,-8904960,-8707072,-8444160,-8312320,-8180992,-8180992,-8180992,-8246784,-8443904,-8575744,-8838912,-9102336,-9431296,-9891840,-10483712,-11140864,-11862016,-12779520,-14024704,-15728640Data -16777216,-15073280,-13697024,-12517376,-11665408,-10944000,-10417664,-9891840,-9431296,-9167872,-8904448,-8707072,-8509952,-8443904,-8378368,-8443904,-8444160,-8641536,-8838912,-9036544,-9365248,-9694464,-10220544,-10746624,-11468800,-12255232,-13238272,-14548992,-16252928Data -16777216,-15859712,-14221312,-12976128,-12124160,-11403264,-10746624,-10286336,-9825792,-9496832,-9233664,-8970496,-8838656,-8772864,-8707328,-8707328,-8773120,-8904960,-9102336,-9299712,-9694208,-10023424,-10483712,-11140864,-11862016,-12713984,-13697024,-15269888,-16777216Data -16777216,-16777216,-14942208,-13697024,-12648448,-11796480,-11206656,-10615040,-10220544,-9891584,-9562624,-9299712,-9167872,-9102080,-9036288,-9036288,-9167872,-9299456,-9496832,-9760000,-10088960,-10483456,-11009536,-11599872,-12320768,-13303808,-14483456,-16252928,-16777216Data -16777216,-16777216,-15925248,-14417920,-13303808,-12386304,-11730944,-11141120,-10615040,-10351872,-9957632,-9760000,-9628672,-9562624,-9496832,-9496832,-9562880,-9694464,-9891840,-10154752,-10483712,-11009536,-11599872,-12124160,-12976128,-14024704,-15335424,-16777216,-16777216Data -16777216,-16777216,-16777216,-15532032,-14286848,-13172736,-12386304,-11796480,-11272192,-10878208,-10483968,-10286336,-10154752,-10023168,-9957632,-9957632,-10088960,-10220544,-10483456,-10746624,-11075328,-11599872,-12189696,-12845056,-13762560,-14942208,-16515072,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-15335424,-14155776,-13303808,-12582912,-11993088,-11599872,-11272192,-10943744,-10746624,-10615040,-10549504,-10615040,-10680832,-10877952,-11140864,-11468800,-11796480,-12320768,-12910592,-13828096,-14811136,-16187392,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-15335424,-14352384,-13565952,-12845056,-12386304,-11927552,-11599872,-11534336,-11403264,-11337728,-11403264,-11468800,-11599872,-11862016,-12189696,-12648448,-13238272,-14024704,-14942208,-16318464,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-15859712,-14811136,-13959168,-13434880,-12976128,-12582912,-12320768,-12320768,-12124160,-12189696,-12320768,-12582912,-12779520,-13238272,-13697024,-14483456,-15335424,-16646144,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16449536,-15400960,-14811136,-14286848,-13762560,-13565952,-13434880,-13303808,-13369344,-13500416,-13762560,-14024704,-14548992,-15204352,-16056320,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216Data -16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16711680,-15925248,-15335424,-15007744,-14811136,-14745600,-14811136,-14942208,-15204352,-15728640,-16318464,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216,-16777216`
« Last Edit: July 21, 2007 by Shockwave »

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### Re: 640x480 vec balls
« Reply #1 on: September 18, 2006 »
Mmm. As we're talking about blitting an entire array, I don't see that the size of the vectorballs makes a lot of difference, we're talking small bobs here after all.  Anyway it runs nice, about 37 - 40 fps and looks good. It's nice to have you around here Nawi, props for posting the code but don't ever come on here and say your code is better than another members again, I don't even care if the member saying such things is a member of DBF or GVY, it won't be tollerated.
Shockwave ^ Codigos
Challenge Trophies Won:

#### nawitus

• C= 64
• Posts: 50
• Karma: 1
##### Re: 640x480 vec balls
« Reply #2 on: September 19, 2006 »
Sorry for that. Anyway, yeah I do think it makes a noticeable difference. Hmm, it has been a while, maybe I should code a demo or two now :p .

#### Shockwave

• good/evil
• Founder Member
• Posts: 17297
• Karma: 489
• evil/good
##### Re: 640x480 vec balls
« Reply #3 on: September 19, 2006 »
A few demos by you would be excellent Nawi, I always enjoy your stuff
Shockwave ^ Codigos
Challenge Trophies Won:

#### Hotshot

• Pentium
• Posts: 1901
• Karma: 80
##### Re: 640x480 vec balls
« Reply #4 on: December 23, 2006 »
I am big fan of vec balls that spin around 3D in 2D. Ace

#### mike_g

• Amiga 1200
• Posts: 435
• Karma: 34
##### Re: 640x480 vec balls
« Reply #5 on: December 29, 2006 »
Nice prog