• Create Account

## Screen Point to Screen Edge

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1AussieBacom  Members

178
Like
0Likes
Like

Posted 22 April 2013 - 06:07 AM

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.

### #2Brother Bob  Moderators

10108
Like
1Likes
Like

Posted 22 April 2013 - 08:18 AM

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;


### #3AussieBacom  Members

178
Like
0Likes
Like

Posted 24 April 2013 - 07:35 PM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.