Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Jun 04, 2024 09:37

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: transformation problem
BeitragVerfasst: Do Feb 01, 2007 17:59 
Offline
DGL Member

Registriert: Do Feb 01, 2007 12:24
Beiträge: 5
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 :oops:.
Please help me :cry: .

Here are the parts of source code:

Code:
  1.  
  2. procedure TForm1.Init;
  3. begin
  4. glClearColor(1.0,1.0,1.0,0.0);
  5. glMatrixMode(GL_PROJECTION);
  6. glFrustum(-0.1, 0.1, -0.1, 0.1, 0.3, 50.0);
  7.  
  8. glMatrixMode(GL_MODELVIEW);
  9. glShadeModel(GL_SMOOTH);
  10.  
  11. glEnable(GL_DEPTH_TEST);
  12. end;
  13.  
  14. procedure TForm1.Draw;
  15. begin
  16. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  17. glLoadIdentity;
  18.  
  19. glTranslatef(0, 0, -10);
  20.  
  21. AXISxyz;
  22.  
  23. if object[1] then
  24. begin
  25. glPushMatrix;
  26. glTranslatef(movex,movey,depth);
  27. glRotate(rotx,1,0,0);
  28. glRotate(roty,0,1,0);
  29. obj1(1);
  30. glPopMatrix;
  31. end;
  32.  
  33. if object[2] then
  34. begin
  35. glPushMatrix;
  36. glTranslatef(movex2,movey2,depth2);
  37. glRotate(rotx2,1,0,0);
  38. glRotate(roty2,0,1,0);
  39. obj2(1,2,1);
  40. glPopMatrix;
  41. end;
  42. SwapBuffers(wglGetCurrentDC);
  43. end;
  44.  
  45. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  46. Shift: TShiftState; X, Y: Integer);
  47. begin
  48. if Button=mbLeft then
  49. begin
  50. mouse:=1;
  51. coordX:=X;
  52. coordY:=Y;
  53. coordX2:=X;
  54. coordY2:=Y;
  55. end;
  56. if Button=mbRight then
  57. begin
  58. mouse:=2;
  59. coordY:=Y;
  60. coordY2:=Y
  61. end;
  62. end;
  63.  
  64. procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  65. Y: Integer);
  66. begin
  67. if not CheckBox1.Checked then //if checked then translating if not then rotating
  68. begin
  69. if mouse=1 then //left
  70. begin
  71. if transform[1] then
  72. begin
  73. rotX:=rotX+(Y-coordY)/2;
  74. rotY:=rotY+(X-coordX)/2;
  75. coordX:=X;
  76. coordy:=Y;
  77. Draw;
  78. end;
  79. if transform[2] then
  80. begin
  81. rotX2:=rotX2+(Y-coordY2)/2;
  82. rotY2:=rotY2+(X-coordX2)/2;
  83. coordX2:=X;
  84. coordy2:=Y;
  85. Draw;
  86. end;
  87. end;
  88. if mouse=2 then //right
  89. begin
  90. if transform[1] then
  91. depth:=depth+(Y-coordY)/10;
  92. if transform[2] then
  93. depth2:=depth2+(Y-coordY2)/10;
  94. coordY:=Y;
  95. coordY2:=Y;
  96. Draw;
  97. end;
  98. end;
  99. if CheckBox1.Checked then
  100. begin
  101. if mouse=1 then //left
  102. begin
  103. if transform[1] then
  104. begin
  105. moveX:=moveX+(X-coordX)/50;
  106. moveY:=moveY-(Y-coordY)/50;
  107. Draw;
  108. end;
  109. if transform[2] then
  110. begin
  111. moveX2:=moveX2+(X-coordX2)/50;
  112. moveY2:=moveY2-(Y-coordY2)/50;
  113. Draw;
  114. end;
  115. coordX:=X;
  116. coordy:=Y;
  117. coordX2:=X;
  118. coordy2:=Y;
  119. end;
  120. end;
  121. end;
  122.  
  123. procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  124. Shift: TShiftState; X, Y: Integer);
  125. begin
  126. mouse:=0;
  127. end;
  128.  
  129. procedure TForm1.obj1(a:GLfloat);
  130. begin
  131. glBegin(GL_POLYGON); //front
  132. glColor3f(1.0,0.0,0.0);
  133. glVertex3f(a, a, a);
  134. glVertex3f(-a, a, a);
  135. glVertex3f(-a, -a, a);
  136. glVertex3f(a, -a, a);
  137. glEnd;
  138. glBegin(GL_POLYGON); //back
  139. glColor3f(0.0,1.0,0.0);
  140. glVertex3f(a, a, -a);
  141. glVertex3f(a, -a, -a);
  142. glVertex3f(-a, -a, -a);
  143. glVertex3f(-a, a, -a);
  144. glEnd;
  145. glBegin(GL_POLYGON); //left
  146. glColor3f(0.0,0.0,1.0);
  147. glVertex3f(-a, a, a);
  148. glVertex3f(-a, a, -a);
  149. glVertex3f(-a, -a, -a);
  150. glVertex3f(-a, -a, a);
  151. glEnd;
  152. glBegin(GL_POLYGON); //right
  153. glColor3f(1.0,1.0,0.0);
  154. glVertex3f(a, a, a);
  155. glVertex3f(a, -a, a);
  156. glVertex3f(a, -a, -a);
  157. glVertex3f(a, a, -a);
  158. glEnd;
  159. glBegin(GL_POLYGON);
  160. glColor3f(0.0,1.0,1.0); //top
  161. glVertex3f(-a, a, -a);
  162. glVertex3f(-a, a, a);
  163. glVertex3f(a, a, a);
  164. glVertex3f(a, a, -a);
  165. glEnd;
  166. glBegin(GL_POLYGON);
  167. glColor3f(1.0,0.0,1.0); //bottom
  168. glVertex3f(-a, -a, -a);
  169. glVertex3f(a, -a, -a);
  170. glVertex3f(a, -a, a);
  171. glVertex3f(-a, -a, a);
  172. glEnd;
  173. end;
  174.  
  175. procedure TForm1.obj2(a,b,c:GLfloat);
  176. begin
  177. glBegin(GL_POLYGON); //front
  178. glColor3f(1.0,0.0,0.0);
  179. glVertex3f(a, b, c);
  180. glVertex3f(-a, b, c);
  181. glVertex3f(-a, -b, c);
  182. glVertex3f(a, -b, c);
  183. glEnd;
  184. glBegin(GL_POLYGON); //back
  185. glColor3f(0.0,1.0,0.0);
  186. glVertex3f(a, b, -c);
  187. glVertex3f(a, -b, -c);
  188. glVertex3f(-a, -b, -c);
  189. glVertex3f(-a, b, -c);
  190. glEnd;
  191. glBegin(GL_POLYGON); //left
  192. glColor3f(0.0,0.0,1.0);
  193. glVertex3f(-a, b, c);
  194. glVertex3f(-a, b, -c);
  195. glVertex3f(-a, -b, -c);
  196. glVertex3f(-a, -b, c);
  197. glEnd;
  198. glBegin(GL_POLYGON); //right
  199. glColor3f(1.0,1.0,0.0);
  200. glVertex3f(a, b, c);
  201. glVertex3f(a, -b, c);
  202. glVertex3f(a, -b, -c);
  203. glVertex3f(a, b, -c);
  204. glEnd;
  205. glBegin(GL_POLYGON);
  206. glColor3f(0.0,1.0,1.0); //top
  207. glVertex3f(-a, b, -c);
  208. glVertex3f(-a, b, c);
  209. glVertex3f(a, b, c);
  210. glVertex3f(a, b, -c);
  211. glEnd;
  212. glBegin(GL_POLYGON);
  213. glColor3f(1.0,0.0,1.0); //bottom
  214. glVertex3f(-a, -b, -c);
  215. glVertex3f(a, -b, -c);
  216. glVertex3f(a, -b, c);
  217. glVertex3f(-a, -b, c);
  218. glEnd;
  219. end;


Other parts of the code are not so important.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Feb 07, 2007 17:49 
Offline
DGL Member

Registriert: Do Feb 01, 2007 12:24
Beiträge: 5
Problem solved!!! Just my stupidity. I forgot to disable the transformation of the second object. That's all. :oops:


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 6 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.081s | 15 Queries | GZIP : On ]