1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
37
38 /***
39 * net.jbeans.j3d.light.PointLight is a JavaBeanized
40 * javax.media.j3d.PointLight
41 *
42 * @version $Revision: 1.3 $
43 * @author Masahiro Takatsuka (masa@jbeans.net)
44 * @see javax.media.j3d.PointLight
45 * @see Serializable
46 */
47
48 public final class PointLight extends javax.media.j3d.PointLight implements Serializable {
49 transient private Point3f tmp = new Point3f();
50
51
52 transient private Color3f color;
53
54 public PointLight() {
55 this(true, LightUtil.WHITE,
56 LightUtil.DEFAULT_POSITION,
57 LightUtil.DEFAULT_ATTENUATION);
58 }
59
60 public PointLight(Color3f color3f, Point3f position, Point3f attenuation) {
61 this(true, color3f, position, attenuation);
62 }
63
64 public PointLight(boolean lightOn, Color3f color3f, Point3f position, Point3f attenuation) {
65 super(lightOn, color3f, position, attenuation);
66 setEnable(true);
67 this.color = new Color3f();
68
69 initialize();
70 }
71
72 private final void initialize() {
73 setCapabilities();
74 }
75
76 private final void setCapabilities() {
77 setInfluencingBounds(J3DUtil.DEFAULT_BOUNDS);
78
79
80 setCapability(PointLight.ALLOW_POSITION_READ);
81 setCapability(PointLight.ALLOW_POSITION_WRITE);
82 setCapability(PointLight.ALLOW_ATTENUATION_READ);
83 setCapability(PointLight.ALLOW_ATTENUATION_WRITE);
84
85
86 setCapability(Light.ALLOW_COLOR_READ);
87 setCapability(Light.ALLOW_COLOR_WRITE);
88
89 setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
90 setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
91
92 setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
93 setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
94
95 setCapability(Light.ALLOW_SCOPE_READ);
96 setCapability(Light.ALLOW_SCOPE_WRITE);
97
98 setCapability(Light.ALLOW_STATE_READ);
99 setCapability(Light.ALLOW_STATE_WRITE);
100
101
102 setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
103 setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE);
104
105 setCapability(Node.ALLOW_BOUNDS_READ);
106 setCapability(Node.ALLOW_BOUNDS_WRITE);
107
108 setCapability(Node.ALLOW_COLLIDABLE_READ);
109 setCapability(Node.ALLOW_COLLIDABLE_WRITE);
110
111 setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
112
113 setCapability(Node.ALLOW_PICKABLE_READ);
114 setCapability(Node.ALLOW_PICKABLE_WRITE);
115 }
116
117 public void setColor(Color color) {
118 if (this.color == null) {
119 this.color = new Color3f(color);
120 } else {
121 this.color.set(color);
122 }
123 setColor(this.color);
124 }
125
126 public Color getColor() {
127 if (this.color == null) {
128 this.color = new Color3f();
129 }
130 getColor(this.color);
131
132 return new Color(this.color.x, this.color.y, this.color.z);
133 }
134
135 public Point3f getPosition() {
136 Point3f pos = new Point3f();
137 getPosition(pos);
138 return pos;
139 }
140
141 public Point3f getAttenuation() {
142 Point3f att = new Point3f();
143 getAttenuation(att);
144 return att;
145 }
146
147 public void setPosition(float x, float y, float z) {
148 this.tmp.set(x, y, z);
149 setPosition(this.tmp);
150 }
151
152 public void setAttenuation(float x, float y, float z) {
153 this.tmp.set(x, y, z);
154 setAttenuation(this.tmp);
155 }
156
157 public Light getPointLight() {
158 return this;
159 }
160
161 /***
162 * Serialization methods
163 */
164 private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
165 setEnable(s.readBoolean());
166 setColor((Color3f) s.readObject());
167 setPosition((Point3f) s.readObject());
168 setAttenuation((Point3f) s.readObject());
169
170 initialize();
171 }
172
173 /***
174 * Serialization methods
175 */
176 private void writeObject(ObjectOutputStream s) throws IOException {
177 s.writeBoolean(getEnable());
178
179 getColor(this.color);
180 s.writeObject(this.color);
181
182 getPosition(this.tmp);
183 s.writeObject(this.tmp);
184
185 getAttenuation(this.tmp);
186 s.writeObject(this.tmp);
187 }
188 }