简体   繁体   中英

Setting a 4x4 Rotation Matrix using Degrees

I would like to ask what the steps are to setting a 4x4 Rotation Matrix using degrees for all separate X, Y, Z axis.

Illustrations would be much appreciated, thanks!

(C++ implementation preferred)

Assuming a C++ program, if you want a header-only library that will do this for you, you can use the amazing glm:

http://glm.g-truc.net/0.9.6/index.html

And use glm::rotate as such:

glm::mat4 Projection = glm::perspective(glm::radians(45.0f), 4.0f / 3.0f, 0.1f, 100.f);
glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
glm::mat4 View = glm::rotate(ViewRotateX, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
glm::mat4 MVP = Projection * View * Model;

You can find the implementation on Github if you are interested in writing your own: matrix_transform.inl

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