1

I already read some articles and even questions in stack overflow. I didn't found what I wanted. I may didn't looked carefully so point me to correct articles/questions if you know any.

Any way, what I want to do is clear. I know camera's position (x',y',z') and I have camera rotation matrix (Matrix3). I also have camera aspect ratio (W/H) and output size (W,H). My POINT is at (x,y,z) and I want a code or (an algorithm so I can write the code) to calculate its position at screen (screen's size is same as camera output's size) as (x'',y'').

Do you know any useful article? I is important for article or algorithm to support camera's rotation matrix.

Thank you all.

Soroush Falahati
  • 2,196
  • 1
  • 27
  • 38

3 Answers3

2

well you need to specify the projection type (ortogonal,perspective... ?) first

  1. transform any point (x,y,z) to camera space

    substract the camera position then apply inverse of camera direction (coordinate system) matrix. Z axis of camera is usually the viewing direction. If you use 4x4 homogenous matrix then the substraction is already in it so do not do it twice!

  2. apply projection

    Orthogonal projection is just scale matrix. Perspective projections are more complex so google for them. This is where aspect ratio is applied and also FOV (field of view) view angles.

  3. clip to screen and Z-buffer space

    now you have x,y,z in projected camera space. To actually obtain screen coordinates with perspective you have to divide by z or w coordinate (depends on math and projection used) so for your 3x3 matrices

        xscr=x/z;
        yscr=y/z;
    

    that is why z-near for projections must be > 0! (otherwise could cause division by zero)

  4. render or process pixel (x,y)

For more info see: Mathematically compute a simple graphics pipeline

[Notes]

If you look at OpenGL tutorials/references or any 3D vector math for rendering you will find tons of stuff. Google homogenous transform matrices or homogenous coordinates.

Spektre
  • 49,595
  • 11
  • 110
  • 380
1

I'm not entirely sure of what it is that you are trying to achieve, however I'm thinking that you are attempting to make the surface of one plane (a screen) line up to be a relative size to another plane. To calculate this ratio you should look into Gaussian Surfaces. And a lot of trig. Hope this helps.

cranberry
  • 294
  • 5
  • 17
0

I do not think you have enough information to perform the calculation!

You can think of your camera as a pinhole camera. It consists of an image plane, and a point through which all light striking the image plane comes. Usually, the image plane is rectangular, and the point through which all incoming light comes is on the normal of the image plane starting from the center of the image plane.

With these restrictions you need the following: - center position of the camera - two vectors (perpendicular to each other) defining the size and attitude of the image plane - distance of the point from the camera plane (this could be called the focal distance, even though it strictly speaking is not the same thing)

(There are really several ways to express these quantities, such as , , .)

If you only have the position and size of the image plane in pixels and camera rotation, you are missing the scale factor. In real world this is equivalent to knowing where you hold a camera and where you point it at, but not knowing the focal length (zoom setting).

There is a lot of literature available, this one popped up first with a search:

http://www.cse.psu.edu/~rcollins/CSE486/lecture12_6pp.pdf

Maybe that helps you to find the correct search terms.

DrV
  • 22,637
  • 7
  • 60
  • 72