From ec9d13e42c9c8674739acefb0769a9273a1048c9 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 22 Apr 2019 20:14:09 -0400
Subject: [PATCH] Refactoring GelGL.
---
VehicleDemo.java | 2
cMesh.java | 102 -------
iCameraPane.java | 18 +
BoundaryRep.java | 2
cLinker.java | 2
CameraPane.java | 363 +++++++++++++++++++++++++
LA.java | 3
Merge.java | 44 +-
cSpring.java | 2
GLShapeDrawer.java | 6
Object3D.java | 235 +---------------
GenericJoint.java | 14
12 files changed, 443 insertions(+), 350 deletions(-)
diff --git a/BoundaryRep.java b/BoundaryRep.java
index 4667636..cbdb1a9 100644
--- a/BoundaryRep.java
+++ b/BoundaryRep.java
@@ -4428,7 +4428,7 @@
}
}
- void CullVertex(javax.media.opengl.GL gl, boolean shadow)
+ void CullVertex(javax.media.opengl.GL glNOTUSED, boolean shadowNOTUSED)
{
CameraPane.glu.gluProject(vect5.x,vect5.y,vect5.z,
CameraPane.tempmat,0, CameraPane.tempmat2,0,
diff --git a/CameraPane.java b/CameraPane.java
index b54e1a7..8c8c173 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -191,6 +191,35 @@
/// INTERFACE
+ public javax.media.opengl.GL GetGL0()
+ {
+ return null;
+ }
+
+ public int GenList()
+ {
+ javax.media.opengl.GL gl = GetGL();
+ return gl.glGenLists(1);
+ }
+
+ public void NewList(int id)
+ {
+ javax.media.opengl.GL gl = GetGL();
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
+ }
+
+ public void CallList(int id)
+ {
+ javax.media.opengl.GL gl = GetGL();
+ gl.glCallList(id);
+ }
+
+ public void EndList()
+ {
+ javax.media.opengl.GL gl = GetGL();
+ gl.glEndList();
+ }
+
public boolean IsBoxMode()
{
return BOXMODE;
@@ -1059,7 +1088,336 @@
gl.glMatrixMode(gl.GL_MODELVIEW);
}
+ public void DrawBox(cVector min, cVector max)
+ {
+ javax.media.opengl.GL gl = GetGL();
+ gl.glBegin(gl.GL_LINES);
+
+ gl.glVertex3d(min.x, min.y, min.z);
+ gl.glVertex3d(min.x, min.y, max.z);
+ gl.glVertex3d(min.x, min.y, min.z);
+ gl.glVertex3d(min.x, max.y, min.z);
+ gl.glVertex3d(min.x, min.y, min.z);
+ gl.glVertex3d(max.x, min.y, min.z);
+
+ gl.glVertex3d(max.x, max.y, max.z);
+ gl.glVertex3d(min.x, max.y, max.z);
+ gl.glVertex3d(max.x, max.y, max.z);
+ gl.glVertex3d(max.x, min.y, max.z);
+ gl.glVertex3d(max.x, max.y, max.z);
+ gl.glVertex3d(max.x, max.y, min.z);
+
+ gl.glEnd();
+ }
+
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
+ {
+ int[] strips = bRep.getRawIndices();
+
+ javax.media.opengl.GL gl = GetGL();
+
+ // TRIANGLE STRIP ARRAY
+ if (bRep.trimmed)
+ {
+ float[] v = bRep.getRawVertices();
+ float[] n = bRep.getRawNormals();
+ float[] c = bRep.getRawColors();
+ float[] uv = bRep.getRawUVMap();
+
+ int count2 = 0;
+ int count3 = 0;
+
+ if (n.length > 0)
+ {
+ for (int i = 0; i < strips.length; i++)
+ {
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
+
+ /*
+ boolean locked = false;
+ float eps = 0.1f;
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
+
+ int dot = 0;
+
+ if ((dot&1) == 0)
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
+
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
+ else
+ {
+ locked = true;
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
+ }
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
+ if (hasnorm)
+ {
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
+ }
+
+ if ((dot&4) == 0)
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
+
+ if (wrap || !locked && (dot&8) != 0)
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
+ else
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
+
+ f.dot = dot;
+ */
+
+ if (!selectmode)
+ {
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+ {
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+ } else
+ {
+ gl.glNormal3f(0, 0, 1);
+ }
+
+ if (c != null)
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
+ {
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+ }
+ }
+ if (flipV)
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+ else
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+
+ count2 += 2;
+ count3 += 3;
+ if (!selectmode)
+ {
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+ {
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+ } else
+ {
+ gl.glNormal3f(0, 0, 1);
+ }
+ if (c != null)
+ {
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+ }
+ }
+ if (flipV)
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+ else
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+
+ count2 += 2;
+ count3 += 3;
+ for (int j = 0; j < strips[i] - 2; j++)
+ {
+ //gl.glTexCoord2d(...);
+ if (!selectmode)
+ {
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+ {
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+ } else
+ {
+ gl.glNormal3f(0, 0, 1);
+ }
+ if (c != null)
+ {
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+ }
+ }
+
+ if (flipV)
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+ else
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+ count2 += 2;
+ count3 += 3;
+ }
+
+ gl.glEnd();
+ }
+ }
+
+ assert count3 == v.length;
+ }
+ else // !trimmed
+ {
+ int count = 0;
+ for (int i = 0; i < strips.length; i++)
+ {
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
+
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
+
+ drawVertex(gl, p, flipV, selectmode);
+ drawVertex(gl, q, flipV, selectmode);
+
+ for (int j = 0; j < strips[i] - 2; j++)
+ {
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
+
+ // if (j%2 == 0)
+ // drawFace(p, q, r, display, null);
+ // else
+ // drawFace(p, r, q, display, null);
+
+ // p = q;
+ // q = r;
+ drawVertex(gl, r, flipV, selectmode);
+ }
+
+ gl.glEnd();
+ }
+ }
+ }
+
+ static cSpring.Point3D temp = new cSpring.Point3D();
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
+
+ public void DrawDynamicMesh(cMesh mesh)
+ {
+ GL gl = GetGL(); // getGL();
+
+ cSpring.PhysicsController3D Phys = mesh.Phys;
+
+ gl.glDisable(gl.GL_LIGHTING);
+
+ gl.glLineWidth(1);
+ gl.glColor3f(1,1,1);
+ gl.glBegin(gl.GL_LINES);
+ double scale = 0;
+ int count = 0;
+ for (int s=0; s<Phys.allSprings.size(); s++)
+ {
+ cSpring.Spring spring = Phys.allSprings.get(s);
+ if(s == 0)
+ {
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
+ }
+ if (mesh.showsprings)
+ {
+ temp.set(spring.a.position);
+ temp.add(spring.b.position);
+ temp.mul(0.5);
+ temp2.set(spring.a.position);
+ temp2.sub(spring.b.position);
+ temp2.mul(spring.restLength/2);
+ temp.sub(temp2);
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
+ temp.add(temp2);
+ temp.add(temp2);
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
+ }
+
+ if (spring.isHandle)
+ continue;
+
+ //if (scale < spring.restLength)
+ scale += spring.restLength;
+ count++;
+ }
+ gl.glEnd();
+
+ if (count == 0)
+ scale = 0.01;
+ else
+ scale /= count * 3;
+
+ //scale = 0.25;
+
+ if (mesh.ShowInfo())
+ {
+ gl.glLineWidth(4);
+ for (int s=0; s<Phys.allNodes.size(); s++)
+ {
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
+ if (node.mass == 0)
+ continue;
+
+ int i = node.springs==null?-1:node.springs.size();
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
+ //temp.normalize();
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
+ gl.glBegin(gl.GL_LINES);
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
+ gl.glEnd();
+ }
+
+ gl.glLineWidth(8);
+ for (int s=0; s<Phys.allNodes.size(); s++)
+ {
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
+
+ if (node.springs != null)
+ {
+ for (int i=0; i<node.springs.size(); i+=1)
+ {
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
+
+ int c = i+1;
+ // c = node.springs.get(i).nbcopies;
+
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
+ gl.glBegin(gl.GL_LINES);
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
+ 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);
+ gl.glEnd();
+ }
+ }
+ }
+
+ gl.glLineWidth(1);
+ }
+
+ gl.glEnable(gl.GL_LIGHTING);
+ }
+
/// INTERFACE
+
+ public void StartTriangles()
+ {
+ javax.media.opengl.GL gl = GetGL();
+ gl.glBegin(gl.GL_TRIANGLES);
+ }
+
+ public void EndTriangles()
+ {
+ GetGL().glEnd();
+ }
+
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
+ {
+ if (!selectmode)
+ {
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
+
+ if (flipV)
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
+ else
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
+ }
+
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
+ }
void SetColor(Object3D obj, Vertex p0)
{
@@ -16695,10 +17053,11 @@
static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
// Depth buffer format
//private int depth_format;
- static public void NextIndex(Object3D o, GL gl)
+
+ public void NextIndex()
{
indexcount+=16;
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
//objects[indexcount] = o;
//System.out.println("indexcount = " + indexcount);
}
diff --git a/GLShapeDrawer.java b/GLShapeDrawer.java
index 38fb421..ccf72d9 100644
--- a/GLShapeDrawer.java
+++ b/GLShapeDrawer.java
@@ -142,7 +142,7 @@
//System.out.println("shape="+shape+" type="+BroadphaseNativeTypes.forValue(shape.getShapeType()));
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
gl.glPushMatrix();
trans.getOpenGLMatrix(glMat);
@@ -552,7 +552,7 @@
static public void drawSphere(iCameraPane display, float radius, int slices, int stacks)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
sphereKey.radius = radius;
Integer glList = sphereDisplayLists.get(sphereKey);
@@ -624,7 +624,7 @@
static public void drawCylinder(iCameraPane display, float radius, float halfHeight, int upAxis)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
gl.glPushMatrix();
switch (upAxis)
diff --git a/GenericJoint.java b/GenericJoint.java
index 90f9509..ab83012 100644
--- a/GenericJoint.java
+++ b/GenericJoint.java
@@ -330,12 +330,14 @@
e.printStackTrace();
}
- display.GetGL().glPushMatrix();
+ //display.GetGL().glPushMatrix();
+ display.PushMatrix(LA.Identity, 1);
Vector3f v = ragdolls.get(0).bodies[0].worldTransform.origin;
// display.GetGL().glTranslatef(-v.x,0,-v.z);
super.DrawNode(display, root, selected);
- display.GetGL().glPopMatrix();
+ //display.GetGL().glPopMatrix();
+ display.PopMatrix(LA.Identity);
// assert(bRep != null);
@@ -453,7 +455,7 @@
public void renderme(iCameraPane display)
{
- GL gl = display!=null?display.GetGL():null;
+ GL gl = display!=null?display.GetGL0():null;
// gl0 = gl;
if (GetDynamicsWorld() != null)
@@ -798,7 +800,7 @@
public void drawCube(iCameraPane display, float extent)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
extent = extent * 0.5f;
@@ -1524,7 +1526,7 @@
public void drawSphere(iCameraPane display, float radius, int slices, int stacks)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
sphereKey.radius = radius;
Integer glList = sphereDisplayLists.get(sphereKey);
@@ -1596,7 +1598,7 @@
public void drawCylinder(iCameraPane display, float radius, float halfHeight, int upAxis)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
gl.glPushMatrix();
switch (upAxis)
diff --git a/LA.java b/LA.java
index 20a9211..a667209 100644
--- a/LA.java
+++ b/LA.java
@@ -623,6 +623,7 @@
private static int indxr[] = new int[4];
private static int indxc[] = new int[4];
+ static double[][] Identity = new double[4][4];
static int SIZE = 0; // 65536*64;
@@ -638,6 +639,8 @@
costable[i] = Math.cos(PI2 * i/SIZE);
sintable[i] = Math.sin(PI2 * i*i/SIZE/SIZE);
}
+
+ LA.matIdentity(Identity);
}
static double cos(double x0)
diff --git a/Merge.java b/Merge.java
index 138d4b1..be363c1 100644
--- a/Merge.java
+++ b/Merge.java
@@ -160,27 +160,27 @@
// debug stuff
if (false) // bRep.averagepoints != null)
{
- javax.media.opengl.GL gl = display.GetGL();
-
- gl.glColor3f(1, 0, 0);
- //gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
- //gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
-
- for (int i=0; i<NumGeometries(GetObject()); i++)
- {
- int i3 = i*3;
-
- float off = 0.005f;
-
- gl.glBegin(gl.GL_LINES);
- gl.glVertex3d(bRep.averagepoints[i3]-off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
- gl.glVertex3d(bRep.averagepoints[i3]+off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]-off, bRep.averagepoints[i3+2]);
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]+off, bRep.averagepoints[i3+2]);
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]-off);
- gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]+off);
- gl.glEnd();
- }
+// javax.media.opengl.GL gl = display.GetGL();
+//
+// gl.glColor3f(1, 0, 0);
+// //gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
+// //gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
+//
+// for (int i=0; i<NumGeometries(GetObject()); i++)
+// {
+// int i3 = i*3;
+//
+// float off = 0.005f;
+//
+// gl.glBegin(gl.GL_LINES);
+// gl.glVertex3d(bRep.averagepoints[i3]-off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
+// gl.glVertex3d(bRep.averagepoints[i3]+off, bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]);
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]-off, bRep.averagepoints[i3+2]);
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1]+off, bRep.averagepoints[i3+2]);
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]-off);
+// gl.glVertex3d(bRep.averagepoints[i3], bRep.averagepoints[i3+1], bRep.averagepoints[i3+2]+off);
+// gl.glEnd();
+// }
}
}
@@ -398,7 +398,7 @@
public void drawCube(iCameraPane display, float extent)
{
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
extent = extent * 0.5f;
diff --git a/Object3D.java b/Object3D.java
index bdfe925..8beaebd 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -5,6 +5,7 @@
import java.util.Vector;
import javax.media.j3d.Transform3D;
+import javax.media.opengl.GL;
import javax.vecmath.Vector3d;
import javax.imageio.ImageIO;
@@ -5371,7 +5372,7 @@
return;
}
- javax.media.opengl.GL gl = display.GetGL();
+ //javax.media.opengl.GL gl = display.GetGL();
/*
if (touched)
@@ -5423,7 +5424,7 @@
//if (displaylist == -1 && usecalllists)
if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
{
- bRep.displaylist = gl.glGenLists(1);
+ bRep.displaylist = display.GenList();
assert(bRep.displaylist != 0);
// System.err.println("glGenLists: " + bRep.displaylist + " for " + this);
//System.out.println("\tgen list " + list);
@@ -5435,14 +5436,16 @@
if (usecalllists)
{
// System.err.println("new list " + bRep.displaylist + " for " + this);
- gl.glNewList(bRep.displaylist, gl.GL_COMPILE); //_AND_EXECUTE);
+ display.NewList(bRep.displaylist);
}
+
CallList(display, root, selected, blocked);
+
// compiled = true;
if (usecalllists)
{
// System.err.println("end list " + bRep.displaylist + " for " + this);
- gl.glEndList();
+ display.EndList();
}
//gl.glDrawBuffer(gl.GL_BACK);
// XXX touched = false;
@@ -5490,7 +5493,7 @@
if (display.DrawMode() == iCameraPane.SHADOW)
{
if (!link2master // tricky to cull in shadow mode.
- && GetBRep().FrustumCull(this, gl, display.LightCamera(), true))
+ && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
{
//System.out.print("CULLED");
culled = true;
@@ -5498,7 +5501,7 @@
}
else
//GetBRep().getBounds(v0, v1, this);
- if (GetBRep().FrustumCull(this, gl, display.RenderCamera(), false))
+ if (GetBRep().FrustumCull(this, null, display.RenderCamera(), false))
culled = true;
// LA.xformPos(v0, display.renderCamera.toScreen, v0);
@@ -5538,7 +5541,7 @@
{
if (GetBRep() != null)
{
- CameraPane.NextIndex(this, gl);
+ display.NextIndex();
// vertex color conflict : gl.glCallList(list);
DrawNode(display, root, selected);
if (this instanceof BezierPatch)
@@ -5595,7 +5598,7 @@
// System.err.println("glCallList: " + bRep.displaylist + " for " + this);
assert(bRep.displaylist != 0);
- gl.glCallList(bRep.displaylist);
+ display.CallList(bRep.displaylist);
// june 2013 drawSelf(display, root, selected);
}
}
@@ -5897,7 +5900,7 @@
// bRep.lock = true;
- javax.media.opengl.GL gl = display.GetGL();
+ //javax.media.opengl.GL gl = display.GetGL();
if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
{
@@ -5914,23 +5917,7 @@
bRep.getMinMax(min, max, 100);
- gl.glBegin(gl.GL_LINES);
-
- gl.glVertex3d(min.x, min.y, min.z);
- gl.glVertex3d(min.x, min.y, max.z);
- gl.glVertex3d(min.x, min.y, min.z);
- gl.glVertex3d(min.x, max.y, min.z);
- gl.glVertex3d(min.x, min.y, min.z);
- gl.glVertex3d(max.x, min.y, min.z);
-
- gl.glVertex3d(max.x, max.y, max.z);
- gl.glVertex3d(min.x, max.y, max.z);
- gl.glVertex3d(max.x, max.y, max.z);
- gl.glVertex3d(max.x, min.y, max.z);
- gl.glVertex3d(max.x, max.y, max.z);
- gl.glVertex3d(max.x, max.y, min.z);
-
- gl.glEnd();
+ display.DrawBox(min, max);
return;
}
@@ -5984,178 +5971,14 @@
new Exception().printStackTrace();
return;
}
-
- // TRIANGLE STRIP ARRAY
- if (bRep.trimmed)
- {
- float[] v = bRep.getRawVertices();
- float[] n = bRep.getRawNormals();
- float[] c = bRep.getRawColors();
- float[] uv = bRep.getRawUVMap();
-
- int count2 = 0;
- int count3 = 0;
-
- if (n.length > 0)
- {
- for (int i = 0; i < strips.length; i++)
- {
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
-
- /*
- boolean locked = false;
- float eps = 0.1f;
- boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
-
- int dot = 0;
-
- if ((dot&1) == 0)
- dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
-
- if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
- gl.glTexCoord2f((float) qv.s, (float) qv.t);
- else
- {
- locked = true;
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
- }
- //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
- gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
- if (hasnorm)
- {
- //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
- gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
- }
-
- if ((dot&4) == 0)
- dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
-
- if (wrap || !locked && (dot&8) != 0)
- gl.glTexCoord2f((float) rv.s, (float) rv.t);
- else
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
-
- f.dot = dot;
- */
-
- if (!selectmode)
- {
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
- {
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
- } else
- {
- gl.glNormal3f(0, 0, 1);
- }
-
- if (c != null)
- //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
- {
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
- }
- }
- if (flipV)
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
- else
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
- //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
-
- count2 += 2;
- count3 += 3;
- if (!selectmode)
- {
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
- {
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
- } else
- {
- gl.glNormal3f(0, 0, 1);
- }
- if (c != null)
- {
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
- }
- }
- if (flipV)
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
- else
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
- //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
-
- count2 += 2;
- count3 += 3;
- for (int j = 0; j < strips[i] - 2; j++)
- {
- //gl.glTexCoord2d(...);
- if (!selectmode)
- {
- if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
- {
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
- } else
- {
- gl.glNormal3f(0, 0, 1);
- }
- if (c != null)
- {
- gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
- }
- }
-
- if (flipV)
- gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
- else
- gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
- //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
- gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
- count2 += 2;
- count3 += 3;
- }
-
- gl.glEnd();
- }
- }
-
- assert count3 == v.length;
- }
- else // !trimmed
- {
- int count = 0;
- for (int i = 0; i < strips.length; i++)
- {
- gl.glBegin(gl.GL_TRIANGLE_STRIP);
-
- Vertex p = bRep.GetVertex(bRep.indices[count++]);
- Vertex q = bRep.GetVertex(bRep.indices[count++]);
-
- drawVertex(gl, p, selectmode);
- drawVertex(gl, q, selectmode);
-
- for (int j = 0; j < strips[i] - 2; j++)
- {
- Vertex r = bRep.GetVertex(bRep.indices[count++]);
-
-// if (j%2 == 0)
-// drawFace(p, q, r, display, null);
-// else
-// drawFace(p, r, q, display, null);
-
-// p = q;
-// q = r;
- drawVertex(gl, r, selectmode);
- }
-
- gl.glEnd();
- }
- }
+
+ display.DrawGeometry(bRep, flipV, selectmode);
} else // catch (Error e)
{
// TRIANGLE ARRAY
if (IsOpaque()) // Static())
{
- gl.glBegin(gl.GL_TRIANGLES);
+ display.StartTriangles();
int facecount = bRep.FaceCount();
for (int i = 0; i < facecount; i++)
{
@@ -6220,7 +6043,7 @@
display.DrawFace(this, p, q, r, face);
}
- gl.glEnd();
+ display.EndTriangles();
}
else
{
@@ -6249,8 +6072,8 @@
//System.out.println("SORT");
java.util.Arrays.sort(facescompare);
-
- gl.glBegin(gl.GL_TRIANGLES);
+
+ display.StartTriangles();
for (int i = 0; i < facecount; i++)
{
Face face = bRep.GetFace(facescompare[i].index);
@@ -6264,11 +6087,12 @@
display.DrawFace(this, p, q, r, face);
}
- gl.glEnd();
+ display.EndTriangles();
}
if (false) // live && support != null && support.bRep != null) // debug weights
{
+ /*
gl.glDisable(gl.GL_LIGHTING);
float[] colorV = new float[3];
@@ -6347,6 +6171,7 @@
// gl.glEnd();
}
}
+ */
}
}
@@ -6405,22 +6230,6 @@
void Print(Vertex v)
{
//System.err.println("(" + v.x + ", " + v.y + ", " + v.z + ")");
- }
-
- void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean selectmode)
- {
- if (!selectmode)
- {
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
- gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
-
- if (flipV)
- gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
- else
- gl.glTexCoord2f((float) pv.s, (float) pv.t);
- }
-
- gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
}
void drawSelf(ClickInfo info, int level, boolean select)
diff --git a/VehicleDemo.java b/VehicleDemo.java
index 2c1a8af..e94648e 100755
--- a/VehicleDemo.java
+++ b/VehicleDemo.java
@@ -529,7 +529,7 @@
public void renderme0(iCameraPane display)
{
//updateCamera();
- GL gl = display.GetGL();
+ GL gl = display.GetGL0();
if (dynamicsWorld != null) {
int numObjects = dynamicsWorld.getNumCollisionObjects();
diff --git a/cLinker.java b/cLinker.java
index 0e3467c..1487169 100644
--- a/cLinker.java
+++ b/cLinker.java
@@ -49,7 +49,7 @@
{
cStatic.point7.set(stack.peek());
/**/
- javax.media.opengl.GL gl = display.GetGL();
+ //javax.media.opengl.GL gl = display.GetGL();
//gl.glBegin(gl.GL_LINES);
//gl.glVertex3d(stack.peek().x, stack.peek().y, stack.peek().z);
diff --git a/cMesh.java b/cMesh.java
index 863e918..d49f23c 100644
--- a/cMesh.java
+++ b/cMesh.java
@@ -1,6 +1,6 @@
import java.util.Hashtable;
-import javax.media.opengl.GL;
+//import javax.media.opengl.GL;
public class cMesh extends cSpring
{
@@ -78,7 +78,7 @@
live = true;
}
-
+
Object3D deepCopy()
{
/*
@@ -545,103 +545,7 @@
if(/*showsprings &&*/ Phys != null)
{
- GL gl = display.GetGL(); // getGL();
-
- gl.glDisable(gl.GL_LIGHTING);
-
- gl.glLineWidth(1);
- gl.glColor3f(1,1,1);
- gl.glBegin(gl.GL_LINES);
- double scale = 0;
- int count = 0;
- for (int s=0; s<Phys.allSprings.size(); s++)
- {
- Spring spring = Phys.allSprings.get(s);
- if(s == 0)
- {
- //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
- }
- if (showsprings)
- {
- temp.set(spring.a.position);
- temp.add(spring.b.position);
- temp.mul(0.5);
- temp2.set(spring.a.position);
- temp2.sub(spring.b.position);
- temp2.mul(spring.restLength/2);
- temp.sub(temp2);
- gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
- temp.add(temp2);
- temp.add(temp2);
- gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
- }
-
- if (spring.isHandle)
- continue;
-
- //if (scale < spring.restLength)
- scale += spring.restLength;
- count++;
- }
- gl.glEnd();
-
- if (count == 0)
- scale = 0.01;
- else
- scale /= count * 3;
-
- //scale = 0.25;
-
- if (ShowInfo())
- {
- gl.glLineWidth(4);
- for (int s=0; s<Phys.allNodes.size(); s++)
- {
- DynamicNode node = Phys.allNodes.get(s);
- if (node.mass == 0)
- continue;
-
- int i = node.springs==null?-1:node.springs.size();
- gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
- //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
- //temp.normalize();
- //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
- gl.glBegin(gl.GL_LINES);
- gl.glVertex3d(node.position.x, node.position.y, node.position.z);
- //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
- gl.glVertex3d(node.position.x + bRep.GetVertex(s).norm.x*scale,
- node.position.y + bRep.GetVertex(s).norm.y*scale,
- node.position.z + bRep.GetVertex(s).norm.z*scale);
- gl.glEnd();
- }
-
- gl.glLineWidth(8);
- for (int s=0; s<Phys.allNodes.size(); s++)
- {
- DynamicNode node = Phys.allNodes.get(s);
-
- if (node.springs != null)
- {
- for (int i=0; i<node.springs.size(); i+=1)
- {
- DynamicNode f = node.springs.get(i).GetOther(node);
-
- int c = i+1;
- // c = node.springs.get(i).nbcopies;
-
- gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
- gl.glBegin(gl.GL_LINES);
- gl.glVertex3d(node.position.x, node.position.y, node.position.z);
- 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);
- gl.glEnd();
- }
- }
- }
-
- gl.glLineWidth(1);
- }
-
- gl.glEnable(gl.GL_LIGHTING);
+ display.DrawDynamicMesh(this);
}
if (live && Globals.isLIVE() && display.DrawMode() == CameraPane.DEFAULT)
diff --git a/cSpring.java b/cSpring.java
index 47b7769..914577b 100644
--- a/cSpring.java
+++ b/cSpring.java
@@ -565,7 +565,7 @@
// }
//new Exception().printStackTrace();
- GL gl = display.GetGL(); // getGL();
+ GL gl = display.GetGL0(); // getGL();
//gl.glDisable(GL.GL_LIGHTING);
diff --git a/iCameraPane.java b/iCameraPane.java
index bfbe44c..866cbe7 100644
--- a/iCameraPane.java
+++ b/iCameraPane.java
@@ -24,7 +24,7 @@
boolean IsFrozen();
- javax.media.opengl.GL GetGL();
+ javax.media.opengl.GL GetGL0();
// Currently in Globals
int DrawMode();
@@ -60,6 +60,22 @@
void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face);
+ void DrawBox(cVector min, cVector max);
+
+ void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode);
+
+ void DrawDynamicMesh(cMesh c);
+
+ void StartTriangles();
+ void EndTriangles();
+
+ int GenList();
+ void NewList(int id);
+ void CallList(int id);
+ void EndList();
+
+ void NextIndex();
+
void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate);
void PrepOcclusion(BoundaryRep br, double[][] transform);
--
Gitblit v1.6.2