simple rotation problem..

hello , i am new to opengl and i am trying to design a 2d arm.
its basicly consist of 3 rectangles.
Everything was fine till i try to rotate the joints of the arm.I couldnt make the pic move continuosly...

the whole arm,wrist and elbow rotations works perfectly individually , but i couldn`t make them move together . If u please have a look at my code you are gonna understand me better . My code is below

note:: Press '1' ,'2','3' to rotate arm,elbow and wrist

[code]
#include
#include
#include
#include
#include

void display(void);
void init(void);
void drawstack(void);
void DrawRectangles(void);
void BaranKeyboardFunc(unsigned char ,int , int );
void readfile(void);
void RandomColor(void);
void ChangeSize(GLsizei w, GLsizei h);
void DrawArmOneJointOne(void);
void DrawArmOneJointTwo(void);
void DrawArmOneJointThree(void);

int flag=0,stackwidth,RecNum,unit,i,DrawCounter;
int g_window,random,random2,random3;
float posx=0.0f;
float posy=0.0f;
float posz=-20.0f;
int bayrak;
FILE *BaranPtr;
float a=0;

float arm1joint1=0,arm1joint2=0,arm1joint3=0;

struct rectangle
{
float x;
float y;
float wit;
float hayt;
float x2;
float y2;
int color1;
int color2;
int color3;
int cakisma;

}rec[100];

int main(int argc,char **argv)
{

// srand(time(NULL));




RandomColor();
glutInit(&argc,argv);
init();

glutMainLoop();
return 0;
}


void init(void){


glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
glutInitWindowSize(800,600);
g_window=glutCreateWindow("Baran Tamer");

glutDisplayFunc(display);
glutKeyboardFunc(BaranKeyboardFunc);
//glutSpecialFunc();
//glutReshapeFunc(ChangeSize); //ekrana fit olan sekilde kullanmak icin bu satiri kapatin


glClearColor(0.0f,0.0f,0.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,800.0f/600.0f,0.1f,100.0f);

glDisable(GL_DEPTH_TEST);



}

void display(void){


glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();



//arm1 joint1
glTranslatef(0,0,-20);
//DrawArmOneJointOne();
if(flag==1)
{
glRotatef(arm1joint1,0.0, 0.0, -20);
arm1joint1++;
}
DrawArmOneJointOne();
//end of arm joint one




//arm1 joint2
glTranslatef(-4,0,0);
if(flag==2)
{
glRotatef( arm1joint2,0.0, 0.0,-20);
arm1joint2++;
}
DrawArmOneJointTwo();
//end of arm joint two


//arm3 joint3
glTranslatef(-4,0,0);
if(flag==3)
{
glRotatef( arm1joint3,0.0, 0.0, -20);
arm1joint3++;

}
DrawArmOneJointThree();
//end of arm joint three






glFlush();
glutSwapBuffers();


}

void DrawArmOneJointOne(void){

glColor3b(100.0,100,100);
glRecti(-4,-1,0,0);




}



void DrawArmOneJointTwo(void){

glColor3b(400.0 ,100.0,100);
glRecti(-4,-1,0,0);

}


void DrawArmOneJointThree(void){

glColor3b(400.0 ,200.0,100);
glRecti(-2,-1,0,0);

}






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

switch(key){

case '1':
flag=1;
printf("joint1");

break;
case '2':
flag=2;
printf("joint2");

break;
case '3':
flag=3;
printf("joint3");

break;

default:
printf("yanlis tus");
break;


return;
}








glutPostRedisplay();



}





void RandomColor(void)
{
int sayac;

for(sayac=0;sayac<RecNum;sayac++){
random=rand()%100+1;
random2=rand()%100+1;
random3=rand()%100+1;

rec[sayac].color1=random;
rec[sayac].color2=random2;
rec[sayac].color3=random3;


}







}







void ChangeSize(GLsizei w, GLsizei h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(float)w/h,0.1f,100.0f);
}





[/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories