/*---------------------*/ /* Ex81Behavior.java */ /*---------------------*/ import java.awt.event.*; import java.awt.AWTEvent; import java.util.Enumeration; //Enumeration import javax.media.j3d.*; //Java3d import javax.vecmath.*; //Point3f,Color3f public class Ex81Behavior extends Behavior{ private WakeupCondition wakeupConditon; private TransformGroup tg; private PolygonAttributes pa; private Transform3D trans = new Transform3D(); private float move1 = 0; private float move2 = 0; //@ add private float direct1 = 1.0f; //@ add private float direct2 = 1.0f; //@ add private boolean wireFlag = false; private boolean f1Flag = false; private boolean f2Flag = false; //@ add public Ex81Behavior(TransformGroup tg, PolygonAttributes pa){ this.tg = tg; //変更対象の幾何ノード this.pa = pa; //変更対象のポリゴン属性 } public void initialize(){ WakeupCriterion[] event = new WakeupCriterion[2]; event[0] = new WakeupOnElapsedFrames(0); event[1] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED); wakeupConditon = new WakeupOr(event); wakeupOn(wakeupConditon); System.out.println("--------------------------------"); System.out.println(" W : ワイヤー/ソリッドの切替"); System.out.println(" F1 : Y軸方向の平行移動ON/OFF"); System.out.println(" F2 : X軸方向の平行移動ON/OFF"); System.out.println("--------------------------------"); } public void processStimulus(Enumeration enumeration){ WakeupCriterion event; AWTEvent[] awtEvent; while(enumeration.hasMoreElements()){ event = (WakeupCriterion)enumeration.nextElement(); if(event instanceof WakeupOnAWTEvent){ //AWTイベント awtEvent = ((WakeupOnAWTEvent)event).getAWTEvent(); processMyKeyEvent(awtEvent); }else if(event instanceof WakeupOnElapsedFrames){ //フレーム経過 processMyFrameEvent(); } } wakeupOn(wakeupConditon); } private void processMyKeyEvent(AWTEvent[] event){ for(int i=0; i 0.80f) direct1 = -1.0f; if(move1 < -0.80f) direct1 = 1.0f; move1 += 0.01f*direct1; } if(f2Flag==true){ if(move2 > 0.80f) direct2 = -1.0f; if(move2 < -0.80f) direct2 = 1.0f; move2 += 0.01f*direct2; } trans.setTranslation(new Vector3f(move2, move1, 0.0f)); tg.setTransform(trans); } if(wireFlag==true){ pa.setPolygonMode(PolygonAttributes.POLYGON_LINE); }else{ pa.setPolygonMode(PolygonAttributes.POLYGON_FILL); } } }