# Screen Point to Screen Edge

This topic is 1735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am having trouble getting a poiny X,Y to the edge of my screen. This point is from a reversed screenspace co-ordinate, I am using it to point someone in the correct direction.

Here is a diagram of what I am trying to do:

The co-ordinates of the 2D point work from the center of the screen to the point of the object.

##### Share on other sites

In normalized device coordinates, where the center of the screen is at (0,0) and the screen ranges from -1 to 1 in both directions, the problem is trivial; you normalize the point with the absolute of the coordinate with largest magnitude.

norm = max(abs(object_pos.x), abs(object_pos.y));
target_pos.x /= norm;
target_pos.y /= norm;


You can also easily transform between your screen space coordinates by scaling and translation. To go to normalized device coordinates, subtract the coordinate of the center of the screen from the point to project and divide the x and y coordinates by half the width and height of the screen, respectively. To to to screen space coordinates you do the reverse; multiply by half the size of the window, and add the center of the screen.

object_pos -= center of screen;
object_pos.x /= .5*width;
object_pos.y /= .5*height;

// do the projection above here

target_pos.x *= .5*width;
target_pos.y *= .5*height;
target_pos += center of screen;


##### Share on other sites

Only had to change the part for my depth duffer doing this when it was negative and not facing an object.

That worked well, thanks.