Android Question Smoothen a compass app?

0CrimsonScythe0

Member
Licensed User
Longtime User
I made a compass app but the rotation of the image is not as smooth as I want it to be. Is there any way it could be made smoother?

P.s , I am a noob so the code might not be that neat or professional as to say.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
   
Dim sensor As PhoneOrientation

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label
    Dim compass As Bitmap
    Dim cv As Canvas
   
    Dim destrect As Rect
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("layout2")
    sensor.StartListening("sensor")
    compass.Initialize(File.DirAssets , "compass.png")
    cv.Initialize(Activity)
    destrect.Initialize(0dip,30dip,320dip , 320dip)
       
   
   
   
   
   
   
End Sub

Sub Activity_Resume
sensor.StartListening("sensor")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
sensor.StopListening


End Sub

Sub sensor_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
Label1.Text = Azimuth
Dim degrees As Float
degrees  = 360-Azimuth
cv.DrawBitmap(compass , Null , destrect)
cv.DrawBitmapRotated(compass , Null ,destrect, degrees)
Activity.Invalidate

   
End Sub


End Sub
 

sorex

Expert
Licensed User
Longtime User
is this needed?

B4X:
cv.DrawBitmap(compass , Null , destrect)

I think you draw it twice, not?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Sounds like maybe the update rate from the sensor is a bit slow, so you are not capturing a very high resolution of the movement/rotation.

Just looking at the PhoneSensors documentation (http://www.b4x.com/android/help/phone.html#phonesensors) & thinking maybe you should try using this with a TYPE_ORIENTATION SensorType in the initializer. If you use Initialize2, you can specify a SensorDelay of 0, which should give you the fastest update rate.

- Colin.
 
Upvote 0

0CrimsonScythe0

Member
Licensed User
Longtime User
Thanks for the suggestion , there was a slight difference , maybe I should use the accelerated surface library so the bitmap can be drawn using hardware acceleration. Does that make sense?
 
Upvote 0
Top