Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package min3d.vos;

import java.nio.FloatBuffer;

import min3d.Utils;
import min3d.interfaces.IDirtyParent;

/**
 * Light must be added to Scene to take effect.
 * 
 * Eg, "scene.lights().add(myLight);"  
 */
public class Light extends AbstractDirtyManaged implements IDirtyParent
{
	/**
	 * Position is relative to eye space, not world space.
	 */
	public Number3dManaged 		position;
	
	/**
	 * Direction is a vector and should be normalized.
	 */
	public Number3dManaged 		direction;  
	
	public Color4Managed 		ambient;
	public Color4Managed 		diffuse;
	public Color4Managed 		specular;
	public Color4Managed 		emissive;
	
	private LightType			_type;

	public Light()
	{
		super(null);
		
		 ambient = new Color4Managed(128,128,128, 255, this);
		 diffuse = new Color4Managed(255,255,255, 255, this);
		 specular = new Color4Managed(0,0,0,255, this);
		 emissive = new Color4Managed(0,0,0,255, this);
		 
		 position = new Number3dManaged(0f, 0f, 1f, this); 			
		 
		 direction = new Number3dManaged(0f, 0f, -1f, this);	
		 _spotCutoffAngle = new FloatManaged(180, this);		
		 _spotExponent = new FloatManaged(0f, this);			
		 
		 _attenuation = new Number3dManaged(1f,0f,0f, this); 	
		 
		 _type = LightType.DIRECTIONAL;								
		 
		 _isVisible = new BooleanManaged(true, this);
		 
		 _positionAndTypeBuffer = Utils.makeFloatBuffer4(0,0,0,0);
		 
		 setDirtyFlag();
	}

	public boolean isVisible()
	{
		return _isVisible.get();
	}
	public void isVisible(Boolean $b)
	{
		_isVisible.set($b);
	}
	
	/**
	 * Default is DIRECTIONAL, matching OpenGL's default value.
	 */
	public LightType type()
	{
		return _type;
	}
	
	public void type(LightType $type)
	{
		_type = $type;
		position.setDirtyFlag(); // .. position and type share same data structure
	}
	
	/**
	 * 0 = no attenuation towards edges of spotlight. Max is 128.
	 * Default is 0, matching OpenGL's default value.
	 */
	public float spotExponent()
	{
		return _spotExponent.get();
	}
	public void spotExponent(float $f)
	{
		if ($f < 0) $f = 0;
		if ($f > 128) $f = 128;
		_spotExponent.set($f);
	}
	
	/**
	 * Legal range is 0 to 90, plus 180, which is treated by OpenGL to mean no cutoff.
	 * Default is 180, matching OpenGL's default value.
	 */
	public float spotCutoffAngle()
	{
		return _spotCutoffAngle.get();
	}
	public void spotCutoffAngle(Float $f)
	{
		if ($f < 0) 
			_spotCutoffAngle.set(0);
		else if ($f <= 90)
			_spotCutoffAngle.set($f);
		else if ($f == 180)
			_spotCutoffAngle.set($f);
		else
			_spotCutoffAngle.set(90);
	}
	
	/**
	 * No cutoff angle (ie, no spotlight effect)
	 * (represented internally with a value of 180)
	 */
	public void spotCutoffAngleNone()
	{
		_spotCutoffAngle.set(180);
	}
	
	public float attenuationConstant()
	{
		return _attenuation.getX();
	}
	public void attenuationConstant(float $normalizedValue)
	{
		_attenuation.setX($normalizedValue);
		setDirtyFlag();
	}
	
	public float attenuationLinear()
	{
		return _attenuation.getY();
	}
	public void attenuationLinear(float $normalizedValue)
	{
		_attenuation.setY($normalizedValue);
		setDirtyFlag();
	}
	
	public float attenuationQuadratic()
	{
		return _attenuation.getZ();
	}
	public void attenuationQuadratic(float $normalizedValue)
	{
		_attenuation.setZ($normalizedValue);
		setDirtyFlag();
	}
	
	/**
	 * Defaults are 1,0,0 (resulting in no attenuation over distance), 
	 * which match OpenGL default values. 
	 */
	public void attenuationSetAll(float $constant, float $linear, float $quadratic)
	{
		_attenuation.setAll($constant, $linear, $quadratic);
		setDirtyFlag();
	}

	//
	
	public void setAllDirty()
	{
		position.setDirtyFlag();
		ambient.setDirtyFlag();
		diffuse.setDirtyFlag();
		specular.setDirtyFlag();
		emissive.setDirtyFlag();
		direction.setDirtyFlag();
		_spotCutoffAngle.setDirtyFlag();
		_spotExponent.setDirtyFlag();
		_attenuation.setDirtyFlag();
		_isVisible.setDirtyFlag();
	}

	public void onDirty()
	{
		setDirtyFlag();
	}
	
	/**
	 * Used by Renderer
	 * Normal clients of this class should use "isVisible" getter/setter.
	 */
	public BooleanManaged _isVisible;

	/**
	 * Used by Renderer
	 */
	public FloatBuffer _positionAndTypeBuffer;

	/**
	 * Used by Renderer
	 */
	public void commitPositionAndTypeBuffer()
	{
		// GL_POSITION takes 4 arguments, the first 3 being x/y/z position, 
		// and the 4th being what we're calling 'type' (positional or directional)
		
		_positionAndTypeBuffer.position(0);
		_positionAndTypeBuffer.put(position.getX());
		_positionAndTypeBuffer.put(position.getY());
		_positionAndTypeBuffer.put(position.getZ());
		_positionAndTypeBuffer.put(_type.glValue());
		_positionAndTypeBuffer.position(0);
	}
	
	/**
	 * Used by Renderer. 
	 * Normal clients of this class should use "useSpotProperties" getter/setter.
	 */
	public FloatManaged _spotExponent; 

	/**
	 * Used by Renderer. Normal clients of this class should use "useSpotProperties" getter/setter.
	 */
	public FloatManaged _spotCutoffAngle;
	
	/**
	 * Used by Renderer. Normal clients of this class should use attenuation getter/setters.
	 */
	public Number3dManaged _attenuation; // (the 3 properties of N3D used for the 3 attenuation properties)
}

Commits for Nextrek/Android/LibrerieNextrek/src/min3d/vos/Light.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000