001: /*
002: * $RCSfile: Billboard.java,v $
003: *
004: * @(#)Billboard.java 1.21 99/03/15 10:27:43
005: *
006: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
007: *
008: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
009: * modify and redistribute this software in source and binary code form,
010: * provided that i) this copyright notice and license appear on all copies of
011: * the software; and ii) Licensee does not utilize the software in a manner
012: * which is disparaging to Sun.
013: *
014: * This software is provided "AS IS," without a warranty of any kind. ALL
015: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
016: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
017: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
018: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
019: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
020: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * $Revision: 1.2 $
033: * $Date: 2005/02/03 23:06:52 $
034: * $State: Exp $
035: */
036: /*
037: * @Author: Rick Goldberg
038: * @Author: Doug Gehringer
039: *
040: */
041: package org.jdesktop.j3d.loaders.vrml97.impl;
042:
043: import javax.media.j3d.Group;
044: import javax.media.j3d.TransformGroup;
045:
046: /** Description of the Class */
047: public class Billboard extends GroupBase {
048:
049: // exposedField
050: SFVec3f axisOfRotation;
051: // Note: this field does *not* change as the Billboard rotates, rather,
052: // this is the axis about which it rotates.
053:
054: Group impl;
055: TransformGroup implTrans;
056: javax.media.j3d.Billboard implBillboard;
057:
058: /**
059: *Constructor for the Billboard object
060: *
061: *@param loader Description of the Parameter
062: */
063: public Billboard(Loader loader) {
064: super (loader);
065: axisOfRotation = new SFVec3f(0.0f, 1.0f, 0.0f);
066: initBillboardFields();
067: }
068:
069: /**
070: *Constructor for the Billboard object
071: *
072: *@param loader Description of the Parameter
073: *@param children Description of the Parameter
074: *@param bboxCenter Description of the Parameter
075: *@param bboxSize Description of the Parameter
076: *@param aor Description of the Parameter
077: */
078: Billboard(Loader loader, MFNode children, SFVec3f bboxCenter,
079: SFVec3f bboxSize, SFVec3f aor) {
080: super (loader, children, bboxCenter, bboxSize);
081: axisOfRotation = aor;
082: initBillboardFields();
083: }
084:
085: /** Description of the Method */
086: public void initImpl() {
087: impl = new Group();
088: implTrans = new TransformGroup();
089: implGroup = implTrans;
090: implNode = impl;
091: implGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
092: implGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
093: implBillboard = new javax.media.j3d.Billboard(implTrans);
094: setAxis();
095: impl.addChild(implBillboard);
096: impl.addChild(implTrans);
097: implBillboard.setTarget(implTrans);
098: implBillboard
099: .setSchedulingBoundingLeaf(loader.infiniteBoundingLeaf);
100: super .replaceChildren();// add the children to the group
101: implReady = true;
102: }
103:
104: /** Sets the axis attribute of the Billboard object */
105: private void setAxis() {
106: float[] axis = axisOfRotation.value;
107: if ((axis[0] == 0.0) && (axis[1] == 0.0) && (axis[2] == 0.0)) {
108: implBillboard
109: .setAlignmentMode(javax.media.j3d.Billboard.ROTATE_ABOUT_POINT);
110: implBillboard.setRotationPoint(0.0f, 0.0f, 0.0f);
111: } else {
112: implBillboard
113: .setAlignmentMode(javax.media.j3d.Billboard.ROTATE_ABOUT_AXIS);
114: implBillboard.setAlignmentAxis(axis[0], axis[1], axis[2]);
115: }
116: }
117:
118: /**
119: * Description of the Method
120: *
121: *@param eventInName Description of the Parameter
122: *@param time Description of the Parameter
123: */
124: public void notifyMethod(String eventInName, double time) {
125: if (eventInName.equals("axisOfRotation")) {
126: setAxis();
127: } else if (eventInName.equals("route_axisOfRotation")) {
128: ;// No-op
129: } else {
130: super .notifyMethod(eventInName, time);
131: }
132: }
133:
134: /**
135: * Description of the Method
136: *
137: *@return Description of the Return Value
138: */
139: public Object clone() {
140: return new Billboard(loader, (MFNode) children.clone(),
141: (SFVec3f) bboxCenter.clone(), (SFVec3f) bboxSize
142: .clone(), (SFVec3f) axisOfRotation.clone());
143: }
144:
145: /**
146: * Gets the type attribute of the Billboard object
147: *
148: *@return The type value
149: */
150: public String getType() {
151: return "Billboard";
152: }
153:
154: /** Description of the Method */
155: void initFields() {
156: super .initFields();
157: initBillboardFields();
158: }
159:
160: /** Description of the Method */
161: void initBillboardFields() {
162: axisOfRotation.init(this , FieldSpec, Field.EXPOSED_FIELD,
163: "axisOfRotation");
164: }
165:
166: }
|