Angle and Rotation to movement

sagicoh

New member
Joined
Nov 11, 2021
Messages
3
I have a cube in a 3D space. There's a camera looking at the cube in rotation (0,0,0) at the beginning.
I can swipe gesture to 1. rotate the camera around the cube, while the cube's center is the center of rotation, and 2. move the cube hoepfully..

I want to move the cube in the correct direction using the swipe vector/angle (which I already have) and camera rotation. The direction should be one of (1,0,0)/(0,0,1)/(0,1,0)

Anyone can help me understand how to do this? using vector/angle (0−360) and the camera rotation to get the direction the cube should move?

thank you!!

(I have a toggle that decides which action swipe does)
 
This is a common question in interactive 3D views: given a 2D vector [imath]\bar v[/imath] translate it into a 3D rotation. In most solutions the length of the vector, i.e., the amount of mouse drag, is proportional to the angle ("amount of the rotation"), but you still have a question of how to choose the rotation axis.

I remember using this approach: the rotation axis is always in the horizontal plane and orthogonal to [imath]\bar v[/imath] (which is also in the horizontal plane). This has a disadvantage of not being able to rotate around Z-axis (I am using the standard OpenGL convention where the user looks down from Z onto the XY plane), but this can be accomplished by a couple of rotations.

You might find other approaches if you search for interactive OpenGL (or WebGL) code samples. But I don't think a perfect scheme exists because in the end you have to map 2D objects (mouse drags) to a 3D space of all 3D rotations.
 
This is a common question in interactive 3D views: given a 2D vector [imath]\bar v[/imath] translate it into a 3D rotation. In most solutions the length of the vector, i.e., the amount of mouse drag, is proportional to the angle ("amount of the rotation"), but you still have a question of how to choose the rotation axis.

I remember using this approach: the rotation axis is always in the horizontal plane and orthogonal to [imath]\bar v[/imath] (which is also in the horizontal plane). This has a disadvantage of not being able to rotate around Z-axis (I am using the standard OpenGL convention where the user looks down from Z onto the XY plane), but this can be accomplished by a couple of rotations.

You might find other approaches if you search for interactive OpenGL (or WebGL) code samples. But I don't think a perfect scheme exists because in the end you have to map 2D objects (mouse drags) to a 3D space of all 3D rotations.
Thanks, I'll try and do as you suggested or look at samples(now I know what to look for). I'm a bit rusty in math so I would appreciate it if u can elaborate more on your approach. thanks again
 
Last edited:
Thanks, I'll try and do as you suggested or look at samples(now I know what to look for). I'm a bit rusty in math so I would appreciate it if u can elaborate more on your approach. thanks again
Do you know how to rotate a 2D vector by 90 degrees?
 
Top