首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >取消引用UnsafeMutablePointer<UnsafeMutableRawPointer>

取消引用UnsafeMutablePointer<UnsafeMutableRawPointer>
EN

Stack Overflow用户
提问于 2017-06-11 02:40:08
回答 0查看 347关注 0票数 2

我有一个正在传递数据的块,我想把它转换成一个浮点数组的数组--例如[0.1,0.2,0.3,1.0,0.3,0.4,0.5,1.0,0.5,0.6,0.7,1.0]。这些数据以data:UnsafeMutablePointer<UnsafeMutableRawPointer>的形式传递给我(内部数组是RGBA值)

fwiw --块参数来自SCNParticleEventBlock

如何将数据解引用到[Float]中?一旦我有了包含内部数组的数组,我就可以用以下命令引用内部数组(colorArray)数据:

代码语言:javascript
复制
let rgba: UnsafeMutablePointer<Float> = UnsafeMutablePointer(mutating: colorArray)
let count = 4
for i in 0..<count {
    print((rgba+i).pointee)
}

fwiw --这是苹果引用数据的示例Objective-C代码(from SCNParticleSystem handle(_:forProperties:handler:) )

代码语言:javascript
复制
[system handleEvent:SCNParticleEventBirth
      forProperties:@[SCNParticlePropertyColor]
          withBlock:^(void **data, size_t *dataStride, uint32_t *indices , NSInteger count) {
              for (NSInteger i = 0; i < count; ++i) {
                  float *color = (float *)((char *)data[0] + dataStride[0] * i);
                  if (rand() & 0x1) { // Switch the green and red color components.
                      color[0] = color[1];
                      color[1] = 0;
                  }
              }
          }];
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44476834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档