Wiley.Games.on.Symbian.OS.A.Handbook.for.Mobile.Development.Apr.2008 (779888), страница 46
Текст из файла (страница 46)
Whenpositional data is available, RunL() is called by the active scheduler(which schedules all current active objects) to handle this obtained data.The function checks whether the position was updated successfully,before requesting the view to update the screen with this newly availablepositional data. It also issues a new request to get updated positional data.The application continues retrieving location data in this manner until itshuts down:void CFindMeActive::RunL(){// If successfully received position infoif( iStatus.Int() == KErrNone ||iStatus.Int() == KPositionPartialUpdate ){// Update the viewiView->PrintPos();// Request the next positioniPositioner.NotifyPositionUpdate( iPositionInfo, iStatus );SetActive();}...// Error handling code omitted for clarity}Active objects implement the DoCancel() function to cancel anyoutstanding asynchronous requests issued by the active object, andperform any necessary cleaning up.
In FindMe, we cancel the notificationrequest in DoCancel() and close the allocated sessions in the destructor.void CFindMeActive::DoCancel(){iPositioner.CancelRequest(EPositionerNotifyPositionUpdate);}CFindMeActive::∼CFindMeActive(){// Cancel any outstanding requests - calls DoCancel()Cancel();iPositioner.Close();iPosServer.Close();}The remaining action is to update the screen with the positiondata received from the server.
This is done via Draw() and GetDegreesString() in class CFindMeAppView. CFindMeAppView usesthe iPositionInfo member of class CFindMeActive to get the198EXPLOITING THE PHONE HARDWAREposition data. The latitude and longitude fields are extracted from it nextand passed to GetDegreesString() to format them appropriately foron-screen display.
GetDegreesString() has been reused from theLocationRefAppForS60 sample application in Nokia’s S60 3rd EditionFP1 SDK.void CFindMeAppView::Draw( const TRect& /*aRect*/ ) const{// If there is new location information found.if( iPosDataFound ){// Get the position information and store it in a// TPosition object.TPosition pos;iMyPos->iPositionInfo.GetPosition(pos);TBuf<20> lat;GetDegreesString(pos.Latitude(),lat);TBuf<20> lon;GetDegreesString(pos.Longitude(),lon);...// Write lat and long to the screen.}}6.4 3D Motion SensorsThe Nintendo Wii has achieved phenomenal sales since its launch, largelyby capturing the imagination of players not traditionally considered partof the current game market.
From the perspective of both the gamedeveloper and game player, the most innovative feature of the Wii is the‘Wiimote.’ The Wiimote itself was one of the primary design aspects of theWii, and, in an interview by Kenji Hall for Business Week in November2006,10 Shigeru Miyamoto describes part of Nintendo’s rationale:‘‘The classic controller was something we had become fond of and gamershad become comfortable with. It had many important elements. But it alsohad come to dictate a lot of what went into games – the way graphicswere made, the way battles were fought in role-playing games, the arc ofin-game stories.
They were all being made to fit one standard. Creativitywas being stifled, and the range of games was narrowing. . .‘‘There are examples of controllers that were made for specific games,such as Konami’s Dance Revolution. And for a long time, we thought thatchanging the interface would broaden game design and loosen creative constraints on programmers. We found that to be true when we released the DS.Around that time, we were also agreeing that we would start from the drawing board with something entirely unlike anything we had made before.’’Their solution was the Wiimote, a wireless controller which is able tosense both rotational orientation and translational acceleration along10The Big Ideas Behind Nintendo’s Wii, BusinessWeek, November 2006 www.businessweek.com/technology/content/nov2006/tc20061116 750580.htm.3D MOTION SENSORS199three dimensional axes.
It achieves this through the use of inbuiltaccelerometers, together with a light sensor. This light sensor is usedin conjunction with an array of light emitting diodes centrally positioned above or below the console’s display (see forums.nintendo.comfor more information). The combination of Wiimote’s accelerometer andlight sensor data allows for six degrees of freedom. The Wiimote can beaugmented with additional features, one of which is the amusingly titled‘Nunchuk,’ which features an accelerometer and a traditional analoguejoystick with two trigger buttons.
The overall result is a game interfacecapable of supporting a huge array of input possibilities that will enablenew and exciting video game experiences.Although the first 3D accelerometers have only just been integratedinto mobile phones and these phones have yet to become widespread theyoffer an exciting new direction for game design on mobile phones. TheNokia 5500 is one of the first such equipped phones having been targetedat sports users, using the built-in motion sensors as both a pedometerand speed/distance tracker for various exercising purposes. Other phoneswith motion sensors include Samsung’s SCH-S310 and NTT’s N702.As we went to press, Nokia announced that, in later N95 firmwarereleases, developers can access raw accelerometer data from a device’sinbuilt tri-axis accelerometer, using the official sensor plug-in downloadable from Forum Nokia (search for ‘Sensor Plug-in for S60 3rd EditionSDK’ at the main page of www.forum.nokia.com).
Nokia Research Center has also developed an accelerometer software plug-in specifically forthe Nokia N95. The plug-in is a C++ software library, which can beused with public S60 platform SDKs, although it is not an official releasefrom Forum Nokia and is meant for research and development purposesonly. For more information, and to download the plug-in, please visitresearch.nokia.com/projects/activity monitor.In order to appreciate how these sensors may be utilized for gameplaylet us consider the Nokia 5500’s 6g accelerometer (i.e., it can detectacceleration forces with a magnitude of up to six times that of earth’sgravity). This accelerometer outputs three 12-bit, signed data values ata frequency of around 37 Hz.11 These outputs correspond to the threephone axes (x, y, z) shown in Figure 6.9.In terms of illustrating the opportunities for creating novel interactionmethods using phones with inbuilt accelerometers, it is worth consideringthe following three Figures (6.10, 6.12, 6.13) which show the recordedoutput from the sensors on the Nokia 5500 in three different scenarios.Note that output has been expressed as acceleration forces in g for clarity.Figure 6.10 shows the three accelerometer outputs when the phonewas static on a desk (representing a horizontal plane).
It can be seen that11Vajk T., Bamford W., Coulton P., and Edwards R., Using a Mobile Phone as a Wii-likeController, The Third International Conference on Games Research and Development 2007(CyberGames 2007), Manchester, UK, 10–11 September 2007.200EXPLOITING THE PHONE HARDWARE+Zx =− lg, y = 0, z = 0−Yx =0, y = − lg , z = 0x = 0, y = lg, z = 0x =lg, y = 0, z = 0−Xx = 0, y = 0, z =− lgx =0, y =0, z =lgFigure 6.9 Nokia 5500 3D motion axes6xyzAcceleration (g)420−2−4−6050100150200250300SamplesFigure 6.10Nokia 5500 accelerometer data (phone at rest on a table)outputs x and y are approximately zero (although some sensor noise isevident), and output z is showing a positive 1g force, which is the effectof gravity on the device.
Note that this noise could be reduced by theapplication of a digital filter on the output values, but, in this case, we areshowing the raw data. Overall, this figure illustrates that gravity providesa means of deducing the orientation of the phone which can then beutilized to provide a ‘tilt’ based controller.In terms of games implemented using tilt on mobile phones, there havebeen numerous implementations of the old marble rolling games using3D MOTION SENSORS201Figure 6.11 Tunnel Run tilt controlled driving gamethe camera and one for the Nokia 5500 using the inbuilt accelerometers.Whilst these games are no doubt fun, they are replicating the existinggame input mechanism of previous games, and one game, thus far, hasexplored tilt in relation to other game genres.
This is the 3D graphicsfirst-person driving game called Tunnel Run shown in Figure 6.11.12In Figure 6.12, we see the accelerometer outputs resulting from severalrapid lateral movements of the phone on a desk. At the start of the graph, wesee outputs in the same state as in Figure 6.10, and then very large acceleration forces on the y axis produced by the movement.