http://www.gamasutra.com/view/feature/3593/games_demystified_super_mario_.php
Don't forget to check out the stick figure programmer's artwork in the second page.
Normally, gravity is calculated as a force between two objects that is directly proportional to the product of their respective masses and inversely proportional to the square of the distance from the objects' centers.
Force of Gravity = Gravitational Constant * ( ( mass1 * mass2 ) / distance2)
To simplify, gravity follows the inverse square law.
Intensity of Gravity = 1 / Distance2
This means that as an object moves closer to a planet, the gravity between them increases exponentially. Conversely, as an object moves away from a planet the gravity between them weakens very quickly.
Traditionally, the force of gravity is applied using the radius of the more massive body. For instance, if we were to calculate the gravity holding a person to Earth we'd plug the Earth's radius into the above equation. Additionally, if the mass is great enough to hold a person down, the celestial body will be round. This is where reality and Super Mario Galaxy differ.
In Galaxy, players are pulled toward each and every arbitrarily shaped planetoid they encounter. At this point all real world physics equations break down and tell us nothing about the gravity in the game, which as in most cases is a trick. Much like the magicians in The Prestige, game developers are always attempting to one up each other with new tricks. As we all know, Nintendo stole the show with its latest.
To accomplish this "trick", the developers use the surface normals of whatever planetoid Mario inhabits to keep him running and jumping happily along. This is how gravity is distributed through completely irregular bodies. A surface normal is a ray or unit vector that runs perpendicular to a plane.
In the illustration above we can see an arrow pointing up from a plane, the arrow represents the surface normal of a plane that points straight up. If we're using a Y-up right handed coordinate system, that normal would be a (0, 1, 0) which means it's not pointing along the x or z axes at all and that the full length of the vector is all in the up direction.
A unit vector always has a length of 1, which is then distributed amongst the x, y, and z directions. The longer one direction is the shorter the others must become.
Don't forget to check out the stick figure programmer's artwork in the second page.