I am wondering how exactly I can convert a location (X Y Z) to a point on screen (X Y).
I have a player (the player you control) who is in (X Y Z) co-ordinates and another player who is also in (X Y Z) co-ordinates.
How exactly can I convert the other player's X Y Z to X Y on screen so that I can draw a name above him/it using the X Y.
Hope that makes sense...
Edit:
Here is my gluProject code:
IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);
FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
FloatBuffer objectCoords = GLAllocation.createDirectFloatBuffer(3);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
GLU.gluProject(x, y, z, modelview, projection, viewport, objectCoords);
eturn objectCoords;
Thanks.
You should be able to deal with that:
To find the screen coordinate corresponding to a point in the world, apply the camera transform to the world point. You don't say what 3D framework you are using, but almost certainly there is an API call you can make to perform this transformation. For example, in the Unity3D framework, you call
Camera.WorldToScreenPoint
, and in OpenGL, you callgluProject
.However, this isn't necessarily the best way to render "head up" displays like character names. Another technique is to create billboards, which are objects in the world that always face the camera. Again, your 3D framework probably has support for this: for example, in Unity3D you might call
object.transform.LookAt(camera.transform)
.a method to plot 3d points in 2d exists. you will have to define a focal length parameter. the following code does it correctly
this code will do it perfectly. even I had made 3d graphics in flash 6 which is based totally on 2d.
this is a maths, not programming question. the answer depends on where you're looking from and where your 'screen' is sitting in relation to your viewpoint and the player.
Essentially you need to draw a line from the viewpoint to the position in 3D, then calculate the x,y coordinates on a 2D plane (the screen) which intersects the line. - i think!