I’ve started a couple games with the great idea of using the accelerometer for the control. Most of the time these games are super fun in theory but end up becoming a nightmare because making the accelerometer play nicely with what the user expects is difficult.
An important aspect of this is calibrating the accelerometer so your code knows where the user thinks zero should be. This can be a difficult process because you have to think in 3 dimensional space.
I conducted an experiment where I held the device steady at multiple angles in landscape mode and recorded the raw accelerometer read out. Soon into the experiment it became obvious what was going on as I’m sure you’ll be able to figure out from the chart below.
It quickly becomes very clear that acceleration.x is an inverse sine wave and acceleration.z is an inverse cosine wave. I couldn’t believe I hadn’t thought of this before but it is very obvious why this happens. The constant acceleration of gravity is pushing down and so therefore by rotating the device you are essentially reading that acceleration at an angle. Naturally it creates these waves because you are moving it in a circular fashion. So now with this knowledge and your trigonometry book from high school you should be able to figure out the best way to calibrate your program for an awesome user experience.
NOTE: I’ve received quite a few requests for code snippets to explain what I’m talking about here. I am working on another follow up blog post that will include some.
At our last Django Meetup Group event, Jayden Windle, the lead engineer at Jetpack, an on demand delivery company, talks building APIs with Django and GraphQL. Watch the video to learn more.
At the last meeting of the San Francisco Django Meetup Group, Wes Kendall gave a talk on how to make a bulletproof Django application by testing it with pytest. Check out his talk here!
Part of the Yeti Lunch and Learn series - our amazing developer, Resdan, gives a presentation on creating a reusable component library. Enjoy the video!