# please solve my problem in rotation and translatio

hai friends

what i want means i want to move the helicopter to its front and back sides only using ‘x’ and ‘X’ keys respectivly. and i will rotate the helicopter where it was using ‘r’ and ‘R’ keys respectively.

this is my sample helicopter program i have doubt in translation and rotation. here i have used wx,wy wz coordinates for the helicopter.i want the helicopter move front and back only. here i have used x and ‘X’ for move front and back respectively. i have used ‘r’ and ‘R’ for rotaion in Positive y axis and negative y axis.
what is my problem is i will move the helicopter to 4 points to x axis. then i will rotate 90 degree in y axis. then i will move the helicopter to 4 points. remain it would go to x axis. but it will not going to its front face.

#include<gl/glut.h>

void drawcube();

int wx=0,wy=0,wz=0;

int fanangle=0;

int i=0;
float backpoint=0;

int angle=0;

void init()
{
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);

}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
gluLookAt(0,5,10,0,0,-2,0,1,0);

``````//body part
``````

glPushMatrix();
glTranslatef(wx,wy,wz);
glRotatef(angle,0,1,0);
glTranslatef(-wx,-wy,-wz);
glPushMatrix();
glScalef(.5,.5,.5);
//glRotatef(-90,0,1,0);
//glRotatef(-30,0,0,1);
glColor3f(1,1,1);
glPushMatrix();
glTranslatef(wx-3,wy,wz);
glScalef(1,1,.7);
gluSphere(body,1.5,30,30);
glScalef(1,1,1.3);
glTranslatef(wx+0.6-wx,wy-wy,wz-wz);
glScalef(1,1,.7);
gluSphere(body,1.5,30,30);
glPopMatrix();

``````//first fan

//beam
glColor3f(0,0,1);
glPushMatrix();
glTranslatef(wx-2.5,wy+1.5,wz);
glRotatef(fanangle,0,1,0);
glScalef(.5,5,.5);
glutSolidCube(0.3);
//glutWireCube(.3);
glPopMatrix();

//fan

glColor3f(1,0,1);
glPushMatrix();
glTranslatef(wx-2.5,wy+2.1,wz);
glRotatef(fanangle,0,1,0);
glScalef(14,.5,.5);
glutSolidCube(.3);
//glutWireCube(.3);
glPopMatrix();

glPushMatrix();
glTranslatef(wx-2.5,wy+2.1,wz);
glRotatef(fanangle,0,1,0);
glScalef(.5,.5,14);
glutSolidCube(.3);
//glutWireCube(.3);
glPopMatrix();

//back
//back body one
glPushMatrix();
glTranslatef(wx-2,wy+0.4,wz);
glScalef(1,0.6,.8);
glRotatef(90,0,1,0);
gluCylinder(back,1.2,0.5,4,30,30);
glPopMatrix();

//back body	 two
glPushMatrix();
glTranslatef(wx-2,wy+0.4,wz);
glRotatef(90,0,1,0);
gluCylinder(back,1.0,0.5,4,30,30);

glPopMatrix();

//back body three
glPushMatrix();
glTranslatef(wx+2,wy+0.4,wz);
glRotatef(90,0,1,0);
gluCylinder(back,0.5,0.3,1,30,30);
glPopMatrix();

//back body four
glColor3f(0,0,1);
glPushMatrix();
glTranslatef(wx+3,wy+0.4,wz);
gluSphere(back,0.3,30,30);
glPopMatrix();

//back top

glPushMatrix();
glPopMatrix();
``````

glPopMatrix();
glPopMatrix();

``````fanangle=(fanangle+5)%360;
glutSwapBuffers();
glutPostRedisplay();
``````

}
void reshape(int w,int h)
{
if(h==0)
h=1;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
gluPerspective(52.0f,w/h,1,1000);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(unsigned char key,int x,int y)
{
switch(key)
{
case 27:
exit(0);
break;
case ‘x’:
wx++;
break;
case ‘X’:
wx–;
break;
case ‘z’:
wz++;
break;
case ‘Z’:
wz–;
break;
case ‘r’:
angle=(angle+1)%360;
break;
case ‘R’:
angle=(angle-1)%360;
break;
}
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGB);
glutInitWindowSize(1024,768);
glutInitWindowPosition(0,0);
glutCreateWindow(“2d Circle”);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

Have you tried switching over to radians?

i think that using an object(X.obj) made whith a graphic softwar (like 3DS max) then load it is butter than that.