From 623dc0fa8cbd9473830a1786f6d49fa808a09439 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 05 May 2019 14:06:12 -0400 Subject: [PATCH] Rename Grafreed --- BoundaryRep.java | 194 ++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 177 insertions(+), 17 deletions(-) diff --git a/BoundaryRep.java b/BoundaryRep.java index 4667636..7b31bc4 100644 --- a/BoundaryRep.java +++ b/BoundaryRep.java @@ -172,16 +172,16 @@ bufV = other.bufV; bufF = other.bufF; - positions = (float[]) GrafreeD.clone(other.positions); - normals = (float[]) GrafreeD.clone(other.normals); - colors = (float[]) GrafreeD.clone(other.colors); - uvmap = (float[]) GrafreeD.clone(other.uvmap); - triangles = (int[]) GrafreeD.clone(other.triangles); + positions = (float[]) Grafreed.clone(other.positions); + normals = (float[]) Grafreed.clone(other.normals); + colors = (float[]) Grafreed.clone(other.colors); + uvmap = (float[]) Grafreed.clone(other.uvmap); + triangles = (int[]) Grafreed.clone(other.triangles); - indices = (int[]) GrafreeD.clone(other.indices); + indices = (int[]) Grafreed.clone(other.indices); - vertices = (Vector<Vertex>) GrafreeD.clone(other.vertices); - faces = (Vector<Face>) GrafreeD.clone(other.faces); + vertices = (Vector<Vertex>) Grafreed.clone(other.vertices); + faces = (Vector<Face>) Grafreed.clone(other.faces); } else { @@ -1518,7 +1518,7 @@ InitFaceIndices(); } - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); //float[] v = new float[100]; for (int loops=1; --loops>=0;) @@ -1548,7 +1548,7 @@ InitFaceIndices(); } - BoundaryRep rep = (BoundaryRep) GrafreeD.clone(this); + BoundaryRep rep = (BoundaryRep) Grafreed.clone(this); //float[] v = new float[100]; for (int loops=10; --loops>=0;) @@ -2670,7 +2670,7 @@ if (Globals.framecount - lastsoundtime > 30) // 0.25 secs { - GrafreeD.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); + Grafreed.wav.play((Math.random()+0.5)/Math.max(tmp.length2(),0.2)); //, 1); lastsoundtime = Globals.framecount; } @@ -3155,7 +3155,27 @@ */ } - void GenUV() + void UnfoldUV() + { + for (int i = 0; i < VertexCount(); i++) + { + Vertex v = GetVertex(i); + + v.x = v.s; + v.y = v.t; + v.z = 0; + + v.norm.x = 0; + v.norm.y = 0; + v.norm.z = 1; + + SetVertex(v, i); + } + } + + float power = 2; + + void GenUV() // float power) { Trim(); @@ -3219,6 +3239,125 @@ y -= 0.5; z -= 0.5; + double ax = Math.abs(x); + double ay = Math.abs(y); + double max = ax; + if (max < ay) + { + max = ay; + } + + if (max == 0) + { + uvmap[i2] = 0.5f; + uvmap[i2+1] = 0.5f; + continue; + } + + x /= max; + y /= max; + + double angle = Math.acos(Math.abs(z*2)); + + double k = angle / Math.PI * 2; + + assert(k >= 0); + + // k == 0 => uv = 0 (center) + // k == 1 => uv = -1,1 (border) + + if (i == 0) + System.out.println("power = " + power); + + double length1 = (ax+ay)/max; + double length2 = Math.sqrt(ax*ax + ay*ay) / max; + + double t = k; + + t = Math.pow(t, 3); + + // Interpolate between k/length2 (center) and k (border) + if (length2 > 0) + k *= (1 - t) / length2 + t; + + double u = k*x; + double v = k*y; + + u /= 2; + v /= 2; + u += 0.5; + v += 0.5; + + uvmap[i2] = (float) u; + uvmap[i2+1] = (float) v; + } + } + + void GenUVold(float power) + { + Trim(); + + cVector boxcenter = null; + cVector minima, maxima; + minima = new cVector(); + maxima = new cVector(); + minima.x = minima.y = minima.z = Double.MAX_VALUE; + maxima.x = maxima.y = maxima.z = -Double.MAX_VALUE; + for (int i = 0; i < VertexCount(); i++) + { + Vertex v = GetVertex(i); + + if (minima.x > v.x) + { + minima.x = v.x; + } + if (minima.y > v.y) + { + minima.y = v.y; + } + if (minima.z > v.z) + { + minima.z = v.z; + } + + if (maxima.x < v.x) + { + maxima.x = v.x; + } + if (maxima.y < v.y) + { + maxima.y = v.y; + } + if (maxima.z < v.z) + { + maxima.z = v.z; + } + } + + boxcenter = new cVector((maxima.x + minima.x) / 2, (maxima.y + minima.y) / 2, (maxima.z + minima.z) / 2); + int i2 = 0, i3 = 0; + for (int i = 0; i < positions.length/3; i++, i3 += 3, i2 += 2) + { +// //uvmap[i2] = (float) normals[i3]*0.5f + 0.5f; // v.x; +// //uvmap[i2 + 1] = (float) normals[i3+1]*0.5f + 0.5f; //z; +// uvmap[i2] = (float) (positions[i3] - boxcenter.x); +// uvmap[i2 + 1] = (float) (positions[i3+2] - boxcenter.z); +// uvmap[i2] = (float) Math.atan2(positions[i3+1] - boxcenter.y, positions[i3] - boxcenter.x); +// uvmap[i2 + 1] = (float)(positions[i3+2] - boxcenter.z); + // box UV + double x = positions[i3] - minima.x; // - Math.floor(positions[i3]); + double y = positions[i3+1] - minima.y; // - Math.floor(positions[i3+1]); + double z = positions[i3+2] - minima.z; // - Math.floor(positions[i3+2]); + + // [-1/2, 1/2] + x /= maxima.x - minima.x; + y /= maxima.y - minima.y; + z /= maxima.z - minima.z; + + x -= 0.5; + y -= 0.5; + z -= 0.5; + // x *= 2; // y *= 2; // z *= 2; @@ -3245,6 +3384,15 @@ z = Math.cos(angle/2); + assert(z >= 0); + assert(z <= 1); + + /**/ + //z = Math.pow(z, power); //1.08f); + + if (i == 0) + System.out.println("power = " + power); + // sqrt(k2*x2 + k2*z2 + y2) = length // k2*x2 + k2*z2 = length2 - y2 // k2 = (length2 - y2) / (x2 + z2) @@ -3255,7 +3403,7 @@ k /= x*x + y*y; } else - GrafreeD.Assert(z == 1); + Grafreed.Assert(z == 1); if (k < 0) k = 0; @@ -3264,6 +3412,7 @@ x *= k; y *= k; + /**/ double max = Math.abs(x); if (max < Math.abs(y)) @@ -3276,10 +3425,15 @@ } // max = Math.sqrt(max*2)/2; +// double x2 = Math.pow(Math.abs(x), 1/power); +// double y2 = Math.pow(Math.abs(y), 1/power); +// double z2 = Math.pow(Math.abs(z), 1/power); +// max = Math.pow(x2 + y2 + z2, power); // if (!(max > 0)) - assert(max > 0); - + //assert(max > 0); + assert(max >= 0); + x /= max; y /= max; z /= max; @@ -3748,6 +3902,11 @@ tsa.getNormals(0, normals); tsa.getTextureCoordinates(0, 0, uvmap); // tsa.getColors(0, colors); + + for (int i=colors.length; --i>=0;) + { + colors[i] = 1; + } int stripcount = tsa.getNumStrips(); triangles = new int[stripcount]; @@ -4428,7 +4587,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, @@ -6200,6 +6359,7 @@ void InitWeights() { + new Exception().printStackTrace(); System.exit(0); int n = 0; int b = 0; @@ -8073,7 +8233,7 @@ if (!trimmed) return; - GrafreeD.linkUV = false; + Grafreed.linkUV = false; try { -- Gitblit v1.6.2