Rotation and Transformation Matrices in Godot
Polysthetic
A brief explainer on how rotations work in Godot, using transformation and basis matrices. In my opinion this is a superior method to quaternions and obviously Euler rotations, and one of the reasons I like Godot.
ā±ļø Timestamps: 0:00 Intro 0:46 Linear algebra of transform and basis matrices 2:26 Global vs local coordinates 5:17 Movement of the origin 6:37 Rotation matrices 10:23 Moving in local coordinates - code that doesn't work 11:48 Moving in local coordinates - rudimentary code 13:04 Transforming vectors into local coordinates 15:37 Moving in local coordinates - good code 16:35 Conclusion
š» Addenda:
- North is actually (0, 0, -1), so -Z is considered forward locally and north globally. I'm not sure why this is the convention, but it could have to do with how cameras are pointed.
- Matrix multiplication is actually partially implemented. You can use Transform.Basis.Xform(movement) to simply multiply the vector by the basis. This is equivalent to Transform.basis.x * movement.x + Transform.basis.y * movement.y + Transform.basis.z * movement.z.
- When rotating objects, it's a good idea to orthonormalise their basis by using Transform.Basis.Orthonormalize(). This will correct for any floating point errors that would otherwise accumulate over time, and result in offsets in scaling and rotation.
š¶ Music tracks from:
- Dillan Witherow - Before Sunrise
- Provided by Lofi Girl
- Watch: https://www.youtube.com/watch?v=sDC_ssw-eWI
You can also visit me at: WEBSITE š https://polysthetic.com THREADLESS š¶ļø https://polysthetic.threadless.com DRIBBBLE š https://dribbble.com/polysthetic YOUTUBE š„ https://youtube.com/c/polysthetic AUDIOMACK š¼ https://audiomack.com/polysthetic ... https://www.youtube.com/watch?v=bS4aQGZ_oU4
82133917 Bytes