DI-Guy SDK Documentation  13.7.1
diguyViewLight.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2022 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
6 /*********************************************************************/
12 #pragma once
13 
14 #ifdef SWIG
15 %module diguyViewLight
16 #else
17 #define CPLUSPLUS_ONLY
18 #endif
19 
20 #ifdef CPLUSPLUS_ONLY
21 class bdiLight;
22 class diguyViewLight;
24 
25 #include <stdio.h> // for NULL definition
26 #include <diguy_constants.h>
27 #include <diguy_typedefs.h>
28 
29 #endif
30 #include <declspec_diguy.h>
31 
32 /****************************************************************************/
35 struct BDI_DECLSPEC_diguy diguyLightRenderDesc
36 {
37  diguyLightRenderDesc() : m_radius(1.0f), m_spot_angle(0.0f), m_spot_exponent(1.0f), m_falloff_r(.1f), m_falloff_rsq(.1f)
38  {
39  }
40  double m_position[4];
41  float m_radius;
42  float m_direction[4];
43  float m_diffuse[3];
44  float m_ambient[3];
45  float m_specular[3];
46  float m_falloff_r;
47  float m_falloff_rsq;
48  float m_spot_angle;
49  float m_spot_exponent;
50 
51 };
52 
62 class BDI_DECLSPEC_diguy diguyViewLight
63 {
64 
65 public:
66 
67 /*****************************************************************************/
77  /*l
78  *b Description:
79  **
80  ** Returns the name of the object. This pointer will
81  ** never be NULL.
82  **
83  *b Returns:
84  **
85  ** name of the object
86  */
87  const char* get_name();
88 
89  /*l
90  *b Description:
91  **
92  ** Returns the type name of the object. This pointer will
93  ** never be NULL.
94  **
95  *b Returns:
96  **
97  ** type name of the object
98  */
99  const char* get_type_name();
100 
101  /*l
102  *b Description:
103  **
104  ** This function sets the direction of this light.
105  **
106  *b Arguments:
107  **
108  *a x,y,z - x,y,z direction, in meters
109  */
110  void set_direction(float x, float y, float z);
111 
112  /*l
113  *b Description:
114  **
115  ** This function gets the direction of this light.
116  ** Values are returned via the passed pointers.
117  **
118  *b Arguments:
119  **
120  *a x,y,z - x,y,z direction, in meters
121  */
122  void get_direction(float* x, float* y, float* z);
123 
124  /*l
125  *b Description:
126  **
127  ** This function sets the position of this light.
128  **
129  *b Arguments:
130  **
131  *a x,y,z - x,y,z position, in meters
132  */
133  void set_position(float x, float y, float z);
134 
135  /*l
136  *b Description:
137  **
138  ** This function gets the position of this light.
139  ** Values are returned via the passed pointers.
140  **
141  *b Arguments:
142  **
143  *a x,y,z - x,y,z position, in meters
144  */
145  void get_position(float* x, float* y, float* z);
146 
147  /*l
148  *b Description:
149  **
150  ** This function sets the ambient color.
151  **
152  *b Arguments:
153  **
154  *a r,g,b,a - red, green, blue, alpha components
155  */
156  void set_ambient_color(float r, float g, float b, float a);
157 
158  /*l
159  *b Description:
160  **
161  ** This function gets the ambient color of this light.
162  ** Values are returned via the passed pointers.
163  **
164  *b Arguments:
165  **
166  *a r,g,b,a - red, green, blue, alpha components
167  */
168  void get_ambient_color(float* r, float* g, float* b, float* a);
169 
170  /*l
171  *b Description:
172  **
173  ** This function sets the diffuse color.
174  **
175  *b Arguments:
176  **
177  *a r,g,b,a - red, green, blue, alpha components
178  */
179  void set_diffuse_color(float r, float g, float b, float a);
180 
181  /*l
182  *b Description:
183  **
184  ** This function gets the diffuse color of this light.
185  ** Values are returned via the passed pointers.
186  **
187  *b Arguments:
188  **
189  *a r,g,b,a - red, green, blue, alpha components
190  */
191  void get_diffuse_color(float* r, float* g, float* b, float* a);
192 
193  /*l
194  *b Description:
195  **
196  ** This function sets the specular color.
197  **
198  *b Arguments:
199  **
200  *a r,g,b,a - red, green, blue, alpha components
201  */
202  void set_specular_color(float r, float g, float b, float a);
203 
204  /*l
205  *b Description:
206  **
207  ** This function gets the specular color of this light.
208  ** Values are returned via the passed pointers.
209  **
210  *b Arguments:
211  **
212  *a r,g,b,a - red, green, blue, alpha components
213  */
214  void get_specular_color(float* r, float* g, float* b, float* a);
215 
217  int get_casts_shadows();
218 
220  int set_scene_objects_cast_shadows(int value);
221  int get_scene_objects_cast_shadows();
222 
225  int set_brightness_multiplier(float multiplier);
226  float get_brightness_multiplier();
227 
229  void set_spot_exponent(float exponent);
230  float get_spot_exponent();
231 
233  void set_falloff_const(float falloff_const);
234  float get_falloff_const();
235 
237  void set_falloff_rsq(float falloff_rsq);
238  float get_falloff_rsq();
239 
240 
241 /*****************************************************************************/
251  /*l
252  *b Description:
253  **
254  ** Loads the specified settings into this light.
255  **
256  *b Returns:
257  **
258  ** 0 on success, -1 on failure
259  */
260  int load_settings(const char* settings_name);
261 
262  /*l
263  *b Description:
264  **
265  ** Loads the specified settings into this light.
266  **
267  *b Returns:
268  **
269  ** 0 on success, -1 on failure
270  */
271  int load_settings(diguyViewLightSettings* settings);
272 
273  /*l
274  *b Description:
275  **
276  ** Applies the light to OpenGL state. Currently DI-Guy only supports
277  ** one light in it's default OpenGL implementation.
278  **
279  ** At least one light must be applied for advanced DI-Guy reference
280  ** shaders to work.
281  */
282  void apply(int i = 0);
283 
284 
285 /*****************************************************************************/
291  /*l
292  *b Description:
293  **
294  ** This is an enumeration of the different callbacks
295  ** that can be registered with add_callback() and
296  ** add_callback_script().
297  **
298  *b Usable From:
299  **
300  *- - C++
301  *- - Script
302  */
303  enum {
304  CALLBACK_ID_SETTINGS_CHANGED = 1
305  };
306 
307 #ifdef CPLUSPLUS_ONLY
308 
309  /*l
310  *b Description:
311  **
312  ** This function adds a user callback.
313  **
314  *b Arguments:
315  **
316  *a callback - pointer to function with prototype
317  *a diguyViewLightCallback (typedefed above)
318  *a callback_id - integer id of when this callback is to be called
319  *a callback_params - struct containing additional parameters
320  *a needed by some callbacks; actual type depends
321  *a on callback_id
322  *a callback_user_data - pointer for user's own use; DI-Guy will
323  *a do nothing to the contents of this pointer
324  *a beyond passing it back when the callback is
325  *a invoked
326  **
327  ** callback_id should be one of the following values:
328  **
329  *i CALLBACK_ID_SETTINGS_CHANGED
330  **
331  ** This callback will be called if the current settings of this
332  ** light change
333  **
334  ** Callbacks return a value of type diguyCallbackReturn,
335  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
336  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
337  ** of the function will not be called; the callback is asserting
338  ** that it has done everything necessary for the function call.
339  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
340  ** handler for the function will be called after the callback.
341  **
342  *b Returns:
343  **
344  ** 0 on success, -1 on failure
345  **
346  *b Callable From:
347  **
348  *- - C++
349  */
350  int add_callback(int callback_id,
351  diguyViewLightCallback* callback,
352  void* callback_params = 0,
353  void* callback_user_data = 0);
354 
355  /*l
356  *b Description:
357  **
358  ** This function removes a user callback. All callbacks matching
359  ** the specified callback_id and callback function will be removed.
360  **
361  *b Arguments:
362  **
363  *a callback_id - integer id of when this callback is to be called
364  *a callback - pointer to function with prototype
365  *a diguyViewLightCallback (typedefed above)
366  **
367  *b Returns:
368  **
369  ** 0 on success, -1 on failure
370  **
371  *b Callable From:
372  **
373  *- - C++
374  */
375  int remove_callback(int callback_id,
376  diguyViewLightCallback* callback);
377 
378  /*l
379  *b Description:
380  **
381  ** This function removes a user callback. All callbacks matching
382  ** the specified callback_id and callback_user_data pointer will
383  ** be removed.
384  **
385  *b Arguments:
386  **
387  *a callback_id - integer id of when this callback is to be called
388  *a callback_user_data - pointer for user's own use
389  **
390  *b Returns:
391  **
392  ** 0 on success, -1 on failure
393  **
394  *b Callable From:
395  **
396  *- - C++
397  */
398  int remove_callback_with_user_data(int callback_id,
399  void* callback_user_data);
400 
401 #endif
402 
403  /*l
404  *b Description:
405  **
406  ** This function adds a user callback script. Callback scripts can
407  ** be removed with remove_callback_script().
408  **
409  *b Arguments:
410  **
411  *a callback_id - integer id of the callback
412  *a callback_script - script text of callback to be added
413  *a callback_script_type - the type of script contained in
414  *a callback_script
415  **
416  ** If NULL is passed for callback_script_type, a default script type
417  ** will be derived based on the default script interpreter of the
418  ** scenario.
419  **
420  *i lua specific:
421  **
422  ** When the script is called, the object for which it is being called
423  ** will be in the callback_object global.
424  **
425  ** To pass NULL when calling from a lua script, use nil.
426  **
427  *b Returns:
428  **
429  ** 0 on success, -1 on failure
430  **
431  *b Callable From:
432  **
433  *- - C++
434  *- - Script
435  */
436  int add_callback_script(int callback_id,
437  const char* callback_script,
438  const char* callback_script_type = NULL);
439 
440  /*l
441  *b Description:
442  **
443  ** This function removes a user callback script previously added with
444  ** add_callback_script().
445  **
446  *b Arguments:
447  **
448  *a callback_id - integer id of the callback
449  *a callback_script - script text of callback previously added
450  *a callback_script_type - the type of script contained in
451  *a callback_script
452  **
453  ** If NULL is passed for callback_script, all callback
454  ** scripts whose ids match callback_id and whose types match
455  ** callback_script_type will be removed.
456  **
457  ** If NULL is passed for callback_script_type, a default script type
458  ** will be derived based on the default script interpreter of the
459  ** scenario.
460  **
461  *i lua specific:
462  **
463  ** To pass NULL when calling from a lua script, use nil.
464  **
465  *b Returns:
466  **
467  ** 0 on success, -1 on failure
468  **
469  *b Callable From:
470  **
471  *- - C++
472  *- - Script
473  */
474  int remove_callback_script( int callback_id, const char* callback_script,
475  const char* callback_script_type = NULL );
476 
477 
478 /****************************************************************************/
479 /****************************************************************************/
480 /****************************************************************************/
487 /****************************************************************************/
488 /****************************************************************************/
489 /****************************************************************************/
490 
491  /*l
492  *b Description:
493  **
494  ** Sets if a light will cast shadow; this will only work in DI-Guy Scenario.
495  */
496  void set_casts_shadows( int casts_shadows, bool clear_shadow_map = false );
497 
500  void set_shadow_volume_size( float volume );
501  float get_shadow_volume_size();
502 
505  void set_shadow_offset_multiplier( float multiplier );
506  float get_shadow_offset_multiplier();
507 
509  void set_spotlight_angle( float angle );
510  float get_spotlight_angle();
511 
513  void bind_shadow_map( int shadow_map_size );
514  void clear_shadow_map();
515  void unbind_shadow_map();
516 
517 
519  void set_active(int active);
520  int get_active();
521 
522  // runtime values
523  int set_shadow_map_update_paused(int pause);
524  int get_shadow_map_update_paused();
525 
526  int set_shadow_map_update_frequency(int frame_frequency);
527  int get_shadow_map_update_frequency();
528 
529  // unused
530  void set_near_plane(float near_plane);
531  float get_near_plane();
532 
533  void set_far_plane(float far_plane);
534  float get_far_plane();
535 
540 #ifdef CPLUSPLUS_ONLY
541 
542  bdiLight* get_scripted_object() {return m_light;}
543 
544 private:
545 
547  diguyViewLight( bdiLight* light );
548 
549 private:
550 
551  bdiLight* m_light;
552  friend class bdiLight;
553 
554 #endif
555 
556 };
The diguyViewLightSettings class holds camera settings data that can be loaded into a diguyViewLight ...
Definition: diguyViewLightSettings.h:45
The diguyViewLight provides a interface around a scene light useful in diguy scenario and the opengl ...
Definition: diguyViewLight.h:60
This class is a simple structure for transmitting diguy lights down to the uniform buffer system this...
Definition: diguyViewLight.h:34
diguyCallbackReturn diguyViewLightCallback(diguyViewLight *light, int callback_id, void *callback_params, void *callback_user_data)
Definition: diguy_typedefs.h:181