Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

FERNANDO-BRASIL

A simple question!

This topic is 5936 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

Hi guys! I''m not good on Math and I''m having some problems... Let''s say I have a PERSON stopped at (X = 0 and Y = 0), and I want it to WALK 10 Kilometers in a ANGLE of 45º. Since it''s 2D, it''s quickly easy. You have to do something like this: x = cos((45 * PI) / 180) * 10; y = sin((45 * PI) / 180) * 10; And you''ll certainly find the new XY position of the PERSON. But, How Do I do this in a 3D world (with X, Y, Z and ANGLEX, ANGLEY and ANGLEZ)? Well, I imagine that a hard combination of that calculation could give me the result I want, but I would like to know, A specific FORMULA to do that directly. Does anyone knows? Thank you guys! Any help will be apreciated. Fernando.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

What you''re looking for is something called Spherical Coordinates.

You can find more information about it at
http://mathworld.wolfram.com/SphericalCoordinates.html

You will need two angles, and a radius. In your case, 10km will be your radius, 45 degrees is the azimuthal angle, and you will need a polar angle. Then use the three equations found at that website to compute the x,y,z values.

Share this post


Link to post
Share on other sites
Anyway it is quite easier if you do not have the angle, but the direction vector.
Normalize the vector.
Now, your new coordinates are:
Xnew = Xold + Xdirection * 10; // or multiply whatever you want to go
Ynew = Yold + Ydirection * 10;
Znew = Zold + Zdirection * 10;

if alpha is the angle on the X/Y Plane, and beta the angle of your direction vector from the X/Y Plane, your normailzed direction vector is:

Xdirection = cos((alpha * PI) / 180) * cos((beta * PI) / 180)
Ydirection = sin((alpha * PI) / 180) * cos((beta * PI) / 180)
Zdirection = sin((beta * PI) / 180)

Share this post


Link to post
Share on other sites
Hi Digicube!

I was lookint at the page you passed me, and I''m having some problems to understand it, cause it''s in a very difficult mathematic language (for me)!

If I understood well, If I want to convert to NORMAL COORDINATES to SPHERICAL COORDINATES i have to do this?:

r = sqrt(x * x + y * y + z * z);
azimuthal = atan(y / x);
polar = acos(z / r);

Am'' I write?

And if I want to convert from SPHERICAL to NORMAL, I have to do:

x = r * cos(azimuthal) * sin(polar);
y = r * sin(azimuthal) * sin(polar);
z = r * cos(polar);


I don''t know if it''s correct, but if were, Now, how DO I do to move the player to the direction I want? What formula I use now? Because that page have a lot of FORMULAS!!! And it''s a hard work for me identifying it! :-)

Thank you a lot!!!
Fernando

Share this post


Link to post
Share on other sites
quote:

r = sqrt(x * x + y * y + z * z);
azimuthal = atan(y / x);
polar = acos(z / r);

x = r * cos(azimuthal) * sin(polar);
y = r * sin(azimuthal) * sin(polar);
z = r * cos(polar);


These are the good formulas.
Do you want an instant or progressive movment?

Share this post


Link to post
Share on other sites
Yes, those are the correct formulas. How do you move the player in the direction you want? Well you will need the two angles to specify a direction. As you can see, it can get a bit messy specifying the direction in terms of angles. So you may want to check out linear algebra techniques and use vectors to specify a direction, hence direction vectors.

Do a search on linear algebra and try to learn the basics.

Also as BloodScourge mentioned, do you want the object to instantly move 10km or slowly move to a distance of 10km?

For instant movement, you just update the original x,y,z values to the new ones with a radius of 10km on the next frame. But if you want to slowly move to a distance of 10km, then you will need to slowly increase the radius each frame.

Share this post


Link to post
Share on other sites
Hi Digicube! I made some searches on the NET, and I think I discovered what the DIRECTION VECTOR is.

See if it''s right:

For example, if I have a MATRIX:

| A B C D |
| E F G H |
| I J K L |
| M N P Q |

The X-Direction Vector will be A, E, I;
The Y-Direction Vector will be B, F, J;
and the Z Direction Vector will be C, G, K;

I think that''s right!

Now, How I could do that?

Don''t be afraid in giving me a resolution, cause I''ve already worked with MATRICES to do rotations, translations, etc , and I think I''ll understand it!

Thank you!

Fernando

Share this post


Link to post
Share on other sites

  • Advertisement
×

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!