#Relative 3D rotation
1 messages · Page 1 of 1 (latest)
The problem with that is I don't set the parent of the picked up object to the camera, so I can't just use the relativity of the parent as a solution
Do you mean you want to rotate the object as though its up and right axes perfectly point up and right on the screen?
Yep, that's it
IIRC there are ways to rotate a vector by passing in an arbitrary up and right vectors, so presumably passing in the camera's up and right vectors would achieve that. I think it involves quaternions... I'll see it I can quickly find it
Oh no, quaternions 
I just woke up so I could well be wrong about this 😂 But I think if you use the vector representing the camera's rotation and the vector representing the object's rotation as as parameters for Quaternion(arc_from, arc_to), you could then multiply your camera-relative rotation by that resulting quaternion to get the equivalent rotation in object-space
Oh, or if that doesn't work, you could maybe figure out the axis of the rotation you want in camera-space, transform that into object-space using Quaternion(arc_from, arc_to), and then use Quaternion(axis, angle) to get the rotation
This is where I'd start tinkering if I were trying to do this myself anyway
Alright, give me a moment to try that out
I am now realizing that I have no idea how to try and use this
You can multiply Vector3 by Quaternion. I think in Godot the vector needs to be on the right (according to the doc), so for example Rotation = Quaternion * Rotation should rotate the vector by the quaternion
I haven't worked with Quaternion in Godot though, only in other frameworks, so there may be quirks about implementation
👍
Quaternions don't seem to work
Or I'm just too dum to understand them
But I made a drawing, hopefully explain how I want the rotation to work if anyone else wants to try helping:
https://cdn.discordapp.com/attachments/1260592101758996550/1260598440434339850/image.png?ex=668fe748&is=668e95c8&hm=2314d39d5e67abe1d69d766e3d702f97d5d0444d7680f15db097f98706b057ac&
Basically like skewering the object
Darn; hopefully someone else has a better idea. Without digging into it myself I don't think I can offer further advice; this is the kind of thing I'd spend a while googling and testing out
UPDATE: I figured it out.
var prev_mouse_pos: Vector2
func _process(delta):
var new_mouse_pos = get_viewport().get_mouse_position()
var pos = new_mouse_pos - prev_mouse_pos
var angle = pos * 0.01
currentGrab.global_rotate(global_transform.basis.x,angle.y)
currentGrab.global_rotate(global_transform.basis.y,angle.x)
prev_mouse_pos = new_mouse_pos