Search in sources :

Example 11 with TransformGroup

use of javax.media.j3d.TransformGroup in project ffx by mjschnie.

the class RendererCache method sphereFactory.

/**
 * <p>
 * sphereFactory</p>
 *
 * @param ap a {@link javax.media.j3d.Appearance} object.
 * @param div a int.
 * @param transform3D a {@link javax.media.j3d.Transform3D} object.
 * @return a {@link javax.media.j3d.BranchGroup} object.
 */
public static final BranchGroup sphereFactory(Appearance ap, int div, Transform3D transform3D) {
    BranchGroup branchGroup;
    if (spherePool.size() > 0) {
        branchGroup = spherePool.remove(0);
        if (branchGroup != null) {
            TransformGroup transformGroup = (TransformGroup) branchGroup.getChild(0);
            transformGroup.setTransform(transform3D);
            Shape3D sphere = (Shape3D) transformGroup.getChild(0);
            sphere.setAppearance(ap);
            return branchGroup;
        }
    }
    branchGroup = new BranchGroup();
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    TransformGroup transformGroup = createTransformGroup(transform3D);
    Shape3D sphere = createSphere(ap, div);
    transformGroup.addChild(sphere);
    branchGroup.addChild(transformGroup);
    branchGroup.compile();
    return branchGroup;
}
Also used : BranchGroup(javax.media.j3d.BranchGroup) Shape3D(javax.media.j3d.Shape3D) TransformGroup(javax.media.j3d.TransformGroup)

Example 12 with TransformGroup

use of javax.media.j3d.TransformGroup in project ffx by mjschnie.

the class GraphicsEvents method systemRotate.

private boolean systemRotate() {
    TransformGroup tg = null;
    GraphicsCanvas.MouseMode mouseMode = graphics3D.getMouseMode();
    if ((mouseMode == GraphicsCanvas.MouseMode.SYSTEMBELOWMOUSE) && atom != null) {
        tg = (TransformGroup) pickResult.getNode(PickResult.TRANSFORM_GROUP);
    } else if (mouseMode == GraphicsCanvas.MouseMode.ACTIVESYSTEM) {
        if (mainPanel.getHierarchy().getActive() != null) {
            tg = mainPanel.getHierarchy().getActive().getTransformGroup();
        }
    }
    if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
        systemRotate.setTransformGroup(tg);
        postId(ROTATEPOST);
        return true;
    }
    return false;
}
Also used : TransformGroup(javax.media.j3d.TransformGroup)

Example 13 with TransformGroup

use of javax.media.j3d.TransformGroup in project ffx by mjschnie.

the class PickOrbitBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes. This is not meant to be called
     * by users. Behavior automatically calls this. You can call this only if
     * you know what you are doing.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if (mevent.isMetaDown() && !mevent.isAltDown()) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                orbit.setTransformGroup(tg);
                orbit.wakeup();
                currentTG = tg;
                if (callback != null) {
                    callback.transformClicked(PickingCallback.ORBIT, currentTG);
                }
            }
        } else if (callback != null) {
            callback.transformChanged(PickingCallback.NO_PICK, null);
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Example 14 with TransformGroup

use of javax.media.j3d.TransformGroup in project ffx by mjschnie.

the class PickPropertiesBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if (!mevent.isMetaDown() && !mevent.isAltDown()) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                drag.wakeup();
                currentTG = tg;
                if (callback != null && mevent.getClickCount() == 2) {
                    callback.transformDoubleClicked(PickingCallback.PROPERTIES, currentTG);
                }
            }
        } else if (callback != null) {
            callback.transformDoubleClicked(PickingCallback.NO_PICK, null);
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Example 15 with TransformGroup

use of javax.media.j3d.TransformGroup in project ffx by mjschnie.

the class GraphicsAxis method createAxis.

/**
 * <p>
 * createAxis</p>
 */
public void createAxis() {
    Appearance ap = new Appearance();
    Color3f col = new Color3f(Color.lightGray);
    Color3f black = new Color3f(Color.black);
    Color3f white = new Color3f(Color.white);
    Material mat = new Material(col, black, col, white, 50.0f);
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    // X-Axis
    Cone xcone = new Cone(2.0f, 3.0f, ap);
    xcone.setUserData(this);
    Transform3D xconeT3d = new Transform3D();
    xconeT3d.setTranslation(new Vector3d(10.0f, 0.0f, 0.0f));
    xconeT3d.setRotation(new AxisAngle4f(0.0f, 0.0f, 1.0f, (float) Math.PI / -2.0f));
    TransformGroup xconeTG = new TransformGroup(xconeT3d);
    xconeTG.addChild(xcone);
    Cylinder xcylinder = new Cylinder(1.0f, 9.0f, ap);
    xcylinder.setUserData(this);
    Transform3D xcyT3d = new Transform3D();
    xcyT3d.setTranslation(new Vector3d(4.5, 0.0, 0.0));
    xcyT3d.setRotation(new AxisAngle4f(0.0f, 0.0f, 1.0f, (float) Math.PI / 2.0f));
    TransformGroup xcyTG = new TransformGroup(xcyT3d);
    xcyTG.addChild(xcylinder);
    setCapabilities(xcone, xcylinder);
    addChild(xconeTG);
    addChild(xcyTG);
    // Y-Axis
    Cone ycone = new Cone(2.0f, 3.0f, ap);
    ycone.setUserData(this);
    Transform3D yconeT3d = new Transform3D();
    yconeT3d.setTranslation(new Vector3d(0.0f, 10.0f, 0.0f));
    TransformGroup yconeTG = new TransformGroup(yconeT3d);
    yconeTG.addChild(ycone);
    Cylinder ycylinder = new Cylinder(1.0f, 9.0f, ap);
    ycylinder.setUserData(this);
    Transform3D ycyT3d = new Transform3D();
    ycyT3d.setTranslation(new Vector3d(0.0, 4.5, 0.0));
    TransformGroup ycyTG = new TransformGroup(ycyT3d);
    ycyTG.addChild(ycylinder);
    setCapabilities(ycone, ycylinder);
    addChild(yconeTG);
    addChild(ycyTG);
    // Z-Axis
    Cone zcone = new Cone(2.0f, 3.0f, ap);
    zcone.setUserData(this);
    Transform3D zconeT3d = new Transform3D();
    zconeT3d.setTranslation(new Vector3d(0.0f, 0.0f, 10.0f));
    zconeT3d.setRotation(new AxisAngle4f(1.0f, 0.0f, 0.0f, (float) Math.PI / 2.0f));
    TransformGroup zconeTG = new TransformGroup(zconeT3d);
    zconeTG.addChild(zcone);
    Cylinder zcylinder = new Cylinder(1.0f, 9.0f, ap);
    zcylinder.setUserData(this);
    Transform3D zcyT3d = new Transform3D();
    zcyT3d.setTranslation(new Vector3d(0.0, 0.0, 4.5));
    zcyT3d.setRotation(new AxisAngle4f(1.0f, 0.0f, 0.0f, (float) Math.PI / 2.0f));
    TransformGroup zcyTG = new TransformGroup(zcyT3d);
    zcyTG.addChild(zcylinder);
    setCapabilities(zcone, zcylinder);
    addChild(zconeTG);
    addChild(zcyTG);
    Sphere sphere = new Sphere(1.0f, ap);
    if (!sphere.getShape().getGeometry(0).isCompiled() && !sphere.getShape().getGeometry(0).isLive()) {
        PickTool.setCapabilities(sphere.getShape(), PickTool.INTERSECT_COORD);
    }
    addChild(sphere);
    // Labels
    ap = new Appearance();
    col = new Color3f(Color.green);
    mat = new Material(col, black, col, white, 50.0f);
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    Font font = new Font("Arial", Font.PLAIN, 4);
    Font3D font3d = new Font3D(font, new FontExtrusion());
    addChild(createAxisLabel("X", font3d, ap, 11.0, 0.0, 0.0));
    addChild(createAxisLabel("Y", font3d, ap, 0.0, 11.0, 0.0));
    addChild(createAxisLabel("Z", font3d, ap, 0.0, 0.0, 11.0));
}
Also used : Cone(com.sun.j3d.utils.geometry.Cone) Font3D(javax.media.j3d.Font3D) Color3f(javax.vecmath.Color3f) Transform3D(javax.media.j3d.Transform3D) Material(javax.media.j3d.Material) Appearance(javax.media.j3d.Appearance) FontExtrusion(javax.media.j3d.FontExtrusion) Font(java.awt.Font) TransformGroup(javax.media.j3d.TransformGroup) Sphere(com.sun.j3d.utils.geometry.Sphere) Cylinder(com.sun.j3d.utils.geometry.Cylinder) Vector3d(javax.vecmath.Vector3d) AxisAngle4f(javax.vecmath.AxisAngle4f)

Aggregations

TransformGroup (javax.media.j3d.TransformGroup)16 Transform3D (javax.media.j3d.Transform3D)6 BranchGroup (javax.media.j3d.BranchGroup)5 Vector3d (javax.vecmath.Vector3d)5 PickResult (com.sun.j3d.utils.picking.PickResult)4 Shape3D (javax.media.j3d.Shape3D)4 MSNode (ffx.potential.bonded.MSNode)2 Color3f (javax.vecmath.Color3f)2 Cone (com.sun.j3d.utils.geometry.Cone)1 Cylinder (com.sun.j3d.utils.geometry.Cylinder)1 Sphere (com.sun.j3d.utils.geometry.Sphere)1 SimpleUniverse (com.sun.j3d.utils.universe.SimpleUniverse)1 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 MSGroup (ffx.potential.bonded.MSGroup)1 MSRoot (ffx.potential.bonded.MSRoot)1 ROLS (ffx.potential.bonded.ROLS)1 MergeFilter (ffx.potential.parsers.MergeFilter)1 Font (java.awt.Font)1 File (java.io.File)1