1 - Calculate the distance between you and the enemy.
Simple pythagoras. If the enemy is too far away, don't bother going any further.
2 - Calculate the angle between where you are looking and where the enemy is.
Use the atanfull() function to locate the absolute angle from your current position to the enemy position, then subtract your viewing angle.
3 - Calculate the position on the radar.
Use the angle with sin and cos each multiplied by the distance to generate a set of radar positions, and then scale them to your radar size. Add in the screen coords of the centre of your radar and you can then use the dot command to draw it
I have example code that does this, but as it uses functions I guess you won't want to see it
But for everyone else, here it is:
sync on
sync rate 60
autocam off
for i=10000 to 10009
make object cube i, 1.0
position object i, rnd(120)-60, 0, rnd(120)-60
next i
Angle=0
do
if upkey() then move camera 0.2
if downkey() then move camera -0.2
if leftkey() then Angle=wrapvalue(angle-1)
if rightkey() then Angle=wrapvalue(angle+1)
if Angle < 0 then inc Angle, 360
yrotate camera Angle
Radar()
sync
loop
function Radar()
lock pixels
ink rgb(0,255,0),0
circle 70,105,2
circle 70,105,50
circle 70,105,60
ink rgb(255,255,255),0
for i=10000 to 10009
if object exist(i)=1
Distance=DistancePointToPoint( camera position x(), 0, camera position z(), object position x(i), 0, object position z(i))
if Distance < 60
Angle=ViewAngleFromPointToPoint( object position x(i), object position z(i), camera angle y(), camera position x(), camera position z() )
dot newxvalue(70, Angle, -Distance), newzvalue(105, Angle, Distance), rgb(255,255,255)
endif
endif
next i
unlock pixels
endfunction
function ViewAngleFromOrigin(x as float,y as float,va as float)
local Result as float
Result=atanfull(x,y)-va
if Result<-180.0
Result=Result+360.0
else
if Result>180.0 then Result=Result-360.0
endif
endfunction Result
function ViewAngleFromPointToPoint(x1 as float, y1 as float, va as float, x2 as float, y2 as float)
Result as float
Result=ViewAngleFromOrigin(x2-x1, y2-y1, va)
endfunction Result
function DistanceFromOrigin(x as float, y as float, z as float)
local Result as float
Result=sqrt( (x*x) + (y*y) + (z*z) )
endfunction Result
function DistancePointToPoint(x1 as float, y1 as float, z1 as float, x2 as float, y2 as float, z2 as float)
local Result as float
Result=DistanceFromOrigin(x1-x2, y1-y2, z1-z2)
endfunction Result
The code is for DBPro, but should run with minimal changes in DBC
*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++
http://www.matrix1.demon.co.uk