uint index = ...// const float *bufferPtr = ...// uint stride = ...// uint vertexCount = ...for (uint i = 0; i < vertexCount; i++) {
float xVal = *bufferPtr++;
float yVal = *bufferPtr++;
float zVal = *bufferPtr++;
bufferPtr += stride;
if (i == index) {
qDebug() << "Vertex coord: " << xVal << " , " << yVal << " , " << zVal;
}}我嘗試用索引直接訪問替換for循環(及其中的條件):float xVal = *(bufferPtr + index * stride + 0);float yVal = *(bufferPtr + index * stride + 1);float zVal = *(bufferPtr + index * stride + 2);qDebug() << "Vertex coord without loop: " << xVal << " , " << yVal << " , " << zVal;但輸出日志給我不同的結果:Vertex coord: 14.574 , -8.236 , 7.644Vertex coord without loop: 20.67 , -19.098 , 18.536Vertex coord: 14.552 , -8.024 , 7.842Vertex coord without loop: -0.361096 , 0.109164 , 0.926117Vertex coord: 14.722 , -8.18 , 7.842Vertex coord without loop: 20.648 , -19.052 , 18.522我無法弄清楚為什么結果不同:(C ++
我有一個帶有條件的for循環如下:
慕婉清6462132
2019-06-02 17:01:03
