Using GLKMath from GLKit in Swift(在 Swift 中使用 GLKit 中的 GLKMath)
问题描述
所以我正在使用 Ray Wenderlich 的教程中的一本名为 iOS Games 的书,并尝试利用其中找到的一些 Objective-C 代码来使我的游戏中角色的加速度计控制工作.不过,我想使用 Swift 而不是 Objective-C.我在尝试创建表示 3D 矢量的 GLKVector3 类型的 var 时遇到了问题.当我输入时:
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)
我收到以下错误:
使用模块 GLKVector3 作为类型.
use of module GLKVector3 as type.
我的 Swift 文件顶部有一个用于 GLKit 的导入:
I have an import at the top of my swift file for GLKit:
import GLKit
任何想法如何从 GLKMath 文件中获取功能以在我的程序中使用?
Any ideas how I can get the functionality from the GLKMath files to use in my program?
推荐答案
Swift 在 1.2 版本中增加了联合支持.导入联合中的字段是只读的,即使使用 var
声明,但可以根据需要在 C 函数之间传递.
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.
Swift 1.2 的发行说明暗示这些字段可能根本无法访问,但至少对于 GLKit
类型它们仍然是可读的:
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 现在可以部分导入包含联合、位域、SIMD 向量类型和 Swift 本身不支持的其他 C 语言功能的 C 聚合.Swift 将无法访问不受支持的字段,但可以在 Swift 中使用具有这些类型的参数和返回值的 C 和 Objective-C API.这包括 Foundation NSDecimal
类型以及 GLKit GLKVector
和 GLKMatrix
类型等.
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 theGLKit GLKVector
andGLKMatrix
types, among others.
这篇关于在 Swift 中使用 GLKit 中的 GLKMath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Swift 中使用 GLKit 中的 GLKMath


基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01