Jump to content
  • Advertisement
Sign in to follow this  
soconne

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

This topic is 4628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Do you already have a 4x4 matrix class with matrix and vector multiplication implemented? Or do you need a 'from scratch' solution?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!