Home - Forums - Documentation - Gallery - Bugs

Working with halos

Crystal Space supports three type of halo lights, nova halos, cross halos and flare halos. We deal with novas and cross halos only in this tutorial. The result will be something, like this:

Image:halo1.jpg


Nova halos are ideal for you, when you want to render star-like lights or suns. You see this kind of halo light on the right side of the screenshot.


Nova halos have the following attributes:

Seed: The size of seed of the halo

Number of spokes: How many spokes are around the seed.

Roundness: The roundness of the halo.


Cross halos have the following attributes:

Cross: How “cross-like” is the light

Intensity: the intensity of the halo


The simple1 example class is a good starting point for us, the Halotest class is just an extension of this class. In our test application first we create a cross and a nova halo. We want to change the properties of the halos (cross, intensity, spokes, etc) runtime. So we need the following variables in the Halotest class:

  int seed;

  int num_spokes;

  float roundness;

  float intensity;

  float cross;

Let’s go to initialize this variables in the constructor:

Halotest::Halotest ()
{
  SetApplicationName ("CrystalSpace.Halotest1");
  //some starting value
  seed=5;
  num_spokes=50;
  roundness=0.5f;
  intensity=5.0f;
  cross=0.5f;
}

In the CreateRoom() function, we create the halos:

light = engine->CreateLight(0, csVector3(-3, 3, 0), 10, csColor(0.5, 0.5, 0.5), CS_LIGHT_DYNAMICTYPE_DYNAMIC);
  light->CreateCrossHalo(5.0,0.5);
  ll->Add (light);
  crosslight=light;

  light = engine->CreateLight(0, csVector3(3, 3,  0), 10, csColor(0.5, 0.5,       0.5),CS_LIGHT_DYNAMICTYPE_DYNAMIC);
  light->CreateNovaHalo(4,100,1.0);
  novalight=light;	
  ll->Add (light);

Important note, that the type of the lights will be dynamic. Why? When the engie created the halos, we can’t change runtime such properties, like number of spokes or roundness. But when we delete the light, and create a new one with the wished properties, we can simulate a runtime changing halo.

The next two function handle this:

void Halotest::CreateCrossHalo()
{
	 csRef<iLight> light;

	 iLightList* ll = room->GetLights ();

	engine->RemoveLight(crosslight);

	light = engine->CreateLight(0, csVector3(-3, 3, 0), 10, csColor(0.5, 

0.5, 0.5), CS_LIGHT_DYNAMICTYPE_DYNAMIC);

	light->CreateCrossHalo(intensity,cross);

  ll->Add (light);

  crosslight=light;
	
}

/* When we regenerate our halos, first we delete the old halo light from the engine
Next we create a new halo with the wished properties, and add to the engine.
*/
void Halotest::CreateNovaHalo()
{
	 csRef<iLight> light;

	 iLightList* ll = room->GetLights ();

	engine->RemoveLight(novalight);

	light = engine->CreateLight(0, csVector3(3, 3, 0), 10, csColor(0.5, 0.5,
 0.5), CS_LIGHT_DYNAMICTYPE_DYNAMIC);

	light->CreateNovaHalo(seed,num_spokes,roundness);

  ll->Add (light);

  novalight=light;

}

Now we set up some key binding to change the wished properties:

For the cross halo:

a: decrease intensity

s: increase intensity

g: decrease cross

h: increase cross


For the nova halo:

w: decrease seed

e: increase seed

z: decrease spokes

e: increase spokes

1: decreasing roundness

2: decreasing roundness


//here ve step our halo related values. Try different stepping numbers to fine the code.
	if (code == 'a')
	{
		if(intensity>0.1f)
		{
			intensity-=0.1f;
			CreateCrossHalo();
		}
		return true;
	}
	
	if (code == 's')
	{
		intensity+=0.1f;
		CreateCrossHalo();
		return true;
	}

	if (code =='g')
	{
		cross-= 0.1f;
		CreateCrossHalo();
		return true;
	}

	//more key handling

  }

So when the user presses a key, we regenereate the halo with the new values.

That’s it. Try it. Here is another example shot after various key pressing:

Image:halo2.jpg

That's it. Enjoy.

| Article | Discussion | View source | History |