|
|
@ -90,45 +90,34 @@ void scene_setup(void) |
|
|
|
struct Entity* player = scene_add_new("player", ET_CAMERA); |
|
|
|
struct Entity* player = scene_add_new("player", ET_CAMERA); |
|
|
|
game_state->player_node = player->id; |
|
|
|
game_state->player_node = player->id; |
|
|
|
vec3 viewer_pos = {10, 5, 100}; |
|
|
|
vec3 viewer_pos = {10, 5, 100}; |
|
|
|
struct Transform* viewer_tran = &player->transform; |
|
|
|
transform_set_position(player, &viewer_pos); |
|
|
|
/* struct Model* player_model = entity_component_add(player, C_MODEL, "sphere.pamesh", NULL); */ |
|
|
|
|
|
|
|
/* model_set_material_param(player_model, "diffuse_color", &color); */ |
|
|
|
|
|
|
|
/* vec4_fill(&color, 1.f, 1.f, 1.f, 1.f); */ |
|
|
|
|
|
|
|
transform_set_position(viewer_tran, &viewer_pos); |
|
|
|
|
|
|
|
int render_width, render_height; |
|
|
|
int render_width, render_height; |
|
|
|
render_width = 1024; |
|
|
|
render_width = 1024; |
|
|
|
render_height = 768; |
|
|
|
render_height = 768; |
|
|
|
struct Camera* camera = &player->camera; |
|
|
|
camera_create(player, render_width, render_height); |
|
|
|
camera_create(camera, &player->transform, render_width, render_height); |
|
|
|
camera_attach_fbo(player, render_width, render_height, 1, 1, 1); |
|
|
|
camera_attach_fbo(camera, render_width, render_height, 1, 1, 1); |
|
|
|
vec4_fill(&player->camera.clear_color, 0.3f, 0.6f, 0.9f, 1.0f); |
|
|
|
vec4_fill(&camera->clear_color, 0.3f, 0.6f, 0.9f, 1.0f); |
|
|
|
|
|
|
|
sound_listener_set(player->id); |
|
|
|
sound_listener_set(player->id); |
|
|
|
|
|
|
|
|
|
|
|
vec4 color = {0.f, 1.f, 1.f, 1.f }; |
|
|
|
vec4 color = {0.f, 1.f, 1.f, 1.f }; |
|
|
|
struct Entity* new_ent = scene_add_new("Model_Entity", ET_STATIC_MESH); |
|
|
|
struct Entity* new_ent = scene_add_new("Model_Entity", ET_STATIC_MESH); |
|
|
|
struct Transform* tran = &new_ent->transform; |
|
|
|
|
|
|
|
vec3 position = {0, 0, -5}; |
|
|
|
vec3 position = {0, 0, -5}; |
|
|
|
transform_translate(tran, &position, TS_WORLD); |
|
|
|
transform_translate(new_ent, &position, TS_WORLD); |
|
|
|
struct Model* box_model = &new_ent->model; |
|
|
|
|
|
|
|
new_ent->renderable = true; |
|
|
|
new_ent->renderable = true; |
|
|
|
model_create(box_model, new_ent->id, "default.pamesh", "Blinn_Phong"); |
|
|
|
model_create(new_ent, "default.pamesh", "Blinn_Phong"); |
|
|
|
model_set_material_param(box_model, "diffuse_color", &color); |
|
|
|
model_set_material_param(new_ent, "diffuse_color", &color); |
|
|
|
int tex = texture_create_from_file("white.tga", TU_DIFFUSE); |
|
|
|
int tex = texture_create_from_file("white.tga", TU_DIFFUSE); |
|
|
|
model_set_material_param(box_model, "diffuse_texture", &tex); |
|
|
|
model_set_material_param(new_ent, "diffuse_texture", &tex); |
|
|
|
vec3 scale = {1, 1, 1}; |
|
|
|
vec3 scale = {1, 1, 1}; |
|
|
|
transform_scale(tran, &scale); |
|
|
|
transform_scale(new_ent, &scale); |
|
|
|
|
|
|
|
|
|
|
|
struct Entity* sound_ent = scene_add_as_child("Sound_ENT", ET_SOUND_SOURCE, new_ent->id); |
|
|
|
struct Entity* sound_ent = scene_add_as_child("Sound_ENT", ET_SOUND_SOURCE, new_ent->id); |
|
|
|
struct Sound_Source* source = &sound_ent->sound_source; |
|
|
|
sound_source_create(sound_ent, false); |
|
|
|
sound_source_create(source, &new_ent->transform); |
|
|
|
sound_source_load_wav(sound_ent, "BigExplosion.wav"); |
|
|
|
if(source) |
|
|
|
//sound_source_relative_set(source, true);
|
|
|
|
{ |
|
|
|
sound_source_volume_set(sound_ent, 1.f); |
|
|
|
sound_source_load_wav(source, "BigExplosion.wav"); |
|
|
|
sound_source_loop_set(sound_ent, true); |
|
|
|
//sound_source_relative_set(source, 1);
|
|
|
|
sound_source_play(sound_ent); |
|
|
|
sound_source_volume_set(source, 1.f); |
|
|
|
|
|
|
|
sound_source_loop_set(source, 1); |
|
|
|
|
|
|
|
sound_source_play(source); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int parent_node = new_ent->id; |
|
|
|
int parent_node = new_ent->id; |
|
|
|
int num_suz = 20; |
|
|
|
int num_suz = 20; |
|
|
@ -142,29 +131,27 @@ void scene_setup(void) |
|
|
|
//struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node);
|
|
|
|
//struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node);
|
|
|
|
struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH); |
|
|
|
struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH); |
|
|
|
suz->renderable = true; |
|
|
|
suz->renderable = true; |
|
|
|
struct Model* suz_model = &suz->model; |
|
|
|
model_create(suz, "suzanne.pamesh", "Blinn_Phong"); |
|
|
|
model_create(suz_model, suz->id, "suzanne.pamesh", "Blinn_Phong"); |
|
|
|
model_set_material_param(suz, "diffuse_color", &color); |
|
|
|
model_set_material_param(suz_model, "diffuse_color", &color); |
|
|
|
|
|
|
|
float spec_str = 80.f; |
|
|
|
float spec_str = 80.f; |
|
|
|
model_set_material_param(suz_model, "specular_strength", &spec_str); |
|
|
|
model_set_material_param(suz, "specular_strength", &spec_str); |
|
|
|
vec3 s_pos = {x, 5, z}; |
|
|
|
vec3 s_pos = {x, 5, z}; |
|
|
|
transform_translate(&suz->transform, &s_pos, TS_WORLD); |
|
|
|
transform_translate(suz, &s_pos, TS_WORLD); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Entity* ground = scene_add_new("Ground", ET_STATIC_MESH); |
|
|
|
struct Entity* ground = scene_add_new("Ground", ET_STATIC_MESH); |
|
|
|
ground->renderable = true; |
|
|
|
ground->renderable = true; |
|
|
|
struct Model* ground_model = &ground->model; |
|
|
|
model_create(ground, "default.pamesh", "Blinn_Phong"); |
|
|
|
model_create(ground_model, ground->id, "default.pamesh", "Blinn_Phong"); |
|
|
|
model_set_material_param(ground, "diffuse_color", &color); |
|
|
|
model_set_material_param(ground_model, "diffuse_color", &color); |
|
|
|
|
|
|
|
int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE); |
|
|
|
int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE); |
|
|
|
model_set_material_param(ground_model, "diffuse_texture", &white_tex); |
|
|
|
model_set_material_param(ground, "diffuse_texture", &white_tex); |
|
|
|
float spec_str = 80.f; |
|
|
|
float spec_str = 80.f; |
|
|
|
model_set_material_param(ground_model, "specular_strength", &spec_str); |
|
|
|
model_set_material_param(ground, "specular_strength", &spec_str); |
|
|
|
vec3 pos = {0, -15, 0}; |
|
|
|
vec3 pos = {0, -15, 0}; |
|
|
|
vec3 scale_ground = {100.f, 2.f, 100.f}; |
|
|
|
vec3 scale_ground = {100.f, 2.f, 100.f}; |
|
|
|
transform_set_position(&ground->transform, &pos); |
|
|
|
transform_set_position(ground, &pos); |
|
|
|
transform_scale(&ground->transform, &scale_ground); |
|
|
|
transform_scale(ground, &scale_ground); |
|
|
|
|
|
|
|
|
|
|
|
/* struct Entity* screen = scene_add_new("Screen", NULL); */ |
|
|
|
/* struct Entity* screen = scene_add_new("Screen", NULL); */ |
|
|
|
/* struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); */ |
|
|
|
/* struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); */ |
|
|
@ -188,11 +175,10 @@ void scene_setup(void) |
|
|
|
x++; z++; |
|
|
|
x++; z++; |
|
|
|
struct Entity* light_ent = scene_add_new("Light_Ent", ET_LIGHT); |
|
|
|
struct Entity* light_ent = scene_add_new("Light_Ent", ET_LIGHT); |
|
|
|
vec3 lt_pos = {x * 20, 0, z * 20}; |
|
|
|
vec3 lt_pos = {x * 20, 0, z * 20}; |
|
|
|
transform_set_position(&light_ent->transform, <_pos); |
|
|
|
transform_set_position(light_ent, <_pos); |
|
|
|
struct Light* light_comp = &light_ent->light; |
|
|
|
light_create(light_ent, LT_POINT); |
|
|
|
light_create(&light_ent->light, light_ent->id, LT_POINT); |
|
|
|
vec3_fill(&light_ent->light.color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z); |
|
|
|
vec3_fill(&light_comp->color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z); |
|
|
|
light_ent->light.intensity = 1.f; |
|
|
|
light_comp->intensity = 1.f; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* struct Entity* sun = scene_add_new("Sun", NULL); */ |
|
|
|
/* struct Entity* sun = scene_add_new("Sun", NULL); */ |
|
|
@ -204,8 +190,6 @@ void debug(float dt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//struct Entity* entity = entity_get(player_node);
|
|
|
|
//struct Entity* entity = entity_get(player_node);
|
|
|
|
struct Entity* entity = entity_get(game_state->player_node); |
|
|
|
struct Entity* entity = entity_get(game_state->player_node); |
|
|
|
struct Camera* cam = &entity->camera; |
|
|
|
|
|
|
|
struct Transform* transform = &entity->transform; |
|
|
|
|
|
|
|
float move_speed = 5.f, move_scale = 3.f, turn_speed = 50.f; |
|
|
|
float move_speed = 5.f, move_scale = 3.f, turn_speed = 50.f; |
|
|
|
vec3 offset = {0, 0, 0}; |
|
|
|
vec3 offset = {0, 0, 0}; |
|
|
|
float turn_up_down = 0.f; |
|
|
|
float turn_up_down = 0.f; |
|
|
@ -252,25 +236,25 @@ void debug(float dt) |
|
|
|
|
|
|
|
|
|
|
|
if(turn_left_right != 0.f) |
|
|
|
if(turn_left_right != 0.f) |
|
|
|
{ |
|
|
|
{ |
|
|
|
transform_rotate(transform, &rot_axis_left_right, -turn_left_right, TS_WORLD); |
|
|
|
transform_rotate(entity, &rot_axis_left_right, -turn_left_right, TS_WORLD); |
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
transform_get_up(transform, &up); |
|
|
|
transform_get_up(entity, &up); |
|
|
|
transform_get_forward(transform, &forward); |
|
|
|
transform_get_forward(entity, &forward); |
|
|
|
transform_get_lookat(transform, &lookat); |
|
|
|
transform_get_lookat(entity, &lookat); |
|
|
|
/* log_message("Up : %s", tostr_vec3(&up)); */ |
|
|
|
/* log_message("Up : %s", tostr_vec3(&up)); */ |
|
|
|
/* log_message("FR : %s", tostr_vec3(&forward)); */ |
|
|
|
/* log_message("FR : %s", tostr_vec3(&forward)); */ |
|
|
|
} |
|
|
|
} |
|
|
|
if(turn_up_down != 0.f) |
|
|
|
if(turn_up_down != 0.f) |
|
|
|
{ |
|
|
|
{ |
|
|
|
transform_rotate(transform, &rot_axis_up_down, turn_up_down, TS_LOCAL); |
|
|
|
transform_rotate(entity, &rot_axis_up_down, turn_up_down, TS_LOCAL); |
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
transform_get_up(transform, &up); |
|
|
|
transform_get_up(entity, &up); |
|
|
|
transform_get_forward(transform, &forward); |
|
|
|
transform_get_forward(entity, &forward); |
|
|
|
transform_get_lookat(transform, &lookat); |
|
|
|
transform_get_lookat(entity, &lookat); |
|
|
|
/* log_message("Up : %s", tostr_vec3(&up)); */ |
|
|
|
/* log_message("Up : %s", tostr_vec3(&up)); */ |
|
|
|
/* log_message("FR : %s", tostr_vec3(&forward)); */ |
|
|
|
/* log_message("FR : %s", tostr_vec3(&forward)); */ |
|
|
|
} |
|
|
|
} |
|
|
@ -287,7 +271,7 @@ void debug(float dt) |
|
|
|
vec3_scale(&offset, &offset, dt); |
|
|
|
vec3_scale(&offset, &offset, dt); |
|
|
|
if(offset.x != 0 || offset.y != 0 || offset.z != 0) |
|
|
|
if(offset.x != 0 || offset.y != 0 || offset.z != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
transform_translate(transform, &offset, TS_LOCAL); |
|
|
|
transform_translate(entity, &offset, TS_LOCAL); |
|
|
|
//log_message("Position : %s", tostr_vec3(&transform->position));
|
|
|
|
//log_message("Position : %s", tostr_vec3(&transform->position));
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -295,7 +279,7 @@ void debug(float dt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct Entity* model = scene_find("Model_Entity"); |
|
|
|
struct Entity* model = scene_find("Model_Entity"); |
|
|
|
vec3 x_axis = {1, 0, 0}; |
|
|
|
vec3 x_axis = {1, 0, 0}; |
|
|
|
transform_rotate(&model->transform, &x_axis, 25.f * dt, TS_WORLD); |
|
|
|
transform_rotate(model, &x_axis, 25.f * dt, TS_WORLD); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(input_is_key_pressed(KEY_M)) |
|
|
|
if(input_is_key_pressed(KEY_M)) |
|
|
@ -304,7 +288,7 @@ void debug(float dt) |
|
|
|
//vec3 y_axis = {0, 0, 1};
|
|
|
|
//vec3 y_axis = {0, 0, 1};
|
|
|
|
//transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_LOCAL);
|
|
|
|
//transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_LOCAL);
|
|
|
|
vec3 amount = {0, 0, -5 * dt}; |
|
|
|
vec3 amount = {0, 0, -5 * dt}; |
|
|
|
transform_translate(&model->transform, &amount, TS_LOCAL); |
|
|
|
transform_translate(model, &amount, TS_LOCAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(input_is_key_pressed(KEY_N)) |
|
|
|
if(input_is_key_pressed(KEY_N)) |
|
|
@ -313,7 +297,7 @@ void debug(float dt) |
|
|
|
/* vec3 y_axis = {0, 0, 1}; */ |
|
|
|
/* vec3 y_axis = {0, 0, 1}; */ |
|
|
|
/* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */ |
|
|
|
/* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */ |
|
|
|
vec3 amount = {0, 0, 5 * dt}; |
|
|
|
vec3 amount = {0, 0, 5 * dt}; |
|
|
|
transform_translate(&model->transform, &amount, TS_LOCAL); |
|
|
|
transform_translate(model, &amount, TS_LOCAL); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|