The problem
I'm using a 3D extension of the well-known "Turtle graphics" to draw plants. My system works by maintaining a position $\vec{p}$ and three vectors:
- The heading $\vec{H}$
- The "up" direction $\vec{U}$
- The "left" direction $\vec{L}$
My problem is now that I want to be able to create 3D objects at the position of the turtle, but with the added difficulty of being "transformed" into the turtle's coordinate system defined by the vectors $\vec{H}, \vec{U}$ and $\vec{L}$, so that the model is "aligned" with the direction and orientation of the turtle. I basically want to achieve that the model is transformed in such a way, that:
- The local origin becomes the turtle position
- The local x-Axis is rotated onto the heading vector $\vec{H}$
- The local y-Axis is rotated onto the right vector $- \vec{L}$
- The local z-Axis is rotated onto the up vector $\vec{U}$
The reason I want this is to be able to spawn 3D models that describe the leaves of a plant on stalks generated by the turtle.
My own idea so far
I'm not very good at linear algebra, but I thought of using a base change matrix of the form: $$A := \begin{pmatrix}\vec{H} & -\vec{L} & \vec{U} \end{pmatrix}$$ And combining that with the translation by $\vec{p}$ to obtain the following model matrix:
$$T := \begin{pmatrix} A & \begin{matrix} p_1 \\ p_2 \\ p_3\end{matrix}\\ \begin{matrix}0 & 0& 0\end{matrix} & 1 \end{pmatrix}$$
Would this achieve the effect I want? I am currently only in the planning phase of the project this will be used in, so I can't check this myself.