here's a radar system that can be scaled, and behaves a little more like you'd expect one to:
+ Code Snippet`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
`Simple Radar by Revenant_chaos\\
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`Email-Revenant_chaos@yahoo.com//
`///////////////////////////////
sync on
hide mouse
distX as float
distY as float
posx as float
posz as float
objdist as float
radarscale as float=.5 `scale is expressed as a decimal, used to scale the radar's screen size
radardist=200 `range that radar will cover
numofradaritems=10 `number of objects to be checked for
`generate some random objects to detect
for tmp=1 to numofradaritems
make object cube tmp,10
position object tmp,rnd(200)-100,0,rnd(200)-100
next tmp
do
set cursor 1,1
if showhud=0 `Display Text
print "fps=",screen fps() `show Frames per second
print "use arrowkeys to move, and mouse to look"
print "use the keypad's + and - to scale the radar"
print "press H to toggle this text"
endif
`keyboard input
control camera using arrowkeys 0,.5,.33
if held=0
if scancode()=78 then radarscale=radarscale+.05
if scancode()=74 then radarscale=radarscale-.05
if inkey$()="h" and showhud=0 then showhud=1
endif
held=scancode()
`mouselook
rotate camera 0,wrapvalue(camera angle Y()+mousemoveX()),0
gosub radar
sync ; loop
radar:
ink rgb(255,0,0),1 `RED
radarscreenposX=radardist*radarscale`Auto position the radar X
radarscreenposY=radardist*radarscale`auto position the radar Y
circle radarscreenposX,radarscreenposY,radardist*radarscale `draw the radar outline circle
dot radarscreenposX,radarscreenposY `draw the player's blip in the center
ink rgb(255,255,255),1 `WHITE
for tmp=1 to numofradaritems
`get our distance from the target
distX=camera position X()-object position X(tmp)
distZ=camera position Z()-object position Z(tmp)
objdist=abs(distX)+abs(distZ) `convert to positive values, then add them
if abs(objdist)<radardist `if positive distance is within range
`get its angle compared to the player's direction
tmpang=wrapvalue(atanfull(distX,distZ)-camera angle Y())
`calculate it's radar coords using trig
posX=0-sin(tmpang)*objdist*radarscale
posZ=cos(tmpang)*objdist*radarscale
dot (radarscreenposX+posX),(radarscreenposY+posZ) `finally, place it's blip
endif
next tmp
return
let me know what you think. if you have any questions, just ask.
edit:
well I decided to further modify the code above, it fixes a bit of the jitters when you get close to an object. the blips are color coded to match the target, and now scale according to the radar scale.
The really only bug comes from the way the distance is checked combined with the sin()/cos(). since the distance is combined (distX+distZ) to place the blip, it isn't really proportional to the actual distX/distZ. for instance, if distX>distZ, the blip's Xdistance and Zdistance (from center) are still equal, because the combined distance is the radius that positions the point in respect to the player.
here it is:
+ Code Snippet`\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
`Simple Radar by Revenant_chaos\\
`>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
`Email-Revenant_chaos@yahoo.com//
`///////////////////////////////
sync on ; hide mouse
distX as float ; distY as float
posx as float ; posz as float
objdist as float
radarscale as float=.08 `scale is expressed as a decimal, used to scale the radar's screen size
radardist=1000 `range that radar will cover
numofradaritems=30 `number of objects to be checked for
refresher as float
set ambient light 50
dim boxcolor(numofradaritems,3)
for tmp=1 to numofradaritems `generate some random objects to detect
make object cube tmp,10
boxcolor(tmp,1)=rnd(255)
boxcolor(tmp,2)=rnd(255)
boxcolor(tmp,3)=rnd(255)
color object tmp,rgb(boxcolor(tmp,1),boxcolor(tmp,2),boxcolor(tmp,3))
position object tmp,rnd(1000)-500,0,rnd(1000)-500
next tmp
do
set cursor 1,1
if showhud=0 `Display Text
print "fps=",screen fps() `show Frames per second
print "use arrowkeys to move, and mouse to look"
print "use the keypad's + and - to scale the radar"
print "press H to toggle this text"
endif
control camera using arrowkeys 0,.5,.33 `keyboard walking
if held=0
if scancode()=78 then radarscale=radarscale+.01 `scale radar
if scancode()=74 then radarscale=radarscale-.01 `scale radar
if inkey$()="h" and showhud=0 then showhud=1 `toggle HUD
endif ; held=scancode()
rotate camera 0,wrapvalue(camera angle Y()+mousemoveX()),0 `mouselook
gosub radar
sync ; loop
radar:
ink rgb(255,0,0),1 `RED
radarscreenposX=radardist*radarscale`Auto position the radar X
radarscreenposY=radardist*radarscale`Auto position the radar Y
circle radarscreenposX,radarscreenposY,radardist*radarscale `Draw the radar outline circle
dot radarscreenposX,radarscreenposY `draw the player's blip in the center
`Draw cross in center of radar
line radarscreenposX,radarscreenposY-(radardist*radarscale),radarscreenposX,radarscreenposY+(radardist*radarscale)
line radarscreenposX-(radardist*radarscale),radarscreenposY,radarscreenposX+(radardist*radarscale),radarscreenposY
ink rgb(255,255,255),1 `WHITE
for tmp=1 to numofradaritems
distX=camera position X()-object position X(tmp)`get our X distance from the target
distZ=camera position Z()-object position Z(tmp)`get our Z distance from the target
objdist=abs(distX)+abs(distZ) `convert to positive values, then add them
if abs(objdist)<radardist `if positive distance is within range
tmpang=wrapvalue(atanfull(distX,distZ)-camera angle Y()) `get its angle compared to the player's direction
ink rgb(boxcolor(tmp,1),boxcolor(tmp,2),boxcolor(tmp,3)),1
circle (radarscreenposX+(0-sin(tmpang)*objdist*radarscale)),(radarscreenposY+cos(tmpang)*objdist*radarscale),(12*radarscale)*(13*radarscale)
endif
next tmp
return
what do you think?