Normand Briere
2019-04-23 ec9d13e42c9c8674739acefb0769a9273a1048c9
Refactoring GelGL.
12 files modified
793 ■■■■■ changed files
BoundaryRep.java 2 ●●● patch | view | raw | blame | history
CameraPane.java 363 ●●●●● patch | view | raw | blame | history
GLShapeDrawer.java 6 ●●●● patch | view | raw | blame | history
GenericJoint.java 14 ●●●●● patch | view | raw | blame | history
LA.java 3 ●●●●● patch | view | raw | blame | history
Merge.java 44 ●●●● patch | view | raw | blame | history
Object3D.java 235 ●●●●● patch | view | raw | blame | history
VehicleDemo.java 2 ●●● patch | view | raw | blame | history
cLinker.java 2 ●●● patch | view | raw | blame | history
cMesh.java 102 ●●●●● patch | view | raw | blame | history
cSpring.java 2 ●●● patch | view | raw | blame | history
iCameraPane.java 18 ●●●●● patch | view | raw | blame | history
BoundaryRep.java
....@@ -4428,7 +4428,7 @@
44284428 }
44294429 }
44304430
4431
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
4431
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
44324432 {
44334433 CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
44344434 CameraPane.tempmat,0, CameraPane.tempmat2,0,
CameraPane.java
....@@ -191,6 +191,35 @@
191191
192192 /// INTERFACE
193193
194
+ public javax.media.opengl.GL GetGL0()
195
+ {
196
+ return null;
197
+ }
198
+
199
+ public int GenList()
200
+ {
201
+ javax.media.opengl.GL gl = GetGL();
202
+ return gl.glGenLists(1);
203
+ }
204
+
205
+ public void NewList(int id)
206
+ {
207
+ javax.media.opengl.GL gl = GetGL();
208
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
209
+ }
210
+
211
+ public void CallList(int id)
212
+ {
213
+ javax.media.opengl.GL gl = GetGL();
214
+ gl.glCallList(id);
215
+ }
216
+
217
+ public void EndList()
218
+ {
219
+ javax.media.opengl.GL gl = GetGL();
220
+ gl.glEndList();
221
+ }
222
+
194223 public boolean IsBoxMode()
195224 {
196225 return BOXMODE;
....@@ -1059,7 +1088,336 @@
10591088 gl.glMatrixMode(gl.GL_MODELVIEW);
10601089 }
10611090
1091
+ public void DrawBox(cVector min, cVector max)
1092
+ {
1093
+ javax.media.opengl.GL gl = GetGL();
1094
+ gl.glBegin(gl.GL_LINES);
1095
+
1096
+ gl.glVertex3d(min.x, min.y, min.z);
1097
+ gl.glVertex3d(min.x, min.y, max.z);
1098
+ gl.glVertex3d(min.x, min.y, min.z);
1099
+ gl.glVertex3d(min.x, max.y, min.z);
1100
+ gl.glVertex3d(min.x, min.y, min.z);
1101
+ gl.glVertex3d(max.x, min.y, min.z);
1102
+
1103
+ gl.glVertex3d(max.x, max.y, max.z);
1104
+ gl.glVertex3d(min.x, max.y, max.z);
1105
+ gl.glVertex3d(max.x, max.y, max.z);
1106
+ gl.glVertex3d(max.x, min.y, max.z);
1107
+ gl.glVertex3d(max.x, max.y, max.z);
1108
+ gl.glVertex3d(max.x, max.y, min.z);
1109
+
1110
+ gl.glEnd();
1111
+ }
1112
+
1113
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1114
+ {
1115
+ int[] strips = bRep.getRawIndices();
1116
+
1117
+ javax.media.opengl.GL gl = GetGL();
1118
+
1119
+ // TRIANGLE STRIP ARRAY
1120
+ if (bRep.trimmed)
1121
+ {
1122
+ float[] v = bRep.getRawVertices();
1123
+ float[] n = bRep.getRawNormals();
1124
+ float[] c = bRep.getRawColors();
1125
+ float[] uv = bRep.getRawUVMap();
1126
+
1127
+ int count2 = 0;
1128
+ int count3 = 0;
1129
+
1130
+ if (n.length > 0)
1131
+ {
1132
+ for (int i = 0; i < strips.length; i++)
1133
+ {
1134
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1135
+
1136
+ /*
1137
+ boolean locked = false;
1138
+ float eps = 0.1f;
1139
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1140
+
1141
+ int dot = 0;
1142
+
1143
+ if ((dot&1) == 0)
1144
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1145
+
1146
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1147
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1148
+ else
1149
+ {
1150
+ locked = true;
1151
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1152
+ }
1153
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1154
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1155
+ if (hasnorm)
1156
+ {
1157
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1158
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1159
+ }
1160
+
1161
+ if ((dot&4) == 0)
1162
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1163
+
1164
+ if (wrap || !locked && (dot&8) != 0)
1165
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1166
+ else
1167
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1168
+
1169
+ f.dot = dot;
1170
+ */
1171
+
1172
+ if (!selectmode)
1173
+ {
1174
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1175
+ {
1176
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1177
+ } else
1178
+ {
1179
+ gl.glNormal3f(0, 0, 1);
1180
+ }
1181
+
1182
+ if (c != null)
1183
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1184
+ {
1185
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1186
+ }
1187
+ }
1188
+ if (flipV)
1189
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1190
+ else
1191
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1192
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1193
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1194
+
1195
+ count2 += 2;
1196
+ count3 += 3;
1197
+ if (!selectmode)
1198
+ {
1199
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1200
+ {
1201
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1202
+ } else
1203
+ {
1204
+ gl.glNormal3f(0, 0, 1);
1205
+ }
1206
+ if (c != null)
1207
+ {
1208
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1209
+ }
1210
+ }
1211
+ if (flipV)
1212
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1213
+ else
1214
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1215
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1216
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1217
+
1218
+ count2 += 2;
1219
+ count3 += 3;
1220
+ for (int j = 0; j < strips[i] - 2; j++)
1221
+ {
1222
+ //gl.glTexCoord2d(...);
1223
+ if (!selectmode)
1224
+ {
1225
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1226
+ {
1227
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1228
+ } else
1229
+ {
1230
+ gl.glNormal3f(0, 0, 1);
1231
+ }
1232
+ if (c != null)
1233
+ {
1234
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1235
+ }
1236
+ }
1237
+
1238
+ if (flipV)
1239
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1240
+ else
1241
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1242
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1243
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1244
+ count2 += 2;
1245
+ count3 += 3;
1246
+ }
1247
+
1248
+ gl.glEnd();
1249
+ }
1250
+ }
1251
+
1252
+ assert count3 == v.length;
1253
+ }
1254
+ else // !trimmed
1255
+ {
1256
+ int count = 0;
1257
+ for (int i = 0; i < strips.length; i++)
1258
+ {
1259
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1260
+
1261
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1262
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1263
+
1264
+ drawVertex(gl, p, flipV, selectmode);
1265
+ drawVertex(gl, q, flipV, selectmode);
1266
+
1267
+ for (int j = 0; j < strips[i] - 2; j++)
1268
+ {
1269
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1270
+
1271
+ // if (j%2 == 0)
1272
+ // drawFace(p, q, r, display, null);
1273
+ // else
1274
+ // drawFace(p, r, q, display, null);
1275
+
1276
+ // p = q;
1277
+ // q = r;
1278
+ drawVertex(gl, r, flipV, selectmode);
1279
+ }
1280
+
1281
+ gl.glEnd();
1282
+ }
1283
+ }
1284
+ }
1285
+
1286
+ static cSpring.Point3D temp = new cSpring.Point3D();
1287
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1288
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1289
+
1290
+ public void DrawDynamicMesh(cMesh mesh)
1291
+ {
1292
+ GL gl = GetGL(); // getGL();
1293
+
1294
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1295
+
1296
+ gl.glDisable(gl.GL_LIGHTING);
1297
+
1298
+ gl.glLineWidth(1);
1299
+ gl.glColor3f(1,1,1);
1300
+ gl.glBegin(gl.GL_LINES);
1301
+ double scale = 0;
1302
+ int count = 0;
1303
+ for (int s=0; s<Phys.allSprings.size(); s++)
1304
+ {
1305
+ cSpring.Spring spring = Phys.allSprings.get(s);
1306
+ if(s == 0)
1307
+ {
1308
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1309
+ }
1310
+ if (mesh.showsprings)
1311
+ {
1312
+ temp.set(spring.a.position);
1313
+ temp.add(spring.b.position);
1314
+ temp.mul(0.5);
1315
+ temp2.set(spring.a.position);
1316
+ temp2.sub(spring.b.position);
1317
+ temp2.mul(spring.restLength/2);
1318
+ temp.sub(temp2);
1319
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1320
+ temp.add(temp2);
1321
+ temp.add(temp2);
1322
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1323
+ }
1324
+
1325
+ if (spring.isHandle)
1326
+ continue;
1327
+
1328
+ //if (scale < spring.restLength)
1329
+ scale += spring.restLength;
1330
+ count++;
1331
+ }
1332
+ gl.glEnd();
1333
+
1334
+ if (count == 0)
1335
+ scale = 0.01;
1336
+ else
1337
+ scale /= count * 3;
1338
+
1339
+ //scale = 0.25;
1340
+
1341
+ if (mesh.ShowInfo())
1342
+ {
1343
+ gl.glLineWidth(4);
1344
+ for (int s=0; s<Phys.allNodes.size(); s++)
1345
+ {
1346
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1347
+ if (node.mass == 0)
1348
+ continue;
1349
+
1350
+ int i = node.springs==null?-1:node.springs.size();
1351
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1352
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1353
+ //temp.normalize();
1354
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1355
+ gl.glBegin(gl.GL_LINES);
1356
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1357
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1358
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1359
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1360
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1361
+ gl.glEnd();
1362
+ }
1363
+
1364
+ gl.glLineWidth(8);
1365
+ for (int s=0; s<Phys.allNodes.size(); s++)
1366
+ {
1367
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1368
+
1369
+ if (node.springs != null)
1370
+ {
1371
+ for (int i=0; i<node.springs.size(); i+=1)
1372
+ {
1373
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1374
+
1375
+ int c = i+1;
1376
+ // c = node.springs.get(i).nbcopies;
1377
+
1378
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1379
+ gl.glBegin(gl.GL_LINES);
1380
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1381
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1382
+ gl.glEnd();
1383
+ }
1384
+ }
1385
+ }
1386
+
1387
+ gl.glLineWidth(1);
1388
+ }
1389
+
1390
+ gl.glEnable(gl.GL_LIGHTING);
1391
+ }
1392
+
10621393 /// INTERFACE
1394
+
1395
+ public void StartTriangles()
1396
+ {
1397
+ javax.media.opengl.GL gl = GetGL();
1398
+ gl.glBegin(gl.GL_TRIANGLES);
1399
+ }
1400
+
1401
+ public void EndTriangles()
1402
+ {
1403
+ GetGL().glEnd();
1404
+ }
1405
+
1406
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1407
+ {
1408
+ if (!selectmode)
1409
+ {
1410
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1411
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1412
+
1413
+ if (flipV)
1414
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1415
+ else
1416
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1417
+ }
1418
+
1419
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1420
+ }
10631421
10641422 void SetColor(Object3D obj, Vertex p0)
10651423 {
....@@ -16695,10 +17053,11 @@
1669517053 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1669617054 // Depth buffer format
1669717055 //private int depth_format;
16698
- static public void NextIndex(Object3D o, GL gl)
17056
+
17057
+ public void NextIndex()
1669917058 {
1670017059 indexcount+=16;
16701
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17060
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1670217061 //objects[indexcount] = o;
1670317062 //System.out.println("indexcount = " + indexcount);
1670417063 }
GLShapeDrawer.java
....@@ -142,7 +142,7 @@
142142
143143 //System.out.println("shape="+shape+" type="+BroadphaseNativeTypes.forValue(shape.getShapeType()));
144144
145
- GL gl = display.GetGL();
145
+ GL gl = display.GetGL0();
146146
147147 gl.glPushMatrix();
148148 trans.getOpenGLMatrix(glMat);
....@@ -552,7 +552,7 @@
552552
553553 static public void drawSphere(iCameraPane display, float radius, int slices, int stacks)
554554 {
555
- GL gl = display.GetGL();
555
+ GL gl = display.GetGL0();
556556
557557 sphereKey.radius = radius;
558558 Integer glList = sphereDisplayLists.get(sphereKey);
....@@ -624,7 +624,7 @@
624624
625625 static public void drawCylinder(iCameraPane display, float radius, float halfHeight, int upAxis)
626626 {
627
- GL gl = display.GetGL();
627
+ GL gl = display.GetGL0();
628628
629629 gl.glPushMatrix();
630630 switch (upAxis)
GenericJoint.java
....@@ -330,12 +330,14 @@
330330 e.printStackTrace();
331331 }
332332
333
- display.GetGL().glPushMatrix();
333
+ //display.GetGL().glPushMatrix();
334
+ display.PushMatrix(LA.Identity, 1);
334335 Vector3f v = ragdolls.get(0).bodies[0].worldTransform.origin;
335336 // display.GetGL().glTranslatef(-v.x,0,-v.z);
336337
337338 super.DrawNode(display, root, selected);
338
- display.GetGL().glPopMatrix();
339
+ //display.GetGL().glPopMatrix();
340
+ display.PopMatrix(LA.Identity);
339341
340342 // assert(bRep != null);
341343
....@@ -453,7 +455,7 @@
453455
454456 public void renderme(iCameraPane display)
455457 {
456
- GL gl = display!=null?display.GetGL():null;
458
+ GL gl = display!=null?display.GetGL0():null;
457459
458460 // gl0 = gl;
459461 if (GetDynamicsWorld() != null)
....@@ -798,7 +800,7 @@
798800
799801 public void drawCube(iCameraPane display, float extent)
800802 {
801
- GL gl = display.GetGL();
803
+ GL gl = display.GetGL0();
802804
803805 extent = extent * 0.5f;
804806
....@@ -1524,7 +1526,7 @@
15241526
15251527 public void drawSphere(iCameraPane display, float radius, int slices, int stacks)
15261528 {
1527
- GL gl = display.GetGL();
1529
+ GL gl = display.GetGL0();
15281530
15291531 sphereKey.radius = radius;
15301532 Integer glList = sphereDisplayLists.get(sphereKey);
....@@ -1596,7 +1598,7 @@
15961598
15971599 public void drawCylinder(iCameraPane display, float radius, float halfHeight, int upAxis)
15981600 {
1599
- GL gl = display.GetGL();
1601
+ GL gl = display.GetGL0();
16001602
16011603 gl.glPushMatrix();
16021604 switch (upAxis)
LA.java
....@@ -623,6 +623,7 @@
623623 private static int indxr[] = new int[4];
624624 private static int indxc[] = new int[4];
625625
626
+ static double[][] Identity = new double[4][4];
626627
627628 static int SIZE = 0; // 65536*64;
628629
....@@ -638,6 +639,8 @@
638639 costable[i] = Math.cos(PI2 * i/SIZE);
639640 sintable[i] = Math.sin(PI2 * i*i/SIZE/SIZE);
640641 }
642
+
643
+ LA.matIdentity(Identity);
641644 }
642645
643646 static double cos(double x0)
Merge.java
....@@ -160,27 +160,27 @@
160160 // debug stuff
161161 if (false) // bRep.averagepoints != null)
162162 {
163
- javax.media.opengl.GL gl = display.GetGL();
164
-
165
- gl.glColor3f(1, 0, 0);
166
- //gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
167
- //gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
168
-
169
- for (int i=0; i<NumGeometries(GetObject()); i++)
170
- {
171
- int i3 = i*3;
172
-
173
- float off = 0.005f;
174
-
175
- gl.glBegin(gl.GL_LINES);
176
- gl.glVertex3d(bRep.averagepoints[i3]-off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
177
- gl.glVertex3d(bRep.averagepoints[i3]+off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
178
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]-off, bRep.averagepoints[i3+2]);
179
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]+off, bRep.averagepoints[i3+2]);
180
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]-off);
181
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]+off);
182
- gl.glEnd();
183
- }
163
+// javax.media.opengl.GL gl = display.GetGL();
164
+//
165
+// gl.glColor3f(1, 0, 0);
166
+// //gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
167
+// //gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
168
+//
169
+// for (int i=0; i<NumGeometries(GetObject()); i++)
170
+// {
171
+// int i3 = i*3;
172
+//
173
+// float off = 0.005f;
174
+//
175
+// gl.glBegin(gl.GL_LINES);
176
+// gl.glVertex3d(bRep.averagepoints[i3]-off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
177
+// gl.glVertex3d(bRep.averagepoints[i3]+off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
178
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]-off, bRep.averagepoints[i3+2]);
179
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]+off, bRep.averagepoints[i3+2]);
180
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]-off);
181
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]+off);
182
+// gl.glEnd();
183
+// }
184184 }
185185 }
186186
....@@ -398,7 +398,7 @@
398398
399399 public void drawCube(iCameraPane display, float extent)
400400 {
401
- GL gl = display.GetGL();
401
+ GL gl = display.GetGL0();
402402
403403 extent = extent * 0.5f;
404404
Object3D.java
....@@ -5,6 +5,7 @@
55 import java.util.Vector;
66
77 import javax.media.j3d.Transform3D;
8
+import javax.media.opengl.GL;
89 import javax.vecmath.Vector3d;
910
1011 import javax.imageio.ImageIO;
....@@ -5371,7 +5372,7 @@
53715372 return;
53725373 }
53735374
5374
- javax.media.opengl.GL gl = display.GetGL();
5375
+ //javax.media.opengl.GL gl = display.GetGL();
53755376
53765377 /*
53775378 if (touched)
....@@ -5423,7 +5424,7 @@
54235424 //if (displaylist == -1 && usecalllists)
54245425 if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
54255426 {
5426
- bRep.displaylist = gl.glGenLists(1);
5427
+ bRep.displaylist = display.GenList();
54275428 assert(bRep.displaylist != 0);
54285429 // System.err.println("glGenLists: " + bRep.displaylist + " for " + this);
54295430 //System.out.println("\tgen list " + list);
....@@ -5435,14 +5436,16 @@
54355436 if (usecalllists)
54365437 {
54375438 // System.err.println("new list " + bRep.displaylist + " for " + this);
5438
- gl.glNewList(bRep.displaylist, gl.GL_COMPILE); //_AND_EXECUTE);
5439
+ display.NewList(bRep.displaylist);
54395440 }
5441
+
54405442 CallList(display, root, selected, blocked);
5443
+
54415444 // compiled = true;
54425445 if (usecalllists)
54435446 {
54445447 // System.err.println("end list " + bRep.displaylist + " for " + this);
5445
- gl.glEndList();
5448
+ display.EndList();
54465449 }
54475450 //gl.glDrawBuffer(gl.GL_BACK);
54485451 // XXX touched = false;
....@@ -5490,7 +5493,7 @@
54905493 if (display.DrawMode() == iCameraPane.SHADOW)
54915494 {
54925495 if (!link2master // tricky to cull in shadow mode.
5493
- && GetBRep().FrustumCull(this, gl, display.LightCamera(), true))
5496
+ && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
54945497 {
54955498 //System.out.print("CULLED");
54965499 culled = true;
....@@ -5498,7 +5501,7 @@
54985501 }
54995502 else
55005503 //GetBRep().getBounds(v0, v1, this);
5501
- if (GetBRep().FrustumCull(this, gl, display.RenderCamera(), false))
5504
+ if (GetBRep().FrustumCull(this, null, display.RenderCamera(), false))
55025505 culled = true;
55035506
55045507 // LA.xformPos(v0, display.renderCamera.toScreen, v0);
....@@ -5538,7 +5541,7 @@
55385541 {
55395542 if (GetBRep() != null)
55405543 {
5541
- CameraPane.NextIndex(this, gl);
5544
+ display.NextIndex();
55425545 // vertex color conflict : gl.glCallList(list);
55435546 DrawNode(display, root, selected);
55445547 if (this instanceof BezierPatch)
....@@ -5595,7 +5598,7 @@
55955598
55965599 // System.err.println("glCallList: " + bRep.displaylist + " for " + this);
55975600 assert(bRep.displaylist != 0);
5598
- gl.glCallList(bRep.displaylist);
5601
+ display.CallList(bRep.displaylist);
55995602 // june 2013 drawSelf(display, root, selected);
56005603 }
56015604 }
....@@ -5897,7 +5900,7 @@
58975900
58985901 // bRep.lock = true;
58995902
5900
- javax.media.opengl.GL gl = display.GetGL();
5903
+ //javax.media.opengl.GL gl = display.GetGL();
59015904
59025905 if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
59035906 {
....@@ -5914,23 +5917,7 @@
59145917
59155918 bRep.getMinMax(min, max, 100);
59165919
5917
- gl.glBegin(gl.GL_LINES);
5918
-
5919
- gl.glVertex3d(min.x, min.y, min.z);
5920
- gl.glVertex3d(min.x, min.y, max.z);
5921
- gl.glVertex3d(min.x, min.y, min.z);
5922
- gl.glVertex3d(min.x, max.y, min.z);
5923
- gl.glVertex3d(min.x, min.y, min.z);
5924
- gl.glVertex3d(max.x, min.y, min.z);
5925
-
5926
- gl.glVertex3d(max.x, max.y, max.z);
5927
- gl.glVertex3d(min.x, max.y, max.z);
5928
- gl.glVertex3d(max.x, max.y, max.z);
5929
- gl.glVertex3d(max.x, min.y, max.z);
5930
- gl.glVertex3d(max.x, max.y, max.z);
5931
- gl.glVertex3d(max.x, max.y, min.z);
5932
-
5933
- gl.glEnd();
5920
+ display.DrawBox(min, max);
59345921
59355922 return;
59365923 }
....@@ -5984,178 +5971,14 @@
59845971 new Exception().printStackTrace();
59855972 return;
59865973 }
5987
-
5988
- // TRIANGLE STRIP ARRAY
5989
- if (bRep.trimmed)
5990
- {
5991
- float[] v = bRep.getRawVertices();
5992
- float[] n = bRep.getRawNormals();
5993
- float[] c = bRep.getRawColors();
5994
- float[] uv = bRep.getRawUVMap();
5995
-
5996
- int count2 = 0;
5997
- int count3 = 0;
5998
-
5999
- if (n.length > 0)
6000
- {
6001
- for (int i = 0; i < strips.length; i++)
6002
- {
6003
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
6004
-
6005
- /*
6006
- boolean locked = false;
6007
- float eps = 0.1f;
6008
- boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
6009
-
6010
- int dot = 0;
6011
-
6012
- if ((dot&1) == 0)
6013
- dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
6014
-
6015
- if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
6016
- gl.glTexCoord2f((float) qv.s, (float) qv.t);
6017
- else
6018
- {
6019
- locked = true;
6020
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6021
- }
6022
- //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
6023
- gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
6024
- if (hasnorm)
6025
- {
6026
- //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
6027
- gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
6028
- }
6029
-
6030
- if ((dot&4) == 0)
6031
- dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
6032
-
6033
- if (wrap || !locked && (dot&8) != 0)
6034
- gl.glTexCoord2f((float) rv.s, (float) rv.t);
6035
- else
6036
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6037
-
6038
- f.dot = dot;
6039
- */
6040
-
6041
- if (!selectmode)
6042
- {
6043
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6044
- {
6045
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6046
- } else
6047
- {
6048
- gl.glNormal3f(0, 0, 1);
6049
- }
6050
-
6051
- if (c != null)
6052
- //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
6053
- {
6054
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6055
- }
6056
- }
6057
- if (flipV)
6058
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6059
- else
6060
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6061
- //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
6062
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6063
-
6064
- count2 += 2;
6065
- count3 += 3;
6066
- if (!selectmode)
6067
- {
6068
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6069
- {
6070
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6071
- } else
6072
- {
6073
- gl.glNormal3f(0, 0, 1);
6074
- }
6075
- if (c != null)
6076
- {
6077
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6078
- }
6079
- }
6080
- if (flipV)
6081
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6082
- else
6083
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6084
- //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
6085
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6086
-
6087
- count2 += 2;
6088
- count3 += 3;
6089
- for (int j = 0; j < strips[i] - 2; j++)
6090
- {
6091
- //gl.glTexCoord2d(...);
6092
- if (!selectmode)
6093
- {
6094
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
6095
- {
6096
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
6097
- } else
6098
- {
6099
- gl.glNormal3f(0, 0, 1);
6100
- }
6101
- if (c != null)
6102
- {
6103
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
6104
- }
6105
- }
6106
-
6107
- if (flipV)
6108
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
6109
- else
6110
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
6111
- //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
6112
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
6113
- count2 += 2;
6114
- count3 += 3;
6115
- }
6116
-
6117
- gl.glEnd();
6118
- }
6119
- }
6120
-
6121
- assert count3 == v.length;
6122
- }
6123
- else // !trimmed
6124
- {
6125
- int count = 0;
6126
- for (int i = 0; i < strips.length; i++)
6127
- {
6128
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
6129
-
6130
- Vertex p = bRep.GetVertex(bRep.indices[count++]);
6131
- Vertex q = bRep.GetVertex(bRep.indices[count++]);
6132
-
6133
- drawVertex(gl, p, selectmode);
6134
- drawVertex(gl, q, selectmode);
6135
-
6136
- for (int j = 0; j < strips[i] - 2; j++)
6137
- {
6138
- Vertex r = bRep.GetVertex(bRep.indices[count++]);
6139
-
6140
-// if (j%2 == 0)
6141
-// drawFace(p, q, r, display, null);
6142
-// else
6143
-// drawFace(p, r, q, display, null);
6144
-
6145
-// p = q;
6146
-// q = r;
6147
- drawVertex(gl, r, selectmode);
6148
- }
6149
-
6150
- gl.glEnd();
6151
- }
6152
- }
5974
+
5975
+ display.DrawGeometry(bRep, flipV, selectmode);
61535976 } else // catch (Error e)
61545977 {
61555978 // TRIANGLE ARRAY
61565979 if (IsOpaque()) // Static())
61575980 {
6158
- gl.glBegin(gl.GL_TRIANGLES);
5981
+ display.StartTriangles();
61595982 int facecount = bRep.FaceCount();
61605983 for (int i = 0; i < facecount; i++)
61615984 {
....@@ -6220,7 +6043,7 @@
62206043
62216044 display.DrawFace(this, p, q, r, face);
62226045 }
6223
- gl.glEnd();
6046
+ display.EndTriangles();
62246047 }
62256048 else
62266049 {
....@@ -6249,8 +6072,8 @@
62496072 //System.out.println("SORT");
62506073
62516074 java.util.Arrays.sort(facescompare);
6252
-
6253
- gl.glBegin(gl.GL_TRIANGLES);
6075
+
6076
+ display.StartTriangles();
62546077 for (int i = 0; i < facecount; i++)
62556078 {
62566079 Face face = bRep.GetFace(facescompare[i].index);
....@@ -6264,11 +6087,12 @@
62646087
62656088 display.DrawFace(this, p, q, r, face);
62666089 }
6267
- gl.glEnd();
6090
+ display.EndTriangles();
62686091 }
62696092
62706093 if (false) // live && support != null && support.bRep != null) // debug weights
62716094 {
6095
+ /*
62726096 gl.glDisable(gl.GL_LIGHTING);
62736097 float[] colorV = new float[3];
62746098
....@@ -6347,6 +6171,7 @@
63476171 // gl.glEnd();
63486172 }
63496173 }
6174
+ */
63506175 }
63516176 }
63526177
....@@ -6405,22 +6230,6 @@
64056230 void Print(Vertex v)
64066231 {
64076232 //System.err.println("(" + v.x + ", " + v.y + ", " + v.z + ")");
6408
- }
6409
-
6410
- void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean selectmode)
6411
- {
6412
- if (!selectmode)
6413
- {
6414
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
6415
- gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
6416
-
6417
- if (flipV)
6418
- gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
6419
- else
6420
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
6421
- }
6422
-
6423
- gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
64246233 }
64256234
64266235 void drawSelf(ClickInfo info, int level, boolean select)
VehicleDemo.java
....@@ -529,7 +529,7 @@
529529 public void renderme0(iCameraPane display)
530530 {
531531 //updateCamera();
532
- GL gl = display.GetGL();
532
+ GL gl = display.GetGL0();
533533
534534 if (dynamicsWorld != null) {
535535 int numObjects = dynamicsWorld.getNumCollisionObjects();
cLinker.java
....@@ -49,7 +49,7 @@
4949 {
5050 cStatic.point7.set(stack.peek());
5151 /**/
52
- javax.media.opengl.GL gl = display.GetGL();
52
+ //javax.media.opengl.GL gl = display.GetGL();
5353
5454 //gl.glBegin(gl.GL_LINES);
5555 //gl.glVertex3d(stack.peek().x, stack.peek().y, stack.peek().z);
cMesh.java
....@@ -1,6 +1,6 @@
11 import java.util.Hashtable;
22
3
-import javax.media.opengl.GL;
3
+//import javax.media.opengl.GL;
44
55 public class cMesh extends cSpring
66 {
....@@ -78,7 +78,7 @@
7878
7979 live = true;
8080 }
81
-
81
+
8282 Object3D deepCopy()
8383 {
8484 /*
....@@ -545,103 +545,7 @@
545545
546546 if(/*showsprings &&*/ Phys != null)
547547 {
548
- GL gl = display.GetGL(); // getGL();
549
-
550
- gl.glDisable(gl.GL_LIGHTING);
551
-
552
- gl.glLineWidth(1);
553
- gl.glColor3f(1,1,1);
554
- gl.glBegin(gl.GL_LINES);
555
- double scale = 0;
556
- int count = 0;
557
- for (int s=0; s<Phys.allSprings.size(); s++)
558
- {
559
- Spring spring = Phys.allSprings.get(s);
560
- if(s == 0)
561
- {
562
- //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
563
- }
564
- if (showsprings)
565
- {
566
- temp.set(spring.a.position);
567
- temp.add(spring.b.position);
568
- temp.mul(0.5);
569
- temp2.set(spring.a.position);
570
- temp2.sub(spring.b.position);
571
- temp2.mul(spring.restLength/2);
572
- temp.sub(temp2);
573
- gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
574
- temp.add(temp2);
575
- temp.add(temp2);
576
- gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
577
- }
578
-
579
- if (spring.isHandle)
580
- continue;
581
-
582
- //if (scale < spring.restLength)
583
- scale += spring.restLength;
584
- count++;
585
- }
586
- gl.glEnd();
587
-
588
- if (count == 0)
589
- scale = 0.01;
590
- else
591
- scale /= count * 3;
592
-
593
- //scale = 0.25;
594
-
595
- if (ShowInfo())
596
- {
597
- gl.glLineWidth(4);
598
- for (int s=0; s<Phys.allNodes.size(); s++)
599
- {
600
- DynamicNode node = Phys.allNodes.get(s);
601
- if (node.mass == 0)
602
- continue;
603
-
604
- int i = node.springs==null?-1:node.springs.size();
605
- gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
606
- //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
607
- //temp.normalize();
608
- //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
609
- gl.glBegin(gl.GL_LINES);
610
- gl.glVertex3d(node.position.x, node.position.y, node.position.z);
611
- //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
612
- gl.glVertex3d(node.position.x + bRep.GetVertex(s).norm.x*scale,
613
- node.position.y + bRep.GetVertex(s).norm.y*scale,
614
- node.position.z + bRep.GetVertex(s).norm.z*scale);
615
- gl.glEnd();
616
- }
617
-
618
- gl.glLineWidth(8);
619
- for (int s=0; s<Phys.allNodes.size(); s++)
620
- {
621
- DynamicNode node = Phys.allNodes.get(s);
622
-
623
- if (node.springs != null)
624
- {
625
- for (int i=0; i<node.springs.size(); i+=1)
626
- {
627
- DynamicNode f = node.springs.get(i).GetOther(node);
628
-
629
- int c = i+1;
630
- // c = node.springs.get(i).nbcopies;
631
-
632
- gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
633
- gl.glBegin(gl.GL_LINES);
634
- gl.glVertex3d(node.position.x, node.position.y, node.position.z);
635
- gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
636
- gl.glEnd();
637
- }
638
- }
639
- }
640
-
641
- gl.glLineWidth(1);
642
- }
643
-
644
- gl.glEnable(gl.GL_LIGHTING);
548
+ display.DrawDynamicMesh(this);
645549 }
646550
647551 if (live && Globals.isLIVE() && display.DrawMode() == CameraPane.DEFAULT)
cSpring.java
....@@ -565,7 +565,7 @@
565565 // }
566566
567567 //new Exception().printStackTrace();
568
- GL gl = display.GetGL(); // getGL();
568
+ GL gl = display.GetGL0(); // getGL();
569569
570570 //gl.glDisable(GL.GL_LIGHTING);
571571
iCameraPane.java
....@@ -24,7 +24,7 @@
2424
2525 boolean IsFrozen();
2626
27
- javax.media.opengl.GL GetGL();
27
+ javax.media.opengl.GL GetGL0();
2828
2929 // Currently in Globals
3030 int DrawMode();
....@@ -60,6 +60,22 @@
6060
6161 void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face);
6262
63
+ void DrawBox(cVector min, cVector max);
64
+
65
+ void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode);
66
+
67
+ void DrawDynamicMesh(cMesh c);
68
+
69
+ void StartTriangles();
70
+ void EndTriangles();
71
+
72
+ int GenList();
73
+ void NewList(int id);
74
+ void CallList(int id);
75
+ void EndList();
76
+
77
+ void NextIndex();
78
+
6379 void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate);
6480
6581 void PrepOcclusion(BoundaryRep br, double[][] transform);