2013-03-26 56 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