Transform: Fixed bug in euler to quaternion conversions | Static_Array: Added overload for operator []= | Widgets: Added changed bool to textfields

This commit is contained in:
2024-12-11 23:28:14 +01:00
parent c4073d7d91
commit 36c6bc5fe7
6 changed files with 36 additions and 15 deletions

View File

@@ -30,4 +30,8 @@ array_contains :: (static_array: Static_Array, value: static_array.Data_Type) ->
operator [] :: (static_array: Static_Array, index: int) -> static_array.Data_Type { operator [] :: (static_array: Static_Array, index: int) -> static_array.Data_Type {
return static_array.data[index]; return static_array.data[index];
} }
operator []= :: (static_array: *Static_Array, index: int, value: static_array.Data_Type) {
static_array.data[index] = value;
}

View File

@@ -130,7 +130,7 @@ quaternion_to_euler :: (q: Quaternion) -> yaw: float, pitch: float, roll: float
cosy_cosp := 1.0 - 2.0 * (q.y * q.y + q.z * q.z); cosy_cosp := 1.0 - 2.0 * (q.y * q.y + q.z * q.z);
yaw = atan2(siny_cosp, cosy_cosp); yaw = atan2(siny_cosp, cosy_cosp);
return pitch, yaw, roll; return yaw, pitch, roll;
} }
set_rotation :: (e: *Entity, orientation: Quaternion, calculate_matrix: bool = true) { set_rotation :: (e: *Entity, orientation: Quaternion, calculate_matrix: bool = true) {

View File

@@ -218,15 +218,17 @@ editor_ui :: () {
ui_label(tprint("Id: %", entity.id)); ui_label(tprint("Id: %", entity.id));
ui_vector_field("Position", *entity.transform.position); updated := ui_vector_field("Position", *entity.transform.position);
euler_rotation := quaternion_to_euler_v3(entity.transform.orientation); euler_rotation := quaternion_to_euler_v3(entity.transform.orientation);
euler_rotation *= RADIANS_TO_DEGREES; euler_rotation *= RADIANS_TO_DEGREES;
ui_vector_field("Rotation", *euler_rotation); updated |= ui_vector_field("Rotation", *euler_rotation);
euler_rotation *= DEGREES_TO_RADIANS; euler_rotation *= DEGREES_TO_RADIANS;
entity.transform.orientation = euler_to_quaternion(euler_rotation); entity.transform.orientation = euler_to_quaternion(euler_rotation);
ui_vector_field("Scale", *entity.transform.scale); updated |= ui_vector_field("Scale", *entity.transform.scale);
update_matrix(*entity.transform); if updated {
update_matrix(*entity.transform);
}
entity_ui(entity); entity_ui(entity);
} }

View File

@@ -94,7 +94,10 @@ generate_member_ui :: (type: *Type_Info_Struct, builder: *String_Builder, path:
if it.type.type == { if it.type.type == {
case .STRUCT; { case .STRUCT; {
info_struct := cast(*Type_Info_Struct) it.type; info_struct := cast(*Type_Info_Struct) it.type;
if info_struct.name == "Vector3" { if info_struct.name == "Quaternion" {
}
else if info_struct.name == "Vector3" {
print_to_builder(builder, "\tui_vector_field(tprint(\"%\"), *e.%);\n", new_path, new_path); print_to_builder(builder, "\tui_vector_field(tprint(\"%\"), *e.%);\n", new_path, new_path);
} else { } else {
generate_member_ui(info_struct, builder, new_path); generate_member_ui(info_struct, builder, new_path);

View File

@@ -80,7 +80,7 @@ coven_init :: (window_title: string, window_width: u32, window_height: u32, full
} }
} }
coven_run :: (game_update_proc: (float), game_update_post_physics_proc: (float)) { coven_run :: (game_update_proc: (float), game_editor_update_proc: (float), game_update_post_physics_proc: (float)) {
time = xx seconds_since_init(); time = xx seconds_since_init();
while !quit { while !quit {
@@ -124,6 +124,8 @@ coven_run :: (game_update_proc: (float), game_update_post_physics_proc: (float))
game_update_post_physics_proc(clamped_dt); game_update_post_physics_proc(clamped_dt);
} }
} else { } else {
game_editor_update_proc(clamped_dt);
if engine.current_scene != null { if engine.current_scene != null {
update_trigger_mesh_colliders(engine.current_scene); update_trigger_mesh_colliders(engine.current_scene);
} }

View File

@@ -285,18 +285,22 @@ ui_int_field :: (label: string, value: *int, identifier: s64 = 0, loc := #caller
ui_set_next_size_x(.CHILDREN_SUM, 1); ui_set_next_size_x(.CHILDREN_SUM, 1);
} }
ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #caller_location) { ui_float_field :: (label: string, value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_container_layout(identifier=identifier, loc=loc); ui_container_layout(identifier=identifier, loc=loc);
ui_set_next_size_x(.CHILDREN_SUM); ui_set_next_size_x(.CHILDREN_SUM);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL); ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{ {
ui_label(label); ui_label(label);
ui_float_field(value, identifier); changed |= ui_float_field(value, identifier);
} }
ui_pop_parent(); ui_pop_parent();
return changed;
} }
ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location) { ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_set_next_background_color(.{0.0,1.0,1.0,0.0}); ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_border_color(.{0.3,0.3,0.3,1.0}); ui_set_next_border_color(.{0.3,0.3,0.3,1.0});
ui_set_next_size_x(.CHILDREN_SUM, 1); ui_set_next_size_x(.CHILDREN_SUM, 1);
@@ -344,6 +348,7 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
<<value = parse_float(*temp_str); <<value = parse_float(*temp_str);
outer.interaction.editing = false; outer.interaction.editing = false;
engine.editor.focused_widget = null; engine.editor.focused_widget = null;
changed = true;
} }
if engine.input.has_char { if engine.input.has_char {
@@ -414,21 +419,26 @@ ui_float_field :: (value: *float, identifier: s64 = 0, loc := #caller_location)
// //
} }
ui_pop_parent(); ui_pop_parent();
return changed;
} }
ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) { ui_vector_field :: (label: string, value: *Vector3, identifier: s64 = 0, loc := #caller_location) -> bool {
changed := false;
ui_container_layout(identifier=identifier, loc=loc); ui_container_layout(identifier=identifier, loc=loc);
ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL); ui_push_parent(ui_state.last_box, .LEFT, .HORIZONTAL);
{ {
ui_label(label); ui_label(label);
ui_label("X"); ui_label("X");
ui_float_field(*value.x); changed |= ui_float_field(*value.x);
ui_label("Y"); ui_label("Y");
ui_float_field(*value.y); changed |= ui_float_field(*value.y);
ui_label("Z"); ui_label("Z");
ui_float_field(*value.z); changed |= ui_float_field(*value.z);
} }
ui_pop_parent(); ui_pop_parent();
return changed;
} }
ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State { ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {