简体   繁体   中英

how can I rotate an object around a point other than the origin point with glm::rotate?

I am trying to make my world rotate around my camera no matter where my camera is. I am not doing any crazy math yet, I am leaving middle school this year and I don't know what quaternions are. My problem is that every time I use glm::rotate function for anything it only allows me to rotate around an axis at the origin point and I can't find a way to fix this. if there is any somewhat simple answer to this problem I am having please let me know how I can rotate my world around any given point. thanks

glm::mat4 look(1.0f);
float Rrotation;
Rrotation = 20.0f;
glm::vec3 the_axis_not_orientation(0.0f, 1.0f, 0.0f);

look = glm::rotate(look, Rrotation, the_axis_not_orientation);

What you actually do is to rotate the model:

model_view = look * rotate

If you want to rotate the view, then you have to swap the order of the matrices. Note, the matrix multiplication is not Commutative :

model_view = rotate * look

For your code that menas:

glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Rrotation, the_axis_not_orientation)
look = rotate * look; 

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