In this beginning Metal video tutorial, you'll learn how to use matrices to translate, scale and rotate models.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3537-beginning-metal/lessons/7
In this beginning Metal video tutorial, you'll learn how to use matrices to translate, scale and rotate models.
hi,
In directx we have “simd friendly DirectXMath” for OpenGL es we have GLKIT maths.
is there any library for use with metal at this stage or do we have to wrap our own matrix functions for now.
thanks
@hsg - there is the SIMD library. matrix_float4x4
for example is a SIMD data type.
You can say for example:
let m = matrix_identity_float4x4
let n = m.inverse
let t = m.transpose
let d = m.determinant
let q = m * n
Etc.
MatrixMath.swift has an extension to matrix_float4x4
which has methods to set up the necessary matrices.
What exactly are you looking for?
hi, thanks for getting back to me so quickly, enjoying. course so far.
yes if have seen MatrixMath.swift (have written some algebra libs in the far distant past). However I really enjoyed relying on bundled algebra libraries such as dxMaths (directx) and glKit(OpenGL es). These had many tried and tested helper functions such as creating projection matrices and rotations around a arbitrary axis etc. I just remember in the past when I had to create my own I spent a huge amount of time debugging them…
so my question
simd - I have always treated this as a black box and never had to time to research, I have just relied on helper libs like dxMath to handle. - thanks I get this now ( you are using types taken from the simd lib)
is metalkit going, to get/does it have, a helper library for projection and all the various transform matrices - just like GLKit has. - MatrixMath.swift is one you have created? not bundled with metal Api.
thanks h
Where are you c++, all is forgiven!
@hsg - this answer took a bit longer - Australian z:zzz:.
You might want to investigate Accelerate - it goes beyond linear algebra. I’m afraid I do anything math-y the hard way so that I know what’s happening, but it’s very inefficient I know. As yet my math is lacking, so I can’t be of great help; but I’m working on it .
In 2014, Apple updated Accelerate, and there’s a video: WWDC14 - Videos - Apple Developer
2017: WWDC17 - Videos - Apple Developer
Jeff Biggus made some playgrounds, but you might need to update the Swift code to be able to run them: GitHub - hyperjeff/Accelerate-in-Swift: Swift example codes for the Accelerate.framework
I find it frustrating that there’s not more documentation and explanations, but I suppose if you know math already, then it’s not necessary.
You could use GLKit, I guess - I did when I started, but didn’t like the opacity. But be careful to realise that the Z axis in OpenGL is -1 to 1, whereas in Metal it’s 0 to 1. I work with perspective projection, which is why I haven’t noticed a great deal of clipping, but according to http://blog.athenstean.com/post/135771439196/from-opengl-to-metal-the-projection-matrix if you work with orthogonal projection it makes a difference.
#awesome
many thanks, didn’t know about accelerate.
fingers crossed for additional support funcs in MetalKit in future.
Thanks for pointing out the problem with using glKit, after further investigation looks like ndc in metal is the same as directx (0 to 1), the projection matrices in apple sample code match the projection matrices defined in DirectX documentation. (looks like Vulcan has gone the same way).
Thanks again for the save…had forgotten about this !!
hello Caroline,
thanks for the awesome course!
I need to inverse a matrix_float4x4 but I get this compile error: value of type ‘matrix_float4x4’ has no member ‘inverse’
am I missing something?
thanks!!
@luizelias - I’m glad you’re enjoying the course
Try something like:
let matrix = matrix_identity_float4x4
let inverse = matrix.inverse
Btw, you can now call it just float4x4
and not matrix_float4x4
. They are both type aliases of simd_float4x4
This video course is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]