< Zurück | Inhalt | Weiter >

From ExplodeBehavior.java


public void processStimulus( java.util.Enumeration criteria )

{

while( criteria.hasMoreElements() )

{

WakeupCriterion wakeUp =

(WakeupCriterion) criteria.nextElement();


if( wakeUp instanceof WakeupOnElapsedTime )

{

//we are starting the explosion,

//apply the appearance changes we require PolygonAttributes polyAttribs =

new PolygonAttributes( PolygonAttributes.POLYGON_POINT,

PolygonAttributes.CULL_NONE, 0 ); m_Shape3D.getAppearance().setPolygonAttributes( polyAttribs );


PointAttributes pointAttribs = new PointAttributes( 3, false ); m_Shape3D.getAppearance().setPointAttributes( pointAttribs );

m_Shape3D.getAppearance().setTexture( null ); m_TransparencyAttributes =

new TransparencyAttributes( TransparencyAttributes.NICEST, 0 );

m_TransparencyAttributes.setCapability( TransparencyAttributes.ALLOW_VALUE_WRITE );

m_Shape3D.getAppearance().setTransparencyAttributes( m_TransparencyAttributes );

}

else

{

//we are mid explosion, modify the GeometryArray m_nFrameNumber++;


m_GeometryArray.getCoordinates( 0, m_CoordinateArray );

m_TransparencyAttributes.

setTransparency( ((float) m_nFrameNumber) / ((float) m_nNumFrames) ); m_Shape3D.getAppearance().

setTransparencyAttributes( m_TransparencyAttributes );


for( int n = 0; n <m_CoordinateArray.length; n+=3 )

{

m_Vector.x = m_CoordinateArray[n]; m_Vector.y = m_CoordinateArray[n+1]; m_Vector.z = m_CoordinateArray[n+2];


m_Vector.normalize();


m_CoordinateArray[n] += m_Vector.x * Math.random() + Math.random();

m_CoordinateArray[n+1] += m_Vector.y * Math.random() + Math.random();

m_CoordinateArray[n+2] += m_Vector.z * Math.random() + Math.random();

}


//assign the new coordinates m_GeometryArray.setCoordinates( 0, m_CoordinateArray );

}

}


if( m_nFrameNumber <m_nNumFrames )

{

//assign the next WakeUpCondition, so we are notified again wakeupOn( m_FrameWakeupCondition );

}

else

{

//we are at the end of the explosion

//reapply the original appearance and GeometryArray coordinates setEnable( false );

m_Shape3D.setAppearance( m_Appearance ); m_GeometryArray.setCoordinates( 0, m_OriginalCoordinateArray );

m_OriginalCoordinateArray = null; m_GeometryArray = null; m_CoordinateArray = null; m_TransparencyAttributes = null;


//if we have a listener notify them that we are done if( m_Listener != null )

wakeupOn( m_Listener.onExplosionFinished( this, m_Shape3D ) );

}


image