1
votes

I have a cube in my OpenGL view which I can rotate when I touch outside of the cube. Now I can detect which side of the cube I touch and now I'm trying to find out towards what side the touch movement is going. So if I touch the top side, the movement can go towards LEFT, RIGHT, FRONT or BACK side of the cube. The cube's orientation can be anything when doing this.

so after figuring that out I'd make it rotate around the correct axis.

I just need an idea of how to implement this.

EDIT: Here's a crude example of what I'm trying to do. Sorry, I'm bad at explaining.

the green thing is a finger touching the red side. The arrow shows the direction the finger is moving. Since it's moving towards the blue side (2), it should return 2. If it moved towards the green side (1), it would return 1 and so on.

1

1 Answers

3
votes

Here is an approach:

When you swipe and lift your finger up, you get two 2D points in screen space: ptBegin and ptEnd. Convert these to 3D (you will need to do an equivalent of gluUnproject to get the 3D coords) and you will get the 3D coordinates ptBegin3D and ptEnd3D in the cube's coordinate system.

Calculate the vector D = ptEnd3D - ptBegin3D.

Now, if you do a dot product of above with the cube face normals (0, 0, 1), (1, 0, 0), etc., you will know from the value which cube face you are moving towards.