Example usage for javax.media.j3d GeometryArray ALLOW_COORDINATE_READ

List of usage examples for javax.media.j3d GeometryArray ALLOW_COORDINATE_READ

Introduction

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

Prototype

int ALLOW_COORDINATE_READ

To view the source code for javax.media.j3d GeometryArray ALLOW_COORDINATE_READ.

Click Source Link

Document

Specifies that this GeometryArray allows reading the array of coordinates.

Usage

From source file:BehaviorTest.java

public WakeupCondition restart(Shape3D shape3D, int nElapsedTime, int nNumFrames, ExplosionListener listener) {
    System.out.println("Will explode after: " + nElapsedTime / 1000 + " secs.");

    m_Shape3D = shape3D;/*from   w ww . j a  va2  s.  c o  m*/
    m_nElapsedTime = nElapsedTime;
    m_nNumFrames = nNumFrames;
    m_nFrameNumber = 0;

    // create the WakeupCriterion for the behavior
    m_InitialWakeupCondition = new WakeupOnElapsedTime(m_nElapsedTime);

    m_Listener = listener;

    // save the GeometryArray that we are modifying
    m_GeometryArray = (GeometryArray) m_Shape3D.getGeometry();

    if (m_Shape3D.isLive() == false && m_Shape3D.isCompiled() == false) {
        // set the capability bits that the behavior requires
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_WRITE);

        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);
    }

    // make a copy of the object's original appearance
    m_Appearance = new Appearance();
    m_Appearance = (Appearance) m_Shape3D.getAppearance().cloneNodeComponent(true);

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

    // make a copy of the models original coordinates
    m_OriginalCoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];
    m_GeometryArray.getCoordinates(0, m_OriginalCoordinateArray);

    // start (or restart) the behavior
    setEnable(true);

    return m_InitialWakeupCondition;
}

From source file:BehaviorTest.java

public ObjectSizeBehavior(GeometryArray geomArray) {
    // save the GeometryArray that we are modifying
    m_GeometryArray = geomArray;//from  w  w  w  . j a va 2 s.  co  m

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

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

    // create the BoundingBox used to
    // calculate the size of the object
    m_BoundingBox = new BoundingBox();

    // create a temporary point
    m_Point = new Point3d();

    // create the WakeupCriterion for the behavior
    WakeupCriterion criterionArray[] = new WakeupCriterion[1];
    criterionArray[0] = new WakeupOnElapsedFrames(20);

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

From source file:BehaviorTest.java

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

    // 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);
}