Results 1 to 5 of 5
  1. #1
    stratosb is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Android accelerometer ball

    Hello all,
    I want to make a small android program to move a ball on the screen as the user rotates his/her phone right,left and up,down.
    I have been searching through the internet for weeks and I am not able to find any help!

    I have used the following code to get the values for yaw, pitch, roll from SensorManager.getRotationMatrix.
    However I don't know how to calculate the position and/or distance that the ball has moved sideways as well as how fast it has moved.
    Can someone help me please?
    Thank you in advance.

    private float [] m_lastAccelFields = new float[3];
    private float [] m_lastMagFields = new float[3];
    private float[] m_rotationMatrix = new float[9];
    private float[] m_inclinationMatrix = new float[9];
    private float[] m_orientation = new float[3];

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
    m_lastAccelFields = event.values.clone();
    }
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
    m_lastMagFields = event.values.clone();
    }
    boolean proceed = SensorManager.getRotationMatrix(m_rotationMatrix, m_inclinationMatrix, m_lastAccelFields, m_lastMagFields);
    if (proceed) {
    sensorManager.getOrientation(m_rotationMatrix, m_orientation);
    float yaw = m_orientation[0] * 57.2957795f;
    float pitch = m_orientation[1] * 57.2957795f;
    float roll = m_orientation[2] * 57.2957795f;
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Android accelerometer ball

    Please go through Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    stratosb is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Android accelerometer ball

    I cannot find the option to edit my post.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Android accelerometer ball

    At the bottom of your post there's an 'Edit Post' button, next to the 'Reply' and 'Reply With Quote'.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Android accelerometer ball

    It may be already too late. In that case, post the code again with the proper tags.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 12-24-2011, 04:41 AM
  2. Ball program
    By codeStone in forum Advanced Java
    Replies: 10
    Last Post: 02-25-2011, 01:32 PM
  3. Need help with a third ball in game.
    By vlan in forum Java Applets
    Replies: 2
    Last Post: 05-30-2010, 03:37 PM
  4. Box Ball Java
    By fcgb9115 in forum New To Java
    Replies: 1
    Last Post: 04-19-2010, 02:33 AM
  5. Problem deleting ball from bouncing ball app
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 09:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •