> -- "steering" effects for driving simulators and games

To get the steering effect you will probably want to set up your
sensor listener to listen for SENSOR_ORIENTATION rather than
SENSOR_ACCELEROMETER because the ORIENTATION sensor will let you know
the angle that the various axis of the phone are angled at.  Well
anyways here is a cut down code snip from my PingPong and
BreakTheBlocks games.  Basically I detect how much of an angle the
phone is on and set the position of the bottom paddle according to
that.  it might be a little confusing please let me know if you have
more questions about this code snippet.  I think I am planning on
writing all of this up[ in a blog post for my own reference in the
future, will post back in this thread if that ever happens.

And the bets tool that is available for trying to understand the raw
data that you can receive from the android SensorListener can be
gathered by playign with the OpenIntents Sensor Simulator
http://www.openintents.org/en/node/6

        public void doSensorChanged(int sensor, float[] values)
        {
                if((sensor == SensorManager.SENSOR_ORIENTATION))
                {
            float max_angle = 25.0f;
            float adjustedRollValue = values[2] + 90.0f;
            float percentileValue = 0.0f;

            if(adjustedRollValue < (90.0f - max_angle))
            {
                percentileValue = 0.0f;
            }
            else if(adjustedRollValue > (90.0f + max_angle))
            {
                percentileValue = 100.0f;
            }
            else
            {
                percentileValue = ((adjustedRollValue-(90.0f -
max_angle)) / (max_angle * 2.0f));
            }

            float xPos = m_canvasRect.width() * percentileValue;
            m_paddleCenterX = Math.round(xPos);
                }
        }

Good luck


---snctln
www.snctln.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to