Hi OpenGL experts,
I'm beginner in OpenGL and I have a very specific problem:
I'm making an application, which creates 3D objects and almost averything work fine, but when I create 2 objects and try to make transformation of the first one, then the second one goes to x=0,y=0,z=doesn't change.
I don't know what to do .
Please help me .
Here are the parts of source code:
Code: procedure TForm1.Init; begin glClearColor(1.0,1.0,1.0,0.0); glMatrixMode(GL_PROJECTION); glFrustum(-0.1, 0.1, -0.1, 0.1, 0.3, 50.0); glMatrixMode(GL_MODELVIEW); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); end; procedure TForm1.Draw; begin glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); glLoadIdentity; glTranslatef(0, 0, -10); AXISxyz; if object[1] then begin glPushMatrix; glTranslatef(movex,movey,depth); glRotate(rotx,1,0,0); glRotate(roty,0,1,0); obj1(1); glPopMatrix; end; if object[2] then begin glPushMatrix; glTranslatef(movex2,movey2,depth2); glRotate(rotx2,1,0,0); glRotate(roty2,0,1,0); obj2(1,2,1); glPopMatrix; end; SwapBuffers(wglGetCurrentDC); end; procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button=mbLeft then begin mouse:=1; coordX:=X; coordY:=Y; coordX2:=X; coordY2:=Y; end; if Button=mbRight then begin mouse:=2; coordY:=Y; coordY2:=Y end; end; procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if not CheckBox1.Checked then //if checked then translating if not then rotating begin if mouse=1 then //left begin if transform[1] then begin rotX:=rotX+(Y-coordY)/2; rotY:=rotY+(X-coordX)/2; coordX:=X; coordy:=Y; Draw; end; if transform[2] then begin rotX2:=rotX2+(Y-coordY2)/2; rotY2:=rotY2+(X-coordX2)/2; coordX2:=X; coordy2:=Y; Draw; end; end; if mouse=2 then //right begin if transform[1] then depth:=depth+(Y-coordY)/10; if transform[2] then depth2:=depth2+(Y-coordY2)/10; coordY:=Y; coordY2:=Y; Draw; end; end; if CheckBox1.Checked then begin if mouse=1 then //left begin if transform[1] then begin moveX:=moveX+(X-coordX)/50; moveY:=moveY-(Y-coordY)/50; Draw; end; if transform[2] then begin moveX2:=moveX2+(X-coordX2)/50; moveY2:=moveY2-(Y-coordY2)/50; Draw; end; coordX:=X; coordy:=Y; coordX2:=X; coordy2:=Y; end; end; end; procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin mouse:=0; end; procedure TForm1.obj1(a:GLfloat); begin glBegin(GL_POLYGON); //front glColor3f(1.0,0.0,0.0); glVertex3f(a, a, a); glVertex3f(-a, a, a); glVertex3f(-a, -a, a); glVertex3f(a, -a, a); glEnd; glBegin(GL_POLYGON); //back glColor3f(0.0,1.0,0.0); glVertex3f(a, a, -a); glVertex3f(a, -a, -a); glVertex3f(-a, -a, -a); glVertex3f(-a, a, -a); glEnd; glBegin(GL_POLYGON); //left glColor3f(0.0,0.0,1.0); glVertex3f(-a, a, a); glVertex3f(-a, a, -a); glVertex3f(-a, -a, -a); glVertex3f(-a, -a, a); glEnd; glBegin(GL_POLYGON); //right glColor3f(1.0,1.0,0.0); glVertex3f(a, a, a); glVertex3f(a, -a, a); glVertex3f(a, -a, -a); glVertex3f(a, a, -a); glEnd; glBegin(GL_POLYGON); glColor3f(0.0,1.0,1.0); //top glVertex3f(-a, a, -a); glVertex3f(-a, a, a); glVertex3f(a, a, a); glVertex3f(a, a, -a); glEnd; glBegin(GL_POLYGON); glColor3f(1.0,0.0,1.0); //bottom glVertex3f(-a, -a, -a); glVertex3f(a, -a, -a); glVertex3f(a, -a, a); glVertex3f(-a, -a, a); glEnd; end; procedure TForm1.obj2(a,b,c:GLfloat); begin glBegin(GL_POLYGON); //front glColor3f(1.0,0.0,0.0); glVertex3f(a, b, c); glVertex3f(-a, b, c); glVertex3f(-a, -b, c); glVertex3f(a, -b, c); glEnd; glBegin(GL_POLYGON); //back glColor3f(0.0,1.0,0.0); glVertex3f(a, b, -c); glVertex3f(a, -b, -c); glVertex3f(-a, -b, -c); glVertex3f(-a, b, -c); glEnd; glBegin(GL_POLYGON); //left glColor3f(0.0,0.0,1.0); glVertex3f(-a, b, c); glVertex3f(-a, b, -c); glVertex3f(-a, -b, -c); glVertex3f(-a, -b, c); glEnd; glBegin(GL_POLYGON); //right glColor3f(1.0,1.0,0.0); glVertex3f(a, b, c); glVertex3f(a, -b, c); glVertex3f(a, -b, -c); glVertex3f(a, b, -c); glEnd; glBegin(GL_POLYGON); glColor3f(0.0,1.0,1.0); //top glVertex3f(-a, b, -c); glVertex3f(-a, b, c); glVertex3f(a, b, c); glVertex3f(a, b, -c); glEnd; glBegin(GL_POLYGON); glColor3f(1.0,0.0,1.0); //bottom glVertex3f(-a, -b, -c); glVertex3f(a, -b, -c); glVertex3f(a, -b, c); glVertex3f(-a, -b, c); glEnd; end;
Other parts of the code are not so important.
|