From 06995fbd05c50886cec8b08adc682815092b5b26 Mon Sep 17 00:00:00 2001 From: Daniel Bross Date: Sun, 30 Mar 2025 23:22:21 +0200 Subject: [PATCH] Custom entity UI, math functions, physics triggers --- core/camera.jai | 4 ++-- core/math.jai | 28 ++++++++++++++++++++++++++++ metaprogram.jai | 17 +++++++++++++++++ physics/physics.jai | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/core/camera.jai b/core/camera.jai index 9eb0d0f..078cf54 100644 --- a/core/camera.jai +++ b/core/camera.jai @@ -1,4 +1,4 @@ -Camera_Type :: enum { +Camera_Projection_Type :: enum { ORTHOGRAPHIC; PERSPECTIVE; } @@ -10,7 +10,7 @@ Camera_Buffer_Data :: struct { } Camera :: struct { - type : Camera_Type; + type : Camera_Projection_Type; position : Vector3; rotation : struct { diff --git a/core/math.jai b/core/math.jai index eef0d1d..008f585 100644 --- a/core/math.jai +++ b/core/math.jai @@ -368,6 +368,34 @@ reflect :: (incident: Vector3, normal: Vector3) -> Vector3 { return reflected; } +get_rotated_direction :: (direction: Vector3, by_pitch: float, by_yaw: float, by_roll: float) -> Vector3 { + pitch := by_pitch * DEGREES_TO_RADIANS; + yaw := by_yaw * DEGREES_TO_RADIANS; + roll := by_roll * DEGREES_TO_RADIANS; + + pitch_mat := Matrix4.{ + 1, 0, 0, 0, + 0, cos(pitch), sin(pitch), 0, + 0, -sin(pitch), cos(pitch), 0, + 0, 0, 0, 1}; + + yaw_mat := Matrix4.{ + cos(yaw), 0, -sin(yaw), 0, + 0, 1, 0, 0, + sin(yaw), 0, cos(yaw), 0, + 0, 0, 0, 1}; + + roll_mat := Matrix4.{ + cos(roll), sin(roll), 0, 0, + -sin(roll), cos(roll), 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1}; + + matrix := yaw_mat * pitch_mat * roll_mat; + + return normalize(to_v3(matrix * Vector4.{direction.x, direction.y, direction.z, 0.0})); +} + quat_to_pitch_yaw_roll :: (using q: Quaternion) -> pitch: float, yaw: float, roll: float { roll := atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z); pitch := atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z); diff --git a/metaprogram.jai b/metaprogram.jai index c3e1381..640b313 100644 --- a/metaprogram.jai +++ b/metaprogram.jai @@ -406,7 +406,9 @@ generate_ui_procedure_for_entity :: (code_struct: *Code_Struct) { ui : String_Builder; print_to_builder(*ui, "#if EDITOR {"); print_to_builder(*ui, "entity_ui_proc :: (e: *%) {\n", name); + generate_member_ui(code_struct.defined_type, *ui); + print_to_builder(*ui, "}\n"); print_to_builder(*ui, "}"); @@ -420,7 +422,13 @@ generate_ui_procedure_for_entity_imgui :: (code_struct: *Code_Struct) { ui : String_Builder; print_to_builder(*ui, "#if EDITOR {"); print_to_builder(*ui, "entity_ui_proc_imgui :: (e: *%) {\n", name); + generate_member_ui_imgui(code_struct.defined_type, *ui); + + if wants_custom_ui(code_struct) { + print_to_builder(*ui, "custom_ui(e);\n"); + } + print_to_builder(*ui, "}\n"); print_to_builder(*ui, "}"); @@ -486,6 +494,15 @@ note_struct :: (code_struct: *Code_Struct) { } } +wants_custom_ui :: (code_struct: *Code_Struct) -> bool { + for note: code_struct.defined_type.notes { + if to_lower_copy(note,, allocator = temp) == "customui" { + return true; + } + } + return false; +} + message: *Message_Import; message_loop :: () { diff --git a/physics/physics.jai b/physics/physics.jai index 2816dd8..a8f9eb0 100644 --- a/physics/physics.jai +++ b/physics/physics.jai @@ -270,7 +270,7 @@ physics_step :: (scene: *Scene, timestep: float) { inv_matrix := inverse(other_e.transform.model_matrix); aabb := other_e.collider.aabb; if point_inside_aabb(aabb, transform_position(e.transform.position, inv_matrix)) { - //add_trigger_overlap_if_new(other_e, e); + add_trigger_overlap_if_new(other_e, e); } } else { point := gjk(e.collider, other_e.collider);