예제 #1
0
파일: skios.c 프로젝트: ryonagana/skios2
static void start_new_game(int reset){
    if(reset){
        ski_player.health = 1;
        ski_player.is_jumping = 0;
        ski_player.angle = 0;
    }

    HUD_Init();
    ski_player.object = &gobj_list[0];
    gobj_list[0].active = 1;
    gobj_list[0].flags = 0;
    gobj_list[0].isAlive = 1;
    gobj_list[0].frames_total = 0;
    gobj_list[0].status = GOBJ_IDLE;
    gobj_list[0].type = 1;
    gobj_list[0].frame_actual = 1;

    playfield.direction = 0;
    playfield.race_begun = false;
    playfield.race_over = false;
    playfield.state = TERRAIN_STOP;

    memset(&key_states, 0, sizeof(int) * 6);
    control_default(&player_control[0]);
    init_playfield(&playfield);

    /* lets garantee that particle is NULL;
     */
    particle_list =  NULL;
    particle_list = particles_clean(particle_list, PARTICLES_OLD_CLEAN);
    particles_init();


}
예제 #2
0
/* MAIN */
int main(int argc, char** argv) {
  
  srand(time(NULL));

  particle particles[P_NUM];
  
  float global_best[SPACE_DIM];

  // Set shifted origin to some place 
  for(int i=0; i<SPACE_DIM; ++i)
    shifted_origin[i] = 83; 
  
  // Init every particle
  for(int i=0; i<P_NUM; ++i)
    particles_init(particles[i]);
  
  for(int i=0; i<COMPUTATIONS; ++i) {
    for(int pos=0; pos<P_NUM; ++pos) {
      for(int direction=0; direction<SPACE_DIM; ++direction) {
	// Compute new position with damping if needed
	particles[pos].position[direction] = particles[pos].position[direction] + particles[pos].vel[direction];
	if(particles[pos].position[direction] < 100 || particles[pos].position[direction] > 100) {
	  float damping_rand = (float)rand() / (float)RAND_MAX;
	  particles[pos].vel[direction] = -damping_rand * particles[pos].vel[direction];
	}
	// Compute new velocity
	float r1 = (float)rand() / (float)RAND_MAX;
	float r2 = (float)rand() / (float)RAND_MAX;
	particles[pos].vel[direction] = INERTIA*particles[pos].vel[direction] + 
	  r1 * C_SOC * (global_best[direction] - particles[pos].position[direction]) +
	  r2 * C_SOC * (particles[pos].personal_best[direction] - particles[pos].position[direction]);

	// Limit velocity
	if(particles[pos].vel[direction] > MAX_VEL)
	  particles[pos].vel[direction] = MAX_VEL;
	else if(particles[pos].vel[direction] < -MAX_VEL)
	  particles[pos].vel[direction] = -MAX_VEL;

	// If needed, update personal and global best
	if (f01(particles[pos].position) < f01(particles[pos].personal_best)) 
	  for(int k=0; k<SPACE_DIM; ++k)
	    particles[pos].personal_best[k] = particles[pos].position[k];
	if (f01(particles[pos].position) < f01(global_best)) 
	  for(int k=0; k<SPACE_DIM; ++k)
	    global_best[k] = particles[pos].position[k];
      }
    }
  }
  std::cout << "Global best : " << f01(global_best) << std::endl;

  std::cout << "Global optimum : (";
  for (int i=0; i<SPACE_DIM; ++i) {
    std::cout << global_best[i];
    if(i!=SPACE_DIM-1)
      std::cout << ", ";
  }
  std::cout << ")" << std::endl;
  return 0;
}
예제 #3
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;
}
예제 #4
0
void load_objectMatrix() {
	char *evalEquation;
	char *evalSources;
	size_t equationSize;
	H3dsMeshObj *mesh;
	int i;

	// script validation
	if (mySection->stringNum != 14) {
		section_error("14 strings needed");
		return;
	}

	local = malloc(sizeof(objectMatrix_section));
	memset(local, 0, sizeof(objectMatrix_section));

	local->myParticleSystem = particles_init(local->myParticleSystem);

	mySection->vars = (void *) local;

	// load the object that will server as sources
	local->object = model_load(mySection->strings[0], USE_CACHE);
	if (!local->object) {
		section_error("objectMatrix: Error loading object sources: %s", mySection->strings[0]);
		return;
	}
	// load the object that will server as particle (and the shader)
	local->obj_part = model_load(mySection->strings[2], USE_CACHE);
	if (!local->object) {
		section_error("objectMatrix: Error loading particle object: %s", mySection->strings[1]);
		return;
	}
	if (model_upload_tex(local->obj_part, mySection->strings[1]) == -1)
		return;
	
	// load layers for drawing the object
	local->layers = layers_load(mySection->strings[3]);
	
	if (mySection->param[0] > 0) {
		local->myParticleSystem->disableDepthTest = 1;
	} else {
		local->myParticleSystem->disableDepthTest = 0;
	}
	
	// Equation defining the rate at which the particles are created (particles created per second)
	local->myParticleSystem->rate.equation = mySection->strings[4];
	
	// We only take into account the first mesh as particle sources
	mesh = &local->object->meshobjlist[0];
	
	// Get and store the particle source positions
	local->myParticleSystem->sourcesCount = mesh->verts;
	local->myParticleSystem->sources      = (tVector *) malloc(sizeof(tVector) * mesh->verts);
	local->myParticleSystem->sourcesColor = (tColor  *) malloc(sizeof(tColor ) * mesh->verts);

	for (i=0; i<local->myParticleSystem->sourcesCount; i++) {
		local->myParticleSystem->sources[i].x = mesh->vertlist[i].x;
		local->myParticleSystem->sources[i].y = mesh->vertlist[i].y;
		local->myParticleSystem->sources[i].z = mesh->vertlist[i].z;
		
		local->myParticleSystem->sourcesColor[i].r = 1.0;
		local->myParticleSystem->sourcesColor[i].g = 1.0;
		local->myParticleSystem->sourcesColor[i].b = 1.0;
	}
	
	// Particle evaluator
	equationSize = strlen(mySection->strings[5]);
	equationSize += strlen(mySection->strings[6]);
	equationSize += strlen(mySection->strings[7]);
	equationSize += strlen(mySection->strings[8]);
	equationSize += strlen(mySection->strings[9]);
	equationSize += strlen(mySection->strings[10]);
	evalEquation = calloc(equationSize+1, sizeof(char));
	strcat(evalEquation, (char *) mySection->strings[5]);
	strcat(evalEquation, (char *) mySection->strings[6]);
	strcat(evalEquation, (char *) mySection->strings[7]);
	strcat(evalEquation, (char *) mySection->strings[8]);
	strcat(evalEquation, (char *) mySection->strings[9]);
	strcat(evalEquation, (char *) mySection->strings[10]);
	local->myParticleSystem->Evaluator.equation = evalEquation;
	
	// Sources evaluator
	equationSize  = strlen(mySection->strings[11]);
	equationSize += strlen(mySection->strings[12]);
	equationSize += strlen(mySection->strings[13]);
	evalSources = calloc(equationSize+1, sizeof(char));
	strcpy(evalSources, (char *) mySection->strings[11]); //-V525
	strcat(evalSources, (char *) mySection->strings[12]);
	strcat(evalSources, (char *) mySection->strings[13]);
	local->myParticleSystem->Sources.equation = evalSources;
	
	// Init the expression evaluation library
	initExpression(&local->myParticleSystem->Sources);
	initExpression(&local->myParticleSystem->Evaluator);
	initExpression(&local->myParticleSystem->rate);
	mySection->loaded=1;
}
예제 #5
0
void metaballs_init() {
  
  graphics_viewport_set_title("Metaballs");
  graphics_viewport_set_dimensions(1280, 720);
  graphics_set_multisamples(16);
  
#ifdef OPEN_GL_CPU
  kernels_init_with_cpu();
#else 
  kernels_init_with_opengl();
#endif
  
  asset_manager_handler(kernel_program, "cl", cl_load_file, kernel_program_delete);
  
  load_folder("./kernels/");
  
  particles_init();
  
  load_folder("./resources/podium/");
  load_folder("./resources/particles/");
  
  renderable* r_podium = asset_get("./resources/podium/podium.obj");
  renderable_set_material(r_podium, asset_get("./resources/podium/podium.mat"));
  
  static_object* s_podium = entity_new("podium", static_object);
  s_podium->renderable = r_podium;
  s_podium->position = v3(32, 10, 32);
  
  camera* cam = entity_new("camera", camera);
  cam->position = v3(50, 50, 50);
  cam->target = v3(32, 20, 32);
  
  light* sun = entity_new("sun", light);
  sun->position = v3(50,40,50);
  sun->ambient_color = v3(0.5, 0.5, 0.5);
  sun->diffuse_color = v3_mul(v3_one(), 2);
  sun->specular_color = v3_mul(v3_one(), 5);
  light_set_type(sun, light_type_spot);  
  
  ui_button* framerate = ui_elem_new("framerate", ui_button);
  ui_button_move(framerate, v2(10,10));
  ui_button_resize(framerate, v2(30,25));
  ui_button_set_label(framerate, "");
  ui_button_disable(framerate);
  
  ui_button* score = ui_elem_new("score", ui_button);
  ui_button_move(score, v2(50, 10));
#ifdef VOLUME_RENDERER
  ui_button_resize(score, v2(125, 25));
  ui_button_set_label(score, "Volume Renderer");
#endif
#ifdef MARCHING_CUBES
  ui_button_resize(score, v2(120, 25));
  ui_button_set_label(score, "Marching Cubes");
#endif
#ifndef VOLUME_RENDERER
#ifndef MARCHING_CUBES
  ui_button_resize(score, v2(80, 25));
  ui_button_set_label(score, "Particles");
#endif
#endif
  ui_button_disable(score);
  
#ifdef VOLUME_RENDERER
  volume_renderer_init();
  volume_renderer_set_camera(cam);
  volume_renderer_set_light(sun);
#endif
 
#ifdef MARCHING_CUBES
  shadow_mapper_init(sun);  
  
  forward_renderer_init();
  forward_renderer_set_camera(cam);
  forward_renderer_set_shadow_light(sun);
  forward_renderer_set_shadow_texture( shadow_mapper_depth_texture() );
  forward_renderer_add_light(sun);

  marching_cubes_init();
#endif
  
}