/* External functions
 */
Game* create_game(void)
{
    int ii;
    Game* G = (Game*)calloc(1, sizeof(Game));
    G->timer = create_timer();
    G->graphics = create_graphics();
    G->ui = create_ui(G->graphics);

    /* Set up camera */
    G->camera = transform_zero;
    G->camera.orientation = quat_from_euler(0, -0.75f * kPi, 0);
    G->camera.position.x = 4.0f;
    G->camera.position.y = 2;
    G->camera.position.z = 7.5f;

    /* Load scene */
    reset_timer(G->timer);
    G->scene = create_scene("lightHouse.obj");
    G->sun_light.position = vec3_create(-4.0f, 5.0f, 2.0f);
    G->sun_light.color = vec3_create(1, 1, 1);
    G->sun_light.size = 35.0f;

    G->lights[0].color = vec3_create(1, 0, 0);
    G->lights[1].color = vec3_create(1, 1, 0);
    G->lights[2].color = vec3_create(0, 1, 0);
    G->lights[3].color = vec3_create(1, 0, 1);
    G->lights[4].color = vec3_create(0, 0, 1);
    G->lights[5].color = vec3_create(0, 1, 1);

    for(ii=0;ii<NUM_LIGHTS;++ii) {
        float x = (20.0f/NUM_LIGHTS) * ii - 8.0f;
        G->lights[ii].color = vec3_create(_rand_float(), _rand_float(), _rand_float());
        G->lights[ii].color = vec3_normalize(G->lights[ii].color);
        if(ii % 2)
            G->lights[ii].position = vec3_create(x, _rand_float()*3 + 2.0f, 0.0f);
        else
            G->lights[ii].position = vec3_create(0.0f, _rand_float()*3 + 2.0f, x);
        G->lights[ii].size = 5;
    }

    get_model(G->scene, 3)->material->specular_color = vec3_create(0.5f, 0.5f, 0.5f);
    get_model(G->scene, 3)->material->specular_coefficient = 1.0f;

    G->dynamic_lights = 1;

    reset_timer(G->timer);
    return G;
}
Exemplo n.º 2
0
void display_render_io_process(struct s_vm* vm, t_display* display)
{
	t_v4	color_io_process;
	t_v4	color_ambient;
	t_v3	light_direction;
	t_mat4	local;
	t_mat4	translate;
	t_mat4	rotation;
	t_quat	quat;
	int		i;

	v4_set(&color_io_process, 0.4f, 0.4f, 1.0f, 0.0f);
	v4_set(&color_ambient, 0.2f, 0.2f, 0.2f, 1.0f);
	v3_set(&light_direction, 0, 0, -1.0f);


	display_mesh_render_start(display->mesh_renderer, MESH_TYPE_VN);
	display_mesh_set_ambient(display->mesh_renderer, &color_ambient);
	display_mesh_set_light_direction(display->mesh_renderer, &light_direction);
	display_mesh_set_diffuse(display->mesh_renderer, &color_io_process);
	display_mesh_set_projection(display->mesh_renderer, &display->projection_view);
	mat4_ident(&local);

	for (i = 0; i < vm->process_count; ++i)
	{
		t_process* process = vm->processes[i];
		float angle = (float)process->cycle_create + (float)display->frame_last_time ;

		int index = process->pc;
		float x = (float) (index % display->memory_stride);
		float y = (float) (index / display->memory_stride);

		x = x * DISPLAY_CELL_SIZE + DISPLAY_CELL_SIZE * 0.5f;
		y = y * DISPLAY_CELL_SIZE + DISPLAY_CELL_SIZE * 0.5f;

		mat4_ident(&translate);
		mat4_translate(&translate, x, y, DISPLAY_CELL_SIZE * 0.5f);

		quat_from_euler(&quat, angle, angle, angle);
		quat_to_mat4(&quat, &rotation);

		mat4_mul(&translate, &rotation, &local);

		display_mesh_set_local(display->mesh_renderer, &local);

		display_mesh_render(display->process_mesh);
	}
}