Yeah I have one, I'm drawing them back to front. I can't figure this out. in the above picture the strip in the middle shouldn't be visible. It behaves like it blends the front and back polygons together on screen but I'm using SOLIDBLEND for the mode.
' this code adapted from one of ETROMIC's (Olof Hånell) effects
Strict
Framework BRL.GLMax2D
Import BRL.System
Import BRL.Basic
Import BRL.pngloader
Import BRL.Retro
?Win32
SetGraphicsDriver(GLMax2DDriver())
?
Graphics 640,480,0'32,60
Const NUM_DEGREES:Int = 20
Const NUM_SECTIONS:Int = 45
Const NUM_POINTS:Int = 5
Const ROTATION_SCALE:Int = 2
'Global baseColor:Int = 2895943
Global baseColor:Int = 13412915
Const bgColor:Int = 2895943
Global cylinderWidth:Int = 150
Global XZ_SCALE:Int = cylinderWidth Shr 1
Global circle_y_step:Int = GraphicsHeight()/NUM_SECTIONS
Global variation_speed:Float = 0.00021
Global cycledifference:Float = 0.022
Global fm:Float = 0.0
Global CP:CirclePlane[] = New CirclePlane[NUM_SECTIONS]
Global polys:Polygon[] = New Polygon[(NUM_SECTIONS-1) * (NUM_POINTS)]
For Local ip:Int = 0 Until polys.length
polys[ip] = Polygon.Create()
Next
Global ptsZ:Int[] = New Int[polys.length]
Global colors:Color[] = New Color[polys.length]
For Local ic:Int = 0 Until polys.length
colors[ic] = New Color
Next
Global order:Int[] = New Int[polys.length]
setupSections()
Global frames:Long = 0
Global fps:Long = 0
Global lastTime:Long = MilliSecs()
SetClsColor(44,48,71)
While Not KeyHit(KEY_ESCAPE)
Cls ' clear the screen
SetBlend(SOLIDBLEND)
SetColor(255,255,255)
SetAlpha(1)
update()
DoFPS()
Flip() ' flip the buffers
FlushMem() ' garbage collection
Wend
Type Point
Field x:Float
Field y:Float
'Field z:Float
Method Set(x1:Float,y1:Float)',z1:Float)
x=x1
y=y1
'z=z1
End Method
End Type
Type Polygon
Field points:Point[] = New Point[4]
Field c:Color = New Color
Field array:Float[] = New Float[6]
Function Create:Polygon()
Local p:Polygon= New Polygon
For Local c:Int = 0 To 3
p.points[c] = New Point
Next
Return p
End Function
Method firstPoints()
'array[0] = points[0].x
'array[1] = points[0].y
'array[2] = points[1].x
'array[3] = points[1].y
'array[4] = points[2].x
'array[5] = points[2].y
array[0] = points[0].x
array[1] = points[0].y
array[2] = points[2].x
array[3] = points[2].y
array[4] = points[1].x
array[5] = points[1].y
End Method
Method secondPoints()
'array[0] = points[2].x
'array[1] = points[2].y
'array[2] = points[3].x
'array[3] = points[3].y
'array[4] = points[0].x
'array[5] = points[0].y
array[0] = points[2].x
array[1] = points[2].y
array[2] = points[0].x
array[3] = points[0].y
array[4] = points[3].x
array[5] = points[3].y
End Method
End Type
Type Color
Field r:Int=255
Field g:Int=255
Field b:Int=255
Method Set(r1:Float,g1:Float,b1:Float)
r=r1
g=g1
b=b1
End Method
End Type
Function rotPoints()
Local diff:Float = 0
For Local i:Int=0 Until NUM_SECTIONS
'CP[i].rotateBy(Float(Float(ROTATION_SCALE)*Sin((fm+diff)*0.0174532925)))
CP[i].rotateBy(Float(Float(ROTATION_SCALE)*Sin(fm+diff)))
'CP[i].rotateBy(.5)
diff:+cycledifference
fm:+variation_speed
Next
End Function
Function update()
rotPoints()
Local yStep:Float = Float(GraphicsHeight()) / Float(NUM_SECTIONS-1)
Local yp:Float = 0
Local xPush:Int = (GraphicsWidth() Shr 1) - (XZ_SCALE Shr 1)
'Local pts:Polygon[] = New Polygon[(NUM_SECTIONS-1) * (NUM_POINTS)]
'Local ptsZ:Int[] = New Int[polys.length]
'Local colors:Color[] = New Color[polys.length]
'Local order:Int[] = New Int[polys.length]
Local n:Int = 0;
Local p:Polygon;
For Local i:Int=0 Until NUM_SECTIONS-1
For Local j:Int=0 Until NUM_POINTS
p = polys[n]'Polygon.Create();
Local p0:Float[] = CP[i].GetPoint(j)
Local p1:Float[] = CP[i].GetPoint(j+1)
Local p2:Float[] = CP[i+1].GetPoint(j+1)
Local p3:Float[] = CP[i+1].GetPoint(j)
p.points[0].Set(Int(p0[0] + xPush +.5), Int(yp+.5))
p.points[1].Set(Int(p1[0] + xPush +.5), Int(yp+.5))
p.points[2].Set(Int(p2[0] + xPush +.5), Int(yp+yStep+.5))
p.points[3].Set(Int(p3[0] + xPush +.5), Int(yp+yStep+.5))
polys[n] = p;
ptsZ[n] = Int(p0[1] + p1[1] + p2[1] + p3[1]) Shr 2
Local c:Int = Int( ptsZ[n] - XZ_SCALE )
Local base_r:Int = ((baseColor Shr 16) & 255) + c
Local base_g:Int = ((baseColor Shr 8) & 255) + c
Local base_b:Int = ((baseColor ) & 255) + c
'If j =2 Then
' base_r = ((bgColor Shr 16) & 255) + c
' base_g = ((bgColor Shr 8) & 255) + c
' base_b = ((bgColor ) & 255) + c
'EndIf
If base_r>255 Then base_r = 255
If base_g>255 Then base_g = 255
If base_b>255 Then base_b = 255
'colors[n] = New Color
colors[n].Set(base_r,base_g,base_b)
n:+1
Next
yp:+yStep
Next
order = zSort(ptsZ)
SetBlend(SOLIDBLEND)
SetColor(255,255,255)
SetAlpha(1)
Local nu:Int = order.length
For Local i:Int=0 Until nu
SetColor(colors[order[i]].r,colors[order[i]].g,colors[order[i]].b);
polys[order[i]].firstPoints()
DrawPoly(polys[order[i]].array);
polys[order[i]].secondPoints()
DrawPoly(polys[order[i]].array);
Next
End Function
Function zSort:Int[](ptsZs:Int[])
Local sorted:Byte = False
Local num:Int = ptsZs.length - 1
Local back:Int[] = New Int[ptsZ.length]
For Local i:Int=0 Until back.length
back[i] = i
Next
' Rem
While sorted=False
sorted = True
For Local i:Int=0 Until num
If ptsZs[i] > ptsZs[i+1] Then
Local backTemp:Int = back[i]
Local tmp:Int = ptsZs[i]
back[i] = back[i+1]
ptsZs[i] = ptsZs[i+1]
back[i+1] = backTemp
ptsZs[i+1] = tmp
sorted = False
EndIf
Next
Wend
'EndRem
Return back
End Function
Function DoFPS()
SetBlend(SOLIDBLEND)
SetColor(255,255,255)
SetAlpha(1)
DrawText "FPS: "+fps,0,0
frames:+1
If MilliSecs()-lastTime>=1000 Then
fps=frames
frames=0
lastTime=MilliSecs()
EndIf
End Function
Function setupSections()
Local sAngle:Float = 0
Local aStep:Float = Float(NUM_DEGREES) / Float(NUM_SECTIONS)
For Local i:Int=0 Until NUM_SECTIONS
CP[i] = CirclePlane.Create(NUM_POINTS, XZ_SCALE, sAngle)
sAngle:+aStep
Next
End Function
Type CirclePlane
Field numPoints:Int = 0
Field rotation:Float = 0
Field degreeStep:Double = 0
Field ps:Float[,]
Field psb:Float[,]
Field scale:Int = 0
Const X:Int = 0
Const Z:Int = 1
Function Create:CirclePlane(pointCount:Int, scale:Int, sRotation:Float)
Local cp:CirclePlane = New CirclePlane
cp.numPoints = pointCount
cp.rotation = Float(sRotation)
cp.scale = scale
cp.degreeStep = Double(360) / Double(pointCount)
cp.ps = New Float[pointCount,2]
cp.rot()
Return cp
End Function
Method rotateBy(deg:Float)
rotation :+ deg
rot()
End Method
Method GetPoint:Float[](which:Int)
Local back:Float[] = New Float[2]
back[0] = ps[which Mod numPoints,0]
back[1] = ps[which Mod numPoints,1]
Return back
End Method
Method rot()
Local ang:Double = 0
For Local i:Int=0 Until numPoints
ps[i,X] = Int(Float(scale) * Cos(rotation + ang) + .5)
ps[i,Z] = Int(Float(scale) * Cos(rotation + ang - (3.1416/2.0)) + Float(scale)+.5)
ang:+degreeStep
Next
End Method
End Type