ポインターの配列を2つのポインターで埋める関数があります。
Vertex* MacePiece::getPositionOffset(int aDirection){
// returns Plate at Position aParent.myPlates[0]
BasePlate** theGroundPlate = this->getPlates();
Vertex* theOffset[] = {0,0};
switch(aDirection){
theOffset[0] = theGroundPlate[0]->getVertexAt(0); //A
theOffset[1] = theGroundPlate[0]->getVertexAt(1); //B
break;
}
return theOffset[0];
}
次に、最初の要素のアドレスを持つポインターを別の関数に渡します。
Vertex* theParentOffset = aParentPiece->getPositionOffset(aDirection);
theConnectingPiece->setPositionInMace(theParentOffset, aDirection);
ここでは、次のようにポイントされた要素を使用しています。
void MacePiece::setPositionInMace(Vertex* aOffset, int aDirection){
// set groundplate position
updateGroundPlatePositionByOffsetVertex(aOffset, aDirection);
}
void MacePiece::updateGroundPlatePositionByOffsetVertex(Vertex* aOffset, int aDirection) {
BasePlate** thePlates = this->getPlates();
// first update GroundPlate's Position
Vertex* A = thePlates[0]->getVertexAt(0);
Vertex* B = thePlates[0]->getVertexAt(1);
Vertex* C = thePlates[0]->getVertexAt(2);
Vertex* D = thePlates[0]->getVertexAt(3);
switch(aDirection){
case MOVE_NORTH:
// still 3D thus 2D's y is 3D'z if camera is looking down Y
// Two Sides are connecting thus Some Plate locations are identical
// A.x defined by parent D.x
A->position[0] = aOffset[1].position[0];
// A.z defined by parent D.z
A->position[2] = aOffset[1].position[2];
//B.x defined by parent C.x
B->position[0] = aOffset[0].position[0];
//B.z defined by parent C.z
B->position[2] = aOffset[0].position[2];
// now set Opposit side (A->D, B->C), since moving north:
// x is the same
// z is reduced by -1 because OpenGL's Z is reducing to far-pane
D->position[0] = A->position[0];
D->position[2] = A->position[2] - 1.0f;
C->position[0] = B->position[0];
C->position[2] = B->position[2] - 1.0f;
break;
具体的にはこのパート:
// A.x defined by parent D.x
A->position[0] = aOffset[1].position[0];
// A.z defined by parent D.z
A->position[2] = aOffset[1].position[2];
//B.x defined by parent C.x
B->position[0] = aOffset[0].position[0];
//B.z defined by parent C.z
B->position[2] = aOffset[0].position[2];
aOffset[1]はaOffset[0]と同じものを返します
配列の**ポインタを渡すと、すべての情報を指すことが失われます。
私は一種の迷宮を作成していますが、それは一方向に失敗します。そのポインタを渡すことの何が問題になっていますか?オフセット[1]でポイントされた正しい要素を取得するにはどうすればよいですか?
そのとても迷惑です。
乾杯クヌート