njSetUserLight Japanese
<-|INDEX|->
Assigns a user-defined light function to a light.

FORMAT

#include <NINJA.H> 
void njSetUserLight( *ptr, func )
NJS_LIGHT *ptr
NJF_LIGHT_FUNC func

PARAMETERS

*ptr
light pointer
func
name of callback function (pointer)

RETURN VALUE

None

ERROR VALUE

None

FUNCTION

Sets a user-defined light function by assigning a light source created with njCreateLight to NJD_USER_LIGHT.

EXAMPLE

#include <NINJA.H> 
...........

NJS_LIGHT light;

void
func(NJS_ARGB* argb, NJS_POINT3* pnt, NJS_VECTOR* nml, NJS_LIGHT* lt)
{
.......
   /*
    *  Example of inner sum of polygon normal line 
    *  and light beam direction 
    */

      deg = - nml->x * NJM_LIGHT_VECTOR(lt). x
      - nml->y * NJM_LIGHT_VECTOR(lt).y
      - nml->z * NJM_LIGHT_VECTOR(lt).z;
 .......
 /* argb */
      argb->a = deg * NJM_LIGHT_DIF(lt).a;
      argb->r = deg * NJM_LIGHT_DIF(lt).r;
      argb->g = deg * NJM_LIGHT_DIF(lt).g;
      argb->b = deg * NJM_LIGHT_DIF(lt).b;
}

/* In main routine */
.......
njInitSystem();
njCreateLight(&light,  NJD_USER_LIGHT);

/* Set user function func to light lt */
njSetUserLight (&light, func);
...........

NOTES

The NJD_USER_LIGHT light must be selected with njCreateLight.
Light functions definable by the user and macros that are used thereby are as follows.
1.Callback functions
<FORMAT>
func(argb, pnt, nml, ptr)
  NJS_ARGB   *argb
  NJS_POINT3 *pnt
  NJS_VECTOR *nml
  NJS_LIGHT  *ptr

<Parameters>
*argb
Pointer after calculation
*pnt
Polygon position vector pointer
*nml
Polygon normal line vector pointer
*ptr
Light pointer set by njCreateLight
2.Macros (with NJS_LIGHT *ptr)

NJM_LIGHT_VECTOR(ptr)
Current light direction: NJS_VECTOR. This is referenced as NJM_LIGHT_VECTOR(ptr).x.

NJM_LIGHT_POINT(ptr)
Current light position: NJS_POINT3. This is referenced as NJM_LIGHT_POINT(ptr).x.

NJM_LIGHT_AMB(ptr)
Ambient light intensity: NJS_ARGB. This normally has a value in the range 0 to 1.f; however, values greater than 1.f are possible. This is referenced as NJM_LIGHT_AMB(ptr).r.

NJM_LIGHT_DIF(ptr
Diffuse light intensity: NJS_ARGB. This normally has a value in the range 0 to 1.f; however, values greater than 1.f are possible. This is referenced as NJM_LIGHT_DIF(ptr).r.

NJM_LIGHT_SPC(ptr)
Specular light intensity: NJS_ARGB. This normally has a value in the range 0 to 1.f; however, values greater than 1.f are possible. This is referenced as NJM_LIGHT_SPC(ptr).r.

NJM_LIGHT_EXP(ptr)
Index: Part of the information contained in the object data; an integer. This provides the specular diffusion. The relationship to SOFTIMAGE is listed below.
NINJA : SOFTIMAGE
  0    :     0
  1    :     1
  2    :     2
  3    :     3
  4    :     4
  5    :     6
  6    :     8
  7    :    12
  8    :    16
  9    :    24
 10    :    32
 11    :    48
 12    :    64
 13    :    96
 14    :   128
 15    :   192
 16    :   256

NJM_LIGHT_COLOR(ptr)
Light color: NJS_ARGB. This provides the light color.

NJM_LIGHT_INIT_VECTOR(ptr)
Light direction before matrix calculation: NJS_VECTOR. This is the initial direction before matrix calculation.

NJM_LIGHT_INIT_POINT(ptr)
Light position before matrix calculation: NJS_POINT3. This is the initial position before matrix calculation.

NJM_LIGHT_MATRIX(ptr)
Light position before matrix calculation. This is the light matrix.

RELATED TOPICS

njCreateLight()

njSetUserLight
<-|INDEX|->

Copyright SEGA ENTERPRISES, LTD., 1997