在Swift中使用GLKit中的GLKMath [英] Using GLKMath from GLKit in Swift

查看:86
本文介绍了在Swift中使用GLKit中的GLKMath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用Ray Wenderlich的教程,使用一本名为iOS Games的书,并尝试利用在那里发现的一些Objective-C代码来使我的游戏作品中的角色的加速计控制成为可能。不过,我想用Swift来代替Objective-C。当我尝试创建一个代表3D矢量的GLKVector3类型的变量时遇到了一个问题。当我输入:

  var raw:GLKVector3 = GLKVector3Make(不相关的东西)



我得到以下错误:

使用模块GLKVector3作为类型。



我在GLKit的swift文件顶部有一个导入:

  import GLKit 

任何想法如何从GLKMath文件中获得用于我的程序的功能? p>

解决方案

Swift在1.2版本中增加了union支持。即使使用 var 声明,导入的联合中的字段也是只读的,但可以根据需要传入和传出C函数。



Swift 1.2的发行说明意味着这些字段可能根本不可访问,但至少对于 GLKit 类型,它们仍可读:


Swift现在可以部分导入包含联合,位域,SIMD向量类型以及Swift中本机不支持的其他C语言功能的C聚合。不支持的字段将无法从Swift访问,但具有参数和这些类型的返回值的C和Objective-C API可以在Swift中使用。这包括Foundation NSDecimal 类型和 GLKit GLKVector GLKMatrix 类型等。



So I'm using a book called iOS Games by tutorials from Ray Wenderlich and trying to utilize some of the objective-C code found there to make the accelerometer control of a character in my game work. Instead of Objective-C though, I want to use Swift. I ran into an issue when trying to create a var of type GLKVector3, which represents a 3D vector. When I type in:

var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)

I get the following error:

use of module GLKVector3 as type.

I have an import at the top of my swift file for GLKit:

import GLKit

Any ideas how I can get the functionality from the GLKMath files to use in my program?

解决方案

Swift has added union support in version 1.2. The fields in imported unions are read-only, even if declared with var, but can be passed to and from C functions as necessary.

The release notes for Swift 1.2 imply that the fields may not be accessible at all, but they are still readable for at least the GLKit types:

Swift can now partially import C aggregates containing unions, bitfields, SIMD vector types, and other C language features that are not natively supported in Swift. The unsupported fields will not be accessible from Swift, but C and Objective-C APIs that have arguments and return values of these types can be used in Swift. This includes the Foundation NSDecimal type and the GLKit GLKVector and GLKMatrix types, among others.

这篇关于在Swift中使用GLKit中的GLKMath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆