Archived

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

dan parker

vectors + movement

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
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