#### Archived

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

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

## 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 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;
}

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

-CProgrammer

##### 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);

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631759
• Total Posts
3002138
×