언어 설정

Menu
Sites
Language
How to use Gravity Sensor in my application
 
Hi,
I have developed an application in which Gravity Sensor is required.how can i use this.I have searched on help menu but i not got it. I am developing web application.
 
 
 
please help me
 
 
 
 
Thanks and regards
Mohit Kumar

Responses

3 댓글
Seoghyun Kang

Hello,

 

You can find the SensorBall sample application in the Tizen SDK.

The SensorBall has the code about the gravity.(js/models/gravity.js) I think it will be helpful for you.

 

The following is the core code. Please refer it.

 

window.addEventListener('devicemotion', onDeviceMotion);

/* models/ball.js */
function setMotionData(event) 
{
   motionData = event;
}


/* models/gravity.js */
function calculateGravityBallPosition() 
   {
   var x = 0,
       y = 0,
       ddx = 0,
       ddy = 0;

   if (motionData !== null) 
   {
      x = -motionData.accelerationIncludingGravity.x;
      y = -motionData.accelerationIncludingGravity.y;
   }
   ddx = x * -cdd;
   ddy = y * cdd;
   dX += ddx;
   dY += ddy;
   dX *= resistance;
   dY *= resistance;
   ballX += dX;
   ballY += dY;
} 

 

 

 

daniel kim

Hi,

Below link has more information about  accelerationIncludingGravity. Please refer it.

   http://www.w3.org/TR/2011/WD-orientation-event-20111201/

Regards.

Alex Dem

Hi,
fyi: there is one more sample game(applicable for Tizen 2.3 too):
https://developer.tizen.org/community/tip-tech/sample-game-using-device-sensors-your-web-applications
Alexey.