vectors + movement
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
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
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
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) 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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement