Sign in to follow this  
adityav89

Would like to know how to create a SuperMario Galaxy type movement

Recommended Posts

adityav89    122
Hello, i would like to know how to create relative movement on a 3d sphere. ie. i have got the earth(is really round in 3d), now i would like to know how to move on it.(Eg. is Super Mario Galaxy for the wii) one thing that i know : person.translate(0, radius, 0) person.rotateX(x) person.rotateZ(y) where x += speed * cos(direction) , y += speed * sin(direction) and direction is the angle the person is facing.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by adityav89
Hello, i would like to know how to create relative movement on a 3d sphere.

ie. i have got the earth(is really round in 3d),
now i would like to know how to move on it.(Eg. is Super Mario Galaxy for the wii)

one thing that i know :
person.translate(0, radius, 0)
person.rotateX(x)
person.rotateZ(y)

where x += speed * cos(direction)
, y += speed * sin(direction)
and direction is the angle the person is facing.
I didn't follow the method described in your post completely (partly because I don't know what the 'translate', 'rotateX', and 'rotateZ' functions do), but I'm not sure if it'll work the way you're expecting. (Have you tried it yet? If so, what were the results?)

In any case, here's how I'd do it. Instead of trying to create the player transform from scratch each frame, store it from frame to frame and update it incrementally.

First, choose an initial transform for the player (e.g. standing at one of the 'poles' of the sphere). Then, for each update:
// Update yaw (note that this is done using a rotation about the local up axis):
person.rotate_about_local_up(yaw_delta);

// Update the position. This will move the player tangent to the sphere, so after this step
// the player will be 'floating' above the sphere a bit.
person.position += person.forward * speed * time_step;

// Get the sphere normal corresponding to the point directly under the player:
vector normal = normalize(person.position);

// Drop the player back down to the surface:
person.position = normal * sphere.radius;

// Now the person is on the surface, but probably isn't perfectly 'upright' with respect
// to it, so we apply a normalizing relative rotation to correct this:
matrix rotation = matrix_rotate_vec_to_vec(person.up, normal);
person.apply_rotation(rotation);
Obviously this skips over quite a few details, but ultimately it breaks down to just a few math functions that should be provided by any good math library. If you need help with the details though, feel free to ask.

(Note that the way in which forward motion is applied above is somewhat approximate with respect to the speed of the player. I used this method because it's simple and straightforward, but a more accurate method would be to move the player along the 'great circle' that lies in the same plane as the player's forward vector. Depending on how this movement is applied, you might still want to 'renormalize' the player position afterwards. The step where you realign the player to the sphere surface would remain the same.)

[Edit: Fixed typo.]

[Edited by - jyk on February 20, 2010 9:26:50 PM]

Share this post


Link to post
Share on other sites
adityav89    122
No, i know about pitch, yaw and roll they're same as rotatingXYZ but would like to know a mathematical sequence to multiply the matrices.

Let assume i got a sphere at point 0,0,0 with radius 10

now i got a man who would like to move above the sphere.

So what do i need to do now?

What i did was
translate the man to (0, 10, 0)
then i need to rotate him along some axis that i just cant get right.

THIS IS MY XNA Code :
----------------------

public void PartOfPlanet(Planet planet)
{
world = Matrix.CreateRotationY(MathHelper.ToRadians(Direction)) * Matrix.CreateTranslation(0, planet.Size + 0.25f, 0) *
Matrix.CreateRotationX(pos.X) * Matrix.CreateRotationZ(pos.Y) * planet.AxisAndAlign;

cam_lookat = world.Translation;
Matrix tmp = Matrix.CreateTranslation(0, 10, 10) * world;
cam_pos = tmp.Translation;
XBase.UpdateCamera(cam_pos, cam_lookat);
}

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by adityav89
No, i know about pitch, yaw and roll they're same as rotatingXYZ but would like to know a mathematical sequence to multiply the matrices.

Let assume i got a sphere at point 0,0,0 with radius 10

now i got a man who would like to move above the sphere.

So what do i need to do now?

What i did was
translate the man to (0, 10, 0)
then i need to rotate him along some axis that i just cant get right.

THIS IS MY XNA Code :
----------------------

public void PartOfPlanet(Planet planet)
{
world = Matrix.CreateRotationY(MathHelper.ToRadians(Direction)) * Matrix.CreateTranslation(0, planet.Size + 0.25f, 0) *
Matrix.CreateRotationX(pos.X) * Matrix.CreateRotationZ(pos.Y) * planet.AxisAndAlign;

cam_lookat = world.Translation;
Matrix tmp = Matrix.CreateTranslation(0, 10, 10) * world;
cam_pos = tmp.Translation;
XBase.UpdateCamera(cam_pos, cam_lookat);
}
If you re-read my post and the article that raigan linked to, you should see that the method(s) being described don't involve building a transform for the player 'from scratch' each update. Rather, the player transform is adjusted incrementally each update, with the goal of keeping the player 'on' the surface beneath them (more or less) and aligned with the surface normal. This is the approach I'd recommend.

Share this post


Link to post
Share on other sites
adityav89    122
I did see the article but however for my really simple game i just created a simple sphere without normals, i also saw how the spherical co-ordinate system works but i didnt get the exact type of movement i needed.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
I did see the article but however for my really simple game i just created a simple sphere without normals, i also saw how the spherical co-ordinate system works but i didnt get the exact type of movement i needed.
Normals shouldn't be a problem. The unit-length normal at any point p on the surface of a sphere can be computed trivially as normalize(p - sphere.center). If the sphere is centered at the origin, that just becomes normalize(p).
Quote:
After some googling for math, i finally know what i need , its how to :
convert 2d Cartesian coords to a point on the sphere OR Spherical coord.
I'm not sure how you would map strictly 2-d motion to a sphere in the way you describe and still get good results, but maybe someone else will be able to offer some advice in that area.

Share this post


Link to post
Share on other sites
adityav89    122
I think im gonna go with the normals method, but i couldnt understand the BasicBlitz code that was written and how its mapped to the input.

it says that u should get the normal vector from the player's pos - center but how to represent the players pos.?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
it says that u should get the normal vector from the player's pos - center but how to represent the players pos.?
Typically you would represent the player's position using a 3-d vector (more specifically, a point [x, y, z] defined relative to the 3-d Cartesian coordinate system).

Does that answer your question?

Share this post


Link to post
Share on other sites
cache_hit    614
Can't you just translate the player in the plane tangent to the sphere in the direction that the player is facing, and then after the translation "clamp" the player to the sphere again? By clamp I mean shoot a ray from the player's final location to the center of the sphere, and set the player's position to the point of intersection. This doesn't even require any trig calculations, only polygon / ray intersections.

SMG of course deals with inside-out motion, for which this will be problematic, but it might be a start.

I'm no expert though, so maybe this method has some implications I'm not considering.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by cache_hit
Can't you just translate the player in the plane tangent to the sphere in the direction that the player is facing, and then after the translation "clamp" the player to the sphere again? By clamp I mean shoot a ray from the player's final location to the center of the sphere, and set the player's position to the point of intersection. This doesn't even require any trig calculations, only polygon / ray intersections.

SMG of course deals with inside-out motion, for which this will be problematic, but it might be a start.

I'm no expert though, so maybe this method has some implications I'm not considering.
This is the method I described in my first reply, and yeah, it should work fine in most cases (there are some caveats though, which I discussed briefly towards the bottom of the post).

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