Jump to content
  • Advertisement
Sign in to follow this  
dontKnowWhatToPick

3d character position in a 2d map

This topic is 3347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!