Example usage for javax.media.j3d WakeupOnAWTEvent WakeupOnAWTEvent

List of usage examples for javax.media.j3d WakeupOnAWTEvent WakeupOnAWTEvent

Introduction

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

Prototype

public WakeupOnAWTEvent(long eventMask) 

Source Link

Document

Constructs a new WakeupOnAWTEvent using Ored EVENT_MASK values.

Usage

From source file:SimpleMorph2.java

/** Set up the criteria to trigger after zero time or when a key is pressed */
public void initialize() {
    wakeConditions = new WakeupCriterion[2];
    wakeConditions[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    wakeConditions[1] = new WakeupOnElapsedFrames(0);
    oredConditions = new WakeupOr(wakeConditions);
    wakeupOn(wakeConditions[0]);/*w  ww  .  j a  v a2  s .c om*/
}

From source file:AvatarTest.java

public CarSteering(TransformGroup tg) {
    m_TransformGroup = tg;//w ww  . j  a v a 2s  .  c  o m

    try {
        m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    } catch (Exception e) {
    }

    wakeupOne = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    wakeupArray[0] = wakeupOne;
    wakeupCondition = new WakeupOr(wakeupArray);
}

From source file:SimpleGame.java

/**
 * This sets up the criteria for triggering the behaviour. We simple want to
 * wait for a key to be pressed.//from   w  w  w .ja  v  a  2  s . c om
 */
public void initialize() {
    theCriterion = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    wakeupOn(theCriterion);
}

From source file:IntersectTest.java

public void initialize() {
    wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

From source file:IntersectTest.java

public void processStimulus(Enumeration criteria) {
    WakeupCriterion wakeup;/*  w w w  .  ja v  a2  s .  c om*/
    AWTEvent[] event;
    int eventId;

    while (criteria.hasMoreElements()) {
        wakeup = (WakeupCriterion) criteria.nextElement();
        if (wakeup instanceof WakeupOnAWTEvent) {
            event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
            for (int i = 0; i < event.length; i++) {
                eventId = event[i].getID();
                if (eventId == MouseEvent.MOUSE_PRESSED) {
                    int x = ((MouseEvent) event[i]).getX();
                    int y = ((MouseEvent) event[i]).getY();
                    pickCanvas.setShapeLocation(x, y);

                    Point3d eyePos = pickCanvas.getStartPosition();
                    pickResult = pickCanvas.pickAllSorted();
                    // Use this to do picking benchmarks
                    /*
                     * long start = System.currentTimeMillis(); for (int
                     * l=0;l <3;l++) { if (l == 0) System.out.print
                     * ("BOUNDS: "); if (l == 1) System.out.print
                     * ("GEOMETRY: "); if (l == 2) System.out.print
                     * ("GEOMETRY_INTERSECT_INFO: ");
                     * 
                     * for (int k=0;k <1000;k++) { if (l == 0) {
                     * pickCanvas.setMode(PickTool.BOUNDS); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 1) {
                     * pickCanvas.setMode(PickTool.GEOMETRY); pickResult =
                     * pickCanvas.pickAllSorted(); } if (l == 2) {
                     * pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
                     * pickResult = pickCanvas.pickAllSorted(); } } long
                     * delta = System.currentTimeMillis() - start;
                     * System.out.println ("\t"+delta+" ms / 1000 picks"); }
                     */
                    if (pickResult != null) {

                        // Get closest intersection results
                        PickIntersection pi = pickResult[0].getClosestIntersection(eyePos);

                        GeometryArray curGeomArray = pi.getGeometryArray();

                        // Position sphere at intersection point
                        Vector3d v = new Vector3d();
                        Point3d intPt = pi.getPointCoordinatesVW();
                        v.set(intPt);
                        spht3.setTranslation(v);
                        sphTrans[0].setTransform(spht3);

                        // Position sphere at closest vertex
                        Point3d closestVert = pi.getClosestVertexCoordinatesVW();
                        v.set(closestVert);
                        spht3.setTranslation(v);
                        sphTrans[1].setTransform(spht3);

                        Point3d[] ptw = pi.getPrimitiveCoordinatesVW();
                        Point3d[] pt = pi.getPrimitiveCoordinates();
                        int[] coordidx = pi.getPrimitiveCoordinateIndices();
                        Point3d ptcoord = new Point3d();
                        for (int k = 0; k < pt.length; k++) {
                            v.set(ptw[k]);
                            spht3.setTranslation(v);
                            sphTrans[k + 2].setTransform(spht3);
                        }

                        // Get interpolated color (if available)
                        Color4f iColor4 = null;
                        Color3f iColor = null;
                        Vector3f iNormal = null;

                        if (curGeomArray != null) {
                            int vf = curGeomArray.getVertexFormat();

                            if (((vf & (GeometryArray.COLOR_3 | GeometryArray.COLOR_4)) != 0)
                                    && (null != (iColor4 = pi.getPointColor()))) {
                                iColor = new Color3f(iColor4.x, iColor4.y, iColor4.z);

                                // Change the point's color
                                redlook.setMaterial(new Material(iColor, new Color3f(0.0f, 0.0f, 0.0f), iColor,
                                        new Color3f(1.0f, 1.0f, 1.0f), 50.0f));
                            }
                            if (((vf & GeometryArray.NORMALS) != 0)
                                    && (null != (iNormal = pi.getPointNormal()))) {
                                System.out.println("Interpolated normal: " + iNormal);
                            }
                        }

                        System.out.println("=============");
                        System.out.println("Coordinates of intersection pt:" + intPt);
                        System.out.println("Coordinates of vertices: ");
                        for (int k = 0; k < pt.length; k++) {
                            System.out.println(k + ":" + ptw[k].x + " " + ptw[k].y + " " + ptw[k].z);
                        }
                        System.out.println("Closest vertex: " + closestVert);
                        if (iColor != null) {
                            System.out.println("Interpolated color: " + iColor);
                        }
                        if (iNormal != null) {
                            System.out.println("Interpolated normal: " + iNormal);
                        }
                    }
                }
            }
        }
    }
    wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
}

From source file:BehaviorTest.java

public StretchBehavior(GeometryArray geomArray) {
    // save the GeometryArray that we are modifying
    m_GeometryArray = geomArray;/*from   w w w  .  ja  v a 2s  .c  om*/

    // set the capability bits that the behavior requires
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);

    // allocate an array for the model coordinates
    m_CoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];

    // retrieve the models original coordinates - this defines
    // the relaxed length of the springs
    m_GeometryArray.getCoordinates(0, m_CoordinateArray);

    // allocate an array to store the relaxed length
    // of the springs from the origin to every vertex
    m_LengthArray = new float[m_GeometryArray.getVertexCount()];

    // allocate an array to store the mass of every vertex
    m_MassArray = new float[m_GeometryArray.getVertexCount()];

    // allocate an array to store the acceleration of every vertex
    m_AccelerationArray = new float[m_GeometryArray.getVertexCount()];

    // allocate a temporary vector
    m_Vector = new Vector3f();

    float x = 0;
    float y = 0;
    float z = 0;

    for (int n = 0; n < m_CoordinateArray.length; n += 3) {
        // calculate and store the relaxed spring length
        x = m_CoordinateArray[n];
        y = m_CoordinateArray[n + 1];
        z = m_CoordinateArray[n + 2];

        m_LengthArray[n / 3] = (x * x) + (y * y) + (z * z);

        // assign the mass for the vertex
        m_MassArray[n / 3] = (float) (50 + (5 * Math.random()));
    }

    // create the WakeupCriterion for the behavior
    WakeupCriterion criterionArray[] = new WakeupCriterion[2];
    criterionArray[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    criterionArray[1] = new WakeupOnElapsedFrames(1);

    // save the WakeupCriterion for the behavior
    m_WakeupCondition = new WakeupOr(criterionArray);
}

From source file:MouseNavigateTest.java

/**
 * Registers which AWT events are of interest to the behaviour
 *///w ww  .j  av  a2  s.com
//*****************************************************************************
public void initialize() {
    WakeupCriterion[] mouseEvents = new WakeupCriterion[3];

    mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);

    m_MouseCriterion = new WakeupOr(mouseEvents);
    wakeupOn(m_MouseCriterion);
}

From source file:KeyNavigateTest.java

public void initialize() {
    WakeupCriterion[] keyEvents = new WakeupCriterion[2];
    keyEvents[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    keyEvents[1] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
    keyCriterion = new WakeupOr(keyEvents);

    wakeupOn(keyCriterion);/*from   w  w w . j av  a  2 s.  c o  m*/
}

From source file:ExText.java

/**
 * Initializes the behavior.//from   w  ww . j  a v a 2 s. c om
 */
public void initialize() {
    super.initialize();
    savedMouseCriterion = mouseCriterion; // from parent class
    mouseAndAnimationEvents = new WakeupCriterion[4];
    mouseAndAnimationEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseAndAnimationEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseAndAnimationEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    mouseAndAnimationEvents[3] = new WakeupOnElapsedFrames(0);
    mouseAndAnimationCriterion = new WakeupOr(mouseAndAnimationEvents);
    // Don't use the above criterion until a button 1 down event
}

From source file:ExText.java

/**
 * Initialize the behavior./*from   w w w . ja v  a  2 s .co m*/
 */
public void initialize() {
    // Wakeup when the mouse is dragged or when a mouse button
    // is pressed or released.
    mouseEvents = new WakeupCriterion[3];
    mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
    mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
    mouseEvents[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
    mouseCriterion = new WakeupOr(mouseEvents);
    wakeupOn(mouseCriterion);
}