From: <edi...@us...> - 2003-08-13 03:59:41
|
Update of /cvsroot/jrman/drafts/src/org/jrman/primitive In directory sc8-pr-cvs1:/tmp/cvs-serv16176/src/org/jrman/primitive Modified Files: Hyperboloid.java Log Message: Fixed Hyperboloid Normals and Bounding Box Index: Hyperboloid.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/primitive/Hyperboloid.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Hyperboloid.java 5 Aug 2003 23:52:18 -0000 1.5 --- Hyperboloid.java 13 Aug 2003 03:59:38 -0000 1.6 *************** *** 38,41 **** --- 38,49 ---- private static Vector3f vtmp = new Vector3f(); + + private static Point3f p1 = new Point3f(); + + private static Point3f p2 = new Point3f(); + + private static Vector3f v1 = new Vector3f(); + + private static Vector3f v2 = new Vector3f(); private float x1; *************** *** 55,64 **** private float thetaMax; - private float maxTheta; - - private float maxZ1; - - private float maxZ2; - public Hyperboloid( float x1, --- 63,66 ---- *************** *** 70,76 **** float thetaMin, float thetaMax, - float maxTheta, - float maxZ1, - float maxZ2, Map parameters, Attributes attributes) { --- 72,75 ---- *************** *** 84,119 **** this.thetaMin = thetaMin; this.thetaMax = thetaMax; - this.maxTheta = maxTheta; - this.maxZ1 = maxZ1; - this.maxZ2 = maxZ2; } 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]; --- 83,104 ---- this.thetaMin = thetaMin; this.thetaMax = thetaMax; } 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 gamma1Min = (float) Math.atan2(y1Min, x1Min); if (gamma1Min < 0) ! gamma1Min += (float) Math.PI * 2f; float gamma1Max = gamma1Min + (thetaMax - thetaMin); float r1 = (float) Math.sqrt((x1 * x1) + (y1 * y1)); ! float[] values1 = analizeAngleCase(r1, gamma1Min, gamma1Max); float x11Min = values1[0]; float x11Max = values1[1]; *************** *** 121,145 **** 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]; --- 106,119 ---- float y11Max = values1[3]; ! float x2Min = x2 * cosTMin - y2 * sinTMin; ! float y2Min = x2 * sinTMin + y2 * cosTMin; ! float gamma2Min = (float) Math.atan2(y2Min, x2Min); if (gamma2Min < 0) ! gamma2Min += (float) Math.PI * 2f; float gamma2Max = gamma2Min + (thetaMax - thetaMin); float r2 = (float) Math.sqrt((x2 * x2) + (y2 * y2)); ! float[] values2 = analizeAngleCase(r2, gamma2Min, gamma2Max); float x22Min = values2[0]; float x22Max = values2[1]; *************** *** 155,186 **** 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]; --- 129,140 ---- Bounds3f b3f = new Bounds3f(xMin, xMax, yMin, yMax, zMin, zMax); return b3f; } private boolean passAngle(float angle, float minAngle, float maxAngle) { ! return minAngle < angle && angle < maxAngle; } ! private float[] analizeAngleCase(float r, float gammaMin, float gammaMax) { float[] values = new float[4]; *************** *** 189,378 **** 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( --- 143,194 ---- float cosGammaMax = (float) Math.cos(gammaMax); float sinGammaMax = (float) Math.sin(gammaMax); ! float xMin = Math.min(r * cosGammaMin, r * cosGammaMax); ! float xMax = Math.max(r * cosGammaMin, r * cosGammaMax); ! float yMin = Math.min(r * sinGammaMin, r * sinGammaMax); ! float yMax = Math.max(r * sinGammaMin, r * sinGammaMax); ! if (passAngle((float) Math.PI / 2f, gammaMin, gammaMax) ! || passAngle( ! (float) Math.PI / 2f + (float) Math.PI * 2f, ! gammaMin, ! gammaMax)) { yMax = r; } ! if (passAngle((float) Math.PI, gammaMin, gammaMax) ! || passAngle( ! (float) Math.PI + (float) Math.PI * 2f, ! gammaMin, ! gammaMax)) { xMin = -r; } ! if (passAngle((float) Math.PI * 3f / 2f, gammaMin, gammaMax) ! || passAngle( ! (float) Math.PI * 3f / 2f + (float) Math.PI * 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; ! } 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( *************** *** 385,409 **** thetaMin, (thetaMin + thetaMax) / 2f, - maxTheta, - maxZ1, - maxZ2, 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( --- 201,219 ---- thetaMin, (thetaMin + thetaMax) / 2f, linearInterpolateParameters(0f, .5f, 0f, 1f), attributes); ! result[1] = ! new Hyperboloid( ! x1, ! y1, ! z1, ! x2, ! y2, ! z2, ! (thetaMin + thetaMax) / 2f, ! thetaMax, ! linearInterpolateParameters(.5f, 1f, 0f, 1f), ! attributes); ! } else { result[0] = new Hyperboloid( *************** *** 416,466 **** thetaMin, thetaMax, - maxTheta, - 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); ! } } } --- 226,269 ---- thetaMin, thetaMax, linearInterpolateParameters(0f, 1f, 0f, .5f), attributes); ! result[1] = ! new Hyperboloid( ! (x1 + x2) / 2f, ! (y1 + y2) / 2f, ! (z1 + z2) / 2f, ! x2, ! y2, ! z2, ! thetaMin, ! thetaMax, ! 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 vDelta = 1f / (vSize - 1); ! Point3fGrid P = shaderVariables.P; ! float theta = thetaMin; ! for (int u = 0; u < uSize; u++) { ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! float nv = 0f; ! for (int v = 0; v < vSize; v++) { ! 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); ! nv += vDelta; ! } ! theta += thetaDelta; } } *************** *** 468,497 **** 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); ! } } } --- 271,296 ---- protected void dice_Ng(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); ! int vSize = Grid.getVSize(); ! float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); ! Vector3fGrid Ng = shaderVariables.Ng; ! for (int u = 0; u < uSize; u++) { float theta = thetaMin + thetaDelta * u; ! float cosTheta = (float) Math.cos(theta); ! float sinTheta = (float) Math.sin(theta); ! float x11 = x1 * cosTheta - y1 * sinTheta; ! float x22 = x2 * cosTheta - y2 * sinTheta; ! float y11 = x1 * sinTheta + y1 * cosTheta; ! float y22 = x2 * sinTheta + y2 * cosTheta; ! p1.set(x11, y11, z1); ! p2.set(x22, y22, z2); ! v1.sub(p1, p2); ! for (int v = 0; v < vSize; v++) { float nv = (float) v / (vSize - 1); ! float xi = (1f - nv) * x11 + nv * x22; ! float yi = (1f - nv) * y11 + nv * y22; ! v2.set(-yi, xi, 0f); ! vtmp.cross(v1, v2); ! Ng.set(u, v, vtmp); ! } } } |