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
我无法弄清楚为什么结果不同:(
慕婉清6462132
DIEA
随时随地看视频慕课网APP
相关分类