This is something to keep in mind as you may need to perform some smoothing on it a quick search will yield lots of info. I did not require any as the data was used in such a way that it did not matter.
Anyway a picture says a thousand words so here is a simple illustration of the readings, due to gravity, to expect. Please note the magnitude of 1 in the following readings will not be exact as stated above. It is used for illustrative purposes only. There are far more detailed descriptions of the readings to expect but I wanted to keep this simple.
Another thing to note is that changes in accelerometer readings do not count as input to the device. This is to prevent accidental activation of the phone from user movement.
This means that the screensaver may have to be disabled while your application is running. If you do this you must be re-enable it on leaving your game to pass the validation process. The code required for this is below. As I am a student I could not afford a WP7 device to test on. This meant I had to rely on the emulator which has no support for accelerometer input or simulation. This was a major problem as the main user input for my game was accelerometer input.
Use augmented reality courtesy of Codeplex. The Code Project , Original source. As I was only learning XNA and have a reasonable grasp of 3D vectors, I decided to use the keyboard to simulate accelerometer input. This example gives a good idea of the approach to take to this solution but is unnecessarily complicated in its implementation and somewhat simplistic in its handling of input although it could be altered or expanded upon. It simply adds or subtracts from one of the accelerometer Vector values x, y or z when the arrow keys are pressed.
What I really required was an interface class, similar to this one, which was easier to understand and performed rotations around each of the axes. This would give me the simulated tilt which I was after. I ended up writing a class which checks whether it is running on the emulator or the phone and decides what input data to collect and how to manipulate it.
I wrote a few simple rotation methods into the class to simulate tilting. They operate around mathematical axes, not the phones axes. For the accelerometer handler to work you must change the namespace to match your project and add references to Microsoft.
Sensors and Microsoft. Phone to your project. Sensors allows use of the accelerometer and Microsoft. Phone allows you to check if the active device is the phone. NET tab and find them in the list. An object of type AccelerometerHandler is created. During construction it checks what device type it is running on.
If it is running on the phone it creates a link to the in-built accelerometer interface, adds a new event handler to the accelerometer to handle what to do when the readings change and activates the accelerometer.
Otherwise it just sets the readings to default values. If the active device is the phone the current reading is normalized and returned. If the active device is the emulator keyboard input is read and rotations are performed.
The resultant vector is normalized and returned. The class provides active and stopAccelerometer methods to start and stop the accelerometer, though they are not really necessary as these are handled autonomously. Keith is a dedicated, hardworking individual. Although he started out as a bespoke furniture maker, hard times and a huge interest in technology led him to become a computer games developer I know it sounds random.
Keith is currently attending the Computer Games Development course at I. Carlow and has skills in a number of languages. Keith is especially interested in mobile platforms and is currently developing for Windows Phone 7. Follow me on twitter for updates or check out my website. Catching and Debugging Errors. Packaging, Publishing, and Managing Applications. Working with the Accelerometer.
Application Bar. WebBrowser Control. Working with Controls and Themes. Creating Trial Applications. Isolated Storage. Using Location Services. Working with the Camera and Photos. Push Notifications. Page 1 Navigate to page number of 2. About this book Introduction Microsoft is injecting new energy into the smart phone marketplace with the sophisticated Windows Phone 7.
This new energy equates to new opportunities for you, the mobile developer. Beginning Windows Phone 7 Development has been written specifically to help you seize these opportunities and begin creating applications for this exciting new mobile device platform.
About the authors Henry Lee, founder of ToeTapz. He works with various Fortune companies, delivering mobile applications and rich Internet applications. He is focusing his energy on delivering mobile applications on Windows Phone 7, Android, and iPhone.
0コメント