2013-03-26 65 views
0

我想弄明白GLKQuaternions的一个奇怪的问题。当试图打印出四元数的信息时,每次w = 0的值。尽管在调试器领域,它清楚地表明-4.37114e-08被存储在这个值中。我不知道为什么。我打印的声明说:GLKQuaternion没有正确访问w变量

NSLog(@"\n\nSLERP: Animation.Current:x:%f,y:%f,z:%f,w:%f and Animation.End:x:%f,y:%f,z:%f,w:%f", animation.Current.x, animation.Current.y, animation.Current.z, animation.Current.w, animation.End.x, animation.End.y, animation.End.z, animation.End.w); 

我的结构是

typedef struct{ 
    GLKQuaternion Start; //starting orientation 
    GLKQuaternion End; //ending orientation 
    GLKQuaternion Current; //current interpolated orientation 
    float Elapsed; //time span in seconds for a slerp fraction between 0 and 1 
    float Duration; //time span in seconds for a slerp fraction between 0 and 1 
}Animation; //enables smooth 3D transitions 

调试器显示以下内容:

enter image description here

注意animation.End.w = -4.37114e-08同时在调试器中声明它= 0。我在打印声明后立即设置了断点。有谁知道这会导致什么?我认为这是干扰我有关w的变量的计算。

回答

2

%f将值仅输出到小数点后6位。

举一个例子,用%.9f输出到9个小数位。显然,-4.37114 * 10^-08将需要6位以上的小数位,所以你需要改变你的NSLog格式。

+0

Woooow。好的,我甚至没有想过这个。奇怪的是,自我C天以来,我还没有遇到过这个问题。我用[NSDecimalNumber numberWithFloat:animation.End.w]修复了它。不幸的是,我在代码中仍然存在一个问题,我需要调试:(。 – TheCodingArt 2013-03-26 02:40:46

+0

@TheGamingArt:这也是我过去错过的一个问题。这是一个很常见的问题,因为人们总是忘记了。 – 2013-03-26 04:18:50