Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helicopter mode #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/spacemouse/SpaceDock.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ margin_right = 128.0
margin_bottom = 128.0
rect_min_size = Vector2( 128, 24 )
text = "Object Mode"
items = [ "Object Mode", null, false, 0, null, "Camera Mode", null, false, 1, null ]
items = [ "Object Mode", null, false, 0, null, "Camera Mode", null, false, 1, null, "Helicopter Mode", null, false, 2, null ]
selected = 0

[node name="SpacerBottom" type="Control" parent="UI"]
Expand Down
15 changes: 14 additions & 1 deletion addons/spacemouse/SpaceMouse.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var translation_speed_ui = null
var rotation_speed_ui = null
var control_type_ui = null
# name for control type
const ControlType = {OBJECT_TYPE = 0, CAMERA_TYPE = 1}
const ControlType = {OBJECT_TYPE = 0, CAMERA_TYPE = 1, HELICOPTER_TYPE=2}
# object or camera control
var control_type = ControlType.OBJECT_TYPE
# adjust fly camera translation
Expand Down Expand Up @@ -176,6 +176,19 @@ func _process(delta):
space_translation = camera_transform.xform(space_translation)
# move the camera back to the original position
camera_transform.origin = camera_origin - space_translation
elif control_type == ControlType.HELICOPTER_TYPE:
# adjust the raw readings into reasonable speeds and apply delta
space_translation *= translate_speed * adjust_translation * delta;
space_rotation *= rotate_speed * adjust_rotation * delta
# rotate the camera in place
# rotation is absolute for vertical axis to keep the horizon level
camera_transform = camera_transform.rotated(Vector3.UP, -space_rotation.y)
# Permits to tilt (dive up/down)
camera_transform = camera_transform.rotated(camera_transform.basis.x.normalized(), -space_rotation.x)
# transform translation into camera local space
space_translation = camera_transform.xform(space_translation)
# move the camera back to the original position
camera_transform.origin = camera_origin - space_translation
# apply the updated temporary transform to the actual viewport camera
camera.transform = camera_transform

Expand Down