I am converting some Objective-C code to Swift code and I have the following problem:
The objective-C code is
SCNNode *textNode = [SCNNode nodeWithGeometry:text];
textNode.transform = CATransform3DInvert(self.chartNode.worldTransform);
This is the converted code I tried:
let textNode = SCNNode(geometry: text)
textNode.transform = CATransform3DInvert(self.chartNode.worldTransform)
However, I get an error: 'SCNMatrix4 is not convertible to CATransform3D'
I realised CATransform3DInvert takes a parameter of type CATransform3D, while the parameter I have included is of type SCNMatrix4.
I tried the following cast attempt:
textNode.transform = CATransform3DInvert(CATransform3D(self.chartNode.worldTransform))
but this does not work.
I then found that both CATransform3D and SCNMatrix4 are both structs and I am unsure about how to convert from one struct to the other (or even if it is possible to convert between structs in Swift?)
Maybe there is another simpler approach?
Any help would be appreciated - Thank you.
Ok,
The link provided by Airspeed Velocity has a nice explanation which is easy to convert to Swift (in fact it's the same).
The CATransform3D etc is Mac OS X based and is not for iOS - instead, on iOS SCNMatrix4 etc is used. In the linked post - the header file you can find the types used is SceneKitTypes.h - if you want to look a copy is on github here: https://github.com/andymatuschak/Khan-Academy-Offer-Acceptance-Toy/blob/master/§/SceneKitTypes.h
I used SCNMatrix4Invert as rintaro mentioned above and it works.
So, the Swift code which works is now:
let textNode = SCNNode(geometry: text)
textNode.transform = SCNMatrix4Invert(self.chartNode.worldTransform)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With