I am trying to translate an OpenGl object around in a helical pattern. I cannot figure this out. Problem is I know I need to increment the angle for the x, y, and z coordinates, but the translate function that I use only moves the object by a translate amount which is specific to the object. The Axis I am using is Y up, Z toward the screen and X to the right.
public override void Move(Figure fig)
{
double angle = 0;
double x = RADIUS * Math.Cos(angle);
double y = (angle / RADIUS);
double z = RADIUS * Math.Sin(angle);
fig.Translate(x, y, z);
angle += .5;
}
public void Translate(double fx, double fy, double fz)
{
translateAmt[0] += fx;
translateAmt[1] += fy;
translateAmt[2] += fz;
}
Here are two ways you could approach this:
Procedurally
Check out the
ProcessHelixfunction in NeHe Lesson 36. A little bit hard to read but you should be able to see the basic loop and calculations used to get the points along a helix.2 Translations and a Rotation
If you perform these transformations in the proper order you can get the helical motion. This is the order you would imagine doing it in your head:
So in OpenGL, you’d do those backwards, as the last matrix specified is the first one applied… translate in +y (time dependent), rotate around y (time dependent), and translate in x.