Posted: 30th Oct 2002 2:20
Radar example, If anyone can improve on this, please feel free (but please post it so we can all use it)..should work with DBP & DB.

+ Code Snippet
Set Display Mode 800,600,16
Sync On
Sync Rate 0
Hide Mouse
AutoCam Off
Color Backdrop 0
`Play here.
`------------------------
RadarRange=20000
EnemyCount=6
EnemySpeed#=4.0
ShipSpeedMax#=6.0
`------------------------
`Make ship object.
Make Object Sphere 1000,25
Position Object 1000,2500,0,2500
`Make test objects.
For T=1 to EnemyCount
   Make Object Cube T,50
   Position Object T,RND(5000),0,RND(5000)
   YRotate Object T,RND(360)
Next T
`Camera start position and range.
Position Camera 2500,0,2500
Set Camera Range 1,RadarRange-1000
`Make and position matrix.
Make Matrix 1,25000,25000,10,10
Position Matrix 1,-12500,-300,-12500

`Main Loop--------------
Do
Line 400,290,400,310
Line 390,300,410,300
`Control ship.
CaX#=WrapValue(CaX#+MouseMoveY()/2)
CaY#=WrapValue(CaY#+MouseMoveX()/2)
Rotate Object 1000,CaX#,CaY#,CaZ#
`Control ship speed.
If Delay>0 Then Dec Delay
If MouseClick()=1 and Delay=0 Then Delay=20:Inc ShipSpeed#,1.0
If MouseClick()=2 and Delay=0 Then Delay=20:Dec ShipSpeed#,1.0
If ShipSpeed#>ShipSpeedMax# Then ShipSpeed#=ShipSpeedMax#
If ShipSpeed#=ShipSpeedMax#
   Center Text 400,25,"Ship speed : Max"
Else
   Center Text 400,25,"Ship speed :"+Str$(ShipSpeed#)
EndIf
Center Text 400,40,"FPS : "+Str$(Screen FPS())
Sync
Loop
`End Loop---------------


Function RADAR(Ship,RadarRange,ObjFrom,ObjTo)
`Ship            =   The object you are controling.
`RadarRange      =   Radar range.
`ObjFrom         =   The first object to check for.
`ObjTo           =   The last object to check for.
`Draw radar.
Ink RGB(255,255,255),0
ELLIPSE 93,504,88,88
Dot 93,504
`Radar range.
G#=RadarRange/84
For T=ObjFrom to ObjTo
   If Object Exist(T)
      ObjX1#=Object Position X(Ship)
      ObjY1#=Object Position Y(Ship)
      ObjZ1#=Object Position Z(Ship)
      ObjX2#=Object Position X(T)
      ObjY2#=Object Position Y(T)
      ObjZ2#=Object Position Z(T)
      Dx#=ABS(ObjX1#-ObjX2#)
      Dy#=ABS(ObjY1#-ObjY2#)
      Dz#=ABS(ObjZ1#-ObjZ2#)
      Dist#=SQRT((Dx#*Dx#)+(Dy#*Dy#)+(Dz#*Dz#))
      `Convert 3d position to 2d position for radar blip.
      XRadar=(Object Position X(T)-Object position X(Ship))/G#
      ZRadar=(Object Position Z(T)-Object position Z(Ship))/G#
      `Angle for radar blip.
      TanAngle=ATANFULL(XRadar,ZRadar)
      If Object Angle X(Ship)>90 and Object Angle X(Ship)Radius#
    Point Object Obj,XPos#,Object Position Y(Obj),ZPos#
    If ABS(A#-A#)>Speed#
      A#=WrapValue(A#-(Speed#/4))
    Else
      A#=WrapValue(A#+(Speed#/4))
    EndIf
EndIf
YRotate Object Obj,A#
Move Object Obj,Speed#
EndFunction


ToXic
Posted: 30th Oct 2002 7:38
very nice,,,,and seems to be pretty acurate as well
Posted: 19th Jan 2003 17:54
It do not work on my DarkBasic.
Hey give's an error:
"SYNTAX ERROR, UNRECONISED PARAMETER"
[email]mail me[/email]
Posted: 19th Jan 2003 17:57
The mail servic do not work.
Here is my e-mail,adres: glennvanbael@msn.com
Sorry i dont spreak good english,
thats by i spreak duth, im from Belgium.
Posted: 23rd Jan 2003 21:04
please send me the shader examples: regulyistvan@hotmail.com
Posted: 26th Jan 2003 15:31
Please get this radar example to work in Dark Basic
Posted: 26th Jan 2003 16:56
I won't work in either DBv1 or DBPro.

The line 'If Object Angle X(Ship)>90 and Object Angle X(Ship)Radius#' has not posted correctly.
Posted: 27th Jan 2003 21:47
If anyone would like me to email them the working Radar code
Email me, marshallblk@aol.com.au, cant get it to post right.

Toxic.
Posted: 27th Jan 2003 22:23
Ok, here's the code ToXic sent me.

+ Code Snippet
Set Display Mode 800,600,16
Sync On
Sync Rate 0
Hide Mouse
AutoCam Off
Color Backdrop 0
`Play here.
`------------------------
EnemyCount=11
Dim EnemySpeed#(EnemyCount)
For T=1 to EnemyCount
   EnemySpeed#(T)=Rnd(6)+4
Next T
RadarRange=20000
ShipSpeedMax#=6.0
`------------------------
`Make ship object.
Make Object Sphere 1000,25
Position Object 1000,2500,0,2500
`Make test objects.
For T=1 to EnemyCount
   Make Object Cube T,50
   Position Object T,RND(5000),0,RND(5000)
   YRotate Object T,RND(360)
Next T
`Camera start position and range.
Position Camera 2500,0,2500
Set Camera Range 1,RadarRange-1000
`Make and position matrix.
Make Matrix 1,25000,25000,10,10
Position Matrix 1,-12500,-300,-12500

`Main Loop--------------
Do
Line 400,290,400,310
Line 390,300,410,300
`Control ship.
CaX#=WrapValue(CaX#+MouseMoveY()/2)
If Inverted=1
CaY#=WrapValue(CaY#-MouseMoveX()/2)
Else
CaY#=WrapValue(CaY#+MouseMoveX()/2)
EndIf
Rotate Object 1000,CaX#,CaY#,CaZ#
`Control ship speed.
If Delay>0 Then Dec Delay
If MouseClick()=1 and Delay=0 Then Delay=20:Inc ShipSpeed#,1.0
If MouseClick()=2 and Delay=0 Then Delay=20:Dec ShipSpeed#,1.0
If ShipSpeed#>ShipSpeedMax# Then ShipSpeed#=ShipSpeedMax#
If ShipSpeed#=<0 Then ShipSpeed#=1.0
`Move ship.
Move Object 1000,ShipSpeed#
`Camera settings.
Position Camera Object Position X(1000),Object Position Y(1000),Object Position Z(1000)
Set Camera to Object Orientation 1000
Move Camera ShipSpeed#+1.0
`Keep the objects in an area.
For T=1 to EnemyCount
   SETOBJECTAREA(T,2500.0,2500.0,10000.0)
Next T
`Check radar.
Inverted=RADAR(1000,RadarRange,1,EnemyCount)
Center Text 400,10,"Mouse to move around, mouse buttons for speed... "
If ShipSpeed#=>ShipSpeedMax#
   Center Text 400,25,"Ship speed : Max"
Else
   Center Text 400,25,"Ship speed :"+Str$(ShipSpeed#)
EndIf
Center Text 400,40,"FPS : "+Str$(Screen FPS())
Sync
Loop
`End Loop---------------


Function RADAR(Ship,RadarRange,ObjFrom,ObjTo)
`Ship            =   The object you are controling.
`RadarRange      =   Radar range.
`ObjFrom         =   The first object to check for.
`ObjTo           =   The last object to check for.
`Draw radar.
Ink RGB(255,255,255),0
ELLIPSE 93,504,88,88
Dot 93,504
`Radar range.
G#=RadarRange/84
For T=ObjFrom to ObjTo
   If Object Exist(T)
      ObjX1#=Object Position X(Ship)
      ObjY1#=Object Position Y(Ship)
      ObjZ1#=Object Position Z(Ship)
      ObjX2#=Object Position X(T)
      ObjY2#=Object Position Y(T)
      ObjZ2#=Object Position Z(T)
      Dx#=ABS(ObjX1#-ObjX2#)
      Dy#=ABS(ObjY1#-ObjY2#)
      Dz#=ABS(ObjZ1#-ObjZ2#)
      Dist#=SQRT((Dx#*Dx#)+(Dy#*Dy#)+(Dz#*Dz#))
      `Convert 3d position to 2d position for radar blip.
      XRadar=(Object Position X(T)-Object position X(Ship))/G#
      ZRadar=(Object Position Z(T)-Object position Z(Ship))/G#
      `Angle for radar blip.
      TanAngle=ATANFULL(XRadar,ZRadar)
      If Object Angle X(Ship)>90 and Object Angle X(Ship)<270
         `If the unit is up side down (Reverse the angle).
         Heading=TanAngle-Object Angle Y(Ship)-180
         Inverted=1
      Else
         Heading=TanAngle-Object Angle Y(Ship)
         Inverted=0
      EndIf
      `Plot the distance and angle for radar blip.
      NewXRadar=(SIN(Heading)*Dist#)/G#
      NewZRadar=(COS(Heading)*Dist#)/G#
      `Display any enemy objects in radar range.
      If Dist#<=RadarRange
         Ink RGB(255,0,0),0
         If Inverted=0
            Dot 93+NewXRadar,504-NewZRadar:Inverted=0
         Else
            `If Inverteded reverse radar.
            OK=0
            If NewXRadar>93 Then X=NewXRadar-93:NewXRadar=X:OK=1
            If NewXRadar<93 and OK=0 Then X=93-NewXRadar:NewXRadar=X:OK=1
            If NewXRadar=93 and OK=0 Then X=93
            Dot X,504-NewZRadar
         EndIf
      EndIf
   EndIf
Next T
EndFunction Inverted

Function SETOBJECTAREA(Obj,XPos#,ZPos#,Radius#)
X#=Object Position X(Obj)
Z#=Object Position Z(Obj)
A#=Object Angle Y(Obj)
Dist#=SQRT((X#-XPos#)^2.0+(Z#-ZPos#)^2.0)
If Dist#>Radius#
    Point Object Obj,XPos#,Object Position Y(Obj),ZPos#
    A#=WrapValue(A#-(EnemySpeed#(Obj)/4))
EndIf
YRotate Object Obj,A#
Move Object Obj,EnemySpeed#(Obj)
EndFunction