• Home
  • Raw
  • Download

Lines Matching +full:32 +full:- +full:particles

6 // This software is provided 'as-is', without any express or implied
67 // NOTE: This structure SHOULD be packed on most systems. It uses 32-bit fields
68 // on 32-bit boundaries, and is a multiple of 64 bits in total (6x32=3x64). If
97 mtx_t particles_lock; // Particles data sharing mutex
102 // Texture declarations (we hard-code them into the source code, since
152 // Maximum number of particles
179 // Minimum delta-time for particle phisics (s)
196 // Global vectors holding all particles. We use two vectors for double
198 static PARTICLE particles[MAX_PARTICLES]; variable
229 printf("Usage: particles [-bfhs]\n"); in usage()
231 printf(" -f Run in full screen\n"); in usage()
232 printf(" -h Display this help\n"); in usage()
233 printf(" -s Run program as single thread (default is to use two threads)\n"); in usage()
249 // Start position of particle is at the fountain blow-out in init_particle()
250 p->x = 0.f; in init_particle()
251 p->y = 0.f; in init_particle()
252 p->z = FOUNTAIN_HEIGHT; in init_particle()
255 p->vz = 0.7f + (0.3f / 4096.f) * (float) (rand() & 4095); in init_particle()
259 p->vx = 0.4f * (float) cos(xy_angle); in init_particle()
260 p->vy = 0.4f * (float) sin(xy_angle); in init_particle()
262 // Scale velocity vector according to a time-varying velocity in init_particle()
264 p->vx *= velocity; in init_particle()
265 p->vy *= velocity; in init_particle()
266 p->vz *= velocity; in init_particle()
268 // Color is time-varying in init_particle()
269 p->r = 0.7f + 0.3f * (float) sin(0.34 * t + 0.1); in init_particle()
270 p->g = 0.6f + 0.4f * (float) sin(0.63 * t + 1.1); in init_particle()
271 p->b = 0.6f + 0.4f * (float) sin(0.91 * t + 2.1); in init_particle()
278 glow_color[0] = p->r; in init_particle()
279 glow_color[1] = p->g; in init_particle()
280 glow_color[2] = p->b; in init_particle()
283 // The particle is new-born and active in init_particle()
284 p->life = 1.f; in init_particle()
285 p->active = 1; in init_particle()
298 if (!p->active) in update_particle()
302 p->life -= dt * (1.f / LIFE_SPAN); in update_particle()
305 if (p->life <= 0.f) in update_particle()
307 p->active = 0; in update_particle()
312 p->vz = p->vz - GRAVITY * dt; in update_particle()
315 p->x = p->x + p->vx * dt; in update_particle()
316 p->y = p->y + p->vy * dt; in update_particle()
317 p->z = p->z + p->vz * dt; in update_particle()
320 if (p->vz < 0.f) in update_particle()
322 // Particles should bounce on the fountain (with friction) in update_particle()
323 if ((p->x * p->x + p->y * p->y) < FOUNTAIN_R2 && in update_particle()
324 p->z < (FOUNTAIN_HEIGHT + PARTICLE_SIZE / 2)) in update_particle()
326 p->vz = -FRICTION * p->vz; in update_particle()
327 p->z = FOUNTAIN_HEIGHT + PARTICLE_SIZE / 2 + in update_particle()
329 PARTICLE_SIZE / 2 - p->z); in update_particle()
332 // Particles should bounce on the floor (with friction) in update_particle()
333 else if (p->z < PARTICLE_SIZE / 2) in update_particle()
335 p->vz = -FRICTION * p->vz; in update_particle()
336 p->z = PARTICLE_SIZE / 2 + in update_particle()
337 FRICTION * (PARTICLE_SIZE / 2 - p->z); in update_particle()
352 // Update particles (iterated several times per frame if dt is too large) in particle_engine()
359 update_particle(&particles[i], dt2); in particle_engine()
366 min_age -= BIRTH_INTERVAL; in particle_engine()
371 if (!particles[i].active) in particle_engine()
373 init_particle(&particles[i], t + min_age); in particle_engine()
374 update_particle(&particles[i], min_age); in particle_engine()
380 dt -= dt2; in particle_engine()
386 // Draw all active particles. We use OpenGL 1.1 vertex
390 #define BATCH_PARTICLES 70 // Number of particles to draw in each batch
408 // always faces the viewer (is coplanar with the view-plane). in draw_particles()
413 // Note that 1) and 2) is the same for all particles (done only once). in draw_particles()
424 // (-1,-1,0), and the lower right corner, PARTICLE_SIZE/2 * (1,-1,0). in draw_particles()
427 quad_lower_left.x = (-PARTICLE_SIZE / 2) * (mat[0] + mat[1]); in draw_particles()
428 quad_lower_left.y = (-PARTICLE_SIZE / 2) * (mat[4] + mat[5]); in draw_particles()
429 quad_lower_left.z = (-PARTICLE_SIZE / 2) * (mat[8] + mat[9]); in draw_particles()
430 quad_lower_right.x = (PARTICLE_SIZE / 2) * (mat[0] - mat[1]); in draw_particles()
431 quad_lower_right.y = (PARTICLE_SIZE / 2) * (mat[4] - mat[5]); in draw_particles()
432 quad_lower_right.z = (PARTICLE_SIZE / 2) * (mat[8] - mat[9]); in draw_particles()
434 // Don't update z-buffer, since all particles are transparent! in draw_particles()
475 // Loop through all particles and build vertex arrays. in draw_particles()
478 pptr = particles; in draw_particles()
482 if (pptr->active) in draw_particles()
486 alpha = 4.f * pptr->life; in draw_particles()
490 // Convert color from float to 8-bit (store it in a 32-bit in draw_particles()
492 ((GLubyte*) &rgba)[0] = (GLubyte)(pptr->r * 255.f); in draw_particles()
493 ((GLubyte*) &rgba)[1] = (GLubyte)(pptr->g * 255.f); in draw_particles()
494 ((GLubyte*) &rgba)[2] = (GLubyte)(pptr->b * 255.f); in draw_particles()
502 vptr->s = 0.f; in draw_particles()
503 vptr->t = 0.f; in draw_particles()
504 vptr->rgba = rgba; in draw_particles()
505 vptr->x = pptr->x + quad_lower_left.x; in draw_particles()
506 vptr->y = pptr->y + quad_lower_left.y; in draw_particles()
507 vptr->z = pptr->z + quad_lower_left.z; in draw_particles()
511 vptr->s = 1.f; in draw_particles()
512 vptr->t = 0.f; in draw_particles()
513 vptr->rgba = rgba; in draw_particles()
514 vptr->x = pptr->x + quad_lower_right.x; in draw_particles()
515 vptr->y = pptr->y + quad_lower_right.y; in draw_particles()
516 vptr->z = pptr->z + quad_lower_right.z; in draw_particles()
520 vptr->s = 1.f; in draw_particles()
521 vptr->t = 1.f; in draw_particles()
522 vptr->rgba = rgba; in draw_particles()
523 vptr->x = pptr->x - quad_lower_left.x; in draw_particles()
524 vptr->y = pptr->y - quad_lower_left.y; in draw_particles()
525 vptr->z = pptr->z - quad_lower_left.z; in draw_particles()
529 vptr->s = 0.f; in draw_particles()
530 vptr->t = 1.f; in draw_particles()
531 vptr->rgba = rgba; in draw_particles()
532 vptr->x = pptr->x - quad_lower_right.x; in draw_particles()
533 vptr->y = pptr->y - quad_lower_right.y; in draw_particles()
534 vptr->z = pptr->z - quad_lower_right.z; in draw_particles()
537 // Increase count of drawable particles in draw_particles()
541 // If we have filled up one batch of particles, draw it as a set in draw_particles()
561 // Draw final batch of particles (if any) in draw_particles()
582 #define FOUNTAIN_SWEEP_STEPS 32
595 1.0000f, 0.0000f, 0.3420f,-0.9397f, 0.4226f,-0.9063f, 0.5000f,-0.8660f,
596 0.7660f,-0.6428f, 0.9063f,-0.4226f, 0.0000f,1.00000f, 0.0000f,1.00000f,
623 for (n = 0; n < FOUNTAIN_SIDE_POINTS - 1; n++) in draw_fountain()
729 tessellate_floor(-1.f, -1.f, 0.f, 0.f, 0); in draw_floor()
730 tessellate_floor( 0.f, -1.f, 1.f, 0.f, 0); in draw_floor()
732 tessellate_floor(-1.f, 0.f, 0.f, 1.f, 0); in draw_floor()
755 l1pos[0] = 0.f; l1pos[1] = -9.f; l1pos[2] = 8.f; l1pos[3] = 1.f; in setup_lights()
761 l2pos[0] = -15.f; l2pos[1] = 12.f; l2pos[2] = 1.5f; l2pos[3] = 1.f; in setup_lights()
795 // Calculate frame-to-frame delta time in draw_scene()
796 dt = (float) (t - t_old); in draw_scene()
815 angle_x = 90.0 - 10.0; in draw_scene()
818 glRotated(-angle_x, 1.0, 0.0, 0.0); in draw_scene()
819 glRotated(-angle_y, 0.0, 1.0, 0.0); in draw_scene()
820 glRotated(-angle_z, 0.0, 0.0, 1.0); in draw_scene()
825 ypos = -15.0 * cos((M_PI / 180.0) * angle_z) + in draw_scene()
828 glTranslated(-xpos, -ypos, -zpos); in draw_scene()
853 // Particles must be drawn after all solid objects have been drawn in draw_scene()
856 // Z-buffer not needed anymore in draw_scene()
924 // Update particles in physics_thread_main()
956 while ((ch = getopt(argc, argv, "fh")) != -1) in main()
973 glfwWindowHint(GLFW_RED_BITS, mode->redBits); in main()
974 glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits); in main()
975 glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits); in main()
976 glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate); in main()
978 width = mode->width; in main()
979 height = mode->height; in main()