001: /*
002: * @(#)PointLight.java 1.17 98/11/05 20:34:53
003: *
004: * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
007: * modify and redistribute this software in source and binary code form,
008: * provided that i) this copyright notice and license appear on all copies of
009: * the software; and ii) Licensee does not utilize the software in a manner
010: * which is disparaging to Sun.
011: *
012: * This software is provided "AS IS," without a warranty of any kind. ALL
013: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
014: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
015: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
016: * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
018: * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
019: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
020: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
021: * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
022: * POSSIBILITY OF SUCH DAMAGES.
023: *
024: * This software is not designed or intended for use in on-line control of
025: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
026: * the design, construction, operation or maintenance of any nuclear
027: * facility. Licensee represents and warrants that it will not use or
028: * redistribute the Software for such purposes.
029: *
030: * $Revision: 1.2 $
031: * $Date: 2005/02/03 23:06:59 $
032: * $State: Exp $
033: */
034: /*
035: * @Author: Rick Goldberg
036: * @Author: Doug Gehringer
037: *
038: */
039: package org.jdesktop.j3d.loaders.vrml97.impl;
040:
041: import javax.media.j3d.AmbientLight;
042: import javax.media.j3d.BoundingSphere;
043: import javax.media.j3d.Link;
044:
045: import javax.media.j3d.SharedGroup;
046: import javax.vecmath.Color3f;
047: import javax.vecmath.Point3f;
048:
049: /** Description of the Class */
050: public class PointLight extends Light {
051:
052: SFFloat ambientIntensity;
053: SFVec3f attenuation;
054: SFColor color;
055: SFFloat intensity;
056: SFVec3f location;
057: SFBool on;
058: SFFloat radius;
059:
060: Color3f lightColor;
061: Point3f lightPos;
062: Point3f lightAtt;
063: BoundingSphere bounds;
064: javax.media.j3d.PointLight pntLight;
065:
066: /**
067: *Constructor for the PointLight object
068: *
069: *@param loader Description of the Parameter
070: */
071: public PointLight(Loader loader) {
072: super (loader);
073:
074: ambientIntensity = new SFFloat(0.0f);
075: attenuation = new SFVec3f(1.0f, 0.0f, 0.0f);
076: color = new SFColor(1.0f, 1.0f, 1.0f);
077: intensity = new SFFloat(1.0f);
078: location = new SFVec3f(0.0f, 0.0f, 0.0f);
079: on = new SFBool(true);
080: radius = new SFFloat(100f);
081:
082: initFields();
083: }
084:
085: /**
086: *Constructor for the PointLight object
087: *
088: *@param loader Description of the Parameter
089: *@param ambientIntensity Description of the Parameter
090: *@param attenuation Description of the Parameter
091: *@param color Description of the Parameter
092: *@param intensity Description of the Parameter
093: *@param location Description of the Parameter
094: *@param on Description of the Parameter
095: *@param radius Description of the Parameter
096: */
097: PointLight(Loader loader, SFFloat ambientIntensity,
098: SFVec3f attenuation, SFColor color, SFFloat intensity,
099: SFVec3f location, SFBool on, SFFloat radius) {
100:
101: super (loader);
102: this .ambientIntensity = ambientIntensity;
103: this .attenuation = attenuation;
104: this .color = color;
105: this .intensity = intensity;
106: this .location = location;
107: this .on = on;
108: this .radius = radius;
109:
110: initFields();
111: }
112:
113: /** Description of the Method */
114: void initImpl() {
115: lightColor = new Color3f();
116: lightPos = new Point3f();
117: lightAtt = new Point3f();
118: bounds = new BoundingSphere();
119: bounds.setRadius((double) radius.value);
120: sharedGroup = new SharedGroup();
121: lightColor.x = color.color[0] * ambientIntensity.value;
122: lightColor.y = color.color[1] * ambientIntensity.value;
123: lightColor.z = color.color[2] * ambientIntensity.value;
124: ambLight = new AmbientLight(on.value, lightColor);
125: ambLight.setInfluencingBounds(bounds);
126: sharedGroup.addChild(ambLight);
127: lightColor.x = color.color[0] * intensity.value;
128: lightColor.y = color.color[1] * intensity.value;
129: lightColor.z = color.color[2] * intensity.value;
130: lightPos.x = location.value[0];
131: lightPos.y = location.value[1];
132: lightPos.z = location.value[2];
133: lightAtt.x = attenuation.value[0];
134: lightAtt.y = attenuation.value[1];
135: lightAtt.z = attenuation.value[2];
136: light = pntLight = new javax.media.j3d.PointLight(on.value,
137: lightColor, lightPos, lightAtt);
138: pntLight.setInfluencingBounds(bounds);
139: sharedGroup.addChild(pntLight);
140: implReady = true;
141: }
142:
143: /**
144: * Description of the Method
145: *
146: *@param eventInName Description of the Parameter
147: *@param time Description of the Parameter
148: */
149: public void notifyMethod(String eventInName, double time) {
150: if (eventInName.equals("AmbientIntensity")) {
151: lightColor.x = color.color[0] * ambientIntensity.value;
152: lightColor.y = color.color[1] * ambientIntensity.value;
153: lightColor.z = color.color[2] * ambientIntensity.value;
154: ambLight.setColor(lightColor);
155: } else if (eventInName.equals("color")
156: || eventInName.equals("intensity")) {
157: lightColor.x = color.color[0] * ambientIntensity.value;
158: lightColor.y = color.color[1] * ambientIntensity.value;
159: lightColor.z = color.color[2] * ambientIntensity.value;
160: ambLight.setColor(lightColor);
161: lightColor.x = color.color[0] * intensity.value;
162: lightColor.y = color.color[1] * intensity.value;
163: lightColor.z = color.color[2] * intensity.value;
164: pntLight.setColor(lightColor);
165: } else if (eventInName.equals("location")) {
166: lightPos.x = location.value[0];
167: lightPos.y = location.value[1];
168: lightPos.z = location.value[2];
169: pntLight.setPosition(lightPos);
170: } else if (eventInName.equals("attenuation")) {
171: lightAtt.x = attenuation.value[0];
172: lightAtt.y = attenuation.value[1];
173: lightAtt.z = attenuation.value[2];
174: pntLight.setAttenuation(lightAtt);
175: } else if (eventInName.equals("on")) {
176: ambLight.setEnable(on.value);
177: pntLight.setEnable(on.value);
178: } else if (eventInName.equals("radius")) {
179: bounds.setRadius((double) radius.value);
180: ambLight.setInfluencingBounds(bounds);
181: pntLight.setInfluencingBounds(bounds);
182: } else if (eventInName.equals("route_on")) {
183: ambLight
184: .setCapability(javax.media.j3d.Light.ALLOW_STATE_WRITE);
185: pntLight
186: .setCapability(javax.media.j3d.Light.ALLOW_STATE_WRITE);
187: } else if (eventInName.equals("route_location")) {
188: pntLight
189: .setCapability(javax.media.j3d.PointLight.ALLOW_POSITION_WRITE);
190: } else if (eventInName.equals("route_attenuation")) {
191: pntLight
192: .setCapability(javax.media.j3d.PointLight.ALLOW_ATTENUATION_WRITE);
193: } else if (eventInName.equals("route_color")
194: || eventInName.equals("route_intensity")) {
195: ambLight
196: .setCapability(javax.media.j3d.Light.ALLOW_COLOR_WRITE);
197: pntLight
198: .setCapability(javax.media.j3d.Light.ALLOW_COLOR_WRITE);
199: } else if (eventInName.equals("route_ambientIntensity")) {
200: ambLight
201: .setCapability(javax.media.j3d.Light.ALLOW_COLOR_WRITE);
202: } else if (eventInName.equals("route_radius")) {
203: ambLight
204: .setCapability(javax.media.j3d.Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
205: pntLight
206: .setCapability(javax.media.j3d.Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
207: }
208: }
209:
210: /**
211: * Description of the Method
212: *
213: *@return Description of the Return Value
214: */
215: public Object clone() {
216:
217: PointLight l = new PointLight(loader,
218: (SFFloat) ambientIntensity.clone(),
219: (SFVec3f) attenuation.clone(), (SFColor) color.clone(),
220: (SFFloat) intensity.clone(),
221: (SFVec3f) location.clone(), (SFBool) on.clone(),
222: (SFFloat) radius.clone());
223: return l;
224: }
225:
226: /**
227: * Gets the type attribute of the PointLight object
228: *
229: *@return The type value
230: */
231: public String getType() {
232: return "PointLight";
233: }
234:
235: /** Description of the Method */
236: void initFields() {
237: ambientIntensity.init(this , FieldSpec, Field.EXPOSED_FIELD,
238: "ambientIntensity");
239: attenuation.init(this , FieldSpec, Field.EXPOSED_FIELD,
240: "attenuation");
241: color.init(this , FieldSpec, Field.EXPOSED_FIELD, "color");
242: intensity.init(this , FieldSpec, Field.EXPOSED_FIELD,
243: "intensity");
244: location.init(this , FieldSpec, Field.EXPOSED_FIELD, "location");
245: on.init(this , FieldSpec, Field.EXPOSED_FIELD, "on");
246: radius.init(this , FieldSpec, Field.EXPOSED_FIELD, "radius");
247: }
248: }
|