Android Question rotate view x , y axis with TouchDragged

Sia

Member
Licensed User
Longtime User
hi,

i tried to rotate and change view with TouchDragged with this code :

B4X:
Sub IP_TouchDown(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    If Pointer <> 0 Then Return False
    LastX = ScreenX
    LastY = ScreenY
    Return True
End Sub


Sub IP_TouchDragged(ScreenX As Int, ScreenY As Int, Pointer As Int) As Boolean
    'If Pointer <> 0 Then Return False

   If ScreenY > Activity.Height/2 Then       
           
    'Rotates the camera on the Y axis
    Point.Set(Camera.Position.X, Camera.Position.Y, Camera.Position.Z)
    RotMatrix.setToRotation(Y_Axis, (LastX - ScreenX) / 5)
    Point.Mul(RotMatrix)
    Camera.Position.Set(Point.X, Point.y, Point.Z)
    Camera.LookAt(0, 0, 0)
    Camera.Update

    LastX = ScreenX
    Return True   
   
   
   
   
            Else            
           
           

   'Rotates the camera on the x axis
    Point.Set(Camera.Position.y, Camera.Position.x, Camera.Position.Z)
    RotMatrix.setToRotation(X_Axis, (LastY - ScreenY) / 5)
    Point.Mul(RotMatrix)
    Camera.Position.Set(Point.y, Point.x, Point.Z)
    Camera.LookAt(0, 0, 0)
    Camera.Update

    LastY = ScreenY
    Return True   
   End If
   
   
End Sub

it work but sometime it has a problem and doesn't work correctly.
why ?
thank you.
 
Top