Skip to main content
gamedev.net
🔒 Locked

getting transformation matrix

Started by ehmdjii 6 replies 1.3k views
Original Post
ehmdjii
ehmdjii
say i have a face (quad) in my 3d space, then its position + orientation can be defined through one 4x4 matrix, right? now how can i get this matrix if i know the coordinates of its vertices? thanks!
Zakwayda
Zakwayda
Quote:
say i have a face (quad) in my 3d space, then its position + orientation can be defined through one 4x4 matrix, right?
It could be defined through an infinite number of 4x4 matrices. So to give you a more useful answer, we need to know more - what you need the matrix for, what local space (if any) the quad vertices were originally defined in, etc. Is this for billboarding? Something else?

Anyway, give us a little more info and I'm sure someone will be able to answer your question.
ehmdjii
ehmdjii
thanks.

the thing is that i want to place a second face to exactly this position+orientation.
ehmdjii
ehmdjii
the face is part of a mesh and all information i have of it are the vertex positions in world space.
how can i generate a matrix out of that?

thanks!
Tybon
Tybon
If you know the winding order of the face then it should be possible. The center of the face would be the position. The normal of the face would be the look vector. The first 2 vertices in the winding order can be used as the up or right vector(which can be determined if you also have the texture coordinates of the vertices). Take the cross product obtain the last missing vector, then you should have the 4x4 matrix.
ehmdjii
ehmdjii
ok, thanks, this sounds like a good idea.
how do i get the matrix actually?

i think a general matrix would be:
r11 r21 r31 tx
r21 r22 r32 ty
r31 r23 r33 tz
0 0 0 1

the transformations should be easy to get, but how do i get r11-r33 from the face's normal?

Tybon
Tybon
The normal/look vector corresponds to r31, r32, r33.

You will need more information about the face to calculate the up(r21, r22, r23) and right(r11, r21, r31) vectors. If you know which vertex corresponds to which corner of quad, then it should be easy. For example, suppose vertex A is the top left corner and vertex B is the top right corner, the B-A will give you the right vector.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.