因此,我正在使用一本名为iOS Games的书,来自Ray Wenderlich的教程,并尝试利用那里发现的一些Objective-C代码,使加速度计控制我游戏中的角色.而不是Objective-C,我想使用Swift.我在尝试创建一个GLKVector3类型的var时遇到了一个问题,它代表了一个3D矢量.当我输入时:
var raw:GLKVector3 = GLKVector3Make(irrelevant stuff)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
使用模块GLKVector3作为类型.
我在我的swift文件顶部有一个导入GLKit:
import GLKit
Run Code Online (Sandbox Code Playgroud)
任何想法如何从我的程序中使用GLKMath文件获取功能?
所以我正在写一个低通加速度计功能来缓和加速度计的抖动.我有一个CGFloat数组来表示数据,我想用这个函数来阻止它:
// Damps the gittery motion with a lowpass filter.
func lowPass(vector:[CGFloat]) -> [CGFloat]
{
let blend:CGFloat = 0.2
// Smoothens out the data input.
vector[0] = vector[0] * blend + lastVector[0] * (1 - blend)
vector[1] = vector[1] * blend + lastVector[1] * (1 - blend)
vector[2] = vector[2] * blend + lastVector[2] * (1 - blend)
// Sets the last vector to be the current one.
lastVector = vector
// Returns the lowpass vector.
return vector
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,lastVector在我的程序顶部定义如下: …