Custom entity UI, math functions, physics triggers

This commit is contained in:
2025-03-30 23:22:21 +02:00
parent 7428ee7fed
commit 06995fbd05
4 changed files with 48 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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);

View File

@@ -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 :: () {

View File

@@ -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);