Cube::Cube(const position_type &where, std::shared_ptr<Texture> texture ) : Object3D(where) { // 8 points, 6 surfaces position_type blf(-1.0, -1.0, 1.0) // front rectangle , brf(1.0, -1.0, 1.0) , trf(1.0, 1.0, 1.0) , tlf(-1.0, 1.0, 1.0) , blr(-1.0, -1.0, -1.0) // rear rectangle , brr(1.0, -1.0, -1.0) , trr(1.0, 1.0, -1.0) , tlr(-1.0, 1.0, -1.0); position_type negZ(0.0, 0.0, -1.0) , posZ(0.0, 0.0, 1.0) , negY(0.0, -1.0, 0.0) , posY(0.0, 1.0, 0.0) , negX(-1.0, 0.0, 0.0) , posX(1.0, 0.0, 0.0); // if changing the order, make sure to change accessors so they grab the correct object this->add_child(new Rectangle(POSITION_INHERIT, { blf, blr, brr, brf }, { negY, negY, negY, negY }, texture)); // bottom negY this->add_child(new Rectangle(POSITION_INHERIT, { trr, brr, blr, tlr }, { negZ, negZ, negZ, negZ }, texture)); // rear negZ this->add_child(new Rectangle(POSITION_INHERIT, { trf, brf, brr, trr }, { posX, posX, posX, posX }, texture)); // right posX this->add_child(new Rectangle(POSITION_INHERIT, { tlr, blr, blf, tlf }, { negX, negX, negX, negX }, texture)); // left negX this->add_child(new Rectangle(POSITION_INHERIT, { tlf, blf, brf, trf }, { posZ, posZ, posZ, posZ }, texture)); // front posZ this->add_child(new Rectangle(POSITION_INHERIT, { tlr, tlf, trf, trr }, { posY, posY, posY, posY }, texture)); // top posY } // Cube
/** * Main function. */ int main(int argc, char *argv[]){ //runs application QApplication a(argc, argv); Settings& sts = Settings::get(); QTranslator trr(&a); trr.load(sts.language(), "./Translation"); a.installTranslator(&trr); Application::MainWindow w; w.show(); w.showMaximized(); return a.exec(); }
Cube::Cube( const position_type &where, Texture::pointer_type texture ) : Object( where, texture ) { glm::vec3 blf( -1.0, -1.0, 1.0 ) // front rectangle , brf( 1.0, -1.0, 1.0 ) , trf( 1.0, 1.0, 1.0 ) , tlf( -1.0, 1.0, 1.0 ) , blr( -1.0, -1.0, -1.0 ) // rear rectangle , brr( 1.0, -1.0, -1.0 ) , trr( 1.0, 1.0, -1.0 ) , tlr( -1.0, 1.0, -1.0 ) ; glm::vec3 negZ( 0.0, 0.0, -1.0 ) , posZ( 0.0, 0.0, 1.0 ) , negY( 0.0, -1.0, 0.0 ) , posY( 0.0, 1.0, 0.0 ) , negX( -1.0, 0.0, 0.0 ) , posX( 1.0, 0.0, 0.0 ) ; // gl_triangle strip // for ccw winding: top left, bottom left, top right, bottom right auto add_components = [ &]( const std::vector<Component::pointer_type>& vec ) { for ( auto& v : vec ) this->components.emplace_back( v ); }; add_components( Triangle::from_quad( std::vector<glm::vec3>( { blf, blr, brf, brr } ), negY, texture ) ); // bottom add_components( Triangle::from_quad( std::vector<glm::vec3>( { trr, brr, tlr, blr } ), negZ, texture ) ); // rear add_components( Triangle::from_quad( std::vector<glm::vec3>( { trf, brf, trr, brr } ), posX, texture ) ); // right posX add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, blr, tlf, blf } ), negX, texture ) ); // left negX add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlf, blf, trf, brf } ), posZ, texture ) ); // front posZ add_components( Triangle::from_quad( std::vector<glm::vec3>( { tlr, tlf, trr, trf } ), posY, texture ) ); // top posY }