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

查看:17
本文介绍了在 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 GLKVectorGLKMatrix 类型等.

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天全站免登陆