From: <ha...@us...> - 2009-07-21 18:30:01
|
Revision: 11278 http://jmol.svn.sourceforge.net/jmol/?rev=11278&view=rev Author: hansonr Date: 2009-07-21 18:29:59 +0000 (Tue, 21 Jul 2009) Log Message: ----------- VRML scaling perspective -- ALMOST! Modified Paths: -------------- trunk/Jmol/src/org/jmol/export/_Exporter.java trunk/Jmol/src/org/jmol/export/_VrmlExporter.java trunk/Jmol/src/org/jmol/export/_X3dExporter.java trunk/Jmol/src/org/jmol/viewer/Token.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/export/_Exporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_Exporter.java 2009-07-21 13:56:27 UTC (rev 11277) +++ trunk/Jmol/src/org/jmol/export/_Exporter.java 2009-07-21 18:29:59 UTC (rev 11278) @@ -226,6 +226,35 @@ final protected static float degreesPerRadian = (float) (360 / (2 * Math.PI)); + protected float getFieldOfView() { + float zoffset = (viewer.getCameraDepth()+ 0.5f); + float scale = viewer.getZoomPercentFloat() / 100f; + // I know multiplying by scale makes no sense. + float angle = scale * (float) (2 * Math.atan(0.5/scale / zoffset)); + return angle; + } + + final protected Point3f pt = new Point3f(); + + protected void getViewpointPosition(Point3f ptAtom) { + //float offsetx = 0.5f + viewer.getTranslationXPercent() / 100f; + //float offsety = 0.5f + viewer.getTranslationYPercent() / 100f; + float zoffset = (viewer.getCameraDepth()+ 0.5f); + float scalePixelsPerAngstrom = viewer.getScalePixelsPerAngstrom(false); + float rotationRadius = viewer.getRotationRadius(); + float scale = viewer.getZoomPercentFloat() / 100f; + //float offsetx = 0.5f + viewer.getTranslationXPercent() / 100f; + //float offsety = 0.5f + viewer.getTranslationYPercent() / 100f; + pt.set(screenWidth / 2, screenHeight / 2, 0); + viewer.unTransformPoint(pt, ptAtom); + float z0 = zoffset * 2 * rotationRadius * scalePixelsPerAngstrom / scale; + pt.set(screenWidth / 2, screenHeight / 2, z0); + viewer.unTransformPoint(pt, pt); + pt.sub(center); + ptAtom.sub(center); + ptAtom.add(pt); + } + protected Vector3f getRotation(Vector3f v) { tempV3.set(v); tempV3.normalize(); Modified: trunk/Jmol/src/org/jmol/export/_VrmlExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-07-21 13:56:27 UTC (rev 11277) +++ trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-07-21 18:29:59 UTC (rev 11278) @@ -44,6 +44,7 @@ import org.jmol.shape.Text; import org.jmol.util.Escape; import org.jmol.util.Quaternion; +import org.jmol.viewer.Token; import org.jmol.viewer.Viewer; public class _VrmlExporter extends _Exporter { @@ -93,6 +94,8 @@ return id; } + final private Point3f ptAtom = new Point3f(); + public void getHeader() { output("#VRML V2.0 utf8 Generated by Jmol " + Viewer.getJmolVersion() + "\n"); @@ -108,15 +111,29 @@ output("Background { skyColor " + rgbFractionalFromColix(viewer.getObjectColix(0), ' ') + " } \n"); // next is an approximation only - float offset = (-5.5f)*viewer.getBoundBoxCenter().z; - float scale = viewer.getZoomPercentFloat() / 100f; - output("Transform{translation 0 0 " + offset + " scale " + scale + " " + scale + " " + scale); - output(" children Transform{rotation "); + getViewpointPosition(ptAtom); + float angle = getFieldOfView(); viewer.getAxisAngle(viewpoint); - output(viewpoint.x + " " + viewpoint.y + " " + viewpoint.z + " " + viewpoint.angle); + output("Viewpoint{fieldOfView " + angle + + " position " + ptAtom.x + " " + ptAtom.y + " " + ptAtom.z + + " orientation " + viewpoint.x + " " + viewpoint.y + " " + (viewpoint.angle == 0 ? 1 : viewpoint.z) + " " + -viewpoint.angle); + output("\n jump TRUE description \"v1\"\n}\n"); + output("\n#Jmol perspective:\n"); + output("#scalePixelsPerAngstrom: " + viewer.getScalePixelsPerAngstrom(false) + "\n"); + output("#cameraDepth: " + viewer.getCameraDepth() + "\n"); + output("#center: " + center + "\n"); + output("#rotationRadius: " + viewer.getRotationRadius() + "\n"); + output("#boundboxCenter: " + viewer.getBoundBoxCenter() + "\n"); + output("#translationOffset: " + viewer.getTranslationScript() + "\n"); + output("#zoom: " + viewer.getZoomPercentFloat() + "\n"); + output("#moveto command: " + viewer.getOrientationText(Token.moveto) + "\n"); + output("#screen width height dim: " + screenWidth + " " + screenHeight + " " + viewer.getScreenDim() + "\n\n"); + output("Transform{");//scale " + scale + " " + scale + " " + scale); + //output(" children Transform{rotation "); + //viewer.getAxisAngle(viewpoint); + //output(viewpoint.x + " " + viewpoint.y + " " + viewpoint.z + " " + viewpoint.angle); output(" children Transform{translation "); - pt.set(screenWidth / 2, screenHeight / 2, viewer.getScreenDim() * 3.5f); - viewer.unTransformPoint(pt, ptAtom); + ptAtom.set(center); ptAtom.scale(-1); output(ptAtom); output("\nchildren [\n"); @@ -125,7 +142,7 @@ public void getFooter() { htDefs = null; output("\n]\n"); - output("}}}\n"); + output("}}\n"); } private void outputAppearance(short colix, boolean isText) { @@ -440,9 +457,6 @@ output("}\n"); } - final private Point3f pt = new Point3f(); - final private Point3f ptAtom = new Point3f(); - public void plotText(int x, int y, int z, short colix, String text, Font3D font3d) { if (z < 3) { viewer.transformPoint(center, pt); Modified: trunk/Jmol/src/org/jmol/export/_X3dExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_X3dExporter.java 2009-07-21 13:56:27 UTC (rev 11277) +++ trunk/Jmol/src/org/jmol/export/_X3dExporter.java 2009-07-21 18:29:59 UTC (rev 11278) @@ -479,7 +479,6 @@ output("\n</Shape>\n"); } - final private Point3f pt = new Point3f(); final private Point3f ptAtom = new Point3f(); public void plotText(int x, int y, int z, short colix, String text, Font3D font3d) { Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2009-07-21 13:56:27 UTC (rev 11277) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2009-07-21 18:29:59 UTC (rev 11278) @@ -292,7 +292,7 @@ //final static int model see mathfunc final static int monitor = command | 35 | setparam | expression | defaultON; final static int move = command | 36; - final static int moveto = command | 37; + public final static int moveto = command | 37; final static int navigate = command | 38; final static int pmesh = command | 39; final static int polyhedra = command | 40; Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-07-21 13:56:27 UTC (rev 11277) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2009-07-21 18:29:59 UTC (rev 11278) @@ -939,11 +939,11 @@ refresh(1, "Viewer:translate()"); } - float getTranslationXPercent() { + public float getTranslationXPercent() { return transformManager.getTranslationXPercent(); } - float getTranslationYPercent() { + public float getTranslationYPercent() { return transformManager.getTranslationYPercent(); } @@ -951,7 +951,7 @@ return transformManager.getTranslationZPercent(); } - String getTranslationScript() { + public String getTranslationScript() { return transformManager.getTranslationScript(); } @@ -1162,7 +1162,7 @@ transformManager.setNavXYZ((int)x, (int)y, (int)z); } - String getOrientationText(int type) { + public String getOrientationText(int type) { return transformManager.getOrientationText(type); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |