# I want to convert world coordinates into camera coordinates

In world space, I have an axis (eg. [-1, 0, 0]) and a point (eg.[2,5,1]). I also have a 4x4 viewmatrix. Now I want to transform that axis and point in camera frame.

I am getting really confused. Does anyone have any idea how should I do this?

I am kinda new to computer vision and all this transformation thing confuses me a bit. From one of the comments, my current train of thought is -

1. Add 1 as fourth component in both axis and point.
2. Multiply these 4D vectors by view matrix. (viewMatrix * vec4)
3. Divide the resultig vectors by fourth component.

Is this process correct?

• Does this answer your question? The view matrix finally explained Commented Aug 18, 2023 at 20:20
• @Theraot I am not sure. Just to confirm, should I add a 1 in both of them? Like in above example, axis becomes [-1, 0, 0, 1] and point becomes [2, 5, 1, 1] and then multiply these with view matrix. Finally, just divide the results by 4th component and ignore the 1? Commented Aug 18, 2023 at 20:35

This is how you decide:

• You add 1 if your vector represents a position, and thus should be translated (which is the case of the point).
• You add 0 for common vectors (which makes sense for the axis, or any direction vector).

Adding 1 is the most common case, because the bulk of data that we need to transform are vertex positions.

The idea behind this is that the fourth component of the vector will be multiplied with the part of the transformation matrix that encodes a translation. And thus using a 0 in the fourth component will nullify the translation.

It might be easier to imagine if you consider a transformation that only has translation. For example, let us say the transformation moves 1 unit along the x axis. And you have your axis vector (-1, 0, 0), after the transformation should it be (0, 0, 0) (moved 1 unit on the x axis) or (-1, 0, 0) (unaffected by translation)? Well, the axis continues to be the same axis, so it is the latter, thus when transforming the latter you augment it with a 0. Of course, it still makes sense to have it affected by mirroring, rotation, shearing, and scaling.

Since there might be scaling, another related decision is if you will normalize the vector after the translation. For example, a direction (such as a surface normal) should be a unit vector, so you will normalize it after you translate it. But for other vectors - despite not representing position - their length is important. For example, if you transformed a velocity vector, it does not make sense to normalize it after the transformation (in this case the scaling could be considered a change in length units).

And thus, you shouldn't have to deal with the case of dividing by 0 from the fourth component.