user3841382
user3841382

Reputation:

3D rotation in OpenGL

So I'm trying to do some rotation operations on an image in openGL based on quaternion information, and I'm wondering, is there a way to define the location of my image by a vector (let's say (001)), and then apply the quaternion to that vector to rotate my image around an arbitrary origin? I've been using GLM for all the math work. (Using C++)

Or is there a better way to do this that I haven't figured out yet?

Upvotes: 1

Views: 778

Answers (2)

kbirk
kbirk

Reputation: 4022

The order in which the transforms should be applied are:

scale -> translation to point of rotation -> rotation -> translation

So your final matrix should be computed:

glm::mat4 finalTransform = translationMat * rotationMat * translationToPointOfRotationMat * scaleMat;

Upvotes: 0

ratchet freak
ratchet freak

Reputation: 48216

If you want to rotate around a point P = {x, y, z} then you can simply translate by -P, rotate around the origin and then translate back by P.

Upvotes: 1

Related Questions