Given the plane vector [n] at a given point [p], and you have an object model at the absolute origin, and you want to render the object at point [p] aligned with the plane, then you must find the following transformation:
- T1 = rotate the absolute x-z plane around the absolute y-axis by the [n]-angle in the plane through absolute z-axis (i.e. angle of [n] to the projection of [n] to the absolute x-y plane = acos()).
- T2 = rotate the absolute x-y plane around the absolute z-axis by the [n]-angle in the absolute x-y plane (i.e. the angle in the absolute x-y plane from the [n] projection above to the absolute x-axis).
- T3 = translate to point [p]
This transformation sequence transforms your object to the plane's point [p] and its aligned axes.
Once you found these transformation T
1, T
2, T
3, you multiply the transformed T
x as follows:
T = (T
1T x T
2T x T
3T)
T
(M
T is the
transposed matrix of M, i.e. mirrored at the diagonal top-left to bottom-right)
With that T transformation matrix, you multiply each object's point and so get the object rendered at the desired location.
E.g. v
plane = T x v
origin
Given
[n] = [n
x, n
y, n
z, 1]
T
[p] = [p
x, p
y, p
z, 1]
T
q = sqrt(n
x2 + n
y2)
r = sqrt(n
x2 + n
y2 + n
z2)
T
1 =
nz/r, | 0, | q/r, | 0 |
0, | 1, | 0, | 0 |
-q/r, | 0, | nz/r, | 0 |
0, | 0, | 0, | 1 |
T
2 =
nx/q, | -nyq, | 0, | 0 |
ny/q, | nx/q, | 0, | 0 |
0, | 0, | 1, | 0 |
0, | 0, | 0, | 1 |
T
3 =
1, | 0, | 0, | px |
0, | 1, | 0, | py |
0, | 0, | 1, | pz |
0, | 0, | 0, | 1 |
I leave the calculation of the T-matrix as exercise ;-)
Cheers
Andi