XYZ to screenX, screenY

This is a discussion on XYZ to screenX, screenY within the Game Programming forums, part of the General Programming Boards category; Like in many games, text is above a player's head that usually has their character's name and healthbar etc. I ...

  1. #1
    Registered User taelmx's Avatar
    Join Date
    Oct 2006
    Location
    Japan
    Posts
    55

    XYZ to screenX, screenY

    Like in many games, text is above a player's head that usually has their character's name and healthbar etc. I was wondering how to take the 3d coordinates of the player and make them into screen coordinates. I'm guessing I'll have to do something with the camera, because taking just the XY from the 3d XYZ wouldn't do much good.

    Could this also be used....lets say for an NPC in an MMO where they sort of "light up" when you hover over them with the mouse? I might not do that. I might have something go over to the NPC and hover over them. ex. Navi from Zelda: Orcarina of Time, she floats around nearby people when you "z-target" them. I want to do the same thing except with "mouse hovering".
    Last edited by taelmx; 11-08-2006 at 11:48 AM.

  2. #2
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Quote Originally Posted by taelmx
    Like in many games, text is above a player's head that usually has their character's name and healthbar etc. I was wondering how to take the 3d coordinates of the player and make them into screen coordinates. I'm guessing I'll have to do something with the camera, because taking just the XY from the 3d XYZ wouldn't do much good.

    Could this also be used....lets say for an NPC in an MMO where they sort of "light up" when you hover over them with the mouse? I might not do that. I might have something go over to the NPC and hover over them. ex. Navi from Zelda: Orcarina of Time, she floats around nearby people when you "z-target" them. I want to do the same thing except with "mouse hovering".
    Are the camera standing still or is it moving? Imagin the player sitting in front of his screen, watching the 3d point "through" the screen. Say the coordinates of the point is (X, Y, Z) according to the screen, the actual screen coordinates will then be (X/(Z+a)*a, Y/(Z+a)*a), where a is the distance from the screen the player has. If the camera isn't in origo and facing straight forward, you will have to transform the XYZ coordinates to acording-to-screen-XYZ coordinates before you can calculate the screen XY coordinates, and for that I don't have any formula. Did that answer your question?

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Unproject the world coords of the object, compute the scale based on distance and render.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21