# [SOLVED] Math-help needed for coordinate transformations (rel. position from abs. position + rotation)

I am pretty new to 3D but boldly started out trying to implement a spaceship simulator. There is a kind of stellar navigation that I’d like to implement
https://worldbuilding.stackexchange.com/questions/23040/creating-a-realistic-worlds-map-stars
The lines originate from a center on a 2D plane to a point above or below the place of interest (Planet in my case) and then lead up- or downward to the point. Since I now all coordinates of all planets this was fairly easy. I already have it working and I am satiesfied how it worked out.

However, my current code only works from a very static perspective. While the spaceship moves around, I would like the map to adapt - not just with regard to the spaceships position (which would be simply adding/substracting the players coordinates), but also with regard to the ships orientation.
E.g.: If the player turns the ship to a planet right below his current heading, his own perspective on his current horizont (the blue circles in my link above) changes. Everything directly ahead of him is somewhere on his perceived Z-axis, etc.

I can try to dig out my trigonometry from school, but I guess there are easier solutions. So I would be grateful for some hints what functions I could use to calculate relative positions of an object with regard to an absolute position and a rotation of a player

If you’re working in jMonkeyEngine, then I suggest you change the player’s perspective by changing the orientation of the camera.

If you really want to calculate the relative locations of points in a rotated frame of reference, then `com.jme3.math.Transform#transformVector()` is probably the cleanest solution.

1 Like

Hi sgold,

thank you for your response. That seems to be exactly what I was looking for. I will give it a try.

1 Like

Or if you have things in world space and you want to find out where they are in local space… to create a map in local space (ie: based on the horizon of the ship) then you can either use spatial.worldToLocal()… or if you don’t have a convenient spatial representing the ship you can look at the code for worldToLocal() to see what it does.

1 Like

I guess in space the up vector isn’t always y-up which starts to hurt my head when you think about it, but check out this example, it may be of interest.

The popping of new spheres represents entering and leaving. Pretty nifty solution to ever increasing detail as you delve into galaxies and solar systems.

1 Like

spatialWorldToLocal() seems to do exactly what I need.

I feel a bit silly for not noticing that method before

1 Like

My result:

1 Like