Example usage for javax.media.j3d Node getUserData

List of usage examples for javax.media.j3d Node getUserData

Introduction

In this page you can find the example usage for javax.media.j3d Node getUserData.

Prototype

public Object getUserData() 

Source Link

Document

Retrieves the userData field from this scene graph object.

Usage

From source file:SimpleCollision.java

/**
 * Where the work is done in this class. A message is printed out using the
 * userData of the object collided with. The wake up condition is then set
 * to the OR'ed criterion again.//  ww  w  . j  av a 2 s. c  om
 */
public void processStimulus(Enumeration criteria) {
    WakeupCriterion theCriterion = (WakeupCriterion) criteria.nextElement();
    if (theCriterion instanceof WakeupOnCollisionEntry) {
        Node theLeaf = ((WakeupOnCollisionEntry) theCriterion).getTriggeringPath().getObject();
        System.out.println("Collided with " + theLeaf.getUserData());
    } else if (theCriterion instanceof WakeupOnCollisionExit) {
        Node theLeaf = ((WakeupOnCollisionExit) theCriterion).getTriggeringPath().getObject();
        System.out.println("Stopped colliding with  " + theLeaf.getUserData());
    } else {
        Node theLeaf = ((WakeupOnCollisionMovement) theCriterion).getTriggeringPath().getObject();
        System.out.println("Moved whilst colliding with " + theLeaf.getUserData());
    }
    wakeupOn(oredCriteria);
}

From source file:VrmlPickingTest.java

public void mouseClicked(MouseEvent e) {
    System.out.println("*** MouseClick ***");

    pickCanvas.setShapeLocation(e);/*  w w w.j a  va 2s.c  o  m*/
    PickResult[] results = pickCanvas.pickAllSorted();

    if (results != null) {
        for (int n = 0; n < results.length; n++) {
            PickResult pickResult = results[n];

            System.out.println("Sorted PickResult " + n + ": " + pickResult);

            Node actualNode = pickResult.getObject();

            if (actualNode.getUserData() != null) {
                System.out.println("Sorted Object " + n + ": " + actualNode.getUserData());
            }
        }
    }

    PickResult pickResult = pickCanvas.pickClosest();

    if (pickResult != null) {
        System.out.println("Closest PickResult: " + pickResult);

        Node actualNode = pickResult.getObject();

        if (actualNode.getUserData() != null) {
            System.out.println("Closest Object: " + actualNode.getUserData());
        }
    }

}

From source file:FourByFour.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;//from  w w w.  j a  v  a 2 s.c  o m
    AWTEvent[] event;
    int id;
    int dx, dy;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                id = event[i].getID();
                if (id == MouseEvent.MOUSE_DRAGGED) {

                    x = ((MouseEvent) event[i]).getX();
                    y = ((MouseEvent) event[i]).getY();

                    dx = x - x_last;
                    dy = y - y_last;

                    x_angle = dy * y_factor;
                    y_angle = dx * x_factor;

                    transformX.rotX(x_angle);
                    transformY.rotY(y_angle);

                    modelTrans.mul(transformX, modelTrans);
                    modelTrans.mul(transformY, modelTrans);

                    transformGroup.setTransform(modelTrans);

                    x_last = x;
                    y_last = y;
                } else if (id == MouseEvent.MOUSE_PRESSED) {

                    x = x_last = ((MouseEvent) event[i]).getX();
                    y = y_last = ((MouseEvent) event[i]).getY();

                    Point3d eyePos = new Point3d();
                    canvas3D.getCenterEyeInImagePlate(eyePos);

                    Point3d mousePos = new Point3d();
                    canvas3D.getPixelLocationInImagePlate(x, y, mousePos);

                    Transform3D transform3D = new Transform3D();
                    canvas3D.getImagePlateToVworld(transform3D);

                    transform3D.transform(eyePos);
                    transform3D.transform(mousePos);

                    Vector3d mouseVec;
                    if (parallel) {
                        mouseVec = new Vector3d(0.f, 0.f, -1.f);
                    } else {
                        mouseVec = new Vector3d();
                        mouseVec.sub(mousePos, eyePos);
                        mouseVec.normalize();
                    }

                    pickRay.set(mousePos, mouseVec);
                    sceneGraphPath = branchGroup.pickAllSorted(pickRay);

                    if (sceneGraphPath != null) {
                        for (int j = 0; j < sceneGraphPath.length; j++) {
                            if (sceneGraphPath[j] != null) {
                                Node node = sceneGraphPath[j].getObject();
                                if (node instanceof Shape3D) {
                                    try {
                                        ID posID = (ID) node.getUserData();
                                        if (posID != null) {
                                            int pos = posID.get();
                                            positions.set(pos, Positions.HUMAN);
                                            canvas2D.repaint();
                                            break;
                                        }
                                    } catch (CapabilityNotSetException e) {
                                        // Catch all CapabilityNotSet
                                        // exceptions and
                                        // throw them away, prevents
                                        // renderer from
                                        // locking up when encountering
                                        // "non-selectable"
                                        // objects.
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    wakeupOn(mouseCriterion);
}