void _set_texcoords(int face) { int column = face % 8; int row = face / 8; texcoords = (boost::array<vec2, 4>){ make_vec2(0.125f*column, 0.5f*row + 0.5f), make_vec2(0.125f*column + 0.125f, 0.5f*row + 0.5f), make_vec2(0.125f*column, 0.5f*row ), make_vec2(0.125f*column + 0.125f, 0.5f*row ), }; }
// arm void board::_setup_background_vertices() { background_vertices[0] = make_vec2(-160.0f*GAME_UNITS_PER_PIXEL, -240.0f*GAME_UNITS_PER_PIXEL); background_vertices[1] = make_vec2( 160.0f*GAME_UNITS_PER_PIXEL, -240.0f*GAME_UNITS_PER_PIXEL); background_vertices[2] = make_vec2(-160.0f*GAME_UNITS_PER_PIXEL, 240.0f*GAME_UNITS_PER_PIXEL); background_vertices[3] = make_vec2( 160.0f*GAME_UNITS_PER_PIXEL, 240.0f*GAME_UNITS_PER_PIXEL); background_colors[0] = background_gradient[0]; background_colors[1] = background_gradient[0]; background_colors[2] = background_gradient[1]; background_colors[3] = background_gradient[1]; }
void ChessFieldModel::make_move(int src_cell, int dst_cell) { if( m_chess_board.get_board_piece(7 - src_cell / 8, src_cell % 8) == ChessPiece::NONE ) { return; } auto src = make_vec2(7 - src_cell/8, src_cell%8); auto dst = make_vec2(7 - dst_cell/8, dst_cell%8); auto res = m_chess_board.make_move(src, dst); if( !res ) { return ; } update_cells(res); }
// arm void particle_system::explode(thing *th, bool kill) { static const unsigned SHOCKWAVE_PARTICLES = 25, DEBRIS_PARTICLES = 75; if (board::current()->thing_lives(th)) { boost::array<vec2, 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)> explosion; unsigned i = 0; while (i < 2*SHOCKWAVE_PARTICLES) { float rho = rand_between(64.0, 81.0); float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); } while (i < 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)) { float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); } add_particles(th->center, make_vec2(1.0, 0.0), explosion); if (kill) board::current()->remove_thing(th); } }
namespace battlemints { const float particle_system::LIFE_EXPECTANCY_INV = 1.0f/(float)particle_system::LIFE_EXPECTANCY; const boost::array<vec2, 4> particle_system::exhaust = { make_vec2( 0.0, 3.0), make_vec2(-9.0, 24.0), make_vec2( 0.0, -3.0), make_vec2(-9.0, -24.0) }; // arm void particle_system::explode(thing *th, bool kill) { static const unsigned SHOCKWAVE_PARTICLES = 25, DEBRIS_PARTICLES = 75; if (board::current()->thing_lives(th)) { boost::array<vec2, 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)> explosion; unsigned i = 0; while (i < 2*SHOCKWAVE_PARTICLES) { float rho = rand_between(64.0, 81.0); float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); explosion[i++] = polar_vec2(rho, rand_near(theta, 0.0625)); } while (i < 2*(SHOCKWAVE_PARTICLES + DEBRIS_PARTICLES)) { float theta = rand_between(0.0, 1.0); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); explosion[i++] = polar_vec2(rand_between(3.0, 7.0)*rand_between(3.0, 7.0), theta); } add_particles(th->center, make_vec2(1.0, 0.0), explosion); if (kill) board::current()->remove_thing(th); } } void particle_system::draw() { glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); vertex_buffer::array_range vertices_one = _vertices.array_one(), vertices_two = _vertices.array_two(); if (vertices_one.second > 0) { glVertexPointer(2, GL_FLOAT, 0, (void*)vertices_one.first); glColorPointer(4, GL_FLOAT, 0, (void*)_colors.array_one().first); glDrawArrays(GL_LINES, 0, vertices_one.second); } if (vertices_two.second > 0) { glVertexPointer(2, GL_FLOAT, 0, (void*)vertices_two.first); glColorPointer(4, GL_FLOAT, 0, (void*)_colors.array_two().first); glDrawArrays(GL_LINES, 0, vertices_two.second); } glDisableClientState(GL_COLOR_ARRAY); } // arm static inline void _add_vertex_array_ranges( particle_system::vertex_buffer::array_range const &v, particle_system::vertex_buffer::array_range const &d) { float *vi = (float*)v.first, *di = (float*)d.first; unsigned count = v.second * 2; for (; count > 0; --count) // XXX vectorize *vi++ += *di++; } // arm void particle_system::tick() { while (!_ages.empty() && _ages.front() >= LIFE_EXPECTANCY) { _vertices.pop_front(); _deltas.pop_front(); _colors.pop_front(); _ages.pop_front(); } if (_ages.empty()) return; _add_vertex_array_ranges(_vertices.array_one(), _deltas.array_one()); _add_vertex_array_ranges(_vertices.array_two(), _deltas.array_two()); color_buffer::iterator ci = _colors.begin(); age_buffer::iterator ai = _ages.begin(); for (; ci != _colors.end(); ++ci, ++ai) { ++*ai; *ci = color(*ai); } } }
int draw( void ) { if(wireframe) { glClearColor(1, 1, 1, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(2); } else { glClearColor(0.2f, 0.2f, 0.2f, 1); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } // effacer l'image glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(key_state('r')) { clear_key_state('r'); reload_program(); } // recupere les mouvements de la souris int mx, my; unsigned int mb= SDL_GetRelativeMouseState(&mx, &my); int mousex, mousey; SDL_GetMouseState(&mousex, &mousey); // deplace la camera if(mb & SDL_BUTTON(1)) orbiter_rotation(camera, mx, my); // tourne autour de l'objet else if(mb & SDL_BUTTON(2)) orbiter_translation(camera, (float) mx / (float) window_width(), (float) my / (float) window_height()); // deplace le point de rotation else if(mb & SDL_BUTTON(3)) orbiter_move(camera, mx); // approche / eloigne l'objet // recupere les transformations Transform model= make_identity(); Transform view= orbiter_view_transform(camera); Transform projection= orbiter_projection_transform(camera, window_width(), window_height(), 45); Transform viewport= make_viewport(window_width(), window_height()); Transform mvp= projection * view * model; Transform mvpInv= make_inverse(mvp); Transform mv= model * view; // affiche l'objet if(program_failed == false) { if(key_state('w')) { clear_key_state('w'); wireframe= !wireframe; } // configuration minimale du pipeline glBindVertexArray(vao); glUseProgram(program); // affecte une valeur aux uniforms // transformations standards program_uniform(program, "modelMatrix", model); program_uniform(program, "modelInvMatrix", make_inverse(model)); program_uniform(program, "viewMatrix", view); program_uniform(program, "viewInvMatrix", make_inverse(view)); program_uniform(program, "projectionMatrix", projection); program_uniform(program, "projectionInvMatrix", make_inverse(projection)); program_uniform(program, "viewportMatrix", viewport); program_uniform(program, "viewportInvMatrix", make_inverse(viewport)); program_uniform(program, "mvpMatrix", mvp); program_uniform(program, "mvpInvMatrix", mvpInv); program_uniform(program, "mvMatrix", mv); program_uniform(program, "normalMatrix", make_normal_transform(mv)); // interactions program_uniform(program, "viewport", make_vec2(window_width(), window_height())); program_uniform(program, "time", (float) SDL_GetTicks()); program_uniform(program, "motion", make_vec3(mx, my, mb & SDL_BUTTON(1))); program_uniform(program, "mouse", make_vec3(mousex, mousey, mb & SDL_BUTTON(1))); // textures for(unsigned int i= 0; i < (unsigned int) textures.size(); i++) { char uniform[1024]; sprintf(uniform, "texture%d", i); program_use_texture(program, uniform, i, textures[i]); } // go glDrawArrays(GL_TRIANGLES, 0, vertex_count); } // affiche les infos begin(widgets); if(program_failed) { label(widgets, "[error] program '%s'", program_filename.path); begin_line(widgets); text_area(widgets, 20, program_log.c_str(), program_area); } else { label(widgets, "program '%s' running...", program_filename.path); if(mesh_filename[0] != 0) { begin_line(widgets); label(widgets, "mesh '%s', %u positions, %u texcoords, %u normals", mesh_filename.path, (unsigned int) mesh.positions.size(), (unsigned int) mesh.texcoords.size(), (unsigned int) mesh.normals.size()); } for(unsigned int i= 0; i < (unsigned int) texture_filenames.size(); i++) { begin_line(widgets); label(widgets, "texture%u '%s'", i, texture_filenames[i].path); } } end(widgets); draw(widgets, window_width(), window_height()); if(key_state('s')) { clear_key_state('s'); screenshot("shader_kit.png"); } if(key_state('c')) { clear_key_state('c'); write_orbiter(camera, "orbiter.txt"); } if(key_state('v')) { clear_key_state('v'); camera= read_orbiter("orbiter.txt"); } return 1; }
void vertex_texcoord( Mesh& m, const float u, const float v ) { vertex_texcoord(m, make_vec2(u, v)); }