vector and matrix operations in swift

I plan to implement a graphics app, which I built and works in mathematica.

Graphics is extremely slow in mathematica, and the interactive part is bad.

I have programmed a lot (~500k lines) in mathematica,

but I am new to swift and metal.


The app is structurally like a Rubik cube.

The user swipes or taps, pieces built of many rectangles rotate, there is a screeching sound.


Is there a library for vector and matrix operations for swift? For metal?

(dot product, matrix times vector, matrix times matrix, transpose, determinant, etc?)


If I had to build it all myself, what would be the best way to do it? classes?


For something similar to a Rubik cube, the controller has to figure out, when the user swipes, over which cubelet he started, the move direction, etc.

Is that all computed in the swift controller part, as opposed to the metal or openGL part?

Replies

You can use the Accelerator framework. It provides C based functions for vector and matrix operations, and those functions are accessible through Swift.


You should also be able to schedule computations using Metal through Swift, but I haven't done so and I believe you would need to provide code to the GPU in a C++ variant.

Apart from the Accelerate framework, SIMD, etc.: There are some Swift projects/libs for vector and matrix math on Github, haven't tested them and I don't know if any of them fits your requirements.

If you want to write your own code and you get stuck on how to implement generic vector value types and so on, you might find this thread interesting.

You can use Metal or OpenGL for the drawing, but on both Mac and iOS there is also a high-level framework for 3D graphics called Scene Kit that allows you to place 3D objects and cameras in space and just leave the drawing to the framework:


developer.apple.com/library/mac/documentation/SceneKit/Reference/SceneKit_Framework/

I'm maintaining a Swift framework that makes it easier to operate on vectors and matrices using Accelerate, git it a try: https://github.com/aleph7/Upsurge