Jump to content
• Advertisement

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

This topic is 3069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

##### Share on other sites
Advertisement
Quote:
 Original post by adityav89Hello, 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

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by adityav89No, 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 10now 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

##### Share on other sites
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

##### Share on other sites
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.

#### Share this post

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5
• Advertisement

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631740
• Total Posts
3001959
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!