2

I would like to move a 3D plane in a 3D space, and have the movement match the screens pixels so I can snap the plane to the edges of the screen.

I have played around with the focal length, camera position and camera scale, and I have managed to get a plane to match the screen pixels in terms of size, however when moving the plane things are not correct anymore.

So basically my current status is that I feed the plane size with values assuming that I am working with standard 2D graphics. So if I set the plane size to 128x128, it more or less is viewed as a 2D sqaure with that exact size.

I am not using and will not use Orthographic view, I am using and will be using Projection view because my application needs some perspective to it.

How can this be calculated?

Does anyone have any links to resources that I can read?

xaid
  • 740
  • 6
  • 18
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – David Heffernan Aug 20 '14 at 11:40

1 Answers1

2

you need to grab the transformation matrices you use in the vertex shader and apply them to the point/some points that represents the plane

that will result in a set of points in -1,-1 to 1,1 (after dividing by w) which you will need to map to the viewport

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • Thanks. What exactly do you mean by "map to the viewport"? Could you elaborate? – xaid Aug 20 '14 at 08:27
  • for example if your viewport is 1500x2000 and you need to map a point to it you do `(x+1)*1500/2` and `(y+1)*2000/2` but you technically don't need it if you wish to limit the plane to the visible screen – ratchet freak Aug 20 '14 at 08:33
  • alright. but X and Y are the coordinates of where I wish to place my object in 2D right? (if that makes sense) – xaid Aug 20 '14 at 09:00
  • by the way I don't think you've understood my question properly. I don't wish to map a point to 2D, I wish to move an object in pixel units instead of 3D units. – xaid Aug 20 '14 at 09:01