Hi, I’m trying to wrap my head around the proper usage of the Batch object. I am rendering a 3x3 matrix of cubes currently with the following code.
class CipherApp : public App {
public:
void setup() override;
void mouseDown( MouseEvent event ) override;
void update() override;
void draw() override;
static const int MAP_SIZE = 6;
CameraPersp mCam;
gl::BatchRef mBlocks[MAP_SIZE][MAP_SIZE][MAP_SIZE];
};
void CipherApp::setup(){
auto lambert = gl::ShaderDef().lambert().color();
gl::GlslProgRef shader = gl::getStockShader( lambert );
for(int i = 0; i < MAP_SIZE; i++) {
for(int j = 0; j < MAP_SIZE; j++) {
for(int k = 0; k < MAP_SIZE; k++) {
auto cube = geom::Cube();
mBlocks[i][j][k] = gl::Batch::create( cube, shader );
}
}
}
mCam.lookAt( vec3( 10, 20, 10 ), vec3( 0 ) );
}
void CipherApp::draw() {
gl::clear();
gl::enableDepthRead();
gl::enableDepthWrite();
gl::setMatrices( mCam );
for( int i = 0; i < MAP_SIZE; i++ ) {
for( int j = 0; j < MAP_SIZE; j++ ) {
for(int k = 0; k < MAP_SIZE; k++) {
gl::ScopedModelMatrix scpModelMatrix;
gl::translate( i, j, k );
gl::color( i / (float)MAP_SIZE, j / (float)MAP_SIZE, k / (float)MAP_SIZE );
mBlocks[i][j][k]->draw();
}
}
}
}
I have read that a batch is a bundle of a mesh and shader. If my chunk of cubes will all utilize the same shader is it overkill to use a Batch for each cube?
My next confusion is inheriting the Batch type so I can specify a specific Cube class. I am looking for each block to store some parameters beyond what is specified in a Batch so I set out to make a Cube class with parameters such as scale and location that inherited a Batch object but was confused when I could not define my new Cubes with
Cube newCube = gl::Batch::create(...)
How can I make Cubes inherit a batch type and create a cube mesh with geom::Cube();