Sign in to follow this  
jbosch

Dynamic gravity vector

Recommended Posts

jbosch    107
Hi,


I have a physics engine in my game. I have to set him the gravity vector to initialize it. That would normally be x,y(0,10). Ok, easy one. But what happens if the container is a mobile, and I want to modify the gravity vector according to the accelerometer information? This is, if I give the mobile phone a 90º inclination, the "ground" is now different than in its initiajl state, I want to reflect this, but at any angle, not just 90º movements.


This can be difficult to explain, so I have attached a picture

[attachment=2380:mobile.png]



Any idea?

Share this post


Link to post
Share on other sites
Hodgman    51226
Does your physics engine provide a function for setting a new gravity vector? Is the question how to change the gravity vector, or how to figure out what the new vector is?
Take your default gravity vector and [url="http://www.google.com.au/search?q=2d+rotation"]rotate[/url] it by the desired angle.

Share this post


Link to post
Share on other sites
jbosch    107
thanks Hodgman,


The question is more about how to calculate this angle.

The accelerometer gives me some information. For example, when the phone is landscape, the acceleration (x,y) its (1,0), and when I put the phone in portrait position, its (0,1).



Any idea?

Thanks!

Share this post


Link to post
Share on other sites
japro    887
So the accelerometer always gives you a normalized vector to the "down"-direction? Then just multiply that vector with the magnitude of your g.

Share this post


Link to post
Share on other sites
jbosch    107
[quote name='japro' timestamp='1305998194' post='4813900']
So the accelerometer always gives you a normalized vector to the "down"-direction? Then just multiply that vector with the magnitude of your g.
[/quote]


whaaw, you are right. Very simple! I feel dumb now jajaja

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this