Witam
Czy stworzenie dynamicznej tablicy w strukturze w ten sposób jest poprawne?
struct BlokE{
short int L;
short int K;
XMFLOAT4X4 B;
std::array <XMFLOAT4X4, 3> N;
};
struct BlokC{
short int Ix;
short int Iy;
BlokE ** Blok;
XMFLOAT4X4 ** W;
XMFLOAT4X4 * H;
};
std::array <BlokC, 4> InventoryB;
...
InventoryB[0].Ix = 10;
InventoryB[0].Iy = 1;
InventoryB[1].Ix = 8;
InventoryB[1].Iy = 6;
InventoryB[2].Ix = 3;
InventoryB[2].Iy = 3;
InventoryB[3].Ix = 1;
InventoryB[3].Iy = 1;
InventoryB[1].Ix = 10;
InventoryB[1].Iy = 1;
for (short int TB_01 = 0; TB_01 < 4; TB_01++){
InventoryB[TB_01].Blok = new BlokE * [InventoryB[TB_01].Ix];
InventoryB[TB_01].W = new XMFLOAT4X4 * [InventoryB[TB_01].Ix + 1];
InventoryB[TB_01].H = new XMFLOAT4X4 [InventoryB[TB_01].Iy + 1];
for (short int TB_02 = 0; TB_02 < InventoryB[TB_01].Ix + 1; TB_02++){
if (TB_02 < InventoryB[TB_01].Ix) InventoryB[TB_01].Blok[TB_02] = new BlokE [InventoryB[TB_01].Iy];
InventoryB[TB_01].W[TB_02] = new XMFLOAT4X4 [InventoryB[TB_01].Iy];
}
}
Sądzę, że w powyższym kodzie jest gdzieś błąd, z racji tego że dalsza część programu nie działa poprawnie.
Dla InventoryB[0]
wyświetla się prawidłowo grafika, jednak dla InventoryB[1]
nic nie wyświetla się, mimo że ich zawartość jest taka sama, a kod który się dla nich wykonuje też jest taki sam.
void USTM_02 (float ISx, float ISy, float IS, short int Num){
XMMATRIX ISM;
for (short int TB_02 = 0; TB_02 < InventoryB[Num].Iy + 1; TB_02++){
if (TB_02 < InventoryB[Num].Iy){
for (short int TB_01 = 0; TB_01 < InventoryB[Num].Ix + 1; TB_01++){
if (TB_01 < InventoryB[Num].Ix){
ISM = XMMatrixTranspose (XMMatrixScaling( IS * 0.8f, IS * 0.8f, 1 ) * XMMatrixTranslation( ISx + TB_01 * IS * 2, ISy + TB_02 * IS * 2, 0));
XMStoreFloat4x4 (&InventoryB[Num].Blok[TB_01][TB_02].B, ISM);
}
ISM = XMMatrixTranspose (XMMatrixScaling( IS * 0.2f, IS * 0.8f, 1 ) * XMMatrixTranslation( ISx + (TB_01 - 0.5f) * IS * 2, ISy + TB_02 * IS * 2, 0));
XMStoreFloat4x4 (&InventoryB[Num].W[TB_01][TB_02], ISM);
}
}
ISM = XMMatrixTranspose (XMMatrixScaling( IS * (InventoryB[Num].Ix + 0.2f), IS * 0.2f, 1 ) * XMMatrixTranslation( 0, ISy + (TB_02 - 0.5f) * IS * 2, 0));
XMStoreFloat4x4 (&InventoryB[Num].H[TB_02], ISM);
}
}
...
float IS = 0.5f;
float ISx = (-InventoryB[0].Ix + 1) * IS;
float ISy = -Height / 1000.0f + IS * 2;
USTM_02 (ISx, ISy, IS, 0);
USTM_02 (ISx, ISy, IS, 1);
...
void DrawM (short int Num){
for (short int TB_02 = 0; TB_02 < InventoryB[Num].Iy + 1; TB_02++){
if (TB_02 < InventoryB[Num].Iy){
for (short int TB_01 = 0; TB_01 < InventoryB[Num].Ix + 1; TB_01++){
if (TB_01 < InventoryB[Num].Ix){
cb.mWorld = XMLoadFloat4x4 (&InventoryB[Num].Blok[TB_01][TB_02].B);
d3d11DevCon->PSSetShaderResources( 0, 1, &texturaU[ltextur1D + ltextur2D + ltextur3D + lModeli + lModeliV+ lModeliP + lModeliPV + 5] );
d3d11DevCon->UpdateSubresource( g_pCBChangesEveryFrame, 0, NULL, &cb, 0, 0 );
d3d11DevCon->DrawIndexed( ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][1], ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][Num], 0 );
}
cb.mWorld = XMLoadFloat4x4 (&InventoryB[Num].W[TB_01][TB_02]);
d3d11DevCon->PSSetShaderResources( 0, 1, &texturaU[ltextur1D + ltextur2D + ltextur3D + lModeli + lModeliV + lModeliP + lModeliPV + 2] );
d3d11DevCon->UpdateSubresource( g_pCBChangesEveryFrame, 0, NULL, &cb, 0, 0 );
d3d11DevCon->DrawIndexed( ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][1], ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][Num], 0 );
}
}
cb.mWorld = XMLoadFloat4x4 (&InventoryB[Num].H[TB_02]);
d3d11DevCon->PSSetShaderResources( 0, 1, &texturaU[ltextur1D + ltextur2D + ltextur3D + lModeli + lModeliV + lModeliP + lModeliPV + 2] );
d3d11DevCon->UpdateSubresource( g_pCBChangesEveryFrame, 0, NULL, &cb, 0, 0 );
d3d11DevCon->DrawIndexed( ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][1], ModelPK[lModeli + lModeliV+ lModeliP + lModeliPV + lModeliB][Num], 0 );
}
}
...
DrawM (0); //prawidłowo
DrawM (1); //nieprawidłowo