Skip to content

Commit

Permalink
Moved AeroBody3D.log_with_base() to mathutils.gd
Browse files Browse the repository at this point in the history
  • Loading branch information
addmix committed Jul 29, 2024
1 parent f7f24b6 commit 82f38ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
12 changes: 4 additions & 8 deletions core/aero_body_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ func _update_debug() -> void:
linear_velocity_to_use = debug_linear_velocity
angular_velocity_to_use = debug_angular_velocity

linear_velocity_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(linear_velocity_to_use, 2.0)
angular_velocity_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(angular_velocity_to_use, 2.0)
linear_velocity_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(linear_velocity_to_use, 2.0)
angular_velocity_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(angular_velocity_to_use, 2.0)

#Godot doesn't run physics engine in-editor.
#A consequence of this is that get_linear_velocity doesn't work.
Expand Down Expand Up @@ -435,8 +435,8 @@ func _update_debug() -> void:
drag_position_sum += surface.transform.origin * surface.drag_force

if lift_sum_vector.is_finite() and drag_sum_vector.is_finite():
lift_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(lift_sum_vector / amount_of_aero_surfaces, 2.0)
drag_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(drag_sum_vector / amount_of_aero_surfaces, 2.0)
lift_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(lift_sum_vector / amount_of_aero_surfaces, 2.0)
drag_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(drag_sum_vector / amount_of_aero_surfaces, 2.0)

if is_equal_approx(lift_sum, 0.0):
lift_sum = 1.0
Expand Down Expand Up @@ -474,7 +474,3 @@ func _update_debug_scale() -> void:
angular_velocity_vector.width = debug_width
drag_debug_vector.width = debug_width
thrust_debug_vector.width = debug_width


static func log_with_base(vector : Vector3, base : float) -> Vector3:
return vector.normalized() * AeroMathUtils.log_with_base(vector.length() + 1, base)
7 changes: 5 additions & 2 deletions core/aero_influencer_3d/aero_influencer_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extends Node3D
class_name AeroInfluencer3D

const AeroMathUtils = preload("../../utils/math_utils.gd")
const AeroNodeUtils = preload("../../utils/node_utils.gd")

##If true, this AeroInfluencer3D will not have any effect on the simulation.
Expand All @@ -24,6 +25,8 @@ var brake_command : float = 0.0
@export var roll_contribution := Vector3.ZERO
##Amount of rotation that brake commands contribute to this node's rotation.
@export var brake_contribution := Vector3.ZERO
##Amount of rotation that throttle commands contribute to this node's rotation.
@export var throttle_contribution := Vector3.ZERO
##Rotation order used when doing control rotations.
@export_enum("XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX") var control_rotation_order : int = 0

Expand Down Expand Up @@ -238,6 +241,6 @@ func update_debug_vectors() -> void:

#don't update invisible vectors
if force_debug_vector.visible:
force_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(_current_force, 2.0) * debug_scale
force_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(_current_force, 2.0) * debug_scale
if torque_debug_vector.visible:
torque_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(_current_torque, 2.0) * debug_scale
torque_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(_current_torque, 2.0) * debug_scale
4 changes: 2 additions & 2 deletions core/aero_influencer_3d/aero_surface_3d/aero_surface_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ func update_debug_vectors() -> void:

#don't update invisible vectors
if lift_debug_vector.visible:
lift_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(_current_lift, 2.0) * debug_scale
lift_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(_current_lift, 2.0) * debug_scale
if drag_debug_vector.visible:
drag_debug_vector.value = global_transform.basis.inverse() * AeroBody3D.log_with_base(_current_drag, 2.0) * debug_scale
drag_debug_vector.value = global_transform.basis.inverse() * AeroMathUtils.v3log_with_base(_current_drag, 2.0) * debug_scale
8 changes: 8 additions & 0 deletions utils/math_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ static func sigmoid(x : float, e : float = E) -> float:



#



static func v3log_with_base(vector : Vector3, base : float) -> Vector3:
return vector.normalized() * log_with_base(vector.length() + 1, base)



#matrix math stuff, very inefficient stuff

Expand Down

0 comments on commit 82f38ef

Please sign in to comment.