5
\$\begingroup\$

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.

The 3 axis looks like that.

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.

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

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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". \$\endgroup\$ – Julien Pires Aug 5 '12 at 18:47
  • \$\begingroup\$ 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. \$\endgroup\$ – Yarg Aug 6 '12 at 3:20
0
\$\begingroup\$

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;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.