Jump to content
  • Advertisement

Archived

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

dan parker

vectors + movement

This topic is 5617 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, I want to make a sphere move around a 3d cube. my sphere has a speed (GLfloat), and a direction (vector). how do i work out the new x,y,z position of the sphere with each loop of the program? manythanks Dan

Share this post


Link to post
Share on other sites
Advertisement
This really depends what your aiming to do exactly. If you only want the sphere to move around the box in a circle just do something like this every frame:

frame+=speed;
if(frame > 360)
{
frame = 0;
}
posx = 3dcube.x+radius*sin(frame*PI/180.0f);

Or do you actually want to calculate this physically correct as in objects orbitting around a planet?

-CProgrammer

Share this post


Link to post
Share on other sites
In case you''re just asking how to calculate the new point from the speed and direction:

1) Scale the direction by the floating point speed.
2) Add this to the current position.

position.x = position.x + (direction.x * speed);
position.y = position.y + (direction.y * speed);
position.z = position.z + (direction.z * speed);

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!