# How to calculate directional and distance vectors?

Hi all

Okay I know this must be the simplest bit of code you will be asked for in a while but my 3D maths skills are way under par…

My situation:
I am trying to create a 2D radar for a 3D space sim.

1. I am trying to calculate the distance between the enemy craft and myself (shouldn’t be too difficult),

2. then calculate wether it is above or below me (this I have decided to do with 6 colliders surrounding my craft and doing a raycast between the enemy and myself. Any better ideas? Keeping in mind that “above” is relative to 360 degrees on 3 axis…)

3. Then comes the hard part, to plot this in 2D. the radar display always has me in static in the center of the display, always pointing north. So, i need to figure out screen coordinates to place the enemy craft at… So if I know the enemy craft is 1000 meters below me to the right at an angle of 35degrees, how in the world would I translate that into: “15 pixels to the right and 12 pixels down from the center of the radar” ?

I was thinking of scaling the distance so the radar works on scale of 1 px for 50m or something similar (not decided on exact scale, yet) but what really bothers me is the 2D coordinate conversion of the Vector3…

Skip the math stuff and use a second camera in orthographic mode, pointing straight down. For radar blips, make child objects attached to your ships that are just unshaded spheres, on a layer only the radar camera sees.

–Eric

From the get-go i have been saying “second camera” it would make life so much simpler…

…but I forgot to mention one thing in my previous post: iPhone! This is an iPhone project and the idea of using another camera scares me a bit in terms of performance.

So let me ask this: if I use the setup like you describe, add everything into the meshCombiner and then draw everything using the two cameras, will that cut performance in half or will half of the models be rendered in one window, the other in the other one and at the end of the day it would take the same processing power it would have taken if I had simply drawn everything in the same window on the same layer? I know i wouldn’t want to do that, i am just curious about the processing power involved on the iPhone.

As it is I also have about 20 interactive OnGUI elements using GUI.DrawTexture that I plan to change over to GUITextures because of the iPhone’s meagre abilities… That combined with 5 to 10 ship models, trail renderers, missiles flying all over the place… will a second camera kill the phone or not?

The second camera would only add one draw call, because it’s presumably just rendering the blips, which can be batched by using low-poly objects. There’s some overhead using two cameras vs. one, but I’m not sure it’s enough to be noticeable, even on the iPhone.

You’re still going to have problems, because GUITextures don’t batch, so you have 20 draw calls = bad… There are various ways to approach that, probably not in this topic though (you can find info on that with a search also).

–Eric

The camera is good news. The GUITextures is not. I thought I read once that we should use that instead of the new GUI system because all GUITextures get drawn in one call…

Oh this is bad!!! So I finally got the radar sorted. The thing that was giving me sleepless nights. I finally got that sorted out just to find out that the easiest part of the entire process is going to kill my project completely…

See my smile turn upside-down…

FWIW, I’m using a bunch of cameras and it’s not a hit on performance in itself.

However, not having occlusion culling per camera, like I need – that just sucks.