January 21, 2021, 04:48:15 AM

Author Topic: Making the little 'radar' which tells you in Elite if you are facing the planet.  (Read 228 times)

Offline JBR

  • Full Member
  • ***
  • Posts: 123

I think it should be done using the dot product from ship to planet and ship to any point in ship direction?

Any advice appreciated.


Offline iWasAdam

  • Hero Member
  • *****
  • Posts: 2057
think of it this way:
every ship has an xz and a y (height). we will ignore the y at the moment

so. every ship position (in reference to you) can be calculated:
mapx = yourx - enemyx
mapz = yourz - enemyz

if you do a 2d plot with your position being centered. all the mapped points now are in relation to you - this gives us a top down 2d (xy) view of the map

if you half the y map positions you get the squeezed version of the map - draw some ellipses...

to set ranges on the ships - you need to do a simple length from you to them - and cull anything over a certain length

now we have a faux 2d/3d map of your position plus the enemy position.

to add the height - you first need
mapy = youry - enemyy
then /2 to fit the squeezed map. then draw a line from the xz enemy map position to the enemy map position + the new mapy :)

Offline STEVIE G

  • Sr. Member
  • ****
  • Posts: 498

I think it should be done using the dot product from ship to planet and ship to any point in ship direction?

Any advice appreciated.


You need the object, be it ship or planets local position relative to your ship, taking into consideration its pitch and roll. Dot product is the way to go. The simplest solution is to just use tformpoint  0,0,0,ship,object , the resulting tformedx,y,z will give you what you need. This can then be scaled / clipped to fit your radar.

Offline JBR

  • Full Member
  • ***
  • Posts: 123
Hi, got this far. It works as I want it, basically keeps the radar dot inside a 128 by 128 circle.

Problem is the scale to keep the dot inside the circle. Just using a 2D circle.

It will switch from the Planet to The Space station but I can't get an even scale to stay within the circle.

I've made the a & b vectors unit vectors, why, I don't know, but the dot product is working for infront/behind.

Any ideas? The Planet has radius 2000 but the Space station is radius 50. My problem is finding the right scale at any distance to utilise the full circle.

Code: [Select]
Function Handle_Planet_Radar()

Local x# = EntityX(Planet_Pivot)
Local y# = EntityY(Planet_Pivot)
Local z# = EntityZ(Planet_Pivot)

ax# = x - EntityX(Camera)
ay# = y - EntityY(Camera)
az# = z - EntityZ(Camera)

dist# = Sqr(ax*ax+ay*ay+az*az)

ax = ax / dist
ay = ay / dist
az = az / dist

TFormPoint 0,0,1, Camera, 0

bx# = TFormedX() - EntityX(Camera)
by# = TFormedY() - EntityY(Camera)
bz# = TFormedZ() - EntityZ(Camera)

rad_orientation = ax*bx + ay*by + az*bz

TFormPoint x,y,z, 0,Camera

dist# = Sqr( ax*ax + bx*bx + cx*cx )

Rad_Scale# = 0.03

rad_x# = TFormedX() * Rad_Scale
rad_y# = -TFormedY() * Rad_Scale

End Function

Online Matty

  • Hero Member
  • *****
  • Posts: 1339
    • MattiesGames
You do not define cx in your code yet you use it for a calculation?
I eat cheese in the trees when its eight degrees

Offline JBR

  • Full Member
  • ***
  • Posts: 123
Thanks Matty,

Fixed the dist = ...

And scale# = (radius of circle) / dist.

All working, thanks guys.



SimplePortal 2.3.6 © 2008-2014, SimplePortal