Zuzu-Typ / PyGLM

Fast OpenGL Mathematics (GLM) for Python
zlib License
214 stars 29 forks source link

How to use 'rotate' with quaternion #217

Open shorttrack789 opened 1 year ago

shorttrack789 commented 1 year ago
        m_model = glm.mat4()
        # translate
        m_model = glm.translate(m_model, self.transf.position.getvec3())
        # rotate
        m_model = glm.rotate(m_model, self.transf.rotation.z, glm.vec3(0, 0, 1))
        m_model = glm.rotate(m_model, self.transf.rotation.y, glm.vec3(0, 1, 0))
        m_model = glm.rotate(m_model, self.transf.rotation.x, glm.vec3(1, 0, 0))
        # scale
        m_model = glm.scale(m_model, (self.transf.scale.x, self.transf.scale.y, self.transf.scale.z))
        return m_model

How to use rotate method with quaternion?

Zuzu-Typ commented 1 year ago

Here's a page that might help you understand how to use Quaternions for rotation: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/

Basically, you create a quaternion from an axis and angle (e.g. using glm.angleAxis) and you apply the rotation by multiplying the quaternion and your point.

If you need further details, feel free to ask (:

shorttrack789 commented 1 year ago

Here's a page that might help you understand how to use Quaternions for rotation: http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/

Basically, you create a quaternion from an axis and angle (e.g. using glm.angleAxis) and you apply the rotation by multiplying the quaternion and your point.

If you need further details, feel free to ask (:

Isn’t there any ways not to use Euler angles?