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

Started by
11 comments, last by dzeligman 14 years, 1 month ago
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.
Advertisement
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]
you might be interested in this article, which recreates (approximately) SMG movement: http://www.gamasutra.com/view/feature/3593/games_demystified_super_mario_.php
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);
}
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.
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.
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.
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.
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.?
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?

This topic is closed to new replies.

Advertisement