Problem with Spot Lights

New Message Reply Date view Thread view Subject view Author view

Henrik Lind (hlind++at++bvu-lads.loral.com)
Wed, 30 Aug 1995 14:39:13 -0700 (PDT)


I am using local illumination spot lights to model flare illumination.
The lights seem to be initialized properly and move properly. But when
I turn them off, it seems they don't always get turned off, i.e., the
landscape remains illuminated. Here is sample code. If you can give
any insight into the problem, I'd be grateful.

Thanks,
Henrik Lind

-------------------------------------------------------------------
/* INITIALIZATION */
{
  pfScene* scene;
  pfLightSource* lSource;
  char lsName[10];
  int i;
  pfLightModel* lm;

  /* Initialize light source node names */
  strcpy(lsName, "G_lightx");

  /* Get light source group */
  scene = pfFindScene("G_scene");
  if (scene == NULL)
  {
    fprintf(stderr, "G_scene not found!\n");
    exit(-1);
  }
  G_lights = pfNewGroup();
  if (G_lights == NULL)
  {
    fprintf(stderr, "G_lights not created!\n");
    exit(-1);
  }
  pfNodeName(G_lights, "G_lights");
  pfAddChild(scene, G_lights);
   
  /* Allocate MAXLIGHTS light sources, naming them G_light0 - G_lightn. */

  for (i = 0; i < MAXLIGHTS; i++)
  {
    lSource = pfNewLSource();
    if (lSource == NULL)
    {
      fprintf(stderr, "unable to alloc light source %d\n", i);
      exit(-1);
    }

    pfSpotLightDir(lSource, 0.0f, 0.0f, -1.0f);
    pfSpotLightCone(lSource, 4.0f, 45.0f);
    pfLightColor(lSource, 1.0f, 1.0f, 1.0f);
    pfLightPos(lSource, 0.0f, 0.0f, 0.0f, 1.0f);
    pfLightOff(lSource);
    lsName[7] = (char)(i + (int)'0');
    pfNodeName(lSource, lsName);
    pfAddChild(G_lights, lSource);
  }
}

-------------------------------------------------------------------
At run time, a flare is bound to a light source by:

for (i = 0; i < MAXLIGHTS; i++)
{
  lSource = (pfLightSource*) pfGetChild(Glights, i);
  if (pfIsLightOn(lSource)) ;
  else
  {
    pfLightColor(lSource, r, g, b);
    pfLightPos(lSource, x, y, z, 1.0f);
    pfPushIdentMatrix();
    pfSpotLightDir(lSource, 0.0f, 0.0f, -1.0f);
    pfSpotLightCone(lSource, 0.0f, 90.0f);
    pfLightOn(lSource);
    pfPopMatrix();
    break;
  }
}

-------------------------------------------------------------------
The position of a flare is updated by:

{
  /* Change flare position */
  pfLightPos(lSource, x, y, z, 1.0f);
  pfPushIdentMatrix();
  pfLightOn(lSource);
  pfPopMatrix();
}

-------------------------------------------------------------------
Finally, a flare is turned off simply by:

pfLightOff(lSource);


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:51 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.