The source code is the tutorial "Metal N-Body" in Documentation API Reference.
for my tutorial I prefer rewrite it in Swift.
in particular is "MetalNBodyTransform" files.
simd::float4x4* mpTransform;
- (BOOL) _acquire:(nullable id<MTLDevice>)device
{
if(device)
{
/
_buffer = [device newBufferWithLength:_size options:0];
if(!_buffer)
{
NSLog(@">> ERROR: Failed to instantiate a buffer for transformation matrix!");
return NO;
} /
/
mpTransform = static_cast<simd::float4x4 *>([_buffer contents]);
if(!mpTransform)
{
NSLog(@">> ERROR: Failed to acquire a host pointer to the transformation matrix buffer!");
return NO;
} /
return YES;
} /
else
{
NSLog(@">> ERROR: Metal device is nil!");
} /
return NO;
} // _acquire
For moment i have set :
mpTransform = float4x4(0.0)
_buffer pass only the lenght not have value in func _acquire.
func resise and fun setUpdate set the value in mpTransform.