From: <edi...@us...> - 2003-08-05 23:52:21
|
Update of /cvsroot/jrman/drafts/src/org/jrman/primitive In directory sc8-pr-cvs1:/tmp/cvs-serv26512/src/org/jrman/primitive Modified Files: Hyperboloid.java Log Message: trying to fix bounding volumne in Hyperboloid. Index: Hyperboloid.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/primitive/Hyperboloid.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Hyperboloid.java 25 Jul 2003 13:56:50 -0000 1.4 --- Hyperboloid.java 5 Aug 2003 23:52:18 -0000 1.5 *************** *** 91,147 **** public BoundingVolume getBoundingVolume() { float r1 = (float) Math.sqrt((x1 * x1) + (y1 * y1)); float r2 = (float) Math.sqrt((x2 * x2) + (y2 * y2)); ! float cosThetaMin = (float) Math.cos(thetaMin); ! float sinThetaMin = (float) Math.sin(thetaMin); ! float cosThetaMax = (float) Math.cos(thetaMax); ! float sinThetaMax = (float) Math.sin(thetaMax); ! float rMax = Math.max(r1, r2); ! float rMin = Math.min(r1, r2); float xMin; ! float xMax = cosThetaMin * rMin; ! xMax = Math.max(xMax, cosThetaMin * rMax); ! xMax = Math.max(xMax, cosThetaMax * rMin); ! xMax = Math.max(xMax, cosThetaMax * rMax); float yMin; float yMax; ! if (thetaMin < Math.PI && thetaMax > Math.PI) ! xMin = -rMax; ! else { ! xMin = cosThetaMin * rMin; ! xMin = Math.min(xMin, cosThetaMin * rMax); ! xMin = Math.min(xMin, cosThetaMax * rMin); ! xMin = Math.min(xMin, cosThetaMax * rMax); } ! if (thetaMin < Math.PI / 2 && thetaMax > Math.PI / 2) ! yMax = rMax; ! else { ! yMax = sinThetaMin * rMin; ! yMax = Math.max(yMax, sinThetaMin * rMax); ! yMax = Math.max(yMax, sinThetaMax * rMin); ! yMax = Math.max(yMax, sinThetaMax * rMax); } ! if (thetaMin < Math.PI * 3 / 2 && thetaMax > Math.PI * 3 / 2) ! yMin = -rMax; ! else { ! yMin = sinThetaMin * rMin; ! yMin = Math.min(yMin, sinThetaMin * rMax); ! yMin = Math.min(yMin, sinThetaMax * rMin); ! yMin = Math.min(yMin, sinThetaMax * rMax); } ! Bounds3f result = new Bounds3f(xMin, xMax, yMin, yMax, z1, z2); ! return result; ! } public Primitive[] split() { float r1 = (float) Math.sqrt((x1 * x1) + (y1 * y1)); ! float r2 = (float) Math.sqrt((x2 * x2) + (y2 * y2)); ! float r = (float)Math.sqrt((x2 -x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)); ! ! Primitive[] result = new Primitive[2]; ! if ((thetaMax - thetaMin) * (float) Math.max(r1, r2) > r) { result[0] = new Hyperboloid( --- 91,378 ---- public BoundingVolume getBoundingVolume() { + //float cosTMin = (float) Math.cos(thetaMin); + //float sinTMin = (float) Math.sin(thetaMin); + //float cosTMax = (float) Math.cos(thetaMax); + //float sinTMax = (float) Math.sin(thetaMax); + //float x1Min = x1 * cosTMin - y1 * sinTMin; + //float y1Min = x1 * sinTMin + y1 * cosTMin; + //float x1Max = x1 * cosTMax - y1 * sinTMax; + //float y1Max = x1 * sinTMax + y1 * cosTMax; + //float gamma1Min = (float) Math.atan2(y1Min, x1Min); + //float gamma1Max = (float) Math.atan2(y1Max, x1Max); + + float gamma1Min = (float) Math.atan2(y1, x1); + if (gamma1Min < 0) + gamma1Min += Math.PI * 2f; + float gamma1Max = gamma1Min + (thetaMax - thetaMin); + if (gamma1Max < 0) + gamma1Max += Math.PI * 2f; + + if ((thetaMax - thetaMin) - (gamma1Max - gamma1Min) > 0.001) + System.out.println("WARNING:" + gamma1Min + ":" + gamma1Max); + float r1 = (float) Math.sqrt((x1 * x1) + (y1 * y1)); + //int angleCase1 = + // whichQuadrant(gamma1Min) + (whichQuadrant(gamma1Max) << 2); + float[] values1 = analizeAngleCase2(r1, gamma1Min, gamma1Max); + float x11Min = values1[0]; + float x11Max = values1[1]; + float y11Min = values1[2]; + float y11Max = values1[3]; + + //float x2Min = x2 * cosTMin - y2 * sinTMin; + //float y2Min = x2 * sinTMin + y2 * cosTMin; + //float x2Max = x2 * cosTMax - y2 * sinTMax; + //float y2Max = x2 * sinTMax + y2 * cosTMax; + //float gamma2Min = (float) Math.atan2(y2Min, x2Min); + //float gamma2Max = (float) Math.atan2(y2Max, x2Max); + + float gamma2Min = (float) Math.atan2(y2, x2); + if (gamma2Min < 0) + gamma2Min += Math.PI * 2f; + float gamma2Max = gamma2Min + (thetaMax - thetaMin); + if (gamma2Max < 0) + gamma2Max += Math.PI * 2f; + + if ((thetaMax - thetaMin) - (gamma2Max - gamma2Min) > 0.001) + System.out.println("WARNING:" + gamma2Min + ":" + gamma2Max); + float r2 = (float) Math.sqrt((x2 * x2) + (y2 * y2)); + //int angleCase2 = + // whichQuadrant(gamma2Min) + (whichQuadrant(gamma2Max) << 2); + float[] values2 = analizeAngleCase2(r2, gamma2Min, gamma2Max); + float x22Min = values2[0]; + float x22Max = values2[1]; + float y22Min = values2[2]; + float y22Max = values2[3]; ! float xMin = Math.min(x11Min, x22Min); ! float xMax = Math.max(x11Max, x22Max); ! float yMin = Math.min(y11Min, y22Min); ! float yMax = Math.max(y11Max, y22Max); ! float zMin = Math.min(z1, z2); ! float zMax = Math.max(z1, z2); ! ! Bounds3f b3f = new Bounds3f(xMin, xMax, yMin, yMax, zMin, zMax); ! //System.out.println("r1:" + r1 + " r2:" + r2); ! //System.out.println(b3f); ! return b3f; ! } ! ! private int whichQuadrant(float angle) { ! int result; ! if (angle > Math.PI * 2f) ! angle -= Math.PI * 2f; ! if (angle >= 0f && angle < Math.PI / 2f) ! result = 0; ! else if (angle >= Math.PI / 2f && angle < Math.PI) ! result = 1; ! else if (angle >= Math.PI && angle < Math.PI * 3f / 2f) ! result = 2; ! else ! result = 3; ! return result; ! } ! ! private boolean passAngle(float angle, float minAngle, float maxAngle) { ! return minAngle <= angle && angle <= maxAngle; ! } ! ! private float[] analizeAngleCase2( ! float r, ! float gammaMin, ! float gammaMax) { ! ! float[] values = new float[4]; ! float cosGammaMin = (float) Math.cos(gammaMin); ! float sinGammaMin = (float) Math.sin(gammaMin); ! float cosGammaMax = (float) Math.cos(gammaMax); ! float sinGammaMax = (float) Math.sin(gammaMax); float xMin; ! float xMax; float yMin; float yMax; ! ! xMin = getMin(r, cosGammaMin, cosGammaMax); ! xMax = getMax(r, cosGammaMin, cosGammaMax); ! yMin = getMin(r, sinGammaMin, sinGammaMax); ! yMax = getMax(r, sinGammaMin, sinGammaMax); ! ! if (passAngle((float) Math.PI / 2f, gammaMin, gammaMax)) { ! yMax = r; } ! if (passAngle((float) Math.PI, gammaMin, gammaMax)) { ! xMin = -r; } ! if (passAngle((float) Math.PI * 3f / 2f, gammaMin, gammaMax)) { ! yMin = -r; } + if (passAngle(0f, gammaMin, gammaMax) + || passAngle((float) Math.PI * 2f, gammaMin, gammaMax)) { + xMax = r; } + values[0] = xMin; + values[1] = xMax; + values[2] = yMin; + values[3] = yMax; + return values; + } ! private float[] analizeAngleCase( ! int angleCase, ! float r1, ! float gammaMin, ! float gammaMax) { ! ! float[] values = new float[4]; ! float cosGammaMin = (float) Math.cos(gammaMin); ! float sinGammaMin = (float) Math.sin(gammaMin); ! float cosGammaMax = (float) Math.cos(gammaMax); ! float sinGammaMax = (float) Math.sin(gammaMax); ! float xMin; ! float xMax; ! float yMin; ! float yMax; ! switch (angleCase) { ! case 0 : // 0 gammaMin 1 gammaMax 1 ! if (gammaMin < gammaMax) { ! xMin = getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! } else { ! xMin = -r1; xMax = r1; yMin = -r1; yMax = r1; } ! break; ! case 1 : // 1 gammaMin 2 gammaMax 1 ! xMin = -r1; ! xMax = r1; ! yMin = -r1; ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! case 2 : // 1 gammaMin 3 gammaMax 1 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = r1; ! yMin = -r1; ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! case 3 : // 3 gammaMin 4 gammaMax 1 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = r1; ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! case 4 : // 4 gammaMin 1 gammaMax 2 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = r1; ! break; ! case 5 : // 5 gammaMin 2 gammaMax 2 ! if ( ! gammaMin < gammaMax) { ! xMin = getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! } else { ! xMin = -r1; xMax = r1; yMin = -r1; yMax = r1; } ! break; ! case 6 : // 6 gammaMin 3 gammaMax 2 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = r1; ! yMin = -r1; ! yMax = r1; ! break; ! case 7 : // 7 gammaMin 4 gammaMax 2 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = r1; ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = r1; ! break; ! case 8 : // 8 gammaMin 1 gammaMax 3 ! xMin = -r1; ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = r1; ! break; ! case 9 : // 9 gammaMin 2 gammaMax 3 ! xMin = -r1; ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! case 10 : //10 gammaMin 3 gammaMax 3 ! if ( ! gammaMin < gammaMax) { ! xMin = getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! } else { ! xMin = -r1; xMax = r1; yMin = -r1; yMax = r1; } ! break; ! case 11 : //11 gammaMin 4 gammaMax 3 ! xMin = -r1; ! xMax = r1; ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = r1; ! break; ! case 12 : //12 gammaMin 1 gammaMax 4 ! xMin = -r1; ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = -r1; ! yMax = r1; ! break; ! case 13 : //13 gammaMin 2 gammaMax 4 ! xMin = -r1; ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = -r1; ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! case 14 : //14 gammaMin 3 gammaMax 4 ! xMin = ! getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = -r1; ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! break; ! default : //15 gammaMin 4 gammaMax 4 ! if ( ! gammaMin < gammaMax) { ! xMin = getMin(r1, cosGammaMin, cosGammaMax); ! xMax = getMax(r1, cosGammaMin, cosGammaMax); ! yMin = getMin(r1, sinGammaMin, sinGammaMax); ! yMax = getMax(r1, sinGammaMin, sinGammaMax); ! } else { ! xMin = -r1; xMax = r1; yMin = -r1; yMax = r1; } ! break; } ! values[0] = xMin; ! values[1] = xMax; ! values[2] = yMin; ! values[3] = yMax; ! return values; ! } ! ! private float getMin(float r, float angle1, float angle2) { ! float result = r * angle1; return Math.min(result, r * angle2); } ! ! private float getMax(float r, float angle1, float angle2) { ! float result = r * angle1; return Math.max(result, r * angle2); } public Primitive[] split() { float r1 = (float) Math.sqrt((x1 * x1) + (y1 * y1)); ! float r2 = (float) Math.sqrt((x2 * x2) + (y2 * y2)); ! float r = ! (float) Math.sqrt( ! (x2 - x1) * (x2 - x1) ! + (y2 - y1) * (y2 - y1) ! + (z2 - z1) * (z2 - z1)); ! Primitive[] result = new Primitive[2]; ! if ((thetaMax - thetaMin) * (float) Math.max(r1, r2) > r) { result[0] = new Hyperboloid( *************** *** 159,195 **** linearInterpolateParameters(0f, .5f, 0f, 1f), attributes); ! result[1] = ! new Hyperboloid( ! x1, ! y1, ! z1, ! x2, ! y2, ! z2, ! (thetaMin + thetaMax) / 2f, ! thetaMax, ! maxTheta, ! maxZ1, ! maxZ2, ! linearInterpolateParameters(.5f, 1f, 0f, 1f), ! attributes); ! } else { result[0] = new Hyperboloid( - (x1 + x2) / 2f, - (y1 + y2) / 2f, - (z1 + z2) / 2f, - x2, - y2, - z2, - thetaMin, - thetaMax, - maxTheta, - maxZ1, - maxZ2, - linearInterpolateParameters(0f, 1f, 0f, .5f), - attributes); - result[1] = - new Hyperboloid( x1, y1, --- 390,411 ---- linearInterpolateParameters(0f, .5f, 0f, 1f), attributes); ! result[1] = ! new Hyperboloid( ! x1, ! y1, ! z1, ! x2, ! y2, ! z2, ! (thetaMin + thetaMax) / 2f, ! thetaMax, ! maxTheta, ! maxZ1, ! maxZ2, ! linearInterpolateParameters(.5f, 1f, 0f, 1f), ! attributes); ! } else { result[0] = new Hyperboloid( x1, y1, *************** *** 203,263 **** maxZ1, maxZ2, ! linearInterpolateParameters(0f, 1f, .5f, 1f), attributes); ! } ! return result; ! } protected void dice_P(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); ! int vSize = Grid.getVSize(); ! float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); ! //float zDelta = (float) (z2 - z1) / (vSize - 1); ! Point3fGrid P = shaderVariables.P; ! for (int u = 0; u < uSize; u++) { float theta = thetaMin + thetaDelta * u; ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! for (int v = 0; v < vSize; v++) { ! //float z = z1 + zDelta * v; ! float z = v / (vSize - 1); ! float xr = (1 - z) * x1 + z * x2; ! float yr = (1 - z) * y1 + z * y2; ! float zr = (1 - z) * z1 + z * z2; ! tmp.x = xr * cosTheta - yr * sinTheta; ! tmp.y = xr * sinTheta + yr * cosTheta; ! tmp.z = zr; ! P.set(u, v, tmp); ! } } } protected void dice_Ng(ShaderVariables shaderVariables) { - int uSize = Grid.getUSize(); ! int vSize = Grid.getVSize(); ! float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); ! Vector3fGrid Ng = shaderVariables.Ng; //float dZ = (-maxZ1 + maxZ2) * maxTheta; ! float dZ = (-z1 + z2) * maxTheta; ! float dX = -x1 + x2; ! float dY = -y1 + y2; ! for (int u = 0; u < uSize; u++) { float theta = thetaMin + thetaDelta * u; ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! for (int v = 0; v < vSize; v++) { ! float z = v / (vSize - 1); ! float vX = (1 - z) * x1 + z * x2; ! float vY = (1 - z) * y1 + z * y2; ! vtmp.x = dZ * (vX * cosTheta + vY * sinTheta); ! vtmp.y = dZ * (vX * sinTheta + vY * cosTheta); ! vtmp.z = ! (dX * sinTheta - dY * cosTheta) ! * (vX * sinTheta + vY * cosTheta) ! + (dX * cosTheta - dY * sinTheta) ! * (vX * cosTheta - vY * sinTheta); ! Ng.set(u, v, vtmp); ! } } } --- 419,497 ---- maxZ1, maxZ2, ! linearInterpolateParameters(0f, 1f, 0f, .5f), attributes); ! result[1] = ! new Hyperboloid( ! (x1 + x2) / 2f, ! (y1 + y2) / 2f, ! (z1 + z2) / 2f, ! x2, ! y2, ! z2, ! thetaMin, ! thetaMax, ! maxTheta, ! maxZ1, ! maxZ2, ! linearInterpolateParameters(0f, 1f, .5f, 1f), ! attributes); ! } ! return result; } protected void dice_P(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); ! int vSize = Grid.getVSize(); ! float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); ! Point3fGrid P = shaderVariables.P; ! //System.out.println("ThetaMin: " + Math.toDegrees(thetaMin)); ! //System.out.println("ThetaMax: " + Math.toDegrees(thetaMax)); ! //System.out.println("P1: " + x1 + ":" + y1 + ":" + z1); ! //System.out.println("P2: " + x2 + ":" + y2 + ":" + z2); ! for ( ! int u = 0; u < uSize; u++) { float theta = thetaMin + thetaDelta * u; ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! for (int v = 0; v < vSize; v++) { ! float nv = (float) v / (vSize - 1); ! float xr = (1f - nv) * x1 + nv * x2; ! float yr = (1f - nv) * y1 + nv * y2; ! float zr = (1f - nv) * z1 + nv * z2; ! tmp.x = xr * cosTheta - yr * sinTheta; ! tmp.y = xr * sinTheta + yr * cosTheta; ! tmp.z = zr; ! P.set(u, v, tmp); ! } } } protected void dice_Ng(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); ! int vSize = Grid.getVSize(); ! float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); ! Vector3fGrid Ng = shaderVariables.Ng; //float dZ = (-maxZ1 + maxZ2) * maxTheta; ! float dZ = ! (-z1 + z2) * -maxTheta; ! float dX = -x1 + x2; ! float dY = -y1 + y2; ! for (int u = 0; u < uSize; u++) { float theta = thetaMin + thetaDelta * u; ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! for (int v = 0; v < vSize; v++) { ! float nv = (float) v / (vSize - 1); ! float vX = (1 - nv) * x1 + nv * x2; ! float vY = (1 - nv) * y1 + nv * y2; ! vtmp.x = dZ * (vX * cosTheta + vY * sinTheta); ! vtmp.y = dZ * (vX * sinTheta + vY * cosTheta); ! vtmp.z = ! maxTheta ! * (dX * sinTheta - dY * cosTheta) ! * (vX * sinTheta + vY * cosTheta) ! - (dX * cosTheta - dY * sinTheta) ! * (vX * cosTheta + vY * sinTheta); ! Ng.set(u, v, vtmp); ! } } } |