void TextImpl::update_graphics() { if (m_has_changed) { m_has_changed = false; m_vertices.resize(m_length * 4); update_vertices(); } }
void handle_stars(struct Polygon *stars[], float speed) { int i; /* if speed is less than 0, we're moving backwards */ int backwards = speed < 0 ? 1 : 0; int offscreen = false; /* move slower than asteroids to simluate a parallax effect */ speed = speed / 3.0f; for (i = 0; i < MAX_STARS; i++) { if (stars[i] == NULL) { stars[i] = construct_star(); } stars[i]->y -= speed; /* if it went below the screen (or above the screen while backwards) */ if (below_screen(*stars[i]) || (above_screen(*stars[i]) && backwards)) { deconstruct_polygon(stars[i]); stars[i] = construct_star(); /* put it below the screen if backwards else above */ stars[i]->y = backwards ? -5.0f : 5.0f; } update_vertices(stars[i]); } }
void ocl_one_step_move(sotl_device_t *dev) { if (gravity_enabled) gravity (dev); #ifdef _SPHERE_MODE_ if (eating_enabled) eating_pacman (dev); if (growing_enabled) growing_ghost (dev); #endif if (force_enabled) // Classic n^2 compute force version n2_lennard_jones (dev); if(detect_collision) atom_collision (dev); if(borders_enabled) border_collision (dev); update_position (dev); #ifdef HAVE_LIBGL if (dev->display) update_vertices (dev); #endif }
void TextImpl::update_graphics() { if (m_has_changed) { m_has_changed = false; if (m_length > TEXT_LEN_LIMIT) m_length = TEXT_LEN_LIMIT; m_quads_len = m_length; update_vertices(); } }
void animation_update(struct Game *game) { /* move towards the player starting position and don't go over it */ if (game->player->y < -3.0f) { game->player->y += 0.05f; } handle_stars(game->stars, game->speed); update_vertices(game->player); }
void ocl_updateModelFromHost(sotl_device_t *dev) { cl_int err; // Transfer model from Host to Accelerator // err = clEnqueueWriteBuffer(dev->queue, model_buffer, CL_TRUE, 0, 2 * vertices_per_atom * 3 * sizeof(float), vertex_model, 0, NULL, NULL); check(err, "Failed to write to model_buffer array"); clFinish(dev->queue); update_vertices(dev); }
void handle_asteroids(struct Polygon *asteroids[], float speed, int max_asteroids) { int i, j; /* if speed is less than 0, we're moving backwards */ int backwards = speed < 0 ? 1 : 0; for (i = 0; i < MAX_ASTEROIDS; i++) { if (asteroids[i] == NULL) { continue; } asteroids[i]->y -= speed; update_vertices(asteroids[i]); /* if it is on screen and we're going backwards */ if (polygon_visible(*asteroids[i]) && backwards) { /* if the asteroid has come back above screen, reset its time */ if (asteroids[i]->below_time != 0) { asteroids[i]->below_time = 0; } } /* if it is below the screen and we're not going backwards */ if (below_screen(*asteroids[i]) && !backwards) { /* if the asteroid is coming in fresh, set its timer */ if (asteroids[i]->below_time == 0) { asteroids[i]->below_time = SDL_GetTicks(); } /* if it's the first time below screen, make a new asteroid */ if (asteroids[i]->first_below == 0) { asteroids[i]->first_below = 1; /* Make a new asteroid if there aren't enough on screen */ if (num_visible_asteroids(asteroids) < max_asteroids) { make_asteroid(asteroids); } } /* once it has been under 5 seconds, remove it leaving open spot */ if (SDL_GetTicks() - asteroids[i]->below_time > 5000) { deconstruct_polygon(asteroids[i]); asteroids[i] = NULL; } } } }
Tile::Tile(GLuint shader_id, int x, int z) { glGenVertexArrays(1, &vao); glGenBuffers(1, &vbo); glGenBuffers(1, &ebo); glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); GLuint posAttrib = glGetAttribLocation(shader_id, "position_model"); GLuint norAttrib = glGetAttribLocation(shader_id, "normal_model"); GLuint texAttrib = glGetAttribLocation(shader_id, "texcoord"); GLuint colAttrib = glGetAttribLocation(shader_id, "color"); glEnableVertexAttribArray(posAttrib); glEnableVertexAttribArray(norAttrib); glEnableVertexAttribArray(texAttrib); glEnableVertexAttribArray(colAttrib); glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), 0 ); glVertexAttribPointer(norAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(3*sizeof(float))); glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(6*sizeof(float))); glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 11*sizeof(float), (void*)(8*sizeof(float))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glEnable(GL_PRIMITIVE_RESTART); glPrimitiveRestartIndex((TILE_SIZE+1)*(TILE_SIZE+1)+TILE_SIZE); reload_vbo = false; reload_ebo = false; needs_rebuild = false; needs_gen = true; show = false; lod(0); set_xz(x,z); update_vertices(); update_indices(); }
void handle_input(struct Game *game) { game->player->angle = 90; /* Move player and make sure they can't go too far off screen */ switch(game->input) { case SDL_SCANCODE_W: if (game->player->y + 0.1f < Y_LENGTH) { game->player->y += 0.1f; } break; case SDL_SCANCODE_S: if (game->player->y - 0.1f > -Y_LENGTH) { game->player->y -= 0.1f; } break; case SDL_SCANCODE_A: if (game->player->x - (game->speed + 0.25f) > -(X_LENGTH - 1.5f)) { game->player->x -= game->speed + 0.25; } game->player->angle = 110; break; case SDL_SCANCODE_D: if (game->player->x + (game->speed + 0.25f) < (X_LENGTH - 1.5f)) { game->player->x += game->speed + 0.25; } game->player->angle = 70; break; } update_vertices(game->player); }
void TextImpl::resize() { update_vertices(); }
void ocl_one_step_move(sotl_device_t *dev) { unsigned begin = atom_set_begin(&dev->atom_set); unsigned end = atom_set_end(&dev->atom_set); if (gravity_enabled) gravity (dev); #ifdef _SPHERE_MODE_ if (eating_enabled) eating_pacman (dev); if (growing_enabled) growing_ghost (dev); #endif if (force_enabled) { if (is_box_mode) { reset_box_buffer(dev); box_count_all_atoms(dev, begin, end); // Calc boxes offsets scan(dev, 0, dev->domain.total_boxes + 1); // Sort atoms in boxes { copy_box_buffer(dev); // Sort box_sort_all_atoms(dev, begin, end); // box_sort_all_atoms used alternate pos & speed buffer, so we should switch... dev->cur_pb = 1 - dev->cur_pb; dev->cur_sb = 1 - dev->cur_sb; } /* Compute potential */ box_lennard_jones(dev, begin, end); } else { // !BOX_MODE // Classic n^2 compute force version n2_lennard_jones (dev); } } if(detect_collision) atom_collision (dev); if(borders_enabled) border_collision (dev); update_position (dev); #ifdef HAVE_LIBGL if (dev->display) update_vertices (dev); #endif }