Hello. This plot continuation of the question , the language is also not fundamental.

There is a plane - the projection of the world ("camera"), given by the point PP:{x,y,z} and the normal PV:{x,y,z} . Absolute random.

All points (array) are also P[N]:{x,y,z} . Points obviously belong to the plane.

Situation: the world is ready, projected onto the camera and awaiting display. It is only necessary to tear 2D coordinates from the camera relative to PP.

The essence of the question: how to rotate the plane (ie, array) so that PP coincides with {0,0,0} , and the plane itself with OXY ? I can drag the plane myself, the quest - turn it.

My thoughts:

  1. on turning matrices (does not the commutation of turning turn the whole raspberry off me?)
  2. somehow based on the vector P [N] -PP (a thought beats into the head, but is not formed)
  3. I am sure that there is a simple solution)
  4. I'm obviously stupid somewhere =) Although there is a suspicion that this is another global problem of engines.

If the task (pull coordinates) is easier solved in another way, I will not get upset)

PS: I beg you, as few matrices as possible

    1 answer 1

    In the general case, the camera lacks the third vector, since there is an infinite set of vectors orthogonal to PV. Therefore, a third PU vector is needed - usually pointing upwards relative to the camera.

    The rotation of the world relative to the camera (camera type) is defined (in the right-side coordinate system, row vectors) as:

     l = PV; r = PU xl; // подразумевается векторное умножение u = PU; // так называемая LookAt матрица ( rx, ux, lx, 0 ) ( ry, uy, ly, 0 ) v_view = v * ( rz, uz, lz, 0 ) ( -dot(r, PP), -dot(u, PP), -dot(l, PP), 1 ) 

    where vector v is the initial position of a point in the world, v_view is the position of a point as viewed from camera. It is understood that the PV and PU vectors have a length of 1.

    Linear transformations (although in this case affine) are most conveniently described by the matrix, since This representation always exists for any such transformation, and it is convenient to work with them.

    UPD: Answer the comment about the application of matrices to vectors.

    This topic is included in the course of linear algebra, but you can read about it separately: Matrix multiplication .

    A vector in 3D is usually (but not always) a 1x4 matrix-row of the form (X, Y, Z, 1) . The fourth component component is necessary for the uniformity of coordinates; this allows multiplying by a matrix to shift the vector by some other.

    Consider an example: let there be a vector h = (hx, hy, hz) . Then, after multiplying by the above matrix A result of the transformation will be:

     h_view = h * A = (h_view_x, h_view_y, h_view_z, 1) // четвёртая компонента в данном случае не важна // и после умножения остаётся равной 1 h_view_x = hx * rx + hy * ry + hz * rz - dot(r, PP) // новый X h_view_y = hx * ux + hy * uy + hz * rz - dot(u, PP) // новый Y h_view_z = hx * lx + hy * ly + hz * lz - dot(l, PP) // новый Z 
    • Hmm, the fact is that all points on the camera plane have already been transferred, i.e. the position of the point on the screen is known, the problem is that the screen itself is rotated) MB I went in a non-standard way, but still ... Roughly speaking, the plane {PP, PV} should be turned into the origin, so that all points have z = 0 Not by projecting, naturally - Sh4dow
    • There is some misunderstanding: 1. The plane (PP, PV) is nonsense, if you imagine it; 2. Rotate the screen? 3. The transformation of a plane into a coordinate origin (which plane?) Is meaningless, since this is the projection of all points to the point (0, 0, 0). If all points of the plane z = 0, then this is just the XY plane. - AlexeyM
    • 1. You can rotate the points last, already on the plane, the result will be the same. While for simplicity, this angle is lowered. While the position is changing, turn around OY and tilt back and forth. From turning around the normal, only the rotation of the final image will change. 2. Apparently, yes) I do not “look” with the camera (point), but with the plane. 3. I apologize not to turn the plane into {0,0,0}, but put it on OXY so that PP is in {0,0,0} and the normal coincides with OZ. Actually, this is my only question, then I can handle it) - Sh4dow
    • All this (and even more - rotation relative to the vector "forward" for the camera) is performed by the above matrix. - AlexeyM
    • Ok, how to get 2D coordinates of all points on a plane with it? For example, PP {0, 10, 10}, PV {0, -10, -10} (look at the origin). Cosines I will pull out. The point {0, 20, 0} should appear in {0, 10 * (2 / sqrt (2))} like. - Sh4dow