34 #include <libFreeWRL.h>
36 #include "../vrml_parser/Structs.h"
37 #include "../main/headers.h"
38 #include "../opengl/OpenGL_Utils.h"
39 #include "RenderFuncs.h"
41 #include "LinearAlgebra.h"
43 #define RETURN_IF_LIGHT_STATE_NOT_US \
44 if (renderstate()->render_light== VF_globalLight) { \
45 if (!node->global) return;\
47 } else if (node->global) return; \
50 #define CHBOUNDS(aaa) \
51 if (aaa.c[0]>1.0) aaa.c[0] = 1.0; \
52 if (aaa.c[0]<0.0) aaa.c[0] = 0.0; \
53 if (aaa.c[1]>1.0) aaa.c[1] = 1.0; \
54 if (aaa.c[1]<0.0) aaa.c[1] = 0.0; \
55 if (aaa.c[2]>1.0) aaa.c[2] = 1.0; \
56 if (aaa.c[2]<0.0) aaa.c[3] = 0.0;
62 vec.x = (double) -((node->direction).c[0]);
63 vec.y = (double) -((node->direction).c[1]);
64 vec.z = (double) -((node->direction).c[2]);
65 normalize_vector(&vec);
66 node->_dir.c[0] = (float) vec.x;
67 node->_dir.c[1] = (
float) vec.y;
68 node->_dir.c[2] = (float) vec.z;
69 node->_dir.c[3] = 0.0f;
71 node->_col.c[0] = ((node->color).c[0]) * (node->intensity);
72 node->_col.c[1] = ((node->color).c[1]) * (node->intensity);
73 node->_col.c[2] = ((node->color).c[2]) * (node->intensity);
78 node->_amb.c[0] = ((node->color).c[0]) * (node->ambientIntensity);
79 node->_amb.c[1] = ((node->color).c[1]) * (node->ambientIntensity);
80 node->_amb.c[2] = ((node->color).c[2]) * (node->ambientIntensity);
89 RETURN_IF_LIGHT_STATE_NOT_US
110 int light = nextlight();
112 float pos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
113 setLightState(light,TRUE);
114 setLightType(light,2);
115 FW_GL_LIGHTFV(light, GL_SPOT_DIRECTION, (GLfloat* )node->_dir.c);
116 FW_GL_LIGHTFV(light, GL_POSITION, (GLfloat* )pos);
117 FW_GL_LIGHTFV(light, GL_DIFFUSE, node->_col.c);
118 FW_GL_LIGHTFV(light, GL_SPECULAR, node->_col.c);
119 FW_GL_LIGHTFV(light, GL_AMBIENT, node->_amb.c);
122 setLightChangedFlag(light);
130 if (!renderstate()->render_light)
return;
131 render_DirectionalLight(node);
137 for (i=0; i<3; i++) node->_loc.c[i] = node->location.c[i];
138 node->_loc.c[3] = 1.0f;
142 node->_col.c[0] = ((node->color).c[0]) * (node->intensity);
143 node->_col.c[1] = ((node->color).c[1]) * (node->intensity);
144 node->_col.c[2] = ((node->color).c[2]) * (node->intensity);
146 CHBOUNDS(node->_col);
149 node->_amb.c[0] = ((node->color).c[0]) * (node->ambientIntensity);
150 node->_amb.c[1] = ((node->color).c[1]) * (node->ambientIntensity);
151 node->_amb.c[2] = ((node->color).c[2]) * (node->ambientIntensity);
153 CHBOUNDS(node->_amb);
178 RETURN_IF_LIGHT_STATE_NOT_US
198 int light = nextlight();
200 float vec[4] = {0.0f, 0.0f, -1.0f, 1.0f};
202 setLightState(light,TRUE);
203 setLightType(light,0);
204 FW_GL_LIGHTFV(light, GL_SPOT_DIRECTION, vec);
205 FW_GL_LIGHTFV(light, GL_POSITION, node->_loc.c);
207 FW_GL_LIGHTF(light, GL_CONSTANT_ATTENUATION,
208 ((node->attenuation).c[0]));
209 FW_GL_LIGHTF(light, GL_LINEAR_ATTENUATION,
210 ((node->attenuation).c[1]));
211 FW_GL_LIGHTF(light, GL_QUADRATIC_ATTENUATION,
212 ((node->attenuation).c[2]));
215 FW_GL_LIGHTFV(light, GL_DIFFUSE, node->_col.c);
216 FW_GL_LIGHTFV(light, GL_SPECULAR, node->_col.c);
217 FW_GL_LIGHTFV(light, GL_AMBIENT, node->_amb.c);
222 FW_GL_LIGHTF(light,GL_LIGHT_RADIUS,node->radius);
223 setLightChangedFlag(light);
231 if (!renderstate()->render_light)
return;
233 render_PointLight(node);
241 for (i=0; i<3; i++) node->_loc.c[i] = node->location.c[i];
242 node->_loc.c[3] = 1.0f;
244 vec.x = (
double) node->direction.c[0];
245 vec.y = (double) node->direction.c[1];
246 vec.z = (
double) node->direction.c[2];
247 dlen = veclength(vec);
249 vec.x = 0.0; vec.y = 0.0, vec.z = -1.0;
251 normalize_vector(&vec);
252 node->_dir.c[0] = (float) vec.x;
253 node->_dir.c[1] = (
float) vec.y;
254 node->_dir.c[2] = (float) vec.z;
255 node->_dir.c[3] = 1.0f;
257 node->_col.c[0] = ((node->color).c[0]) * (node->intensity);
258 node->_col.c[1] = ((node->color).c[1]) * (node->intensity);
259 node->_col.c[2] = ((node->color).c[2]) * (node->intensity);
261 CHBOUNDS(node->_col);
264 node->_amb.c[0] = ((node->color).c[0]) * (node->ambientIntensity);
265 node->_amb.c[1] = ((node->color).c[1]) * (node->ambientIntensity);
266 node->_amb.c[2] = ((node->color).c[2]) * (node->ambientIntensity);
268 CHBOUNDS(node->_amb);
278 RETURN_IF_LIGHT_STATE_NOT_US
283 int light = nextlight();
285 setLightState(light,TRUE);
286 setLightType(light,1);
287 FW_GL_LIGHTFV(light, GL_SPOT_DIRECTION, node->_dir.c);
288 FW_GL_LIGHTFV(light, GL_POSITION, node->_loc.c);
290 FW_GL_LIGHTF(light, GL_CONSTANT_ATTENUATION,
291 ((node->attenuation).c[0]));
292 FW_GL_LIGHTF(light, GL_LINEAR_ATTENUATION,
293 ((node->attenuation).c[1]));
294 FW_GL_LIGHTF(light, GL_QUADRATIC_ATTENUATION,
295 ((node->attenuation).c[2]));
297 FW_GL_LIGHTFV(light, GL_DIFFUSE, node->_col.c);
298 FW_GL_LIGHTFV(light, GL_SPECULAR, node->_col.c);
299 FW_GL_LIGHTFV(light, GL_AMBIENT, node->_amb.c);
302 ft = cosf(node->beamWidth);
303 FW_GL_LIGHTF(light, GL_SPOT_BEAMWIDTH,ft);
308 ft = cosf(node->cutOffAngle);
309 FW_GL_LIGHTF(light, GL_SPOT_CUTOFF, ft);
310 setLightChangedFlag(light);
317 if (!renderstate()->render_light)
return;
318 render_SpotLight(node);
322 void pushLocalLight(
int lastlight);
323 void popLocalLight();
326 void sib_prep_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
329 if ( renderstate()->render_light != VF_globalLight){
330 saveLightState2(&lastlight);
331 pushLocalLight(lastlight);
335 void sib_prep_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
337 if ( renderstate()->render_light != VF_globalLight){
338 saveLightState2(&lastlight);
339 pushLocalLight(lastlight);
344 void sib_prep_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
346 if ( renderstate()->render_light != VF_globalLight){
347 saveLightState2(&lastlight);
348 pushLocalLight(lastlight);
354 void sib_fin_DirectionalLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
356 if ( renderstate()->render_light != VF_globalLight) {
357 lastlight = getLocalLight();
358 if(numberOfLights() > lastlight) {
359 setLightChangedFlag(numberOfLights()-1);
360 refreshLightUniforms();
362 restoreLightState2(lastlight);
366 void sib_fin_SpotlLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
368 if (renderstate()->render_light != VF_globalLight) {
369 lastlight = getLocalLight();
370 if(numberOfLights() > lastlight) {
371 setLightChangedFlag(numberOfLights()-1);
372 refreshLightUniforms();
374 restoreLightState2(lastlight);
378 void sib_fin_PointLight(
struct X3D_Node *parent,
struct X3D_Node *sibAffector){
380 if (renderstate()->render_light != VF_globalLight) {
381 lastlight = getLocalLight();
382 if(numberOfLights() > lastlight) {
383 setLightChangedFlag(numberOfLights()-1);
384 refreshLightUniforms();
387 restoreLightState2(lastlight);