001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/FollowViewPlugin.java,v 1.1 2005/04/20 21:04:39 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dfly.plugins;
019:
020: import javax.media.j3d.ViewPlatform;
021: import javax.media.j3d.TransformGroup;
022: import javax.media.j3d.Transform3D;
023: import javax.media.j3d.BranchGroup;
024: import javax.vecmath.Vector3f;
025: import com.sun.j3d.utils.universe.PlatformGeometry;
026: import org.jdesktop.j3dfly.J3dFlyContext;
027: import org.jdesktop.j3dfly.utils.vpbehaviors.HoverBehavior;
028: import org.jdesktop.j3dfly.utils.vpbehaviors.VPVehicleCollision;
029:
030: import com.sun.j3d.utils.universe.SimpleUniverse;
031:
032: /**
033: * This Plugin updates the View side of the scene graph and adds a Behavior
034: * so that the ViewPlatform follows the ViewingPlatform instead of
035: * being coincident
036: *
037: * @author Paul Byrne
038: * @version $Revision: 1.1 $
039: */
040: public class FollowViewPlugin extends J3dFlyPlugin {
041:
042: private TransformGroup followTG = null;
043:
044: /**
045: * @param enabled true if the plugin should add it's scene graph components
046: * to the scene and begin operation at construction time
047: *
048: * @param toolBG the BranchGraph which should contain any scene graph components
049: * for the plugin
050: */
051: public FollowViewPlugin() {
052: super ();
053:
054: }
055:
056: /**
057: * Returns the class of the plugin preference.
058: *
059: * Plugins that require more preference information should provide a
060: * subclass of PluginPrefernece that contains all the extra preference
061: * data. This class must be Serializable.
062: */
063: public Class getPluginPreferenceClass() {
064: return FollowViewPluginPreference.class;
065: }
066:
067: public void installPlugin(PluginPreference pluginPref,
068: J3dFlyContext j3dflyContext) {
069: super .installPlugin(pluginPref, j3dflyContext);
070: SimpleUniverse universe = j3dflyContext.getUniverse();
071:
072: j3dflyContext.getLocale().setLive(false);
073: ViewPlatform vp = universe.getViewingPlatform()
074: .getViewPlatform();
075: universe.getViewingPlatform().getViewPlatformTransform()
076: .removeChild(vp);
077: Transform3D trans = new Transform3D();
078: trans.set(new Vector3f(0, 1f, 5f));
079: followTG = new TransformGroup(trans);
080: followTG.addChild(vp);
081: universe.getViewingPlatform().getViewPlatformTransform()
082: .addChild(followTG);
083:
084: PlatformGeometry platformGeom = new PlatformGeometry();
085: platformGeom.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
086: platformGeom
087: .addChild(new org.jdesktop.j3dfly.utils.vpbehaviors.vehicles.SimpleVehicle());
088: universe.getViewingPlatform().setPlatformGeometry(platformGeom);
089:
090: j3dflyContext.getLocale().setLive(true);
091: }
092:
093: public void uninstallPlugin() {
094: super .uninstallPlugin();
095: SimpleUniverse universe = j3dflyContext.getUniverse();
096: j3dflyContext.getLocale().setLive(false);
097: ViewPlatform vp = universe.getViewingPlatform()
098: .getViewPlatform();
099: followTG.removeChild(vp);
100: universe.getViewingPlatform().getViewPlatformTransform()
101: .removeChild(followTG);
102:
103: universe.getViewingPlatform().getViewPlatformTransform()
104: .addChild(vp);
105:
106: universe.getViewingPlatform().setPlatformGeometry(null);
107: j3dflyContext.getLocale().setLive(true);
108:
109: }
110:
111: /**
112: * Get the title of the plugin
113: */
114: public String getPluginTitle() {
115: return "Follow View";
116: }
117:
118: /**
119: * Returns the control panel for this plugin, or null if there
120: * is no control panel
121: */
122: public javax.swing.JPanel getControlPanel() {
123: return null;
124: }
125:
126: public static class FollowViewPluginPreference extends
127: PluginPreference {
128: public FollowViewPluginPreference() {
129: super ();
130: }
131:
132: public FollowViewPluginPreference(boolean enabled,
133: boolean installed) {
134: super (enabled, installed);
135: }
136:
137: public J3dFlyPlugin instantiatePlugin() {
138: return new FollowViewPlugin();
139: }
140:
141: /**
142: * Return a description of this plugin
143: */
144: public String getDescription() {
145: return "Setup the 'camera' to follow the view";
146: }
147:
148: /**
149: * Return the name of the Plugin for this prefernece.
150: * This is the name that will appear in the list of plugins
151: */
152: public String getName() {
153: return "Follow View";
154: }
155:
156: }
157:
158: }
|