Radar Math ^^ I suck at this

Well

I basically want a radar, as seen here

Now for this tow ork with my real application I somehow need to be able to calcualte the radar local coordinates for objects. This is where I’m stuck.

I have
-> The position of my ship as Vector3f
-> The rotation of my ship as Quaternion
-> The position of the radarObject in worldspace

Now I need to somehow get the coordiante of the radarObject in ship local space. eg if its in front/behind me 0,0,z

[java]
Vector3f rawPosition = pos.asVector3f(); //pos being my object to display
rawPosition = myPos.subtract(rawPosition);
myRot.multLocal(rawPosition); // toLocal

			System.out.println(ro.id + " " + rawPosition);
			ro.position = rawPosition.divide(this.radarRange).multLocal(this.radarRadius); // just scale the final variable into the radar range and scale of subscene, this seems to work.

[/java]

You could probably use shipSpatial.worldToLocal(objectWorldPosition, objectLocalPosition)

Just do everything in world coords, subtract your ship position and scale down the resulting vectors?

@normen said: Just do everything in world coords, subtract your ship position and scale down the resulting vectors?

Hm but wouldn’t I need to convert to local in the end anyways? (The radar is out fo the ships perspective, and since I have ful 3d space, a simpler psuedo 3d one does not work fine I’m afraid.

@sgold said: You could probably use shipSpatial.worldToLocal(objectWorldPosition, objectLocalPosition)
Hm I have no spatials at that part of the engine directly, but I guess i could create some dummy ones that mimic the ships position for this. Not the cleanest way, but might work just fine enough.
@Empire Phoenix said: Hm but wouldn't I need to convert to local in the end anyways? (The radar is out fo the ships perspective, and since I have ful 3d space, a simpler psuedo 3d one does not work fine I'm afraid.

Yeah but as its world coords you just need to attach it to a node and place it where you want it. “Within” the radar you see a small version of the actual relations then.

Hm then I need to sync the camera of the radar scene or? But that might not be a actual problem.

@Empire Phoenix said: Hm then I need to sync the camera of the radar scene or? But that might not be a actual problem.

No, why? You could even attach the radar scene to the gui node if theres no depth issues. In what I suggest you automatically get a smaller version of the original space, centered on your ship. I take it thats what you want for the radar, right?

If you just want something else’s world coordinate in your ships local space (including rotation) then it’s pretty easy.

[java]
Vector3f posObject = …
Vector3f posShip = …
Quaternion rotShip = …

Vector3f localPos = posObject.subtract(posShip);
localPos = rotShip.inverse().mult(localPos);
[/java]

…off the top of my head.

1 Like

Yep thats it,

I even tested opposite, but should have used inverse instead ^^

Now it works, time to improve the code quality ^^ wich kinda degraded a little. :stuck_out_tongue: