3d character position in a 2d map

Started by
11 comments, last by rethan 14 years, 9 months ago
Hi all I have a character moving around in a 3d world and I also have a 512x512 texture that is the 2d representation of the 3d world, that is, the top view map of the world. As i move my character around I would like to see its current 3d position converted to a 2d map position but im not sure how this can be achieved. Some ideas on how this can be done would be very appreciated Happy thanks
Advertisement
Well, the obvious choice is to take the x and y coordinates of the player position (assuming z-axis is up), and then divide by map_size/mini_map_size.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Hi swiftcoder

What exactly do you mean by mini_map_size?

thank you
Quote:Original post by dontKnowWhatToPick
What exactly do you mean by mini_map_size?
The size of the small representation of the map - in this case 512.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

What he is saying is that, given you are using an X,Y,Z coordinate system, you must find the correlation between a unit in the 3d world and a unit on the mini map.

Say your 3d map is 1000 units wide in the X direction and 1000 units wide in the Y direction, and your mini-map is 512x512. 1000/512 will give you the size correlation. Then, when you want to show the character on the mini-map, you would take it's X and Y coordinates in the 3d world, and divide them by the quotient before. This will give you an X and Y coordinate on the scale of your mini map.
Does your minimap represent the entire 3D world or just a small area close to the player?

If your minimap is small version of the entire world then it is a matter of getting a mapping/scaling factor. However if you are wanting to create a minimap of just the area close to the player (similar to what I did in my ghost toast game) then what you probably want to do is take the players position and plant it in the centre of the minimap.

Based on the forward and right direction that the player is facing, you can define the Y and X axis of your minimap accordingly. Once you have these two directional vectors you need a scaling factor to define how much of the 3D world should be visible in the minimap.

You can now generate your minimap wrt the players current position.
Hi guys

The minimap represents the entire world.

Chadwell but what if the units are not the same in both axis and is more like 1000x350 for example?
Quote:Original post by dontKnowWhatToPick
what if the units are not the same in both axis and is more like 1000x350 for example?


Then just scale each dimension accordingly (world X to map X and world Y to map Y).
If your world is WORLD_WIDTH by WORLD_HEIGHT, and your minimap is MINI_WIDTH by MINI_HEIGHT, then, if you're showing the whole world in the minimap, you can place the player (at PLAYER_WORLD_X, PLAYER_WORLD_Y) in the minimap like so:

PLAYER_MINI_X = MINI_WIDTH * ( PLAYER_WORLD_X / WORLD_WIDTH )
PLAYER_MINI_Y = MINI_HEIGHT * ( PLAYER_WORLD_Y / WORLD_HEIGHT )

What the math is doing is taking the player's world coordinates and dividing them with the world width/height such that you end up with a (parameterized)
position that is from 0 (left side) to 1 (right side). Now that you have the position as a %, you can multiply by the minimap's dimentions to get the position with respect to the minimap.
oh yeah makes sense :p

Thanks for the help guys.

This topic is closed to new replies.

Advertisement