[B3D] 3D Elite Style Scanner

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

 

Krischan

Betreff: [B3D] 3D Elite Style Scanner

BeitragMi, Sep 29, 2010 16:22
Antworten mit Zitat
Benutzer-Profile anzeigen
Diese Demo zeigt die Verwendung eines 3D Weltraum Scanners so wie im Spiel "Elite". Es zeigt den Inhalt eines Typefields in einer bestimmten Entfernung mit Radarechos und Stangen an - letztere repräsentieren die relative Höhe zum zentrierten Raumschiff. Die Demo erzeugt zwei prozedurale Texturen, die zusammengeblendet einen hübschen glühenden Radarschirm ergeben.

Pfeiltasten/Maus zur Steuerung, LMT=schneller fliegen, RMT=Scannerreichweite halbieren.

EDITH: Codezeilen gekürzt, Farbschemata hinzugefügt und mehr Konstanten zum Deklarieren eingebaut.

Viel Spass!

user posted image

BlitzBasic: [AUSKLAPPEN]
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
b\entity=CreateCone(16)
b\blip=CreateSphere(6,radar)
b\pole=CreateCube(radar)
b\x=Rnd(-range,range)
b\y=Rnd(-range,range)
b\z=Rnd(-range,range)
b\vx=Rnd(-0.1,0.1)
b\vy=Rnd(-0.1,0.1)
b\vz=Rnd(-0.1,0.1)
b\r=Rand(255)
b\g=Rand(255)
b\b=Rand(255)
b\size=2

; align "ship" to its flight vector
AlignToVector b\entity,b\vx,b\vy,b\vz,2,1

; create the entity itself
PositionEntity b\entity,b\x,b\y,b\z
EntityFX b\entity,1
EntityColor b\entity,b\r,b\g,b\b
ScaleEntity b\entity,b\size,b\size*2,b\size
EntityAutoFade b\entity,1,range

; creates a radar blip
EntityFX b\blip,1
EntityOrder b\blip,-100
EntityColor b\blip,b\r,b\g,b\b

; creates a blip pole
EntityFX b\pole,1
EntityOrder b\pole,-100
EntityColor b\pole,b\r,b\g,b\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
b\x=b\x+b\vx
b\y=b\y+b\vy
b\z=b\z+b\vz
PositionEntity b\entity,b\x,b\y,b\z

; get distance to object
d=EntityDistance(b\entity,cam)

; within scanner range?
If d<range Then

visible=visible+1

; show blip and its pole
ShowEntity b\pole
ShowEntity b\blip

; transform position
TFormPoint (b\x,b\y,b\z,0,cam)
rx=-TFormedX()/halfscale*div
rz=TFormedZ()/halfscale*div
ry=TFormedY()*div

; reposition/scale blip
PositionEntity b\blip,0,0,0
TranslateEntity b\blip,rx,rz,ry/scale*VertScale
ScaleEntity b\blip,bs,bs,bs

; reposition/scale pole
PositionEntity b\pole,0,0,0
ScaleEntity b\pole,ps,ps,ry/doublescale*VertScale
TranslateEntity b\pole,rx,rz,ry/doublescale*VertScale

Else

; hide blip and its pole
HideEntity b\pole
HideEntity b\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
  • Zuletzt bearbeitet von Krischan am Mi, Sep 29, 2010 18:20, insgesamt einmal bearbeitet

ToeB

BeitragMi, Sep 29, 2010 16:26
Antworten mit Zitat
Benutzer-Profile anzeigen
Nettes teil sehr schön Wink

Kann man sicherlich mal gut gebrauchen !!

mfg ToeB
Religiöse Kriege sind Streitigkeiten erwachsener Männer darum, wer den besten imaginären Freund hat.
Race-Project - Das Rennspiel der etwas anderen Art
SimpleUDP3.0 - Neuste Version der Netzwerk-Bibliothek
Vielen Dank an dieser Stelle nochmal an Pummelie, welcher mir einen Teil seines VServers für das Betreiben meines Masterservers zur verfügung stellt!
 

Krischan

BeitragDi, Okt 12, 2010 17:15
Antworten mit Zitat
Benutzer-Profile anzeigen
Hier ein Update - anstelle von Cubes und Spheres werden nun Quads verwendet, die auch texturiert werden können. Sieht nun besser aus:

user posted image

BlitzBasic: [AUSKLAPPEN]
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

b\scale=Rnd(1,Rnd(2,Rnd(3,4)))

Select method

; random cubic placement
Case "cubic":

b\x=Rnd(-range,range)*Factor
b\y=Rnd(-range,range)*Factor
b\z=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
b\x=EntityX(temp)
b\y=EntityY(temp)
b\z=EntityZ(temp)

End Select

; color
col=Rnd(1)
If col>0.50 And col<=1.00 Then b\r=255 : b\g= 0 : b\b= 0 : tex=SUNTEX_RED : b\scale=b\scale/2.00
If col>0.20 And col<=0.50 Then b\r=255 : b\g=255 : b\b= 0 : tex=SUNTEX_YEL : b\scale=b\scale/1.00
If col>0.10 And col<=0.20 Then b\r= 0 : b\g= 0 : b\b=255 : tex=SUNTEX_BLU : b\scale=b\scale*1.25
If col>0.00 And col<=0.05 Then b\r=255 : b\g=255 : b\b=255 : tex=SUNTEX_WHI : b\scale=b\scale*1.50

; create the entity itself
b\entity=CreateQuad(False,1.0,tex,3,2+32,b\r,b\g,b\b,1.00)
PositionEntity b\entity,b\x,b\y,b\z
PointEntity b\entity,cam
EntityBlend b\entity,3

; creates a radar blip
b\blip=CreateQuad(radar,1.0,tex,3,2+32,b\r,b\g,b\b,1.00)
EntityOrder b\blip,-100
RotateMesh b\blip,90,0,0

; creates a blip pole
b\pole=CreateQuad(radar,1.0,False,3,2+32,b\r,b\g,b\b,0.50)
EntityOrder b\pole,-50
RotateMesh b\pole,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(b\entity,cam) Then

d=EntityDistance(b\entity,cam)
s=Exp(1.0/d*(Factor*10))*b\scale
If s<d*0.005 Then s=d*0.005
ScaleEntity b\entity,s,s,s
ShowEntity b\entity
PointEntity b\entity,cam

Else

HideEntity b\entity

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(b\entity,cam)

; hide radar blip/pole
HideEntity b\pole
HideEntity b\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(b\blip,b\r,b\g,b\b,a)
UpdateQuad(b\pole,b\r,b\g,b\b,a*0.5)

; show blip and its pole
ShowEntity b\pole
ShowEntity b\blip

; transform position
TFormPoint (b\x,b\y,b\z,0,cam)
rx=TFormedX()/halfscale*div
rz=TFormedZ()/halfscale*div
ry=-TFormedY()*div

; reposition/scale blip
PositionEntity b\blip,0,0,0
TranslateEntity b\blip,rx,rz,ry/scale*VertScale
ScaleEntity b\blip,bs,bs,bs

; reposition/scale pole
PositionEntity b\pole,0,0,0
ScaleEntity b\pole,ps,ps,Abs(ry/doublescale*VertScale)
TranslateEntity b\pole,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

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group