예제 #1
0
void render_objectMatrix () {	
	int i;
	tParticle *myParticle;
	
	local = (objectMatrix_section *) mySection->vars;
	
	// Insert the default section values into the size equation
	insertSectionVariables(&local->myParticleSystem->Evaluator);
	insertSectionVariables(&local->myParticleSystem->rate);
		
	particles_generate(local->myParticleSystem);
	particles_update  (local->myParticleSystem);

	if (local->myParticleSystem->particlesCount <= 0) return;
	
	if (local->myParticleSystem->disableDepthTest > 0) glDisable(GL_DEPTH_TEST);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	
		// place the sources
		place_object (&local->myParticleSystem->Sources);
		
		// Render the objects instead of the particle system's particles
		myParticle = local->myParticleSystem->firstParticle;
	
		for (i = 0; i < local->myParticleSystem->particlesCount; i++) {
			if (myParticle->life <= 0.0f) // skip dead particles
				continue;
		
			// glColor4d(myParticle->red, myParticle->green, myParticle->blue, myParticle->alpha);
				
			glPushMatrix();

				glTranslated (myParticle->position.x, myParticle->position.y, myParticle->position.z);
				glRotated    (myParticle->rotation.x, 1, 0, 0);
				glRotated    (myParticle->rotation.y, 0, 1, 0);
				glRotated    (myParticle->rotation.z, 0, 0, 1);
				glScaled     (myParticle->size*myParticle->scale.x, myParticle->size*myParticle->scale.y, myParticle->size*myParticle->scale.z);	
			
				render_objectLayers (local->obj_part, local->layers, local->myParticleSystem->disableDepthTest);
			
			glPopMatrix();
			
		myParticle = myParticle->nextParticle;
	}
		
	if (local->myParticleSystem->disableDepthTest == 1)
		glEnable(GL_DEPTH_TEST);
			
	glPopMatrix();
}
예제 #2
0
void metaballs_update() {

  camera* cam = entity_get("camera");
  light* sun = entity_get("sun");

  Uint8 keystate = SDL_GetMouseState(NULL, NULL);
  if(keystate & SDL_BUTTON(1)){
    float a1 = -(float)mouse_x * frame_time() * 0.25;
    float a2 = (float)mouse_y * frame_time() * 0.25;
    
    cam->position = v3_sub(cam->position, cam->target);
    cam->position = m33_mul_v3(m33_rotation_y( a1 ), cam->position );
    cam->position = v3_add(cam->position, cam->target);
    
    cam->position = v3_sub(cam->position, cam->target);
    vector3 rotation_axis = v3_normalize(v3_cross( v3_sub(cam->position, v3_zero()) , v3(0,1,0) ));
    cam->position = m33_mul_v3(m33_rotation_axis_angle(rotation_axis, a2 ), cam->position );
    cam->position = v3_add(cam->position, cam->target);
  }
  
  if(keystate & SDL_BUTTON(3)){
    sun->position.x += (float)mouse_y / 2;
    sun->position.z -= (float)mouse_x / 2;
  }

  mouse_x = 0;
  mouse_y = 0;

  particles_update(frame_time());
  
  ui_button* framerate = ui_elem_get("framerate");
  ui_button_set_label(framerate, frame_rate_string());
  
#ifdef MARCHING_CUBES
  marching_cubes_metaball_data( particle_positions_memory(), particles_count() );
  marching_cubes_clear();
  marching_cubes_update();
#endif

#ifdef VOLUME_RENDERER
  volume_renderer_metaball_data( particle_positions_memory(), particles_count() );
  volume_renderer_update();
#endif
  
}
예제 #3
0
파일: particles.c 프로젝트: naclander/tome
// Runs on particles thread
void thread_particle_run(particle_thread *pt, plist *l)
{
	lua_State *L = pt->L;
	particles_type *ps = l->ps;
	if (!ps || !ps->l || !ps->init || !ps->alive || ps->i_want_to_die) return;

	if (setjmp(pt->panicjump) == 0) {
		// Update
		lua_getglobal(L, "__fcts");
		lua_pushnumber(L, l->updator_ref);
		lua_rawget(L, -2);
		lua_pushnumber(L, l->emit_ref);
		lua_rawget(L, -3);

		if (!lua_isfunction(L, -2) || !lua_istable(L, -1)) {
	//		printf("L(%x) Particle updater error %x (%d, %d) is nil: %s / %s\n", (int)L, (int)l, l->updator_ref, l->emit_ref, lua_tostring(L, -1), lua_tostring(L, -2));
			lua_pop(L, 2);
		}
		else {
			bool run = FALSE;
			lua_pushstring(L, "ps");
			lua_rawget(L, -2);
			if (!lua_isnil(L, -1)) run = TRUE;
			lua_pop(L, 1);

			if (run) {
				if (lua_pcall(L, 1, 0, 0))
				{
	//				printf("L(%x) Particle updater error %x (%d, %d): %s\n", (int)L, (int)l, l->updator_ref, l->emit_ref, lua_tostring(L, -1));
	//				ps->i_want_to_die = TRUE;
					lua_pop(L, 1);
				}
			}
		}
		lua_pop(L, 1); // global table

		particles_update(L, ps, TRUE);
	} else {
		// We panic'ed! This particule is borked and needs to die
		ps->i_want_to_die = TRUE;
	}
}
예제 #4
0
int dgreed_main(int argc, const char** argv) {
	log_init("pview.log", LOG_LEVEL_INFO);
	video_init(800, 600, "PView");
	rand_init(666);

	GuiDesc style = greed_gui_style(false);

	gui_init(&style);
	particles_init("greed_assets/", 5);

	TexHandle empty = tex_load("greed_assets/empty.png");

	if(psystem_descs_count < 1) 
		LOG_ERROR("No particle systems described!");
	
	int active_backg = 0;
	int active_desc = 0;
	const char* active_desc_name = psystem_descs[active_desc].name;

	RectF gui_area = rectf(0.0f, 0.0f, 520.0f, 80.0f);		
	RectF gui_area2 = rectf(0.0f, 500.0f, 280.0f, 600.0f);
	Vector2 button_prev_pos = vec2(10.0f, 10.0f);
	Vector2 button_next_pos = vec2(280.0f, 10.0f);
	Vector2 button_backg_pos = vec2(10.0f, 550.0f);
	Vector2 label_name_pos = vec2(20.0f, 60.0f);
	char label_text[256];
	
	while(system_update()) {
		RectF src = rectf_null();
		RectF dest = {0.0f, 0.0f, EDITOR_WIDTH, EDITOR_HEIGHT};
		Color c = backgrounds[active_backg % ARRAY_SIZE(backgrounds)];
		video_draw_rect(empty, 0, &src, &dest, c);
		if(mouse_down(MBTN_LEFT)) {
			uint x, y;
			mouse_pos(&x, &y);
			Vector2 pos = vec2((float)x, (float)y);
			if(!rectf_contains_point(&gui_area, &pos))
				if(!rectf_contains_point(&gui_area2, &pos))
					particles_spawn(active_desc_name, &pos, 0.0f);
		}	

		particles_update(time_ms() / 1000.0f);

		sprintf(label_text, "Current psystem: %s", active_desc_name);
		gui_label(&label_name_pos, label_text); 	
		if(gui_button(&button_prev_pos, "Previuos")) 
			active_desc = MAX(0, active_desc-1);
		if(gui_button(&button_next_pos, "Next"))
			active_desc = MIN(psystem_descs_count-1, active_desc+1);
		if(gui_button(&button_backg_pos, "Background color"))
				active_backg++;
		active_desc_name = psystem_descs[active_desc].name;	

		particles_draw();
		draw_grid(0, 12.0f);

		video_present();
	}	

	tex_free(empty);
	particles_close();
	gui_close();
	greed_gui_free();
	video_close();
	
	log_close();
	return 0;
}
예제 #5
0
파일: skios.c 프로젝트: ryonagana/skios2
int game_loop(){


    unsigned redraw = 0;

    game_rect t;
    rect_Zero(&t);
    sprite_sheet = gamespr_create("ski1.bmp");

    animation_init();
    init_player();
    start_new_game(0);


    while(!mainloop){

        ALLEGRO_EVENT e;
        ALLEGRO_TIMEOUT timeout;
        int i;

        al_init_timeout(&timeout, 0.06);

        bool  late = al_wait_for_event_until(g_queue, &e, &timeout);





        if(late){
            switch(e.type){
                case ALLEGRO_EVENT_DISPLAY_CLOSE:
                    mainloop = 1;
                    break;

                 case ALLEGRO_EVENT_KEY_UP:
                        player_poll_kbd_up(&e);
                 break;

                 case ALLEGRO_EVENT_KEY_DOWN:
                        player_poll_kbd_dn(&e);
                 break;

                case ALLEGRO_EVENT_TIMER:

                /* main clock updates 1/60ms (60FPS LOCK) */
                    if(e.timer.source == g_timer){
                        particle_list = particles_clean(particle_list, 0);
                        particles_update(particle_list);
                        player_update_screen();
                        player_update(&ski_player, &playfield);



                        for(i = 1; i < MAX_SPRITES; i++){
                           update_enemy(i);
                        }

                        update_enemy_behavior(gobj_list, &playfield);

                        redraw =  1;
                    }

                     /* update for the chronomenter run every 100ms only) */
                    if( e.timer.source == timer_chrono){
                        HUD_UpdateChrono();
                        DMSG("%d", al_get_timer_count(timer_chrono));




                    }

                    break;
            }


            if( redraw == 1 && al_event_queue_is_empty(g_queue)){
                    redraw = 0;
                    al_clear_to_color(WHITE_COLOR);


                    particles_draw(NULL, particle_list);
                    player_draw(ski_player.object->position.x, ski_player.object->position.y );

                    for(i = 1; i < MAX_OBJECTS; i++){
                         int enemy_type = gobj_list[i].type;
                         draw_enemy(enemy_type, i, 0,0, gobj_list[i].position.x, gobj_list[i].position.y, 32,32);

                    }

                    HUD_create_stats_box();
                    al_flip_display();
            }
        }

    }

    HUD_destroy();
    unload_spritesheets();
    window_deinit();
    particle_list = particles_clean(particle_list, PARTICLES_ALL_CLEAN);
    return EXIT_SUCCESS;
}