[bb] 3D Elite Style Scanner by Krischan [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : 3D Elite Style Scanner
Author : Krischan
Posted : 1+ years ago

Description : This demo shows the use of a 3D space scanner like in the game "Elite". It shows a type field within a given distance with "blips" and "poles" attached to the blips - they represent the relative height to the centered spaceship. The demo creates two procedural textures blended together to get a nice glowing radar screen. Arrows/Mouse to move, LMB=increase speed, RMB=halves scanner range. Have fun!

Edit: shortened code and added color schemes / more constants to declare.



Code :
Code: blitzbasic
AppTitle "3D Elite Style Scanner"

Graphics3D 800,600,32,2

Const TurnSpeed#    = 4.00      ; cam turn speed
Const RollSpeed#    = 0.50      ; cam roll speed
Const CameraSpeed#  = 1.00      ; cam move speed
Const Objects%      = 2000      ; number of space objects
Const RadarSize%    = 256       ; radar size in pixels

Const PoleWidth#    = 1.0       ; width of poles
Const BlipSize#     = 3.0       ; size of radar blip
Const VertScale#    = 1.0       ; height multiplicator of pole/blip
Const RadarBorder#  = 0.9       ; range within 1.0 to display

; color scheme: blue
Const R1%=  0,G1%=128,B1%=192   ; grid lines color
Const R2%=  0,G2%= 16,B2%= 32   ; scanner background color
Const R3%=  0,G3%=128,B3%=255   ; scanner border glow color

; color scheme: green
;Const R1%=  0,G1%=192,B1%=  0   ; grid lines color
;Const R2%=  0,G2%= 32,B2%=  0   ; scanner background color
;Const R3%=  0,G3%=255,B3%=  0   ; scanner border glow color

Type blip
    
    Field entity%
    Field blip%
    Field pole%
    Field x#,y#,z#
    Field vx#,vy#,vz#
    Field r%,g%,b%
    Field size#
    
End Type

Global WIDTH%=GraphicsWidth()
Global HEIGHT%=GraphicsHeight()
Local TIMER%=CreateTimer(60)

; camera
Local CAM%=CreateCamera()
CameraRange CAM,1,WIDTH+RadarSize

; setup radar
Local RADAR=InitRadar(RadarSize,512,10,CAM)

; setup objects
InitObjects(RADAR,Objects,1000)

MoveMouse WIDTH/2,HEIGHT/2

While Not KeyHit(1)
    
    Local range%=256,visible%
    
    ; move player
    Movement(CAM)
    
    ; RMB = short range radar
    If MouseDown(2) Then range=128
    
    ; update radar
    visible%=UpdateRadar(CAM,RADAR,RadarSize,range,90)
    
    RenderWorld
    
    WaitTimer TIMER
    
    Text 0, 0,"Scanner range....: "+range
    Text 0,15,"Objects / visible: "+Objects+" / "+visible
    
    Flip
    
Wend

End

; populate scene with dummy objects
Function InitObjects(radar%,number%=100,range#=500.0)
    
    Local i%,b.blip
    
    For i=1 To number
        
        b.blip = New blip
        bentity=CreateCone(16)
        blip=CreateSphere(6,radar)
        bpole=CreateCube(radar)
        bx=Rnd(-range,range)
        by=Rnd(-range,range)
        bz=Rnd(-range,range)
        bvx=Rnd(-0.1,0.1)
        bvy=Rnd(-0.1,0.1)
        bvz=Rnd(-0.1,0.1)
        b=Rand(255)
        bg=Rand(255)
        b=Rand(255)
        bsize=2
        
        ; align "ship" to its flight vector
        AlignToVector bentity,bvx,bvy,bvz,2,1
        
        ; create the entity itself
        PositionEntity bentity,bx,by,bz
        EntityFX bentity,1
        EntityColor bentity,b,bg,b
        ScaleEntity bentity,bsize,bsize*2,bsize
        EntityAutoFade bentity,1,range
        
        ; creates a radar blip
        EntityFX blip,1
        EntityOrder blip,-100
        EntityColor blip,b,bg,b
        
        ; creates a blip pole
        EntityFX bpole,1
        EntityOrder bpole,-100
        EntityColor bpole,b,bg,b
        
    Next
    
End Function

; simple spaceship movement
Function Movement(cam%,sensitivity#=1.0)
    
    Local roll#,cz#,tx#,ty#,multi%=1
    
    ; arrows = move / SHIFT or LMB = Turbo
    cz=(KeyDown(200)-KeyDown(208))*CameraSpeed
    roll=(KeyDown(203)-KeyDown(205))*RollSpeed
    If KeyDown(42) Or KeyDown(54) Or MouseDown(1) Then multi=10
    
    tx=Normalize(MouseX(),0,WIDTH , 1,-1)
    ty=Normalize(MouseY(),0,HEIGHT,-1, 1)
    
    If ty<0 Then ty=(Abs(ty)^sensitivity)*-1 Else ty=ty^sensitivity
    If tx<0 Then tx=(Abs(tx)^sensitivity)*-1 Else tx=tx^sensitivity
    
    TurnEntity cam,ty*TurnSpeed,tx*TurnSpeed,roll*TurnSpeed
    MoveEntity cam,0,0,cz*multi
	
End Function

; creates a nice elite stype radar sprite at screen bottom
Function InitRadar(scale#,size%=512,quads%=8,parent%=False,sharp#=1.0,blur#=50.0)
    
    Local RADAR%=CreateQuad()
    EntityParent RADAR,parent
    Local tex1%=CreateGridTexture(size,quads)
    Local tex2%=CreateGlowTexture(size,sharp,blur)
    
    ; apply textures to radar quad
    EntityFX RADAR,1
    ScaleEntity RADAR,scale,scale,scale
    PositionEntity RADAR,0,-HEIGHT+(RadarSize*0.75),WIDTH
    TextureBlend tex1,2
    TextureBlend tex2,3
    EntityTexture RADAR,tex1,0,1
    EntityTexture RADAR,tex2,0,2
    EntityBlend RADAR,1
    
    ; create centered ship marker (you!)
    Local CENTER%=CreateCone(3,1,RADAR)
    RotateMesh CENTER,30,0,0
    PositionEntity CENTER,0,0,0
    ScaleEntity CENTER,1.0/32,1.0/32,1.0/32
    EntityFX CENTER,1
    EntityColor CENTER,255,255,0
    
    EntityOrder CENTER,-20
    EntityOrder RADAR,-10
    
    Return RADAR
    
End Function

; updates the radar scene
Function UpdateRadar(cam%,radar%,scale#=128.0,range#=256.0,angle#=60.0)
    
    Local b.blip
    Local d#
    Local rx#,ry#,rz#
    
    Local halfscale#=scale/2.0
    Local doublescale#=scale*2.0
    Local ps#=PoleWidth/scale
    Local bs#=BlipSize/halfscale
    Local div#=((scale/2.0)/range)*RadarBorder
    
    Local visible%=0
    
    For b.blip = Each blip
        
        ; dumb object movement
        bx=bx+bvx
        by=by+bvy
        bz=bz+bvz
        PositionEntity bentity,bx,by,bz
        
        ; get distance to object
        d=EntityDistance(bentity,cam)
        
        ; within scanner range?
        If d<range Then
            
            visible=visible+1
            
            ; show blip and its pole
            ShowEntity bpole
            ShowEntity blip
            
            ; transform position
            TFormPoint (bx,by,bz,0,cam)
            rx=-TFormedX()/halfscale*div
            rz=TFormedZ()/halfscale*div
            ry=TFormedY()*div
            
            ; reposition/scale blip
            PositionEntity blip,0,0,0
            TranslateEntity blip,rx,rz,ry/scale*VertScale
            ScaleEntity blip,bs,bs,bs
            
            ; reposition/scale pole
            PositionEntity bpole,0,0,0
            ScaleEntity bpole,ps,ps,ry/doublescale*VertScale
            TranslateEntity bpole,rx,rz,ry/doublescale*VertScale
            
        Else
            
            ; hide blip and its pole
            HideEntity bpole
            HideEntity blip
            
        EndIf
        
    Next
    
    ; radar always points to cam
    RotateEntity radar,-angle,180,0
    
    Return visible
    
End Function

; simple quad creation
Function CreateQuad(r%=255,g%=255,b%=255,a#=1.0)
    
    Local mesh%,surf%,v1%,v2%,v3%,v4%
    
    mesh=CreateMesh()
    surf=CreateSurface(mesh)
    
    v1=AddVertex(surf,-1,1,0,1,0)
    v2=AddVertex(surf,1,1,0,0,0)
    v3=AddVertex(surf,-1,-1,0,1,1)
    v4=AddVertex(surf,1,-1,0,0,1)
    
    VertexColor surf,v1,r,g,b,a
    VertexColor surf,v3,r,g,b,a
    VertexColor surf,v2,r,g,b,a
    VertexColor surf,v4,r,g,b,a
    
    AddTriangle(surf,0,1,2)
    AddTriangle(surf,3,2,1)
    
    FlipMesh mesh
    
    Return mesh
    
End Function

; create procedural glowing border texture
Function CreateGlowTexture(size%=512,sharpness#=1.0,blur#=50.0)
    
    Local strength#=512*1.0/size*sharpness
    Local tex%=CreateTexture(size,size,3)
    Local tb%=TextureBuffer(tex)
    
    Local x%,y%,i#,j%,col%,rgb%,rc%,gc%,bc%
    
    LockBuffer tb
    
    For x=0 To size-1
        
        For y=0 To size-1
            
            ; clear colors
            rgb=0*$1000000+0*$10000+0*$100+0
            WritePixelFast x,y,rgb,tb
            
        Next
        
    Next
    
    For j=1 To (size/2)-2
        
        ; exponential falloff
        col=j*strength/Exp((((size/2)-2)-j)*(strength/blur))
        
        If col>224 Then col=Normalize(col,224,255,224,0)
        If col<0 Then col=0
        
        ; multiply RGB with brightness
        rc=R3*col Shr 8
        gc=G3*col Shr 8
        bc=B3*col Shr 8
        
        rgb=255*$1000000+rc*$10000+gc*$100+bc
        
        For i=0 To 360 Step 0.05
            
            WritePixelFast ((size-2)/2.0)+(Sin(i)*j),((size-2)/2.0)+(Cos(i)*j),rgb,tb
            
        Next
        
    Next
    
    UnlockBuffer tb
    
    Return tex
    
End Function

; normalize a value
Function Normalize#(value#=128.0,vmin#=0.0,vmax#=255.0,nmin#=0.0,nmax#=1.0)
    
    Return ((value#-vmin#)/(vmax#-vmin#))*(nmax#-nmin#)+nmin#
    
End Function

; create radar grid texture
Function CreateGridTexture(size%=512,quads%=16)
    
    Local x%,y%,j%,i#,rgb%,col%,r%,g%,b%
    Local steps%=size/quads
    
    Local tex%=CreateTexture(size,size,3+8)
    Local buffer%=TextureBuffer(tex)
    
    SetBuffer buffer
    
    ; background color
    Color R2,G2,B2
    Rect 0,0,size,size,1
    
    ; create grid
    Color R1,G1,B1
    For x=0 To quads-1
        For y=0 To quads-1
            Rect x*steps,y*steps,steps+1,steps+1,0
        Next
    Next
    
    Color 255,255,255
    
    LockBuffer buffer
    
    ; create glowing border and delete pixels outside the circle
    For j=(size/2)-6 To size
        
        For i=0 To 360 Step 0.05
            
            x=((size-2)/2.0)+(Sin(i)*j)
            y=((size-2)/2.0)+(Cos(i)*j)
            
            col=0
            If j<=(size/2) Then col=Normalize(j,(size/2)-6,(size/2),255,0)
            
            ; multiply RGB with brightness
            r=R3*col Shr 8
            g=G3*col Shr 8
            b=B3*col Shr 8
            
            rgb=0*$1000000+r*$10000+g*$100+b
            
            If x>=0 And x<size And y>=0 And y<size Then
				
                WritePixelFast x,y,rgb,buffer
                
            EndIf
            
        Next
        
    Next
	
    UnlockBuffer buffer
    
    SetBuffer BackBuffer()
    
    Return tex
    
End Function


Comments :


puki(Posted 1+ years ago)

 Cool.


BlitzSupport(Posted 1+ years ago)

 Yeah, very nicely done. The demo itself has a really good feel to it too.


_PJ_(Posted 1+ years ago)

 Nice! I love the effect and how it's been done as a textured mesh rather than direct 2D drawing :)Really useful!


Krischan(Posted 1+ years ago)

 For a clean 3D only variant take a look at this. Here I'm using quads as blips and poles to create the radar echoes instead of cubes and spheres. They are textured, too! Looks even more cool now.
Code: BASIC
AppTitle "3D Elite Style Scanner Example"

SeedRnd 7

Graphics3D 800,600,32,2

Const TurnSpeed#    = 4.00        ; cam turn speed
Const RollSpeed#    = 0.50        ; cam roll speed
Const CameraSpeed#  = 0.25        ; cam move speed
Const Objects%      = 1000        ; number of space objects
Const RadarSize%    = 300         ; radar size in pixels
Const Factor#       = 1.0         ; scale factor
Const UniverseRange#= 250.0       ; "universe" range
Const Maxrange#     = 64.0        ; Scanner Range in Lightyears

Const PoleWidth#    =  1.0        ; width of poles
Const BlipSize#     =  8.0        ; size of radar blip
Const VertScale#    =  1.0        ; height multiplicator of pole/blip
Const RadarBorder#  =  0.8        ; range within 1.0 to display
Const Distribution$ = "spherical" ; star distribution (cubic, spherical)

Const R1%=  0,G1%=128,B1%=192   ; grid lines color
Const R2%=  0,G2%= 16,B2%= 32   ; scanner background color
Const R3%=  0,G3%=128,B3%=255   ; scanner border glow color

Type blip
    
    Field entity%
    Field blip%
    Field pole%
    Field x#,y#,z#
    Field r%,g%,b%
    Field scale#
    
End Type

Global WIDTH%=GraphicsWidth()
Global HEIGHT%=GraphicsHeight()
Global SUNTEX_RED%=CreateSunTexture(256,255,128,128) : TextureBlend SUNTEX_RED,3
Global SUNTEX_YEL%=CreateSunTexture(256,255,224,192) : TextureBlend SUNTEX_YEL,3
Global SUNTEX_BLU%=CreateSunTexture(256,128,128,255) : TextureBlend SUNTEX_BLU,3
Global SUNTEX_WHI%=CreateSunTexture(256,255,255,255) : TextureBlend SUNTEX_WHI,3
Local TIMER%=CreateTimer(60)

; camera
Local CAM%=CreateCamera()
CameraRange CAM,1.0/Factor,(WIDTH*Factor)+RadarSize

; setup radar
Local RADAR=InitRadar(RadarSize,512,10,CAM)

; setup objects
InitObjects(CAM,RADAR,Objects,UniverseRange,Distribution)

MoveMouse WIDTH/2,HEIGHT/2

MoveEntity CAM,0,0,-0.1*Factor

While Not KeyHit(1)
    
    Local range%=Maxrange
    
    ; move player
    Movement(CAM)
    
    ; RMB = short range radar
    If MouseDown(2) Then range=Maxrange/2.0
    
    ; update objects
    UpdateObjects(CAM)
    
    ; update radar
    UpdateRadar(CAM,RADAR,RadarSize,range*Factor,100)
    
    RenderWorld
    
    WaitTimer TIMER
    
    Flip 0
    
Wend

End

; populate scene with dummy objects
Function InitObjects(cam%,radar%,number%=100,range#=500.0,method$="cubic")
    
    Local i%,b.blip,col#,tex%
    
    AmbientLight 255,255,255
    
    Local temp%=CreatePivot()
    
    For i=1 To number
        
        b.blip = New blip
        
        bscale=Rnd(1,Rnd(2,Rnd(3,4)))
        
        Select method
                
            ; random cubic placement
            Case "cubic":
                
                bx=Rnd(-range,range)*Factor
                by=Rnd(-range,range)*Factor
                bz=Rnd(-range,range)*Factor
                
            ; random spherical placement
            Case "spherical":
                
                PositionEntity temp,0,0,0
                TurnEntity temp,Rnd(-Rnd(0,360),Rnd(0,360)),Rnd(0,Rnd(0,360)),0
                MoveEntity temp,0,0,Rnd(Rnd(Rnd(range),range),range)*Factor
                bx=EntityX(temp)
                by=EntityY(temp)
                bz=EntityZ(temp)
                
        End Select
        
        ; color
        col=Rnd(1)
        If col>0.50 And col<=1.00 Then b=255 : bg=  0 : b=  0 : tex=SUNTEX_RED : bscale=bscale/2.00
        If col>0.20 And col<=0.50 Then b=255 : bg=255 : b=  0 : tex=SUNTEX_YEL : bscale=bscale/1.00
        If col>0.10 And col<=0.20 Then b=  0 : bg=  0 : b=255 : tex=SUNTEX_BLU : bscale=bscale*1.25
        If col>0.00 And col<=0.05 Then b=255 : bg=255 : b=255 : tex=SUNTEX_WHI : bscale=bscale*1.50
        
        ; create the entity itself
        bentity=CreateQuad(False,1.0,tex,3,2+32,b,bg,b,1.00)
        PositionEntity bentity,bx,by,bz
        PointEntity bentity,cam
        EntityBlend bentity,3
        
        ; creates a radar blip
        blip=CreateQuad(radar,1.0,tex,3,2+32,b,bg,b,1.00)
        EntityOrder blip,-100
        RotateMesh blip,90,0,0
        
        ; creates a blip pole
        bpole=CreateQuad(radar,1.0,False,3,2+32,b,bg,b,0.50)
        EntityOrder bpole,-50
        RotateMesh bpole,90,0,0
        
    Next
    
End Function

; simple spaceship movement
Function Movement(cam%,sensitivity#=1.0)
    
    Local roll#,cx#,cz#,tx#,ty#,multi%=1
    
    ; arrows = move / SHIFT or LMB = Turbo
    cz=(KeyDown(200)-KeyDown(208))*CameraSpeed
    ;cx=(KeyDown(205)-KeyDown(203))*CameraSpeed
    roll=(KeyDown(203)-KeyDown(205))*RollSpeed
    If KeyDown(42) Or KeyDown(54) Or MouseDown(1) Then multi=10
    
    tx=Normalize(MouseX(),0,WIDTH , 1,-1)
    ty=Normalize(MouseY(),0,HEIGHT,-1, 1)
    
    If ty<0 Then ty=(Abs(ty)^sensitivity)*-1 Else ty=ty^sensitivity
    If tx<0 Then tx=(Abs(tx)^sensitivity)*-1 Else tx=tx^sensitivity
    
    TurnEntity cam,ty*TurnSpeed,tx*TurnSpeed,roll*TurnSpeed
    MoveEntity cam,cx*multi,0,cz*multi
    
End Function

; creates a nice elite stype radar sprite at screen bottom
Function InitRadar(scale#,size%=512,quads%=8,parent%=False,sharp#=1.0,blur#=50.0)
    
    Local RADAR%=CreateQuad()
    EntityParent RADAR,parent
    
    Local tex1%=CreateGridTexture(size,quads)
    Local tex2%=CreateGlowTexture(size,sharp,blur)
    
    ; apply textures to radar quad
    EntityFX RADAR,1+16
    ScaleEntity RADAR,scale,scale,scale
    PositionEntity RADAR,0,-HEIGHT+(RadarSize*0.6),WIDTH
    TextureBlend tex1,2
    TextureBlend tex2,3
    EntityTexture RADAR,tex1,0,1
    EntityTexture RADAR,tex2,0,2
    EntityBlend RADAR,1
    
    ; create centered ship marker (you!)
    Local CENTER%=CreateCone(4,1,RADAR)
    RotateMesh CENTER,-100,0,0
    PositionEntity CENTER,0,0,0
    ScaleEntity CENTER,1.0/32,1.0/32,1.0/32
    EntityFX CENTER,1
    EntityColor CENTER,255,255,0
    
    EntityOrder RADAR,-50
    EntityOrder CENTER,-100
    
    Return RADAR
    
End Function

Function UpdateObjects(cam%)
    
    Local b.blip,d#,s#
    
    For b.blip = Each blip
        
        If EntityInView(bentity,cam) Then
            
            d=EntityDistance(bentity,cam)
            s=Exp(1.0/d*(Factor*10))*bscale
            If s<d*0.005 Then s=d*0.005
            ScaleEntity bentity,s,s,s
            ShowEntity bentity
            PointEntity bentity,cam
            
        Else
            
            HideEntity bentity
            
        EndIf
        
    Next
    
End Function

; update quad color / alpha
Function UpdateQuad(mesh%,r%=255,g%=255,b%=255,a#=1.0)
    
    Local v%,surf=GetSurface(mesh,1)
    
    For v=0 To 3
        
        VertexColor surf,v,r,g,b,a
        
    Next
    
End Function

; updates the radar scene
Function UpdateRadar(cam%,radar%,scale#=128.0,range#=256.0,angle#=60.0)
    
    Local b.blip
    Local d#,a#
    Local rx#,ry#,rz#
    
    Local halfscale#=scale/2.0
    Local doublescale#=scale*2.0
    Local ps#=PoleWidth/scale
    Local bs#=BlipSize/halfscale
    Local div#=((scale/2.0)/range)*RadarBorder
    
    Local visible%=0
    
    For b.blip = Each blip
        
        ; get distance to object
        d=EntityDistance(bentity,cam)
        
        ; hide radar blip/pole
        HideEntity bpole
        HideEntity blip
        
        ; object within scanner range?
        If d<range*2 Then
            
            ; within scanner range?
            If d<range Then
                
                ; soft fade out objects reaching radar border
                a=Normalize(d,range*RadarBorder,range,1,0)
                If a>1 Then a=1 Else If a<0 Then a=0
                UpdateQuad(blip,b,bg,b,a)
                UpdateQuad(bpole,b,bg,b,a*0.5)
                
                ; show blip and its pole
                ShowEntity bpole
                ShowEntity blip
                
                ; transform position
                TFormPoint (bx,by,bz,0,cam)
                rx=TFormedX()/halfscale*div
                rz=TFormedZ()/halfscale*div
                ry=-TFormedY()*div
            
                ; reposition/scale blip
                PositionEntity blip,0,0,0
                TranslateEntity blip,rx,rz,ry/scale*VertScale
                ScaleEntity blip,bs,bs,bs
            
                ; reposition/scale pole
                PositionEntity bpole,0,0,0
                ScaleEntity bpole,ps,ps,Abs(ry/doublescale*VertScale)
                TranslateEntity bpole,rx,rz,ry/doublescale*VertScale
                
            EndIf
            
        EndIf
        
    Next
    
    ; radar always points to cam
    RotateEntity radar,angle,0,0
    
    Return visible
    
End Function

; advanced quad creation
Function CreateQuad(parent%=False,scale#=1.0,tex%=False,blend%=False,fx%=False,r%=255,g%=255,b%=255,a#=1.0)
    
    Local mesh%=CreateMesh()
    Local surf%=CreateSurface(mesh)
    
    Local v0%=AddVertex(surf, 1, 1,0,0,0)
    Local v1%=AddVertex(surf,-1, 1,0,1,0)
    Local v2%=AddVertex(surf,-1,-1,0,1,1)
    Local v3%=AddVertex(surf, 1,-1,0,0,1)
    
    AddTriangle surf,v0,v1,v2
    AddTriangle surf,v0,v2,v3
    
    If parent Then EntityParent mesh,parent
    If fx Then EntityFX mesh,fx
    If tex Then EntityTexture mesh,tex
    If blend Then EntityBlend mesh,blend
    
    EntityColor mesh,r,g,b
    EntityAlpha mesh,a
    
    VertexColor surf,v0,r,g,b,a
    VertexColor surf,v1,r,g,b,a
    VertexColor surf,v2,r,g,b,a
    VertexColor surf,v3,r,g,b,a
    
    ScaleEntity mesh,scale,scale,scale
    
    Return mesh
    
End Function

; create procedural glowing border texture
Function CreateGlowTexture(size%=512,sharpness#=1.0,blur#=50.0)
    
    Local strength#=512*1.0/size*sharpness
    Local tex%=CreateTexture(size,size,3)
    Local tb%=TextureBuffer(tex)
    
    Local x%,y%,i#,j%,col%,rgb%,rc%,gc%,bc%
    
    LockBuffer tb
    
    For x=0 To size-1
        
        For y=0 To size-1
            
            ; clear colors
            rgb=0*$1000000+0*$10000+0*$100+0
            WritePixelFast x,y,rgb,tb
            
        Next
        
    Next
    
    For j=1 To (size/2)-2
        
        ; exponential falloff
        col=j*strength/Exp((((size/2)-2)-j)*(strength/blur))
        
        If col>224 Then col=Normalize(col,224,255,224,0)
        If col<0 Then col=0
        
        ; multiply RGB with brightness
        rc=R3*col Shr 8
        gc=G3*col Shr 8
        bc=B3*col Shr 8
        
        rgb=255*$1000000+rc*$10000+gc*$100+bc
        
        For i=0 To 360 Step 0.05
            
            WritePixelFast ((size-2)/2.0)+(Sin(i)*j),((size-2)/2.0)+(Cos(i)*j),rgb,tb
            
        Next
        
    Next
    
    UnlockBuffer tb
    
    Return tex
    
End Function

; normalize a value
Function Normalize#(value#=128.0,vmin#=0.0,vmax#=255.0,nmin#=0.0,nmax#=1.0)
    
    Return ((value#-vmin#)/(vmax#-vmin#))*(nmax#-nmin#)+nmin#
    
End Function

; create radar grid texture
Function CreateGridTexture(size%=512,quads%=16)
    
    Local x%,y%,j%,i#,rgb%,col%,r%,g%,b%
    Local steps%=size/quads
    
    Local tex%=CreateTexture(size,size,3+8)
    Local buffer%=TextureBuffer(tex)
    
    SetBuffer buffer
    
    ; background color
    Color R2,G2,B2
    Rect 0,0,size,size,1
    
    ; create grid
    Color R1,G1,B1
    For x=0 To quads-1
        For y=0 To quads-1
            Rect x*steps,y*steps,steps+1,steps+1,0
        Next
    Next
    
    Color 255,255,255
    
    LockBuffer buffer
    
    ; create glowing border and delete pixels outside the circle
    For j=(size/2)-6 To size
        
        For i=0 To 360 Step 0.05
            
            x=((size-2)/2.0)+(Sin(i)*j)
            y=((size-2)/2.0)+(Cos(i)*j)
            
            col=0
            If j<=(size/2) Then col=Normalize(j,(size/2)-6,(size/2),255,0)
            
            ; multiply RGB with brightness
            r=R3*col Shr 8
            g=G3*col Shr 8
            b=B3*col Shr 8
            
            rgb=0*$1000000+r*$10000+g*$100+b
            
            If x>=0 And x<size And y>=0 And y<size Then
                
                WritePixelFast x,y,rgb,buffer
                
            EndIf
            
        Next
        
    Next
    
    UnlockBuffer buffer
    
    SetBuffer BackBuffer()
    
    Return tex
    
End Function

; create a stunning sun texture
Function CreateSunTexture(size%=512,r%=255,g%=255,b%=255)
    
    Local tex%=CreateTexture(size,size,3)
    Local tb%=TextureBuffer(tex)
    
    Local i#,j%,col%,rgb%
    Local x%,y%,xx%,yy%
    Local a%
    
    LockBuffer tb
    
    For j=0 To (size/2)-1
        
        col=255-Normalize(j,0,(size/2)-1,0,255)
        If col>255 Then col=255
        rgb=col*$1000000+col*$10000+col*$100+col
        
        For i=0 To 360 Step 0.05
            
            WritePixelFast (size/2)+(Sin(i)*j),(size/2)+(Cos(i)*j),rgb,tb
            
        Next
        
    Next
    
    UnlockBuffer tb
    
    Local tempcam%=CreateCamera()
    Local tempsun%=CreatePivot()
    
    CreateQuad(tempsun,size/4.0,tex,3,1+8+16,r*1.00,g*1.00,b*1.00,1.00)
    CreateQuad(tempsun,size/1.5,tex,3,1+8+16,r*1.00,g*1.00,b*1.00,1.00)
    CreateQuad(tempsun,size/1.2,tex,3,1+8+16,r*0.75,g*0.75,b*0.50,0.75)
    CreateQuad(tempsun,size/1.0,tex,3,1+8+16,r*0.50,g*0.50,b*0.50,0.50)
    
    PositionEntity tempsun,0,0,WIDTH
    
    RenderWorld
    
    FreeEntity tempsun
    
    LockBuffer BackBuffer()
    LockBuffer tb
    
    For x=0 To size-1
        
        For y=0 To size-1
            
            xx=(WIDTH/2)-(size/2)+x
            yy=(HEIGHT/2)-(size/2)+y
            
            rgb=ReadPixelFast(xx,yy,BackBuffer())
            
            r=(rgb And $ff0000)/$10000
            g=(rgb And $ff00)/$100
            b=(rgb And $ff)
            a=255
            
            If (r+g+b)/3 < 32 Then a=Normalize((r+g+b)/3,0,32,0,255)
            
            rgb=(r+g+b)/3*$1000000+r*$10000+g*$100+b
            
            WritePixelFast x,y,rgb,tb
            
        Next
        
    Next
    
    UnlockBuffer tb
    UnlockBuffer BackBuffer()
    
    RenderWorld
    
    FreeEntity tempcam
    
    Return tex
    
End Function



puki(Posted 1+ years ago)

 Here are the two images together, it makes it easier to cross-reference:


Blitzplotter(Posted 1+ years ago)

 Indeed, very cool & inspiring - lovely piece of coding. In fact it inpsired me to look at the relative distance of the planets & their paths through our solar system:-<a href="http://www.solarviews.com/eng/solarsys.htm" target="_blank">http://www.solarviews.com/eng/solarsys.htm</a> [/i]