/* Mykeynavbeh.java * Originally based on code from BackgroundApp.java *   @(#)BackgroundApp.java 1.1 00/09/22 14:03 * * portions Copyright (c) 1996-2000 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */
import java.awt.*;
import javax.media.j3d.*;import javax.vecmath.*;
import com.sun.j3d.utils.universe.SimpleUniverse;import com.sun.j3d.utils.universe.PlatformGeometry;import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.loaders.Scene;import com.sun.j3d.loaders.objectfile.ObjectFile;import java.io.*;
import java.awt.event.KeyListener;import java.awt.event.KeyEvent;
import java.util.*;
import java.awt.event.*;
import javax.sound.sampled.DataLine;import javax.sound.sampled.AudioInputStream;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.Clip;import javax.sound.sampled.LineUnavailableException;import javax.sound.sampled.UnsupportedAudioFileException;
import java.net.*;
public class Mykeynavbeh extends Frame implements Runnable, KeyListener {
private SimpleUniverse universe = null; private Canvas3D canvas = null; private TransformGroup viewtrans = null;
private TransformGroup tg_2 = null; private Transform3D t3d_2 = null;
private Transform3D t3dstep = new Transform3D(); private Matrix4d matrix = new Matrix4d();
private String typedKey = "0"; private String keyOrder = "0";
private Thread thread = new Thread(this);
private int q_state = 1;// coming private int a_state = 0;// staying
private double z_q_total = 0.0; private double z_a_total = 0.0; private double r_q_total = 0.0; private double r_a_total = 0.0;
private int question = 0;
public Mykeynavbeh() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config); add("Center", canvas); universe = new SimpleUniverse(canvas);
BranchGroup scene = createSceneGraph(); universe.getViewingPlatform().setNominalViewingTransform();
universe.getViewer().getView().setBackClipDistance(100.0);
canvas.addKeyListener(this);
universe.addBranchGraph(scene); }
private BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(), 10000.0);
viewtrans = universe.getViewingPlatform().getViewPlatformTransform();
KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(viewtrans); keyNavBeh.setSchedulingBounds(bounds); PlatformGeometry platformGeom = new PlatformGeometry(); platformGeom.addChild(keyNavBeh); universe.getViewingPlatform().setPlatformGeometry(platformGeom);
Background background = new Background(); background.setColor(1.0f, 1.0f, 1.0f); background.setApplicationBounds(bounds); objRoot.addChild(background);
objRoot.addChild(createPomeranian()); objRoot.addChild(createButterfly());
return objRoot; }
private BranchGroup createPomeranian() {
BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D();
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
t3d.setTranslation(new Vector3d(1.0, -0.125, -3.0)); t3d.setRotation(new AxisAngle4f(0.0f, 1.0f, 0.0f, 0.25f)); t3d.setScale(1.0);
tg.setTransform(t3d);
tg_2 = new TransformGroup(); t3d_2 = new Transform3D();
tg_2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
t3d_2.setTranslation(new Vector3d(-1.0, -0.125, -3.0)); t3d_2.setRotation(new AxisAngle4f(0.0f, 1.0f, 0.0f, 0.25f)); t3d_2.setScale(1.0);
tg_2.setTransform(t3d_2);
MovingPomeranian pomeranian = new MovingPomeranian("model/Pomeranian_dance_sm_up_sm.obj", "model/Pomeranian_dance_sm.obj", true); MovingPomeranian pomeranian2 = new MovingPomeranian("model/Pomeranian_dance_sm_up_sm.obj", "model/Pomeranian_dance_sm.obj", false);
tg.addChild(pomeranian.tg); tg_2.addChild(pomeranian2.tg);
tg.addChild(pomeranian); tg_2.addChild(pomeranian2);
objRoot.addChild(tg); objRoot.addChild(tg_2); // objRoot.addChild(createLight());
objRoot.compile();
return objRoot;
}
private BranchGroup createButterfly() {
BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D();
t3d.setTranslation(new Vector3d(0.5, 0.43, 0.0)); t3d.setScale(0.12); tg.setTransform(t3d);
FlyingButterfly butterfly = new FlyingButterfly("model/Butterfly_1_w_closed_flip.obj", "model/Butterfly_1_flip.obj", 1.0, 0.0, 0.0, 7, true); FlyingButterfly butterfly2 = new FlyingButterfly("model/Butterfly_1_w_closed_flip.obj", "model/Butterfly_1_flip.obj", 0.3, 10.0, -0.3, 6, false); tg.addChild(butterfly.tg); tg.addChild(butterfly2.tg);
tg.addChild(butterfly); tg.addChild(butterfly2);
objRoot.addChild(tg); objRoot.addChild(createAmbientLight());
objRoot.compile();
return objRoot;
}
private BranchGroup createObjLoad(String filename) {
BranchGroup objRoot = new BranchGroup();
TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(1.0); tg.setTransform(t3d);
ObjectFile loader = new ObjectFile(ObjectFile.RESIZE); Scene s = null;
File file = new java.io.File(filename);
try { s = loader.load(file.toURI().toURL()); } catch (Exception e) { System.err.println(e); System.exit(1); }
tg.addChild(s.getSceneGroup());
objRoot.addChild(tg);
objRoot.compile();
return objRoot;
}
/* * private Light createLight() { DirectionalLight light = new * DirectionalLight(true, new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-0.3f, * 0.2f, -1.0f)); *Â * light.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0)); *Â * return light; } */
private Light createAmbientLight() { AmbientLight light = new AmbientLight(new Color3f(0.1f, 0.1f, 0.1f));
light.setInfluencingBounds(new BoundingSphere(new Point3d(), 100.0));
return light; }
public void getSound(String fname) { Clip clip = null;
try { URL url = this.getClass().getClassLoader().getResource(fname); AudioInputStream audioIn = AudioSystem.getAudioInputStream(url); clip = AudioSystem.getClip(); clip.open(audioIn);
clip.start();
} catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
public static void main(String args[]) {
Mykeynavbeh window = new Mykeynavbeh();
window.setSize(800, 600);
window.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
window.setVisible(true); }
public void run() { }
public void keyTyped(KeyEvent e) { char key = e.getKeyChar(); typedKey = String.valueOf(key);
if (key == '4') {
t3dstep.rotY(Math.PI / 32); tg_2.getTransform(t3d_2); t3d_2.get(matrix); t3d_2.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d_2.mul(t3dstep); t3d_2.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg_2.setTransform(t3d_2);
}
if (key == '2') {
t3dstep.rotY(-Math.PI / 32); tg_2.getTransform(t3d_2); t3d_2.get(matrix); t3d_2.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d_2.mul(t3dstep); t3d_2.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg_2.setTransform(t3d_2);
}
if (key == '3') {
t3dstep.set(new Vector3d(0.0, 0.0, 0.1f)); tg_2.getTransform(t3d_2); t3d_2.mul(t3dstep); tg_2.setTransform(t3d_2);
}
if (key == '8') {
t3dstep.set(new Vector3d(0.0, 0.0, -0.1f)); tg_2.getTransform(t3d_2); t3d_2.mul(t3dstep); tg_2.setTransform(t3d_2);
}
if (key == '1') {
t3dstep.set(new Vector3d(-0.1, 0.0, 0.0f)); tg_2.getTransform(t3d_2); t3d_2.mul(t3dstep); tg_2.setTransform(t3d_2);
}
if (key == '5') {
t3dstep.set(new Vector3d(0.1, 0.0, 0.0f)); tg_2.getTransform(t3d_2); t3d_2.mul(t3dstep); tg_2.setTransform(t3d_2);
}
if (key == 'h') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_h: " + keyOrder);
}
if (key == 'p') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_p: " + keyOrder); }
if (key == 'w') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_w: " + keyOrder);
}
if (key == 'u') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_u: " + keyOrder);
}
if (key == 't') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_t: " + keyOrder);
}
if (key == 'd') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_d: " + keyOrder);
}
if (key == 'm') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_m: " + keyOrder);
}
if (key == 'n') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_n: " + keyOrder);
}
if (key == 'i') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_i: " + keyOrder);
}
if (key == 'o') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_o: " + keyOrder);
}
if (key == 'g') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_g: " + keyOrder);
}
if (key == 'y') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_y: " + keyOrder);
}
if (key == 'c') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_c: " + keyOrder);
}
if (key == 'l') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_l: " + keyOrder);
}
if (key == 'a') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_a: " + keyOrder);
}
if (key == 's') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_s: " + keyOrder);
}
if (key == 'f') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_f: " + keyOrder);
} if (key == 'j') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_j: " + keyOrder);
} if (key == 'k') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_k: " + keyOrder);
} if (key == 'b') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_b: " + keyOrder);
} if (key == 'r') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_r: " + keyOrder);
}
if (key == '.') {
keyOrder = keyOrder + typedKey; System.out.println("keyOrder_.: " + keyOrder);
switch (keyOrder) { case "0hp.": getSound("Hey Pom.wav"); break;
case "0wu.": getSound("What's up.wav"); break;
case "0ht.": getSound("Hi there!.wav"); break;
case "0dhm.": getSound("Do you hear me.wav"); break;
case "0onminpt.": getSound("OK. Never mind. I need a.wav"); break;
case "0gm.": getSound("Good morning_P.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Good morning_Q_E.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Good morning_Q_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Good morning_Q_C.wav"); break;
case "0hipntmy.": getSound("Hi, I'm Ponta. Nice to_P.wav"); try { thread.sleep(3000); } catch (InterruptedException ae) { } getSound("I'm Queen. Nice to_Q_E.wav"); try { thread.sleep(3000); } catch (InterruptedException ae) { } getSound("I'm Queen. Nice to_Q_S.wav"); try { thread.sleep(4000); } catch (InterruptedException ae) { } getSound("I'm Queen. Nice to_Q_C.wav"); break;
case "0ww.": getSound("Wow_P.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("You must talk_Q.wav"); break;
case "0ictrsmflwatst.": getSound("I can't remember so manyV-6_P.wav"); try { thread.sleep(4000); } catch (InterruptedException ae) { } getSound("Did you say something_Q.wav"); break;
case "0ng.": getSound("Nothing_P.wav"); try { thread.sleep(1500); } catch (InterruptedException ae) { } getSound("Will you watch my little_Q.wav"); break;
case "0np.": getSound("No problem_P.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Thank you in advance_Q.wav"); try { thread.sleep(1200); } catch (InterruptedException ae) { } getSound("April! Come here!V10_Q_E.wav"); try { thread.sleep(2500); } catch (InterruptedException ae) { } getSound("April! Come here!V10_Q_S.wav"); try { thread.sleep(2500); } catch (InterruptedException ae) { } getSound("April! Come here!V10_Q_C.wav");
a_state = 1;// coming z_q_total = 0.0; q_state = 2;// going
break;
case "0hahayd.": getSound("Hi, April. How are you_P.wav"); try { thread.sleep(3500); } catch (InterruptedException ae) { } getSound("Good_A_E.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Good_A_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Good_A_C.wav"); break;
case "0yasc.": getSound("You are so cute!_P.wav"); try { thread.sleep(1800); } catch (InterruptedException ae) { } getSound("Thank you!_A_E.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Thank you!_A_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Thank you!_A_C.wav"); break;
case "0yslys.": getSound("You sound like yourV-6_P.wav"); try { thread.sleep(2000); } catch (InterruptedException ae) { } getSound("Did you say something_A.wav"); try { thread.sleep(2000); } catch (InterruptedException ae) { } getSound("Here are three questions_A.wav"); break;
case "0wyajlys.": getSound("What_You are just like_P.wav"); try { thread.sleep(3000); } catch (InterruptedException ae) { } getSound("Is that your brother_He is so_A.wav"); break;
case "0yhalt.": getSound("Yeah, he's always like that_P.wav"); break;
case "0idtkitagtobt.": getSound("I don't know if that's a_P.wav"); break;
case "0waygtam.": getSound("What are you going to ask_P.wav"); try { thread.sleep(1500); } catch (InterruptedException ae) { } getSound("I have legs but cannot_A.wav");// I have legs but cannot walk. //What am I? Choose from a bottle, //a candle, and a chair. question = 1; break;
case "0ulmt.": getSound("Umm...let me think_P.wav"); break;
case "0achy.": getSound("A chair! Yes!V10_P.wav");// A chair! Yes! try { thread.sleep(2000); } catch (InterruptedException ae) { } switch (question) { case 1: getSound("Correct!_A_E.wav");// Correct! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_C.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { }
getSound("What has a neck but no_A.wav");// What has a neck but no head? //What am I? question = 2;
break;
case 2: case 3: getSound("Wrong!_A_E.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_S2.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_C.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } break;
default: getSound("I didn't ask you_A.wav");// I didn't ask you anything yet. try { thread.sleep(1500); } catch (InterruptedException ae) { } break;
}
break;
case "0abty.": getSound("A bottle! Yes!V10_P.wav");// A bottle! Yes! try { thread.sleep(2000); } catch (InterruptedException ae) { }
switch (question) { case 2: getSound("Correct!_A_E.wav");// Correct! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_C.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { }
getSound("I'm tall when I'm_A.wav");// I'm tall when I'm young,  //and I'm short when I'm old. // What am I? question = 3;
break;
case 1: case 3: getSound("Wrong!_A_E.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_S2.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_C.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { }
break;
default: getSound("I didn't ask you_A.wav");// I didn't ask you anything yet. try { thread.sleep(1500); } catch (InterruptedException ae) { } break;
}
break;
case "0acnimi.": getSound("A candle! I made it!V10_P.wav");// A candle! I made it! try { thread.sleep(2500); } catch (InterruptedException ae) { }
switch (question) { case 3: getSound("Correct!_A_E.wav");// Correct! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_S.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Correct!_A_C.wav"); try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("April, come here. ThankV10_A_E.wav");// April, come here. Thank you, Ponta! try { thread.sleep(4000); } catch (InterruptedException ae) { } getSound("April, come here. ThankV10_A_S.wav"); try { thread.sleep(4000); } catch (InterruptedException ae) { } getSound("April, come here. ThankV10_A_C.wav");
z_a_total = 0.0; a_state = 2;// going
break;
case 1: case 2: getSound("Wrong!_A_E.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_S2.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { } getSound("Wrong!_A_C.wav");// Wrong! try { thread.sleep(1000); } catch (InterruptedException ae) { }
break;
default: getSound("I didn't ask you_A.wav");// I didn't ask you anything yet. try { thread.sleep(1500); } catch (InterruptedException ae) { } break;
}
break;
/* default: try { thread.sleep(4000); } catch (InterruptedException ae) { } getSound("I can't hear you!_A.wav"); break; */ }
keyOrder = "0"; System.out.println("keyOrder_0: " + keyOrder);
}
}
public void keyReleased(KeyEvent e) { }
public void keyPressed(KeyEvent e) { }
class MovingPomeranian extends Behavior {
public TransformGroup tg = null; public Transform3D t3d = null; private Transform3D t3dstep = new Transform3D(); private WakeupOnElapsedFrames wakeFrame = null;
private Switch selector = new Switch(Switch.CHILD_MASK); private BitSet flag_i = new BitSet(2);
private int count = 0;
private double x = 0.0f; private double z = 0.0f;
private boolean pome;
public MovingPomeranian(String filename, String filename2, boolean pom) {
pome = pom;
tg = new TransformGroup(); t3d = new Transform3D();
t3d.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d.setScale(1.0); tg.setTransform(t3d);
selector.setCapability(Switch.ALLOW_SWITCH_WRITE);
flag_i.clear(); flag_i.set(1); selector.setChildMask(flag_i);
selector.addChild(createObjLoad(filename)); selector.addChild(createObjLoad(filename2));
tg.addChild(selector); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); this.setSchedulingBounds(bounds); }
public void initialize() { wakeFrame = new WakeupOnElapsedFrames(15); wakeupOn(wakeFrame); }
public void processStimulus(Enumeration criteria) {
if (pome) { x = (Math.random() - 0.5) * 0.05; z = (Math.random() - 0.5) * 0.05;
t3dstep.set(new Vector3d(x, 0.0, z)); tg.getTransform(t3d); t3d.mul(t3dstep); tg.setTransform(t3d);
}
flag_i.clear(); flag_i.set(count % 2); selector.setChildMask(flag_i);
count++;
wakeupOn(wakeFrame); } }
class FlyingButterfly extends Behavior {
public TransformGroup tg = null; public Transform3D t3d = null; private Transform3D t3dstep = new Transform3D(); private WakeupOnElapsedFrames wakeFrame = null;
private Switch selector = new Switch(Switch.CHILD_MASK); private BitSet flag_i = new BitSet(2);
private int count = 0; private int fc = 0;
private boolean queen = true;
private double x = 0.0f; private double y = 0.0f;
private boolean firstTime_q = true; private boolean firstTime_a = true;
private double z_q = 0.0f; private double z_a = 0.0f; private double r_q = 0.0f; private double r_a = 0.0f;
public FlyingButterfly(String filename, String filename2, double size, double x, double y, int frameCount, boolean bfyQueen) {
fc = frameCount; queen = bfyQueen;
tg = new TransformGroup(); t3d = new Transform3D();
t3d.setTranslation(new Vector3d(x, y, 0.0)); t3d.setRotation(new AxisAngle4f(0.0f, 1.0f, 0.0f, 1.57f)); t3d.setScale(size); tg.setTransform(t3d);
selector.setCapability(Switch.ALLOW_SWITCH_WRITE);
flag_i.clear(); flag_i.set(1); selector.setChildMask(flag_i);
selector.addChild(createObjLoad(filename)); selector.addChild(createObjLoad(filename2));
tg.addChild(selector); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); this.setSchedulingBounds(bounds); }
public void initialize() { wakeFrame = new WakeupOnElapsedFrames(fc); wakeupOn(wakeFrame); }
public void processStimulus(Enumeration criteria) {
if (queen) { switch (q_state) { case 1:// coming if (z_q_total >= -8.0) { System.out.println("z_q_total: " + z_q_total); z_q = -0.5; z_q_total += z_q;
} else { z_q = -(Math.random()) * 0.01; r_q = (Math.random() - 0.5) * 0.3;
r_q_total += r_q; }
x = (Math.random() - 0.5) * 0.3; y = (Math.random() - 0.5) * 0.1;
break;
case 2:// going if (firstTime_q) { r_q_total += 3.14; t3dstep.rotY(-r_q_total); tg.getTransform(t3d); t3d.get(matrix); t3d.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d.mul(t3dstep); t3d.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg.setTransform(t3d);
firstTime_q = false; } if (z_q_total >= -55.0) { z_q = -1.0; z_q_total += z_q; r_q = 0.0; } else { z_q = -(Math.random()) * 0.01; r_q = (Math.random() - 0.5) * 0.3;
r_q_total += r_q; }
x = (Math.random() - 0.5) * 0.3; y = (Math.random() - 0.5) * 0.1;
break;
}
t3dstep.set(new Vector3d(x, y, z_q)); tg.getTransform(t3d); t3d.mul(t3dstep); tg.setTransform(t3d);
t3dstep.rotY(r_q); tg.getTransform(t3d); t3d.get(matrix); t3d.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d.mul(t3dstep); t3d.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg.setTransform(t3d);
} else { switch (a_state) { case 0:// staying break;
case 1:// coming if (z_a_total >= -45.0) { z_a = -5.0; z_a_total += z_a;
} else { z_a = -(Math.random()) * 0.05; r_a = (Math.random() - 0.5) * 0.9;
r_a_total += r_a; }
x = (Math.random() - 0.5) * 1.0; y = (Math.random() - 0.5) * 0.5;
break;
case 2:// going if (firstTime_a) { r_a_total += 3.14; t3dstep.rotY(-r_a_total); System.out.println("-r_a_total: " + -r_a_total); tg.getTransform(t3d); t3d.get(matrix); t3d.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d.mul(t3dstep); t3d.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg.setTransform(t3d);
firstTime_a = false; } if (z_a_total >= -150.0) { z_a = -2.0; z_a_total += z_a; r_a = 0.0; } else { z_a = -(Math.random()) * 0.05; r_a = (Math.random() - 0.5) * 0.9;
r_a_total += r_a; System.out.println("r_a_total: " + r_a_total); }
x = (Math.random() - 0.5) * 1.0; y = (Math.random() - 0.5) * 0.5;
break;
}
t3dstep.set(new Vector3d(x, y, z_a)); tg.getTransform(t3d); t3d.mul(t3dstep); tg.setTransform(t3d);
t3dstep.rotY(r_a); tg.getTransform(t3d); t3d.get(matrix); t3d.setTranslation(new Vector3d(0.0, 0.0, 0.0)); t3d.mul(t3dstep); t3d.setTranslation(new Vector3d(matrix.m03, matrix.m13, matrix.m23)); tg.setTransform(t3d);
}
flag_i.clear(); flag_i.set(count % 2); selector.setChildMask(flag_i);
count++;
wakeupOn(wakeFrame); } }
}