/Users/lyon/j4p/src/j3d/cr325/Target.java
|
1 package j3d.cr325;
2
3 import j3d.Utils;
4 import utils.SystemUtils;
5
6 import javax.media.j3d.*;
7 import javax.vecmath.Matrix3d;
8 import javax.vecmath.Vector3d;
9
10 /**
11 * DocJava, Inc.
12 * http://www.docjava.com
13 * Programmer: dlyon
14 * Date: Mar 10, 2004
15 * Time: 4:36:29 PM
16 */
17 public class Target {
18 /**
19 * Switch that is used to swap the target models
20 */
21 private static Switch targetSwitch = getTargetSwitch();
22
23 public static Switch getTargetSwitch() {
24 if (targetSwitch != null) return targetSwitch;
25 Switch s = new Switch(0);
26 s.setCapability(Switch.ALLOW_SWITCH_WRITE);
27 return s;
28 }
29
30 public static BranchGroup getTargetGroup() {
31 BranchGroup theTarget = new BranchGroup();
32 Switch s = getTargetSwitch();
33 TransformGroup targetRotationTransformGroup = new TransformGroup();
34 Transform3D targetRotationTransform = new Transform3D();
35 Matrix3d targetRotationMatrix = new Matrix3d();
36 targetRotationMatrix.rotY(Math.PI / 2);
37 targetRotationTransform.set(
38 targetRotationMatrix,
39 new Vector3d(0.0, 0.0, -30.0), 1.0);
40 targetRotationTransformGroup.setTransform(targetRotationTransform);
41 targetRotationTransformGroup.addChild(s);
42 String fileSep = SystemUtils.getDirectorySeparator();
43 String fileName = "gifs"+fileSep+"animation1.gif";
44 s.addChild(
45 Utils.getTextureSphere(1,0,0.5,fileName)
46 );
47 String fileName1 = "color"+fileSep+"airplane.JPEG";
48 s.addChild(
49 Utils.getTextureSphere(1,0,0.5,fileName1)
50 );
51
52 TransformGroup targetMotionTransformGroup = new TransformGroup();
53 targetMotionTransformGroup.setCapability(
54 TransformGroup.ALLOW_TRANSFORM_READ);
55 targetMotionTransformGroup.setCapability(
56 TransformGroup.ALLOW_TRANSFORM_WRITE);
57 targetMotionTransformGroup.addChild(
58 targetRotationTransformGroup);
59 Alpha a = new Alpha(-1, 0, 0, 3000, 0, 0);
60
61 Utils.addMotion( a, targetMotionTransformGroup, theTarget);
62 return theTarget;
63 }
64 }
65