   Creating a map in a 3D World (SOLVED)
  I am trying to create a map in a 3D world, just a simple maze:what i want todo is make a FUNCTION that will position blocks with the maze array.at the moment i have // Maze constsconst int Row = 10;const int Column = 10;const int MazeSize = Row * Column;const float BlockWidth = 13.0f;const float BlockLength = 24.0f;int gMazeArray[Row][Column]={{1,1,1,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1}};MazeModels.resize(MazeSize,0);for (unsigned int i=0; i<MazeModels.size(); i++){MazeModels = new CMaze();MazeModels->setPosition(D3DXVECTOR3(0.0f, 0.0f, 0.0f));//position of the blocks}//so i have 100 blocks all in 1 place on top of each otherso i have the maze array structure 'gMazeArray' and i'm rendering all the blocks by creating a vector container holding all the pointers to the objects so i can set the size and positions of the blocks.What i am struggling with is comming up with a way so that i can position the blocks in conjunction with the mazeArray, 1 is a block and 0 is an empty space.So if anyone could give me some advice it will be very appreciated[Edited by - Prog101 on December 9, 2006 7:22:54 AM]
  what?just type 1's or 0's into that array init list   ;  Pardon Anonymous Poster, if you dont understand , ask and i will try to explain it better.   ;  you already said that mazearray has 1 and 0 in it to set if there is a block or not.doesn't that answer your own question of how to position blocks in the maze? just set 1 or 0 to set blocks in the maze.   ;Quote:Original post by Anonymous Posteryou already said that mazearray has 1 and 0 in it to set if there is a block or not.doesn't that answer your own question of how to position blocks in the maze? just set 1 or 0 to set blocks in the maze.No, it doesn't.He's asking how to use his maze array to represent real blocks in a 3D environment. I'd use a nested for loop. The pseudocode below explains how to draw a grid with a square at each position where you've set a 1 in your array. It only draws the floor quad. I'll leave it up to you how to figure out how to draw the rest.(Pseudocode)EDIT: I realize now you're using DirectX. I don't know DirectX, so someone else will have to step in here to give a more relevant example.For each row in array {    For each column in array {   If array[row, column] != 0 {  DrawBlock(row, column)   }    }}function DrawBlock(row, column) {    top = row * 50    bottom = top + 50    left = column * 50    right = left + 50    glBegin(GL_QUADS)    // Draw bottom face    glVertex3i(left, 0, top)    glVertex3i(right, 0, top)    glVertex3i(right, 0, bottom)    glVertex3i(left, 0, bottom)    // Here's where you'd draw the rest of the faces of the cube. Refer    // to above.    glEnd()};  Ah! I see nowwhen he was asking how to 'position' the blocks in the mazehe was really asking how to 'Render' the blocks in the mazeSorry for the confusion.   ;  I am using .x meshs for the blocks, here is just where i set up the positons of the blocks in the world, i Render the blocks somewhere else. The Render works fine its just positoning them to mapright so now i have the following code// Maze constsconst float BlockWidth = 20;const float BlockLength = 20;const int Row = 10;const int Column = 10;const int MazeSize = Row + Column;std::vector <CMaze*> MazeModels;// Pointer to a Maze objectsint BlockCount, BlockPosCount;int gMazeArray[Row][Column]={{1,1,1,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1}};voidGame::Create(){// see how many blocks we need to make the mazefor (int maze_row=0; maze_row<Column; maze_row++){for (int maze_col=0; maze_col<Row; maze_col++){if (gMazeArray[maze_row][maze_col]!=0){BlockCount++;}}}// now make the block objectsMazeModels.resize(BlockCount,0);for (unsigned int i=0; i<MazeModels.size(); i++){MazeModels = new CMaze();MazeModels->setSize(1.0f);MazeModels->create(dxMgr.getD3DDevice());objects.push_back((CGameObject*)MazeModels);}}//////////////////////////////////////////////////////// PlaceBlock()//////////////////////////////////////////////////////voidGame::PlaceBlock(int DstCol, int DstRow){float SetRow = static_cast<float>(DstRow * BlockWidth);float SetCol = static_cast<float>(DstCol * BlockLength);int iter = BlockPosCount-1;{ MazeModels[iter]->setPosition(D3DXVECTOR3(SetRow, 0.0f,SetCol));}}Does this look right?[Edited by - Prog101 on December 9, 2006 6:54:41 AM];Quote:Original post by Prog101I am using .x meshs for the blocks, here is just where i set up the positons of the blocks in the world, i Render the blocks somewhere else. The Render works fine its just positoning them to mapright so now i have the following code*** Source Snippet Removed ***Does this look right?Not really. I'm not quite sure what you're doing with the vector. You're putting stuff in it, but you're not remembering where the blocks should be. I assume that's what the call to PlaceBlock was for, but you never call it. Also you have  a bug in your loops. You're doing "for (int maze_row=0; maze_row<Column; maze_row++)". You're using the max Column as the limit to your maze_row. It's only working properly because Column and Row are equal to each other. You should change this to "for (int maze_row=0; maze_row<Row; maze_row++)   ;  Ok gotcha, well here is the code that i am using and it is working spot on, if it could be improved upon i would like them to post it cheers?constWALL_MODEL = 1;// Maze constsconst int Row = 23;const int Column = 21;const int MazeSize = Row * Column;const float BlockWidth = 20;const float BlockLength = 20;std::vector <CMaze*> MazeModels;// Pointer to a Maze objectsint BlockCount, BlockPosCount;int gMazeArray[Row][Column]={{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},{1,0,1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,0,1},{1,0,1,1,0,1,0,1,0,0,0,0,0,1,0,1,0,1,1,0,1},{1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1},{1,0,1,1,1,0,1,1,0,0,0,0,0,1,1,0,1,1,1,0,1},{1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,1},{1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,1,1},{0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,0},{1,1,1,0,1,0,1,0,1,1,0,1,1,0,1,0,1,0,1,1,1},{0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0},{1,1,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,1,1},{0,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,0},{0,0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,0,0},{1,1,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1},{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},{1,1,0,1,0,1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,1},{1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1},{1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1},{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};voidGame::Create(){// see how many blocks we need to make the maze by iterating through    // the maze Array and catch all the WALL_MODEL valuesfor (int maze_row=0; maze_row<Row; maze_row++){for (int maze_col=0; maze_col<Column; maze_col++){if (gMazeArray[maze_row][maze_col]== WALL_MODEL){BlockCount++;}}}// now make the block objectsMazeModels.resize(BlockCount,0);for (unsigned int i=0; i<MazeModels.size(); i++){MazeModels = new CMaze();MazeModels->setSize(1.0f);MazeModels->create(dxMgr.getD3DDevice());objects.push_back((CGameObject*)MazeModels);}   // now loop through the the maze array and pass the co-ordinates   // to the PlaceBlock functionfor (int maze_row=0; maze_row<Row; maze_row++){for (int maze_col=0; maze_col<Column; maze_col++){if (gMazeArray[maze_row][maze_col]== WALL_MODEL){BlockPosCount++;PlaceBlock(maze_col, maze_row);}}}//////////////////////////////////////////////////////// PlaceBlock() this functions sets the blocks in there positions // by multiplying the Row or Column in the array by the size of the block//////////////////////////////////////////////////////voidGame::PlaceBlock(int DstCol, int DstRow){float SetRow = static_cast<float>(DstRow * BlockWidth);float SetCol = static_cast<float>(DstCol * BlockLength);int iter = BlockPosCount-1;{ MazeModels[iter]->setPosition(D3DXVECTOR3(SetRow, 0.0f,SetCol));}}