|
|
|
@ -69,31 +69,53 @@ void game_init(void) |
|
|
|
|
player_node = player->node; |
|
|
|
|
vec3 viewer_pos = {0, 0, 10}; |
|
|
|
|
struct Transform* viewer_tran = entity_component_get(player, C_TRANSFORM); |
|
|
|
|
transform_set_position(viewer_tran, viewer_pos); |
|
|
|
|
/* struct Entity* player_pitch = scene_add_as_child("player_pitch", NULL, player); */ |
|
|
|
|
/* player_pitch_node = player_pitch->node; */ |
|
|
|
|
/* entity_component_add(player_pitch, C_CAMERA, 800, 600); */ |
|
|
|
|
struct Camera* camera = entity_component_add(player, C_CAMERA, 800, 600); |
|
|
|
|
transform_set_position(viewer_tran, &viewer_pos); |
|
|
|
|
struct Entity* player_pitch = scene_add_as_child("player_pitch", NULL, player); |
|
|
|
|
player_pitch_node = player_pitch->node; |
|
|
|
|
entity_component_add(player_pitch, C_CAMERA, 800, 600); |
|
|
|
|
/* struct Camera* camera = entity_component_add(player, C_CAMERA, 800, 600); */ |
|
|
|
|
|
|
|
|
|
struct Entity* new_ent = scene_add_new("Model_Entity", NULL); |
|
|
|
|
struct Transform* tran = entity_component_get(new_ent, C_TRANSFORM); |
|
|
|
|
vec3 position = {0, 0, -5}; |
|
|
|
|
transform_translate(tran, position, TS_WORLD); |
|
|
|
|
struct Model* model = entity_component_add(new_ent, C_MODEL, "default.pamesh"); |
|
|
|
|
transform_translate(tran, &position, TS_WORLD); |
|
|
|
|
entity_component_add(new_ent, C_MODEL, "default.pamesh"); |
|
|
|
|
struct Transform* model_tran = entity_component_get(new_ent, C_TRANSFORM); |
|
|
|
|
//vec3 axis = {0.f, 1.f, 0.f};
|
|
|
|
|
//transform_rotate(model_tran, axis, (45.f), TS_WORLD);
|
|
|
|
|
vec3 scale = {1, 1, 2}; |
|
|
|
|
transform_scale(model_tran, scale); |
|
|
|
|
transform_scale(model_tran, &scale); |
|
|
|
|
|
|
|
|
|
struct Entity* suz = scene_add_as_child("Suzanne", NULL, new_ent); |
|
|
|
|
entity_component_add(suz, C_MODEL, "suzanne.pamesh"); |
|
|
|
|
struct Transform* s_tran = entity_component_get(suz, C_TRANSFORM); |
|
|
|
|
vec3 s_pos = {3, 0, 0}; |
|
|
|
|
transform_translate(s_tran, s_pos, TS_WORLD); |
|
|
|
|
transform_translate(s_tran, &s_pos, TS_WORLD); |
|
|
|
|
|
|
|
|
|
/* Set cursor mode */ |
|
|
|
|
input_cursor_mode_set(CM_LOCKED); |
|
|
|
|
struct Entity* ground = scene_add_new("Ground", NULL); |
|
|
|
|
struct Model* ground_model = entity_component_add(ground, C_MODEL, "plane.pamesh"); |
|
|
|
|
ground_model->color.x = 1.f; |
|
|
|
|
struct Transform* ground_tran = entity_component_get(ground, C_TRANSFORM); |
|
|
|
|
vec3 pos = {0, -3, -3}; |
|
|
|
|
vec3 scale_ground = {0.5f, 0.5f, 3.f}; |
|
|
|
|
transform_set_position(ground_tran, &pos); |
|
|
|
|
transform_scale(ground_tran, &scale_ground); |
|
|
|
|
|
|
|
|
|
mat4 m1, m2, r1, r2, f1, f2; |
|
|
|
|
mat4_identity(&m1); |
|
|
|
|
mat4_identity(&m2); |
|
|
|
|
mat4_identity(&r1); |
|
|
|
|
mat4_identity(&r2); |
|
|
|
|
mat4_identity(&f1); |
|
|
|
|
mat4_identity(&f2); |
|
|
|
|
|
|
|
|
|
mat4_rot_x(&m1, TO_RADIANS(25.f)); |
|
|
|
|
mat4_rot_x(&m2, TO_RADIANS(25.f)); |
|
|
|
|
mat4_rot_x(&f1, TO_RADIANS(5.f)); |
|
|
|
|
mat4_rot_x(&f2, TO_RADIANS(5.f)); |
|
|
|
|
|
|
|
|
|
mat4_mul(&r1, &f1, &m1); |
|
|
|
|
mat4_mul(&r2, &m1, &f1); |
|
|
|
|
|
|
|
|
|
run(); |
|
|
|
|
} |
|
|
|
@ -101,9 +123,9 @@ void game_init(void) |
|
|
|
|
void debug(float dt) |
|
|
|
|
{ |
|
|
|
|
struct Entity* entity = entity_get(player_node); |
|
|
|
|
//struct Entity* entity_pitch = entity_get(player_pitch_node);
|
|
|
|
|
struct Entity* entity_pitch = entity_get(player_pitch_node); |
|
|
|
|
struct Transform* transform = entity_component_get(entity, C_TRANSFORM); |
|
|
|
|
//struct Transform* pitch_transform = entity_component_get(entity_pitch, C_TRANSFORM);
|
|
|
|
|
struct Transform* pitch_transform = entity_component_get(entity_pitch, C_TRANSFORM); |
|
|
|
|
float move_speed = 5.f, turn_speed = 50.f; |
|
|
|
|
vec3 offset = {0, 0, 0}; |
|
|
|
|
float turn_up_down = 0.f; |
|
|
|
@ -121,16 +143,18 @@ void debug(float dt) |
|
|
|
|
|
|
|
|
|
double cursor_lr, cursor_ud; |
|
|
|
|
input_cursor_pos_get(&cursor_lr, &cursor_ud); |
|
|
|
|
input_cursor_pos_set(0.0, 0.0); |
|
|
|
|
|
|
|
|
|
if(input_mousebutton_state_get(GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS)) |
|
|
|
|
{ |
|
|
|
|
const double scale = 0.5; |
|
|
|
|
turn_up_down = cursor_ud * turn_speed * dt * scale; |
|
|
|
|
input_cursor_mode_set(CM_LOCKED); |
|
|
|
|
const double scale = 0.25; |
|
|
|
|
turn_up_down = -cursor_ud * turn_speed * dt * scale; |
|
|
|
|
turn_left_right = cursor_lr * turn_speed * dt * scale; |
|
|
|
|
input_cursor_pos_set(0.0, 0.0); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
input_cursor_mode_set(CM_NORMAL); |
|
|
|
|
turn_up_down *= dt; |
|
|
|
|
turn_left_right *= dt; |
|
|
|
|
} |
|
|
|
@ -147,52 +171,51 @@ void debug(float dt) |
|
|
|
|
turn_up_down = 0.f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct Entity* ground = scene_find("Ground"); |
|
|
|
|
struct Transform* ground_tran = entity_component_get(ground, C_TRANSFORM); |
|
|
|
|
//transform = ground_tran;
|
|
|
|
|
//transform_rotate(ground_tran, rot_axis_left_right, 50.f * dt, TS_WORLD);
|
|
|
|
|
|
|
|
|
|
if(turn_left_right != 0.f) |
|
|
|
|
{ |
|
|
|
|
transform_rotate(transform, rot_axis_left_right, -turn_left_right, TS_WORLD); |
|
|
|
|
vec3 up = {0.f}; |
|
|
|
|
vec3 forward = {0.f}; |
|
|
|
|
transform_get_up(transform, up); |
|
|
|
|
transform_get_forward(transform, forward); |
|
|
|
|
/* log_message("Up : %.3f, %.3f, %.3f", up[0], up[1], up[2]); */ |
|
|
|
|
/* log_message("Forward : %.3f, %.3f, %.3f", forward[0], forward[1], forward[2]); */ |
|
|
|
|
/* log_message("ROT : %.3f, %.3f, %.3f", */ |
|
|
|
|
/* TO_DEGREES(quat_pitch(transform->rotq)), */ |
|
|
|
|
/* TO_DEGREES(quat_yaw(transform->rotq)), */ |
|
|
|
|
/* TO_DEGREES(quat_roll(transform->rotq))); */ |
|
|
|
|
//transform_rotate(transform, rot_axis_left_right, turn_left_right, TS_WORLD);
|
|
|
|
|
transform_rotate(transform, &rot_axis_left_right, -turn_left_right, TS_WORLD); |
|
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
|
transform_get_up(transform, &up); |
|
|
|
|
transform_get_forward(transform, &forward); |
|
|
|
|
transform_get_lookat(transform, &lookat); |
|
|
|
|
log_message("Up : %s", tostr_vec3(&up)); |
|
|
|
|
log_message("FR : %s", tostr_vec3(&forward)); |
|
|
|
|
} |
|
|
|
|
if(turn_up_down != 0.f) |
|
|
|
|
{ |
|
|
|
|
transform_rotate(transform, rot_axis_up_down, -turn_up_down, TS_LOCAL); |
|
|
|
|
//transform_rotate(pitch_transform, rot_axis_up_down, -turn_up_down, TS_LOCAL);
|
|
|
|
|
/* log_message("ROT : %.3f, %.3f, %.3f", */ |
|
|
|
|
/* TO_DEGREES(quat_pitch(pitch_transform->rotq)), */ |
|
|
|
|
/* TO_DEGREES(quat_yaw(pitch_transform->rotq)), */ |
|
|
|
|
/* TO_DEGREES(quat_roll(pitch_transform->rotq))); */ |
|
|
|
|
vec3 up = {0.f}; |
|
|
|
|
vec3 forward = {0.f}; |
|
|
|
|
transform_get_up(transform, up); |
|
|
|
|
transform_get_forward(transform, forward); |
|
|
|
|
log_message("Up : %s", tostr_vec3(up)); |
|
|
|
|
log_message("FR : %s", tostr_vec3(forward)); |
|
|
|
|
//transform_rotate(transform, &rot_axis_up_down, turn_up_down, TS_LOCAL);
|
|
|
|
|
transform_rotate(pitch_transform, &rot_axis_up_down, turn_up_down, TS_LOCAL); |
|
|
|
|
vec3 up = {0.f, 0.f, 0.f}; |
|
|
|
|
vec3 forward = {0.f, 0.f, 0.f}; |
|
|
|
|
vec3 lookat = {0.f, 0.f, 0.f}; |
|
|
|
|
transform_get_up(transform, &up); |
|
|
|
|
transform_get_forward(transform, &forward); |
|
|
|
|
transform_get_lookat(transform, &lookat); |
|
|
|
|
log_message("Up : %s", tostr_vec3(&up)); |
|
|
|
|
log_message("FR : %s", tostr_vec3(&forward)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Movement */ |
|
|
|
|
if(input_map_state_get("Move_Forward", GLFW_PRESS)) offset[2] -= move_speed; |
|
|
|
|
if(input_map_state_get("Move_Backward", GLFW_PRESS)) offset[2] += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Left", GLFW_PRESS)) offset[0] -= move_speed; |
|
|
|
|
if(input_map_state_get("Move_Right", GLFW_PRESS)) offset[0] += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Up", GLFW_PRESS)) offset[1] += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Down", GLFW_PRESS)) offset[1] -= move_speed; |
|
|
|
|
|
|
|
|
|
vec3_scale(offset, offset, dt); |
|
|
|
|
if(offset[0] != 0 || offset[2] != 0 || offset[1] != 0) |
|
|
|
|
if(input_map_state_get("Move_Forward", GLFW_PRESS)) offset.z -= move_speed; |
|
|
|
|
if(input_map_state_get("Move_Backward", GLFW_PRESS)) offset.z += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Left", GLFW_PRESS)) offset.x -= move_speed; |
|
|
|
|
if(input_map_state_get("Move_Right", GLFW_PRESS)) offset.x += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Up", GLFW_PRESS)) offset.y += move_speed; |
|
|
|
|
if(input_map_state_get("Move_Down", GLFW_PRESS)) offset.y -= move_speed; |
|
|
|
|
|
|
|
|
|
vec3_scale(&offset, &offset, dt); |
|
|
|
|
if(offset.x != 0 || offset.y != 0 || offset.z != 0) |
|
|
|
|
{ |
|
|
|
|
transform_translate(transform, offset, TS_LOCAL); |
|
|
|
|
log_message("Position : %.3f, %.3f, %.3f", |
|
|
|
|
transform->position[0], |
|
|
|
|
transform->position[1], |
|
|
|
|
transform->position[2]); |
|
|
|
|
transform_translate(transform, &offset, TS_LOCAL); |
|
|
|
|
log_message("Position : %s", tostr_vec3(&transform->position)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(input_key_state_get(GLFW_KEY_SPACE, GLFW_PRESS)) |
|
|
|
@ -200,23 +223,27 @@ void debug(float dt) |
|
|
|
|
struct Entity* model = entity_get(2); |
|
|
|
|
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); |
|
|
|
|
vec3 x_axis = {1, 0, 0}; |
|
|
|
|
transform_rotate(mod_tran, x_axis, 25.f * dt, TS_WORLD); |
|
|
|
|
transform_rotate(mod_tran, &x_axis, 25.f * dt, TS_WORLD); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(input_key_state_get(GLFW_KEY_M, GLFW_PRESS)) |
|
|
|
|
{ |
|
|
|
|
struct Entity* model = entity_get(3); |
|
|
|
|
struct Entity* model = entity_get(2); |
|
|
|
|
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); |
|
|
|
|
vec3 y_axis = {0, 1, 0}; |
|
|
|
|
transform_rotate(mod_tran, y_axis, 25.f * dt, TS_LOCAL); |
|
|
|
|
vec3 y_axis = {0, 0, 1}; |
|
|
|
|
transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_LOCAL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(input_key_state_get(GLFW_KEY_N, GLFW_PRESS)) |
|
|
|
|
{ |
|
|
|
|
struct Entity* model = entity_get(3); |
|
|
|
|
/* struct Entity* model = entity_get(3); */ |
|
|
|
|
/* struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); */ |
|
|
|
|
/* vec3 amount = {0, 0, -5 * dt}; */ |
|
|
|
|
/* transform_translate(mod_tran, amount, TS_LOCAL); */ |
|
|
|
|
struct Entity* model = entity_get(2); |
|
|
|
|
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); |
|
|
|
|
vec3 amount = {0, 0, -5 * dt}; |
|
|
|
|
transform_translate(mod_tran, amount, TS_LOCAL); |
|
|
|
|
vec3 y_axis = {0, 0, 1}; |
|
|
|
|
transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|