### Creating a cube with multiple planes

Hello all,

I am trying to create a cube that can be viewed in multiple layers along what i assume would be the Z axis -

For example

00
00

This would be the first layer, then under this would be

11
11

(only filling this space on the screen, where a key would be required to view the next layer down)

If anyone has played dwarf fortress i want something that is similar to the way Z levels work.

I have tried creating this with 3d vectors and arrays but am only just starting in Games Development at Uni and getting quite confused.

Its for a project i am working on with a friend to create a simulation of ants moving in a terrarium, and we are trying to figure out the 'sand' in which the ants will dig

There is no requirement of size (the hope is that users will be able to define a cube size)

we dont want anyone to do it for us, just maybe give us some hints about where we may start with this.

Many thanks for any help --

CJ

(P.S this is a personal project and not Uni related!!)
Last edited on
 I have tried creating this with 3d vectors ... and getting quite confused.

The syntax for multi-dimensional std::vectors is awkward, but I’d give them a second chance.
Supposing you want your ‘ground’ to be described not by digits, but by weird characters like @, #, & or worst, you can try something like this (just hints):

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` ``````#include #include #include #include #include // Let's choose some symbols which are likely to be there on a large variety // of keyboards: const std::vector print_symbols { '@', '#', '*', '+', '-' }; struct Cube { static std::mt19937 eng; int edge; std::vector>> cube; Cube(); Cube(int edge_arg); int getRndInt(int min, int max); int createCube(); void fillCubeWithRndVals(); friend std::ostream& operator<<(std::ostream& os, const Cube& rhs) { int level { 1 }; for(const auto& a : rhs.cube) { os << "level " << level << ":\n"; for(const auto& b : a) { for(const auto& c : b) { os << static_cast(c); } os << '\n'; } os << "\n\n"; ++level; } return os; } }; std::mt19937 Cube::eng { static_cast( std::chrono::high_resolution_clock::now() .time_since_epoch() .count() ) }; Cube::Cube() : edge {} { createCube(); } Cube::Cube(int edge_arg) : edge { edge_arg } { createCube(); } int Cube::getRndInt(int min, int max) { std::uniform_int_distribution<> rnd(min, max); return rnd(Cube::eng); } int Cube::createCube() { if(!edge) { edge = getRndInt(2, 5); } // choose your boundaries cube.resize(edge); for(auto& square : cube) { square.resize(edge); for(auto& row : square) { row.resize(edge); } // all zero initialized } std::cout << "Cube edge is: " << edge << "\nStarting cube is:\n" << *this; fillCubeWithRndVals(); std::cout << "\nAfter filling with random values:\n" << *this; return edge; } void Cube::fillCubeWithRndVals() { for(auto& square : cube) { for(auto& row : square) { for(auto& cell : row) { cell = print_symbols.at(getRndInt(0, 4)); } } } } void waitForEnter(); int main() { Cube cube; waitForEnter(); return 0; } void waitForEnter() { std::cout << "\nPress ENTER to continue...\n"; std::cin.ignore(std::numeric_limits::max(), '\n'); }``````

Output:
 ```Cube edge is: 2 Starting cube is: level 1: level 2: After filling with random values: level 1: #+ *+ level 2: *# ++ Press ENTER to continue...```

Good luck!
Brilliant we will give these a shot and see how it works, we managed to have some success with 3D areays but feel that vectors will still be the way, also, we are filling with all sorts of symbols! Will keep you posted how it turns out,

Many thanks

CJ
Topic archived. No new replies allowed.