view_to_light (VIEW* view, var num,var mode);

Sets the given view to the position of a shadow throwing dynamic light, for rendering a scene from a light position. A7.64 Copies light data into the hit struct.

Parameters:

view - the view to be set to the light position, or NULL.
num - the light number from 1 = closest to 8 = furthest.
mode - CAST = consider only lights with a CAST flag; SPOTLIGHT = consider only spot lights.

Returns:

Number of lights yet to render that overlap with the frustum of the current view, including the current light (0..8).

Modifies:

view.x y z - set to the light position.
view.clip_near- set to 1.
view.clip_far - set to the light range.
view.pan tilt - set to the light angles if it is a spot or directional light; otherwise unaffected.
view.genius - set to the light emitting entity, or to NULL if it's a light placed in the level.
hit.x y z - set to the light position.
hit.nx ny nz - set to the light direction.
hit.blue green red - set to the light color.
hit.entity - set to the light emitting entity, or to NULL if it's a light placed in the level.
hit.model - pointer to the D3DLIGHT9 struct of the light.

Remarks:

Speed:

Slow when called the first time for the current view; fast in subsequent calls.

Edition:

A7.20  C   LC 

Example (lite-C):

// sets up to six views for rendering from a light position
// returns 0, 1, or 6 dependent on how many views are to render for this light
function shadowmap_view_setup(light_num)
{
  view_light_front.pan = -1; // for checking whether it's a spot light
  var num = view_to_light(view_light_front,light_num,CAST); // set view to the light position
  if (num == 0) return 0; // no further shadow throwing lights to render
  if (view_light_front.pan >= 0) return 1; // sun or spot light? render front view only
  view_light_front.pan = 0;
  view_to_light(view_light_right,light_num,CAST);
  view_to_light(view_light_back,light_num,CAST);
  view_to_light(view_light_left,light_num,CAST);
  view_to_light(view_light_up,light_num,CAST);
  view_to_light(view_light_down,light_num,CAST);
  return 6;
}

See also:

VIEW, stage, c_scan,view_to_matrix, ent_nextlight

► latest version online