Can't translate/rotate points used in line/quad strips??

Hi, Im in the middle of writing my first opengl project. Its attempting to simulate a cantilever square beam bending under an end load. Im using VS.NET

Im trying to draw a quad strip down the length of each side of the beam to generate the sides. I also have to take into consideration the fact that the beam is bending so each strip must be rotated a little as theyre being drawn. Here is a bit of code from my project:

glPushMatrix();
glBegin(GL_QUAD_STRIP);
do{

  x=L*(i/500);
  i=i+1;
  incx=(x+(L/500));
  
  w=5*((P*x*x)*((3*L)-x))/(6*E*I);
  theta=atan2(w,incx)*(180/PI);
  
  
  glTranslatef(incx,-w,0.0);
  glRotatef(-theta,0.0,0.0,1.0);
  glTranslatef(-incx,w,0.0);
  
  
  glColor4f(0.0,1.0,0,1.0);
  glVertex3f(incx,-w+1,0.0);
  glVertex3f(incx,-w-1,0.0);
  
  

  GLfloat var1=(incx-oldx);
  GLfloat var2=(w-oldw);

  GLfloat dx2=var1*var1;
  GLfloat dy2=var2*var2;

  length=length+(sqrt(dx2+dy2));  //length of curve

  oldx=incx;
  oldw=w;
  
  
  }while(length<=L && length>0);
  glEnd();
  glPopMatrix;

Im basically starting a Quad strip and then generating 2 verticies until the length is determined. But it seems as though my translate and rotate lines arent doing anything.

Ive tested this little loop using polygons and they rotate fine. The main problem is translating and rotating the next set of points to be used in a quad/line strip. is that possible? or do you have to wait until the whole strip is done?

[This message has been edited by KenR7A (edited 11-29-2002).]

You’re not allowed to change the matrices inside a glBegin/glEnd pair.

As the other poster noted you can not use any matrix commands between glbegin/end.

But what you can do it, is move the points using math inside.

glTranslate is just basicly moving the vecto rpoints N number of points along the X axis.
Just add/sub each vertex.

now glRotate is a little more tricky, you have to rotate via the current axis point, with sin/cos function on each point. 3D rotation is a bit move complex.

glPushMatrix();
glBegin(GL_QUAD_STRIP);
do{

  x=L*(i/500);
  i=i+1;
  incx=(x+(L/500));
  
  w=5*((P*x*x)*((3*L)-x))/(6*E*I);
  theta=atan2(w,incx)*(180/PI);
  
  
  glTranslatef(incx,-w,0.0);
  glRotatef(-theta,0.0,0.0,1.0);
  glTranslatef(-incx,w,0.0);
  
  
  glColor4f(0.0,1.0,0,1.0);
  glVertex3f(incx,-w+1,0.0);
  glVertex3f(incx,-w-1,0.0);
  
  

  GLfloat var1=(incx-oldx);
  GLfloat var2=(w-oldw);

  GLfloat dx2=var1*var1;
  GLfloat dy2=var2*var2;

  length=length+(sqrt(dx2+dy2));  //length of curve

  oldx=incx;
  oldw=w;
  
  
  }while(length<=L && length>0);
  glEnd();
  glPopMatrix;

Im basically starting a Quad strip and then generating 2 verticies until the length is determined. But it seems as though my translate and rotate lines arent doing anything.

Ive tested this little loop using polygons and they rotate fine. The main problem is translating and rotating the next set of points to be used in a quad/line strip. is that possible? or do you have to wait until the whole strip is done?

[This message has been edited by KenR7A (edited 11-29-2002).][/b]<HR></BLOCKQUOTE>

[This message has been edited by nexusone (edited 11-30-2002).]

ouch…ok, I see now. thanks for the help, I shouldve caught that one on my own. lets see if I can do this with math now.

[This message has been edited by KenR7A (edited 11-30-2002).]

alright! got it:

glBegin(GL_QUAD_STRIP);
do{
		
		x=L*(i/500);
		i=i+1;
		incx=(x+(L/500));
		
		w=5*((P*x*x)*((3*L)-x))/(6*E*I);
		theta=atan2(-w,incx);
		
		/**begin translation and rotation**/
		GLfloat savx=incx;
		GLfloat savwp=-w+1;
		GLfloat savwn=-w-1;

		//move to origin
		savx=savx-incx; 
		savwp=savwp+w;
		savwn=savwn+w;

		//rotate about z axis
		GLfloat xp1= savx*cos(theta)-savwp*sin(theta);
		GLfloat yp1= savx*sin(theta)+savwp*cos(theta);
		GLfloat xp2= savx*cos(theta)-savwn*sin(theta);
		GLfloat yp2= savx*sin(theta)+savwn*cos(theta);

		//move back to original coordinates
		xp1=xp1+incx;
		yp1=yp1-w;
		xp2=xp2+incx;
		yp2=yp2-w;
		/**end translation and rotation**/

		glColor4f(0.0,1.0,0,1.0);
		glVertex3f(xp1,yp1,0.0);
		glVertex3f(xp2,yp2,0.0);
		
		

		GLfloat var1=(incx-oldx);
		GLfloat var2=(w-oldw);

		GLfloat dx2=var1*var1;
		GLfloat dy2=var2*var2;

		length=length+(sqrt(dx2+dy2));  //length of curve

		oldx=incx;
		oldw=w;
		
		
		}while(length<=L && length>0);
		glEnd();

Im glad that my professor taught us the math behind rotations rather than say “glRotate is all you need!” thanks again

[This message has been edited by KenR7A (edited 11-30-2002).]