This is a follow-up to my earlier question:

Game Editor - When screen is clicked, how do you identify which object that is clicked?

Something I've noticed is that picking only calculates a ray and checks for the closest objects that intersects it, but since this method isn't working for placing object in a 3D World what are the best way of doing that? A ray is just a line that goes from one point in a certain direction, it checks the first object that intersects it that is closest. But not if you don't have any objects.

I've used one method for calculating a position with an Isometric Camera, but currently I have an arc ball camera and it doesn't produce the same results. Is there a general way that actually produces a good coordinate?

This is currently the method I'm trying to understand, but I've found no tutorials/information on how to actually translate numbers between 0 and 1 to real coordinates on the screen.

3D Arc Ball Camera with this method:

public static Vector3 GetScreenCoordinates(MouseState Mouse, Viewport viewport, Matrix Projection, Matrix View, Matrix World)
    Vector3 pos1 = viewport.Unproject(new Vector3(Mouse.X, Mouse.Y, 0), Projection, View, World);
    Vector3 pos2 = viewport.Unproject(new Vector3(Mouse.X, Mouse.Y, 1), Projection, View, World);
    Vector3 dir = Vector3.Normalize(pos2 - pos1);

    return dir;
  • \$\begingroup\$ Do you mean that you're in an empty 3D world and you're trying to place an object with screen clicks? \$\endgroup\$
    – Polar
    Mar 18, 2013 at 18:05
  • 1
    \$\begingroup\$ Your question depends on what coordinate system you want these coordinates in: Device Coordinates (all pixels on the monitor), Application/Screen Coordinates (all pixels in the application window, ie. Mouse.X/Mouse.Y), View Coordinates (3d from the viewer's location), or World Coordinates. \$\endgroup\$ Mar 18, 2013 at 18:08
  • 1
    \$\begingroup\$ Also, the comment on your original thread:(gamedev.stackexchange.com/a/31341/18568) gives some good links for understanding the sequence of transformations between coordinate systems. First, figure out what system you want them in, then take Mouse.X and Mouse.Y and apply the correct transformations. \$\endgroup\$ Mar 18, 2013 at 18:14
  • \$\begingroup\$ @ShotgunNinja There is the slight issue that with just an x and a y value (mouse position), with no reference points, you can't obtain a 3D location. \$\endgroup\$
    – Polar
    Mar 18, 2013 at 19:41

1 Answer 1


Use a plane or three planes to check collision against them.

If the world is empty you need to collide with something... one easy solution is setting a reference plane... usually the ground... and check ray collision against the plane to get coordinates in world space...

when you work with objects in an editor, the easier is working in world coordinates... and being independent of screen coordinates...

Here is a video of the editor i'm doing now... where you can see how it is done...

  • \$\begingroup\$ Why is a ray-cast insufficient? \$\endgroup\$
    – Anko
    Mar 19, 2013 at 8:08
  • \$\begingroup\$ if you want to place objects in an empty world you need a plane reference to let the ray collide with something... and get coordinates in world space... that is the most interesting... \$\endgroup\$
    – Blau
    Mar 19, 2013 at 9:19
  • \$\begingroup\$ But creating a plane at Y: 0 is not very effective if you wish to have a more dynamic editor. I've used your example earlier to calculate the location, but to dynamically set the plane to whatever fits the camera. Say I rotate the camera so it's 90 degrees from the ground, meaning that the ground is below the camera but not seen by the matrices; why would I still get an Y: 0 in when I click about say 50 pixels above from Y or something. To somehow dynamically place this plane depending on the camera location. \$\endgroup\$
    – Deukalion
    Mar 19, 2013 at 12:44
  • \$\begingroup\$ you can combine collision against a plane or three planes and against the current 3d models like I show in the video... I only let to rotate the camera around Up vector... and it's enough to edit/model my isometric world... \$\endgroup\$
    – Blau
    Mar 19, 2013 at 16:51
  • \$\begingroup\$ Only problem with your method is that I can't get a good value on Y -Axis, because everything in the scene shouldn't be at 0 without any height. And it isn't an isometric camera. This works, but won't give me the height: pastebin.com/Z6nR2H5H \$\endgroup\$
    – Deukalion
    Mar 20, 2013 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .