简体   繁体   中英

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?

如果要围绕点P = {x, y, z}旋转,则可以简单地按-P平移,围绕原点旋转,然后按P向后平移。

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM