What you are searching for is called fixed point math. The reason to do this on Android is that many current devices don't have a floating point processing unit. This will change in future devices i'm sure (all second generation devices seem to have an FPU).
If you work in Java it does not pay of using fixed point math compared to using floating point math. For some reasons integer divisions are extremely costly and at the end of the day you will need to get the non-fractional part of the fixed point number which involves a division (or right shift). If you use fixed point math in native code via the NDK you might see a bit of a speed up on older devices. If you stay in Java land i strongly suggest to staying with floating point math. I'm also pretty sure that the decision to use of fixed point math in the Google Maps API is not due to performance considerations but due to precision considerations. Floats lose stuff when not handled with care (and even with care taken). It's the same for financial applications. In both cases its recommended to use fixed point integer math. On 8 Jun., 16:08, Neilz <[email protected]> wrote: > Right, ok. > > So in my example, I have Bitmaps being drawn to the Canvas (using an > adaptation of SpriteMethodTest which I referred to a few days ago). > > 1) The Canvas.drawBitmap() method takes two floats as coordinates, so > how can I avoid using them? Or if i was to pass 'integer' values, > would that mean they were treated as such, regardless of the method > signature? > > 2) Typical x and y points for my bitmaps are X: 281.01068 Y: > 455.04297. When bitmaps get drawn to the screen, is this all wasted > precision? Is drawing at 281.01068 any different from drawing at > 281.31343? > > On Jun 8, 2:32 pm, Mark Murphy <[email protected]> wrote: > > > Neilz wrote: > > > Hi all. I've read this in a few articles, that one should avoid > > > floating point operations within the physics update of a game. > > > > But how do you really achieve this? Surely all half decent games are > > > going to involve this kind of maths? > > > Use integer math. > > > > Does it mean, convert all your variables to int, or use double > > > instead, or simply just cut it out as much as possible? > > > For example, look at the Google Maps API, compared to the Location API. > > > A Location object has a double for getLatitude() and getLongitude(). For > > light uses, that's fine. > > > However, for Google Maps, trying to do everything in floating point > > would get too slow. Hence, the GeoPoint class has latitude and longitude > > as integer microdegrees -- 1E6 times the double value in degrees. This > > allows Google Maps to maintain a fair bit of precision while sticking > > with integer math. > > > What you need to do for your game is come up with appropriate units of > > measurement such that you won't need fractional units, for whatever > > degree of precision you want. For example, instead of kilometers, do > > your calculations in meters, or centimeters, or millimeters. > > > -- > > Mark Murphy (a Commons > > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > > Warescription: Three Android Books, Plus Updates, One Low Price! -- 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

