我是 C++ 指针的新手,从指针获取值时遇到问题。
我有一个指针 verticesPosBegin ,它指向用于保存顶点位置的数组的开头。每个顶点存储为一个 3 分量浮点向量 (xyz)。
我需要从中获取每个顶点并访问其 x、y、z 值。
我是通过以下方式做到的:
NxVec3* positions = (NxVec3*)data.verticesPosBegin;
for(int i=0;i<nrVertices;i++)
{
NxVec3* p1 = (NxVec3*)positions;
printf("Vertex coordinates x: %d, y: %d, z: %d\n", p1->x, p1->y, p1->z);
positions++;
}
(NxVec3 是一种由我使用的物理引擎定义的类型,它基本上是一种形式的结构(float x,float y,float z))
但这并没有让我得到坐标的值,而是地址,我猜,因为它们代表了非常大的数字。任何帮助将不胜感激。