typedef struct {
float Position[3];
float Color[4];
float VertexNormal[3];
} Vertex;
typedef struct WingedEdge{
struct WingedEdge* sym;
struct WingedEdge* next;
struct WingedEdge* prev;
Vertex** vertex;
GLushort** indexPointer;
} WingedEdge;
Vertex* vertices;
GLushort* indices;
struct WingedEdge* wingedEdges;
int numberOfVertices; //initialized elsewhere
int numberOfIndices; //initialized elsewhere,this is multiplied by three since I am not using a struct for the indices
vertices = (Vertex *) malloc(numberOfVertices * sizeof(Vertex));
indices = (GLushort *) malloc(numberOfIndices * sizeof(GLushort) * 3);
wingedEdges = (struct WingedEdge*)malloc(sizeof(struct WingedEdge)*numberOfIndices*3);
for (int i = 0; i < numberOfIndices*3; i+=3) {
wingedEdges[i].indexPointer = (&indices+i);
wingedEdges[i+1].indexPointer = (&indices+i);
wingedEdges[i+2].indexPointer = (&indices+i);
wingedEdges[i].vertex = (&vertices+indices[i]);
wingedEdges[i+1].vertex = (&vertices+indices[i+1]);
wingedEdges[i+2].vertex = (&vertices+indices[i+2]);
NSLog(@"%hu %hu %hu", *(indices+i),*(indices+i+1),indices[i+2]);
NSLog(@"%f %f %f", (vertices+indices[i])->Position[0], (vertices+indices[i])->Position[1], (vertices+indices[i])->Position[2]);
NSLog(@"%f %f %f", (vertices+indices[i+1])->Position[0], (vertices+indices[i+1])->Position[1], (vertices+indices[i+1])->Position[2]);
NSLog(@"%f %f %f", (vertices+indices[i+2])->Position[0], (vertices+indices[i+2])->Position[1], (vertices+indices[i+2])->Position[2]);
NSLog(@"%hu", **(wingedEdges[i].indexPointer));
}
試圖尋找在其他一些問題,指針和結構,但我沒有發現任何東西。我收到最後一次NSLog調用的錯誤。 NSLog中所有使用索引和頂點調用的東西都是正確的,所以它看起來可能是一個簡單的語法錯誤或指針問題。另外,我如何增加indexPointer指向的指針?由於indexPointer指向一個索引指針,因此我想通過indexPointer訪問index + 1和index + 2。
其中是變量索引初始化代碼? – changx
我添加了它,不能把所有東西都放在這裏,否則它會很大,但是所有與wingedEdges相關的代碼應該在這裏。 – MCH
如果您想知道爲什麼我使用指向指針的指針,那麼只是爲了防止頂點或索引中的值發生更改,這樣我就不必再次更改wingedEdge中的值。 – MCH