We also set an animation property to make it loop and here is the result :


pointLight.RenderStates.UseOwnAmbientLight = true;

pointLight.RenderStates.AmbientLight = Color.White;

pointLight.Pos.Z = -0.25f;

pointLight.Mesh = lightMesh;


This is really simple : first we create a BrumeAnimation object of type RST (rotation, scale and translate animation, this is the default), then we set an animation name and an animation time.

The time is in seconds so that our animation will last 3 seconds.

Now we have to add the animation keys. Brume's animation engine is capable of animation interpolation so we only have to declare the main animation keys. The other keys will be automatically generated for us.


Home


This part looks complicated but in reallity it's really simple.

First we create a table of AnimatedElement. This structure may contain as much elements as you wants. In fact it depends of your mesh complexity.

For a human skeleton you can animate as much bones as you like (and then create a large table) but for our light we just want to animate the sphere so we just need one entry.

We name our element "pointLight" (note that this is arbitrary in this case because the mesh is simple but with complex meshes this name must match the frame names) and we create a table of 4 translation keys for the element.

The keys represent the point light positions during the animation. So at time 0.0f, the light will be at the initial position, then 1 second later it will be at (-1.0, 0, -0.25), 2 seconds later at (1, 0, -0.25) and finally at the end of the animation time, the light will come back to his initial position.

To end with animation setup we just assign the animation to the pointLight object :


int level = 0;

this.GlobalAmbientLight = Color.FromArgb(255, level, level, level);


pointLight.Animation = animation;

pointLight.AnimationStates.PlayMode = BrumeAnimationParams.PLAY_LOOP;


BrumeSphereColored sphere = new BrumeSphereColored(this, "sphere", 0.5f, 50, 50, Color.Green);

sphere.Pos.Y = 0.8f;


The first pane will be colored in blue and be placed on the left.

The second pane will be textured with a Brume default texture and placed on the right.

Both panes won't use culling so that they will be visible on both sides (you can place the camera behind the panes and look at the light)

To add some interest to the scene, we also add a green sphere on top of the panes :


Ok ! That's cool !

But to add some life to our sample we will also associate an animation with our spot light.

This will show us the effects of light computation when the scene is changing.

For the animation we will naturaly use Brume's animation engine.

This engine is available for each Brume's object so that our point light (it's an object) may also be animated.

Here is the animation declaration :


The light is now moving in front of the panes !

To end this tutorial, notice that in the "MoveScene" method we added a method call "pointLight.Update()" to compute new light position for each frame. This is not done automatically for performance reasons (you can modify this call to be made every N frames to achieve better performance but less realistic lightning effect).


Now that we placed our objects, all we have to do is to define the spot light :


// light

BrumeSphereMeshColored lightMesh = new BrumeSphereMeshColored(this, "lightMesh", 0.05f, 10, 10, Color.Yellow);

pointLight = new BrumePointLight(this, "pointLight", new BrumeVector(0, 0, -0.5f), Color.White, 1.5f, 0.5f);

pointLight.Enabled = true;


// sets an animation for the light

BrumeAnimation animation = new BrumeAnimation();

animation.Name = "Move Light";

animation.TotalTime = 3.0f;


Home


animation.AnimatedElements = new BrumeAnimatedElement[1];

animation.AnimatedElements[0].Name = "pointLight";

animation.AnimatedElements[0].TranslationKeys = new BrumeTranslationKey[4];

animation.AnimatedElements[0].TranslationKeys[0].Time = 0.0f;

animation.AnimatedElements[0].TranslationKeys[0].Translation = pointLight.Pos;

animation.AnimatedElements[0].TranslationKeys[1].Time = 1.0f;

animation.AnimatedElements[0].TranslationKeys[1].Translation = new BrumeVector(-1.0f, 0, -0.25f);

animation.AnimatedElements[0].TranslationKeys[2].Time = 2.0f;

animation.AnimatedElements[0].TranslationKeys[2].Translation = new BrumeVector(1.0f, 0, -0.25f);

animation.AnimatedElements[0].TranslationKeys[3].Time = 3.0f;

animation.AnimatedElements[0].TranslationKeys[3].Translation = pointLight.Pos;


// panes

BrumeSquareColored pane1 = new BrumeSquareColored(this, "pane1", 50, Color.FromArgb(0, 0, 128));

pane1.RenderStates.Culling = BrumeRenderParams.CULLING_NO;

pane1.Pos.X = -0.5f;

BrumeSquareTextured pane2 = new BrumeSquareTextured(this, "pane2", 50);

pane2.RenderStates.Texture[0] = this.GetTexture("multitex1.tga");

pane2.RenderStates.Culling = BrumeRenderParams.CULLING_NO;

pane2.Pos.X = 0.5f;


First we define a sphere mesh. This mesh will help us to determine the position of our point light. This sphere will have a bright yellow color.

Then we create our point light at position (0,0,-0.5f) (just in front of the panes) with a White light color, a range of 1.5f and an attenuation of 0.5f.

Finally we enable the light. In Brume all lights must be enabled in order to be computed in the scene (this is for performance reasons).

Ok, now that the light is defined we still need to associate it with our yellow sphere mesh. For this task we will use the fact that in Brume even lights are objects. And every Brume object may be associated with a mesh (note that a mesh may be associated with many objects to lower memory footprint).

So we use the "Mesh" attribute of the light to associate our yellow sphere with the spot light :


Tutorial : Point lights


Before the association, we also tell that the light object will use his own ambient light and that this ambient light will be pure White.

We do this because the scene will have no ambient light by default (remember the level variable set to 0 at the begining of this tutorial). So we won't be able to distinguish the yellow sphere in a dark scene and this is the reason for setting a dedicated ambient light for our yellow sphere.

Now the result must look like this :


This tutorial will show you how to set up a point light in a dark scene and its behaviour on colored and textured surfaces.

It also introduces the use on Brume animation engine.

First create an empty project with a camera and black background color (look at the previous tutorials).

Then set the global ambient color to a dark value :


For the purpose of this tutorial we will use a variable for the darkness intensity : by default we will set Black color for ambient light.

We then add two panes to demonstrate the effects of light on surfaces :


 


Please click here to install flash player in order to see this website