From: <ha...@us...> - 2009-12-24 21:52:13
|
Revision: 12001 http://jmol.svn.sourceforge.net/jmol/?rev=12001&view=rev Author: hansonr Date: 2009-12-24 21:52:05 +0000 (Thu, 24 Dec 2009) Log Message: ----------- version=11.9.13_dev # code: refactoring lighting Modified Paths: -------------- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/g3d/Shade3D.java trunk/Jmol/src/org/jmol/viewer/ColorManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2009-12-24 21:33:15 UTC (rev 12000) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2009-12-24 21:52:05 UTC (rev 12001) @@ -2297,7 +2297,7 @@ * shading and lighting * ***************************************************************/ - public static void flushShadesAndSphereCaches() { + private static void flushCaches() { Colix3D.flushShades(); Sphere3D.flushSphereCache(); } @@ -2305,64 +2305,91 @@ final static float[] lighting = Shade3D.lighting; public synchronized static void setSpecular(boolean specular) { - lighting[Shade3D.SPECULAR_ON] = (specular ? 1f : 0f); + float val = (specular ? 1f : 0f); + if (lighting[Shade3D.SPECULAR_ON] == val) + return; + lighting[Shade3D.SPECULAR_ON] = val; + flushCaches(); } public static boolean getSpecular() { return (lighting[Shade3D.SPECULAR_ON] != 0); } - public synchronized static void setSpecularPower(int specularPower) { - lighting[Shade3D.SPECULAR_POWER] = specularPower; - lighting[Shade3D.INTENSE_FRACTION] = specularPower / 100f; + public synchronized static void setSpecularPower(int val) { + if (val < 0) { + setSpecularExponent(-val); + return; + } + if (lighting[Shade3D.SPECULAR_POWER] == val) + return; + lighting[Shade3D.SPECULAR_POWER] = val; + lighting[Shade3D.INTENSE_FRACTION] = val / 100f; + flushCaches(); } public static int getSpecularPower() { return (int) lighting[Shade3D.SPECULAR_POWER]; } - public synchronized static void setSpecularPercent(int specularPercent) { - lighting[Shade3D.SPECULAR_PERCENT]= specularPercent; - lighting[Shade3D.SPECULAR_FRACTION] = specularPercent / 100f; + public synchronized static void setSpecularPercent(int val) { + if (lighting[Shade3D.SPECULAR_PERCENT] == val) + return; + lighting[Shade3D.SPECULAR_PERCENT]= val; + lighting[Shade3D.SPECULAR_FRACTION] = val / 100f; + flushCaches(); } public static int getSpecularPercent() { return (int) lighting[Shade3D.SPECULAR_PERCENT]; } - public synchronized static void setSpecularExponent(int specularExponent) { - lighting[Shade3D.SPECULAR_EXPONENT] = specularExponent; - lighting[Shade3D.PHONG_EXPONENT] = (int) Math.pow(2, specularExponent); + public synchronized static void setSpecularExponent(int val) { + if (lighting[Shade3D.SPECULAR_EXPONENT] == val) + return; + lighting[Shade3D.SPECULAR_EXPONENT] = val; + lighting[Shade3D.PHONG_EXPONENT] = (int) Math.pow(2, val); lighting[Shade3D.USE_PHONG] = 0; + flushCaches(); } public static int getSpecularExponent() { return (int) lighting[Shade3D.SPECULAR_EXPONENT]; } - public static void setPhongExponent(int phongExponent) { - lighting[Shade3D.PHONG_EXPONENT] = phongExponent; - float x = (float) (Math.log(phongExponent) / Math.log(2)); + public static void setPhongExponent(int val) { + if (lighting[Shade3D.PHONG_EXPONENT] == val + && lighting[Shade3D.USE_PHONG] != 0) + return; + lighting[Shade3D.PHONG_EXPONENT] = val; + float x = (float) (Math.log(val) / Math.log(2)); boolean usePhong = (x != (int) x); lighting[Shade3D.USE_PHONG] = (usePhong ? 1 : 0); + flushCaches(); } public static int getPhongExponent() { return (int) lighting[Shade3D.PHONG_EXPONENT]; } - public synchronized static void setDiffusePercent(int diffusePercent) { - lighting[Shade3D.DIFFUSE_PERCENT]= diffusePercent; - lighting[Shade3D.DIFFUSE_FRACTION]= diffusePercent / 100f; + public synchronized static void setDiffusePercent(int val) { + if (lighting[Shade3D.DIFFUSE_PERCENT] == val) + return; + lighting[Shade3D.DIFFUSE_PERCENT]= val; + lighting[Shade3D.DIFFUSE_FRACTION]= val / 100f; + flushCaches(); } public static int getDiffusePercent() { return (int) lighting[Shade3D.DIFFUSE_PERCENT]; } - public synchronized static void setAmbientPercent(int ambientPercent) { - lighting[Shade3D.AMBIENT_PERCENT] = ambientPercent; - lighting[Shade3D.AMBIENT_FRACTION] = ambientPercent / 100f; + public synchronized static void setAmbientPercent(int val) { + if (lighting[Shade3D.AMBIENT_PERCENT] == val) + return; + lighting[Shade3D.AMBIENT_PERCENT] = val; + lighting[Shade3D.AMBIENT_FRACTION] = val / 100f; + flushCaches(); } public static int getAmbientPercent() { @@ -2373,12 +2400,6 @@ return new Point3f(Shade3D.xLight, Shade3D.yLight, Shade3D.zLight); } - /* - public void setLightsourceZ(float dist) { - Shade3D.setLightsourceZ(dist); - } - */ - private final Vector3f vectorAB = new Vector3f(); private final Vector3f vectorAC = new Vector3f(); private final Vector3f vectorNormal = new Vector3f(); Modified: trunk/Jmol/src/org/jmol/g3d/Shade3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2009-12-24 21:33:15 UTC (rev 12000) +++ trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2009-12-24 21:52:05 UTC (rev 12001) @@ -360,15 +360,4 @@ return t >> 23; } - /* - static void setLightsourceZ(float z) { - zLightsource = z; - magnitudeLight = - (float)Math.sqrt(xLightsource * xLightsource + - yLightsource * yLightsource + - zLightsource * zLightsource); - //dump(); - } -*/ - } Modified: trunk/Jmol/src/org/jmol/viewer/ColorManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2009-12-24 21:33:15 UTC (rev 12000) +++ trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2009-12-24 21:52:05 UTC (rev 12001) @@ -333,95 +333,4 @@ :ColorEncoder.getColorIndexFromPalette(-val, -colorLo, -colorHi, palette)); } - /* - void flushCachedColors() { - } - */ - - private static void flushCaches() { - Graphics3D.flushShadesAndSphereCaches(); - } - - static void setSpecular(boolean specular) { - if (Graphics3D.getSpecular() == specular) - return; - Graphics3D.setSpecular(specular); - flushCaches(); - } - - static boolean getSpecular() { - return Graphics3D.getSpecular(); - } - - static void setSpecularPercent(int specularPercent) { - if (Graphics3D.getSpecularPercent() == specularPercent) - return; - Graphics3D.setSpecularPercent(specularPercent); - flushCaches(); - } - - static int getSpecularPercent() { - return Graphics3D.getSpecularPercent(); - } - - static void setSpecularExponent(int specularExponent) { - if (Graphics3D.getSpecularExponent() == specularExponent) - return; - Graphics3D.setSpecularExponent(specularExponent); - flushCaches(); - } - - static void setSpecularPower(int specularPower) { - if (specularPower < 0) { - if (Graphics3D.getSpecularExponent() == -specularPower) - return; - Graphics3D.setSpecularExponent(-specularPower); - } else { - if (Graphics3D.getSpecularPower() == specularPower) - return; - Graphics3D.setSpecularPower(specularPower); - } - flushCaches(); - } - - static void setDiffusePercent(int diffusePercent) { - if (Graphics3D.getDiffusePercent() == diffusePercent) - return; - Graphics3D.setDiffusePercent(diffusePercent); - flushCaches(); - } - - static int getDiffusePercent() { - return Graphics3D.getDiffusePercent(); - } - - static void setAmbientPercent(int ambientPercent) { - if (Graphics3D.getAmbientPercent() == ambientPercent) - return; - Graphics3D.setAmbientPercent(ambientPercent); - flushCaches(); - } - - static int getAmbientPercent() { - return Graphics3D.getAmbientPercent(); - } - - static void setPhongExponent(int phongExponent) { - if (Graphics3D.getPhongExponent() == phongExponent) - return; - Graphics3D.setPhongExponent(phongExponent); - flushCaches(); - } - - static int getPhongExponent() { - return Graphics3D.getPhongExponent(); - } - - /* - void setLightsourceZ(float dist) { - Graphics3D.setLightsourceZ(dist); - flushCaches(); - } - */ - } Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-12-24 21:33:15 UTC (rev 12000) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-12-24 21:52:05 UTC (rev 12001) @@ -553,7 +553,7 @@ * final Hashtable imageCache = new Hashtable(); * * void flushCachedImages() { imageCache.clear(); - * colorManager.flushCachedColors(); } + * Graphics3D.flushCachedColors(); } */ Hashtable getAppletInfo() { @@ -595,13 +595,13 @@ // transfer default global settings to managers and g3d - ColorManager.setAmbientPercent(global.ambientPercent); - ColorManager.setDiffusePercent(global.diffusePercent); - ColorManager.setSpecular(global.specular); - ColorManager.setSpecularPercent(global.specularPercent); - ColorManager.setSpecularPower(-global.specularExponent); - ColorManager.setPhongExponent(global.phongExponent); - ColorManager.setSpecularPower(global.specularPower); + Graphics3D.setAmbientPercent(global.ambientPercent); + Graphics3D.setDiffusePercent(global.diffusePercent); + Graphics3D.setSpecular(global.specular); + Graphics3D.setSpecularPercent(global.specularPercent); + Graphics3D.setSpecularPower(-global.specularExponent); + Graphics3D.setPhongExponent(global.phongExponent); + Graphics3D.setSpecularPower(global.specularPower); if (modelSet != null) animationManager.setAnimationOn(false); @@ -5218,7 +5218,7 @@ // 11.9.13 if (key.equalsIgnoreCase("phongExponent")) { - ColorManager.setPhongExponent(value); + Graphics3D.setPhongExponent(value); break; } @@ -5306,11 +5306,11 @@ break; } if (key.equalsIgnoreCase("specularPower")) { - ColorManager.setSpecularPower(value); + Graphics3D.setSpecularPower(value); break; } if (key.equalsIgnoreCase("specularExponent")) { - ColorManager.setSpecularPower(-value); + Graphics3D.setSpecularPower(-value); break; } if (key.equalsIgnoreCase("specular")) { @@ -5326,15 +5326,15 @@ return; } if (key.equalsIgnoreCase("specularPercent")) { - ColorManager.setSpecularPercent(value); + Graphics3D.setSpecularPercent(value); break; } if (key.equalsIgnoreCase("diffusePercent")) { - ColorManager.setDiffusePercent(value); + Graphics3D.setDiffusePercent(value); break; } if (key.equalsIgnoreCase("ambientPercent")) { - ColorManager.setAmbientPercent(value); + Graphics3D.setAmbientPercent(value); break; } @@ -5671,7 +5671,7 @@ break; } if (key.equalsIgnoreCase("specular")) { - ColorManager.setSpecular(value); + Graphics3D.setSpecular(value); break; } if (key.equalsIgnoreCase("slabEnabled")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |