How to apply a position, scale and quaternion to a vertex ??

Started by
3 comments, last by soconne 18 years, 6 months ago
I have a position, scale and quaternion. How do I apply this transformation to a single vertex? For instance: float pos[3]; float scale[3]; float quaternion[4]; I've tried searching the forums but everyone only talks about appyling a quaternion, not the position and scale as well. Arent' they needed too?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
Do you already have a 4x4 matrix class with matrix and vector multiplication implemented? Or do you need a 'from scratch' solution?
Yes, I already have matrix transformations implemented. But I would like to know how to transform vectors by quaternions from scratch, or is it easier to transform them to matrices?
Author Freeworld3Dhttp://www.freeworld3d.org
Quote:Yes, I already have matrix transformations implemented. But I would like to know how to transform vectors by quaternions from scratch, or is it easier to transform them to matrices?
You can do it from scratch, but for multiple transformations the matrix form is probably more convenient and efficient.

Here's the from-scratch solution. This assumes standard quaternion multiplication order (you'll have to switch things around if you're using 'reverse' order).

The transformations you mention are usually performed in the order scale->rotate->translate. To scale the vector, simply multiply each component by the corresponding scale factor.

The next step is to rotate the vector by the quaternion. The equation for this is v' = q*quat(v)*conj(q). conj() returns the conjugate of a quaternion (all components but w negated), and quat() returns a quaternion with the same xyz components as the input vector and a w of 0 (typically). v' is also a quaternion; its xyz components are the rotated vector. Finally, translation is a simple vector addition.

For the matrix form, you would construct matrices S, R and T that represent the scaling, rotation, and translation, respectively. S and T are straightfoward; for R you need a quat-to-matrix function (if you get one from a reference, make sure the conventions match). The matrices are then multiplied together as T*R*S (column vectors) or S*R*T (row vectors). You can also exploit the many trivial operations in the matrix mults to create the final matrix more efficiently.
Awsome, thanks alot.
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement