Skip to main content
gamedev.net
🔒 Locked

Coordinate Conversion

Started by turd7000 5 replies 1.1k views
Original Post
turd7000
turd7000
I would have searched for this, but I am unsure of the terminology. I want to convert distance from pixel coordinates to relative coordinates. Relative coordinates I define to be coordinates relative to a (0, 0, 0) point in 3D space(for example, the coordinates found in a VertexBuffer using CustomVertex.PositionColored vertices). Pixel coordinates would be relative to the upper left corner of a window. What I need to do is take a line in pixels, whose distance is easy to compute, and then convert the distance to relative coordinates. More visually, imagine a 3D world, which is viewed from the very top, so you only see one plane, the ground plane. You want to measure the distance between two points on the plane you see. You can draw a line on the screen in pixels, but how to do you convert that to the distance in relative coords, or, alternately, can you determine the bounds(up, down, left and right) in relative coordinates of your view?
Cowboy Coder
Cowboy Coder
You question is confusing. To calculate relative coordinates you subtract one point from another. But you say relative to 0,0,0? Are you trying to convert 2D to 3D.

Perhaps you should draw a diagram.
turd7000
turd7000
I first convert from the 3D virtual space where vertexbuffers exist by positioning the camera on the up(say y) axis. This way I see the x-z plane. Now I want to convert from pixel coordinates, where 0,0 is always in the top left corner of the window, to these virtual coordinates which change as the camera pans and zooms.

I imagine that since it's some sort of matrix multiplication which takes the virtual 3D coords and transforms them to 2D window coords, it would likely be something like the reverse operation.
Cowboy Coder
Cowboy Coder
Perhaps if you explained more what you were actually trying to do? What is this for?
Namethatnobodyelsetook
Namethatnobodyelsetook
The problem with the reverse is that you get a ray. A line in 3D space from the near plane to the far plane. Two objects in very different 3D positions can end up on the same 2D pixel, so the reverse is that a 2D pixel can be at many 3D points in space. Once you have a ray, you need to determine where it intersects your ground. That will provide you with 3D point you want.

Perhaps this thread will help you. It covers 3D to 2D and 2D to 3D ray conversion. (sorry it's linked to the wrong post in the thread)
turd7000
turd7000
Looks perfect, thanks a bunch!
turd7000
turd7000
Say that I force one my camera's coordinates to be constant, so I only see variability in two dimensions. Basically, I'm looking at a 2D plane. Is there any way to find the world coordinate boundaries of that 2D plane which I see with the camera?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.