View Javadoc
1   /* -------------------------------------------------------------------
2    * Java source file for the class SpotLight
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:05 $
11   * 
12   * $Id: SpotLight.java,v 1.3 2004/03/03 11:53:05 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
23  package net.jbeans.j3d.light;
24  
25  /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26  import java.awt.*;
27  import java.io.*;
28  import javax.media.j3d.Light;
29  import javax.media.j3d.Node;
30  import javax.vecmath.*;
31  
32  import net.jbeans.j3d.util.*;
33  import net.jbeans.j3d.vecmath.*;
34  
35  /*====================================================================
36                    Implementation of class SpotLight                   
37  ====================================================================*/
38  /***
39   * generally describe SpotLight in here
40   * 
41   * @version $Revision: 1.3 $
42   * @author Masahiro Takatsuka (masa@jbeans.net)
43   * @see javax.media.j3d.SpotLight
44   * @see Serializable
45   */
46  
47  public final class SpotLight extends javax.media.j3d.SpotLight implements Serializable {
48  	transient private Vector3f tmpV = new Vector3f();
49  	transient private Point3f tmpP = new Point3f();	
50  	
51  	/* for Light */
52  	transient private Color3f color;
53  
54      public SpotLight() {
55  		this(true, LightUtil.WHITE,
56  			 LightUtil.DEFAULT_POSITION,
57  			 LightUtil.DEFAULT_ATTENUATION,
58  			 LightUtil.DEFAULT_DIRECTION,
59  			 LightUtil.DEFAULT_SPREAD_ANGLE,
60  			 LightUtil.DEFAULT_CONCENTRATION);
61      }
62  
63  	public SpotLight(Color3f color3f, Point3f position, Point3f attenuation,
64  					   Vector3f direction, float spreadAngle, float concentration) {
65          this(true, color3f, position, attenuation, direction, spreadAngle, concentration);
66      }
67  
68      public SpotLight(boolean lightOn, Color3f color3f, Point3f position, Point3f attenuation, Vector3f direction, float spreadAngle, float concentration) {
69          super(lightOn, color3f, position, attenuation, direction, spreadAngle, concentration);
70  		setEnable(true);		// turn it on as default.
71  		this.color = new Color3f();
72  		
73  		initialize();
74      }
75  
76  	private final void initialize() {
77  		setCapabilities();
78  	}
79  	
80  	private final void setCapabilities() {
81  		setInfluencingBounds(J3DUtil.DEFAULT_BOUNDS);
82  
83  		/* -------------------- from SpotLight --------------------- */
84  		setCapability(SpotLight.ALLOW_SPREAD_ANGLE_READ);		
85  		setCapability(SpotLight.ALLOW_SPREAD_ANGLE_WRITE);
86  		setCapability(SpotLight.ALLOW_CONCENTRATION_READ);		
87  		setCapability(SpotLight.ALLOW_CONCENTRATION_WRITE);
88  		setCapability(SpotLight.ALLOW_DIRECTION_READ);		
89  		setCapability(SpotLight.ALLOW_DIRECTION_WRITE);
90  		
91  		/* -------------------- from PointLight --------------------- */
92  		setCapability(PointLight.ALLOW_POSITION_READ);		
93  		setCapability(PointLight.ALLOW_POSITION_WRITE);
94  		setCapability(PointLight.ALLOW_ATTENUATION_READ);		
95  		setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
96  		
97  		/* ----------------------- from Light.class ----------------------- */
98  		setCapability(Light.ALLOW_COLOR_READ);
99  		setCapability(Light.ALLOW_COLOR_WRITE);
100 		
101 		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
102 		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
103 
104 		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
105 		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
106 
107 		setCapability(Light.ALLOW_SCOPE_READ);
108 		setCapability(Light.ALLOW_SCOPE_WRITE);
109 
110 		setCapability(Light.ALLOW_STATE_READ);
111 		setCapability(Light.ALLOW_STATE_WRITE);
112 		
113 		/* ----------------------- from Node.class ------------------------ */
114 		setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
115 		setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE);		
116 
117 		setCapability(Node.ALLOW_BOUNDS_READ);
118 		setCapability(Node.ALLOW_BOUNDS_WRITE);		
119 		
120 		setCapability(Node.ALLOW_COLLIDABLE_READ);
121 		setCapability(Node.ALLOW_COLLIDABLE_WRITE);		
122 
123 		setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
124 
125 		setCapability(Node.ALLOW_PICKABLE_READ);
126 		setCapability(Node.ALLOW_PICKABLE_WRITE);		
127 	}
128 
129 	public void setColor(Color color) {
130 		if (this.color == null) {
131 			this.color = new Color3f(color);
132 		} else {
133 			this.color.set(color);
134 		}
135 		setColor(this.color);
136 	}
137 
138 	public Color getColor() {
139 		if (this.color == null) {
140 			this.color = new Color3f();
141 		}
142 		getColor(this.color);
143 
144 		return new Color(this.color.x, this.color.y, this.color.z);
145 	}
146 	
147 	public Point3f getPosition() {
148 		Point3f pos = new Point3f();
149 		getPosition(pos);
150 		return pos;
151 	}
152 
153 	public Point3f getAttenuation() {
154 		Point3f att = new Point3f();
155 		getAttenuation(att);
156 		return att;
157 	}
158 
159 	public Vector3f getDirection() {
160 		Vector3f dir = new Vector3f();
161 		getDirection(dir);
162 		return dir;
163 	}
164 
165 	public void setPosition(float x, float y, float z) {
166 		this.tmpP.set(x, y, z);
167 		setPosition(this.tmpP);
168 	}
169 
170 	public void setAttenuation(float x, float y, float z) {
171 		this.tmpP.set(x, y, z);
172 		setAttenuation(this.tmpP);
173 	}
174 
175 	public void setDirection(float x, float y, float z) {
176 		this.tmpV.set(x, y, z);
177 		setDirection(this.tmpV);
178 	}
179 	
180 	public Light getSpotLight() {
181 		return this;
182 	}
183 
184     /***
185      * Serialization methods
186      */
187     private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
188 		setEnable(s.readBoolean());
189 		setColor((Color3f) s.readObject());
190 		setPosition((Point3f) s.readObject());
191 		setAttenuation((Point3f) s.readObject());
192 		setDirection((Vector3f) s.readObject());
193 		setSpreadAngle(s.readFloat());
194 		setConcentration(s.readFloat());
195 
196 		initialize();
197     }
198 
199     /***
200      * Serialization methods
201      */
202     private void writeObject(ObjectOutputStream s) throws IOException {
203 		s.writeBoolean(getEnable());
204 
205 		getColor(this.color);
206 		s.writeObject(this.color);
207 
208 		getPosition(this.tmpP);
209 		s.writeObject(this.tmpP);
210 
211 		getAttenuation(this.tmpP);
212 		s.writeObject(this.tmpP);
213 
214 		getDirection(this.tmpV);
215 		s.writeObject(this.tmpV);
216 
217 		s.writeFloat(getSpreadAngle());
218 		s.writeFloat(getConcentration());		
219     }
220 }// SpotLight