View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class DirectionalLight
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: DirectionalLight.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 DirectionalLight               
37  ====================================================================*/
38  /***
39   * net.jbeans.j3d.light.DirectionalLight is a JavaBeanized
40   * javax.media.j3d.DirectionalLight
41   * 
42   * @version $Revision: 1.3 $
43   * @author Masahiro Takatsuka (masa@jbeans.net)
44   * @see javax.media.j3d.DirectionalLight
45   * @see Serializable
46   */
47  
48  public final class DirectionalLight extends javax.media.j3d.DirectionalLight implements Serializable {
49  	transient private Vector3f dir = new Vector3f();
50  	
51  	/* for Light */
52  	transient private Color3f color;
53  
54      public DirectionalLight() {
55  		this(true, LightUtil.WHITE, LightUtil.DEFAULT_DIRECTION);
56      }
57  
58      public DirectionalLight(Color3f color3f, Vector3f direction) {
59          this(true, color3f, direction);
60      }
61  
62      public DirectionalLight(boolean lightOn, Color3f color3f, Vector3f direction) {
63          super(lightOn, color3f, direction);
64  
65  		setEnable(true);		// turn it on as default.
66  		this.color = new Color3f();
67  		
68  		initialize();
69      }
70  
71  	private final void initialize() {
72  		setCapabilities();
73  	}
74  
75  	private final void setCapabilities() {
76  		setInfluencingBounds(J3DUtil.DEFAULT_BOUNDS);
77  
78  		/* -------------------- from DirectionalLight --------------------- */
79  		setCapability(DirectionalLight.ALLOW_DIRECTION_READ);		
80  		setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE);
81  		
82  		/* ----------------------- from Light.class ----------------------- */
83  		setCapability(Light.ALLOW_COLOR_READ);
84  		setCapability(Light.ALLOW_COLOR_WRITE);
85  		
86  		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
87  		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
88  
89  		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ);
90  		setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
91  
92  		setCapability(Light.ALLOW_SCOPE_READ);
93  		setCapability(Light.ALLOW_SCOPE_WRITE);
94  
95  		setCapability(Light.ALLOW_STATE_READ);
96  		setCapability(Light.ALLOW_STATE_WRITE);
97  		
98  		/* ----------------------- from Node.class ------------------------ */
99  		setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
100 		setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE);		
101 
102 		setCapability(Node.ALLOW_BOUNDS_READ);
103 		setCapability(Node.ALLOW_BOUNDS_WRITE);		
104 		
105 		setCapability(Node.ALLOW_COLLIDABLE_READ);
106 		setCapability(Node.ALLOW_COLLIDABLE_WRITE);		
107 
108 		setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
109 
110 		setCapability(Node.ALLOW_PICKABLE_READ);
111 		setCapability(Node.ALLOW_PICKABLE_WRITE);		
112 	}
113 
114 	public void setColor(Color color) {
115 		if (this.color == null) {
116 			this.color = new Color3f(color);
117 		} else {
118 			this.color.set(color);
119 		}
120 		setColor(this.color);
121 	}
122 
123 	public Color getColor() {
124 		if (this.color == null) {
125 			this.color = new Color3f();
126 		}
127 		getColor(this.color);
128 
129 		return new Color(this.color.x, this.color.y, this.color.z);
130 	}
131 
132 	public Vector3f getDirection() {
133 		Vector3f vec = new Vector3f();
134 		getDirection(vec);
135 
136 		return vec;
137 	}
138 
139 	public void setDirection(float x, float y, float z) {
140 		this.dir.set(x, y, z);
141 		setDirection(this.dir);
142 	}
143 	
144 	public Light getDirectionalLight() {
145 		return this;
146 	}
147 
148     /***
149      * Serialization methods
150      */
151     private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
152 		setEnable(s.readBoolean());
153 		setColor((Color3f) s.readObject());
154 		setDirection((Vector3f) s.readObject());
155 
156 		initialize();
157     }
158 
159     /***
160      * Serialization methods
161      */
162     private void writeObject(ObjectOutputStream s) throws IOException {
163 		s.writeBoolean(getEnable());
164 
165 		getColor(this.color);
166 		s.writeObject(this.color);
167 
168 		getDirection(this.dir);
169 		s.writeObject(this.dir);
170     }
171 }// DirectionalLight