# Draw a 3D object at specific coordinates on the screen

I'm creating an application which allows the user to manipulate 3D models.

I would like to draw 3 axis representing the world coordinate system in 3D in order to give the user an idea where he is. These axis are represented by a 3D model. Now I want these axis to be always shown at the bottom left of the screen. I know how to draw them but not how to project them at specific coordinates on the screen.

How can i achieve this?

EDIT:

I use XNA. The axes have been created with 3DSMax, each axes is a cylinder surmounted by a cone. When I load the 3DSMax file, I get an instance of the Model class.

I've just tried to draw it normally and it appears at the center of the scene. After that, i don't know what to do to make it appears at the bottom left of the screen regardless of where the camera looks, as if that was part of the UI. 3DSMax has the same thing at the bottom left of each frame.

• What technologies are you using? What have you tried? How are you representing the axes by a 3D model? – jcora Aug 2 '12 at 13:39
• I'm pretty sure that's not how you draw lines. – jcora Aug 2 '12 at 14:44
• Takumi, put the info you just wrote in your question. – Thraka Aug 2 '12 at 16:03

First of all pixel on the screen is a ray in your 3d world - all scene behind this pixel.

Second, what you must know, that any point in 3d converted into 2d motinor space via multiplying 3 matrices:

pointIn2DSpace = pointIn3DSpace * WorldMatrix * ViewMatrix * ProjectionMatrix


So you can do a back conversion, multiplying "monitor" point with inverted WVP matrix:

pointIn3DSpace = pointIn2DSpace * Invert(WorldMatrix * ViewMatrix * ProjectionMatrix)


Now you can calculate some 3D point behind the pixel to the "depth of monitor". Let x and y will be you coordinates, than you must convert point (x, y, 0) and (x, y, 1) into 3D-space and get some ray from them.

Having two point you can easily get a ray and calculate required position on this ray.

Last step is just find in XNA docs where to get this matrices and do some math. Good luck.

• Thanks for your response. But I don't understand your explanation about ray and position on the ray. I understand that a 3D point is converted in 2D screen point by doing World * View * Projection and doing the opposite will convert from 2D to 3D. I've tried to invert the WVP matrix and transform my 2D point, and set the 3D position to the matrix of my model. But it doesn't work. When I move my camera, my model moves but doesn't stay at the same position on the screen. I think i've missed something, probably what you try to explain about ray and "depth of monitor". – Julien Pires Aug 5 '12 at 18:47
• When you convert 2D point to 3D you will get a point on "monitor plane". If you want to place object "deeper" then you must move it in direction which is perpendicular to that "monitor" frame. Now about moving - since you change position of your camera you change VIEW matrix, so you must recalculate position of your fixed object. – Yarg Aug 6 '12 at 3:20

If you want this 3D-model to be in a specific point in relation to your moving camera then just update the position when you update the camera position. If you are using XNA then just do something like:

axesPos = camPos + camOri.Front * distZ + camOri.Left * distX+ camOri.Down * distY;