PDA

View Full Version : animating a NURBS surface



dnstapes
10-13-2000, 08:54 AM
I need to know how to do simple animation of a NURBS surface. I have written some code, and so far I have made the NURB surface, and started the animation process. My approach to this is to slightly adjust the control points to animate. Right now I have set up my program so that when I press the 'a' key, the control points are adjusted once. I would like to be able to press the 'a' key and have the animation go until I press the 'a' key again. While the animation is going, I would like to be able to do other stuff, like simple keyboard input. For example, when I press the arrow keys, the NURB surface rotates. I would like to be able to do that while my object is being animated. Here is a snippet of code from the keyboard function. Anyone have any ideas?
thanks
dana

if (animate) {
if (count==5)
{
count=0;
backwards=!backwards;
}
for(int y=0; y<4; y++)
{
if (!backwards)
{
ctrlpoints[1][y][2]=ctrlpoints[1][y][2]+0.2;
ctrlpoints[2][y][2]=ctrlpoints[2][y][2]-0.2;
ctrlpoints[3][y][2]=ctrlpoints[3][y][2]+0.3;
}
else
{
ctrlpoints[1][y][2]=ctrlpoints[1][y][2]-0.2;
ctrlpoints[2][y][2]=ctrlpoints[2][y][2]+0.2;
ctrlpoints[3][y][2]=ctrlpoints[3][y][2]-0.3;
}
}
count++;
}

10-21-2000, 01:06 PM
Originally posted by dnstapes:
I need to know how to do simple animation of a NURBS surface. I have written some code, and so far I have made the NURB surface, and started the animation process. My approach to this is to slightly adjust the control points to animate. Right now I have set up my program so that when I press the 'a' key, the control points are adjusted once. I would like to be able to press the 'a' key and have the animation go until I press the 'a' key again. While the animation is going, I would like to be able to do other stuff, like simple keyboard input. For example, when I press the arrow keys, the NURB surface rotates. I would like to be able to do that while my object is being animated. Here is a snippet of code from the keyboard function. Anyone have any ideas?
thanks
dana

if (animate) {
if (count==5)
{
count=0;
backwards=!backwards;
}
for(int y=0; y<4; y++)
{
if (!backwards)
{
ctrlpoints[1][y][2]=ctrlpoints[1][y][2]+0.2;
ctrlpoints[2][y][2]=ctrlpoints[2][y][2]-0.2;
ctrlpoints[3][y][2]=ctrlpoints[3][y][2]+0.3;
}
else
{
ctrlpoints[1][y][2]=ctrlpoints[1][y][2]-0.2;
ctrlpoints[2][y][2]=ctrlpoints[2][y][2]+0.2;
ctrlpoints[3][y][2]=ctrlpoints[3][y][2]-0.3;
}
}
count++;
}

Here's what you do to use the arrow keys:
void SpecialKeys(int key, int x, int y)
{

if(key == GLUT_KEY_LEFT)
//whatever you want to move

if(key == GLUT_KEY_RIGHT)
//whatever you want to move
if(key == GLUT_KEY_UP)
//whatever you want to move

if(key == GLUT_KEY_DOWN)
//whatever you want to move


// Refresh the Window
glutPostRedisplay();
}
then register this function in main like this
glutSpecialFunc(SpecialKeys);

For turning the animation off and on you need a keyboard function like this:

void keyboard(unsigned char key, int x, int y )
{

switch( key ){

case 'a':

AnimationEnable = !AnimationEnable;
break;

case 'q':
exit(0);

case 'r':
reset( );
break;
}
glutPostRedisplay();
}

then register the function in main as follows
glutKeyboardFunc( keyboard);

I hope this helps
Guillermo Vargas
gvc@fern.csustan.edu