Hier ein Update - anstelle von Cubes und Spheres werden nun Quads verwendet, die auch texturiert werden können. Sieht nun besser aus:
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] AppTitle "3D Elite Style Scanner Example"
SeedRnd 7
Graphics3D 800,600,32,2
Const TurnSpeed# = 4.00 Const RollSpeed# = 0.50 Const CameraSpeed# = 0.25 Const Objects% = 1000 Const RadarSize% = 300 Const Factor# = 1.0 Const UniverseRange#= 250.0 Const Maxrange# = 64.0
Const PoleWidth# = 1.0 Const BlipSize# = 8.0 Const VertScale# = 1.0 Const RadarBorder# = 0.8 Const Distribution$ = "spherical"
Const R1%= 0,G1%=128,B1%=192 Const R2%= 0,G2%= 16,B2%= 32 Const R3%= 0,G3%=128,B3%=255
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)
Local CAM%=CreateCamera() CameraRange CAM,1.0/Factor,(WIDTH*Factor)+RadarSize
Local RADAR=InitRadar(RadarSize,512,10,CAM)
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 Movement(CAM) If MouseDown(2) Then range=Maxrange/2.0 UpdateObjects(CAM) UpdateRadar(CAM,RADAR,RadarSize,range*Factor,100) RenderWorld WaitTimer TIMER Flip 0 Wend
End
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 Case "cubic": b\x=Rnd(-range,range)*Factor b\y=Rnd(-range,range)*Factor b\z=Rnd(-range,range)*Factor 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 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 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 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 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
Function Movement(cam%,sensitivity#=1.0) Local roll#,cx#,cz#,tx#,ty#,multi%=1 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,cx*multi,0,cz*multi End Function
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) 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 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
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
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 d=EntityDistance(b\entity,cam) HideEntity b\pole HideEntity b\blip If d<range*2 Then If d<range Then 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) ShowEntity b\pole ShowEntity b\blip TFormPoint (b\x,b\y,b\z,0,cam) rx=TFormedX()/halfscale*div rz=TFormedZ()/halfscale*div ry=-TFormedY()*div PositionEntity b\blip,0,0,0 TranslateEntity b\blip,rx,rz,ry/scale*VertScale ScaleEntity b\blip,bs,bs,bs 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 RotateEntity radar,angle,0,0 Return visible End Function
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
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 rgb=0*$1000000+0*$10000+0*$100+0 WritePixelFast x,y,rgb,tb Next Next For j=1 To (size/2)-2 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 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
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
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 Color R2,G2,B2 Rect 0,0,size,size,1 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 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) 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
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
|