Creating LMS Scenes

A scene of the LMS is defined by a file in the XML format. This file stores information about the components floor, lights, boxes and cameras. As follows you can see the general structure of such a scene file. Creating your own scenes, it can be used as a pattern. The diverse tags will be explained subsequently.
<?xml version="1.0" encoding="UTF-8"?>   definition of the XML file. Identical for all files.    
<Scene ...>                              begin tag of the scene
  <Floor .../>                           the floor
  <Lights>                               the lights
<SpotLight .../>
<SpotLight .../>
</Lights>
  <StaticObjects>
<WorldObject>
<ParentTransformGroup ...>
<ChildTransformGroup ...>
<Box .../> definition of a box
</ChildTransformGroup>
<ChildTransformGroup ...>
<Box .../>
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>
</StaticObjects>
   <Cameras>                             the cameras
<Camera ...>
<TransformGroup .../>
</Camera>
<Camera ...>
<TransformGroup .../>
</Camera>
</Cameras>
</Scene>

Below the LMS root directory is named as %lms-home% (e.g. C:\Programme\lms)
In the example, we create a scene named myScene.xml in the directory %lms-home%/scenario/myScenario.

The XML Tag

The XML tag defines the XML file. It is identical for all scenes.

<?xml version="1.0" encoding="UTF-8"?> 

The Scene Tag

At this entry the definition of a scene begins. In order to define the correct structure of the XML file, a xsd file (xsd=XML Scheme Definition) gets intgrated. This works as follows:

<Scene 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Scene.xsd">

The xsd file (Scene.xsd) is located in the directory %lms-home%/config/Scene. If you store your scene file into this directory, you can copy the scene tag like it is given above. If your scene file is located in another directory, you can either copy the file �Scene.xsd� into this directory or create a relative path starting at the scene file and pointing to the scheme definition. The latter case looks as follows:

<Scene 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../config/Scene/Scene.xsd">

The scene tag is closed at the end of the file.

</Scene>

The Floor Tag

Here, the floor of the scene gets defined. On the floor, the robots can move. It has a fixed size and a texture, that can be sensed as the brightness of the floor by the light sensor of the RCX. The size of the floor is specified in meters. The texture can be an optional picture of the format �gif�, �jpg� or �png�. The path is set relatively to %lms-home%. In our example, the file �floor.gif� is located in the directory %lms-home%/scenario/myScenario. The floor has height and width 1 meter. At the end, the tag is closed with �/>�.

<Floor Length="1.0" Width="1.0" GifFilename="scenario/myScenario/floor.gif" />

Following these simple steps, we created a basic scene. If you open it in the LMS, you can see the following:

Defining the Lights

Additionally, directed spotlights can be set up in the scene file. The definition of these lights begins with the Lights tag, followed by one or more SpotLight tags. At the end of the SpotLights the Lights tag gets closed:

<Lights>
<SpotLight .../>
<SpotLight .../>
</Lights>

The SpotLight Tag

A characteristic light source is described in the following way:

<SpotLight PositionX="-0.5" PositionY="0.5" PositionZ="1" 
DirectionX="0.5" DirectionY="-.5" DirectionZ="-1"
Concentration="40" SpreadAngle="3"
Red="220" Green="50" Blue="50" />

In this example, a red light gets defined. You can notice explicitly the effects on the by way of trial loaded robot (ATF1).

without any light source
with a red light source

 

A SpotLight has 11 parameters. The first there of them characterise the coordinates of X,Y and Z of the light. All values refer to the centre of the floor and are given in meters. Thus, in this example, the light is generated by a light source that is located one meter above the floor, on the left upper corner of the floor. The following three parameters characterise the direction of the light. Here, the direction gets the negative values of the coordinates of the position, so the light gleams exactly to the centre.

The parameter Concentration specifys the magnitude of the bundling of the light. The angle of beam spred, that is the angle of the cone of light is caracterised by the parameter SpreadAngle. The last three parameters finally, specify the colour of the light using the RGB colour values.
Now, we integrate a second spotlight located 2 meters above the floor, that illuminates the floor homogeneously:

<SpotLight PositionX="0" PositionY="0" PositionZ="2" 
DirectionX="0" DirectionY="0" DirectionZ="-1"
Concentration="100" SpreadAngle="30"
Red="150" Green="150" Blue="150" />

Static Objects

Static objects are integrated in a StaticObject tag. Using static objects, you can define obstacles on the floor. This can get relevant, if you wanted to set up a barrier around the floor in order to make the robot not leave the floor, for instance. The definitions begin with the tag:

<StaticObjects>

In this tag, the boxes get defined and finally, the tag gets closed with:

</StaticObjects>

WorldObjets

The WorldObjects integrate particular obstacles. StaticObjects can contain multiple WorldObjects.

Nesting of StaticObjects

The actual obstacles (defined by the tag <Box ...>) get incorporated into a ChildTransformGroup. This ChildTransformGroup is ranked among a ParentTransformGroup, which is an integral part of a so-called WorldObject. Here, you see an example of a simple yellow box in the centre of the floor. Later, we are going to complete this box with a second turned box to a house:

<StaticObjects>
<WorldObject>
<ParentTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0"
Value21="0" Value22="1" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0"
Value21="0" Value22="1" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>
</StaticObjects>

The particular parameters of the box tag represent the width, the length and the height as well as the colour of the obstacle. A lot more complex is the 4x4 matrix, that gets defined in the ChildTransformGroups. Using this matrix, you can position and rotate the boxes.
I am not going to go into details concerning the mathematic background of this matrix, because this would go beyond the scope of this tutorial. Instead, I am going to give instructions how to use this matrix.

Altering the Position

In the XML definition of the ChildTransformGroup, you can identify the following matrix:

=

In this example, the parameters dx, dy and dz are 0, respectively. This means that the postition of this Object is not altered. Now, let us move the object 50cm rightwards and 10cm upward. To achieve this, we need to set Value14=�0.5� and Value24=�0.1� and thus we get the following:

<ChildTransformGroup 
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">

Rotating an Object:

Now, we integrate a second object as the �roof of the house�. It is located a bit higher than the first object and it has other dimensions:

<StaticObjects>
<WorldObject>
<ParentTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0"
Value21="0" Value22="1" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0.1"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.119" Length="0.06" Height="0.06"
Red="200" Green="0" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>
</StaticObjects>

In order to rotate this object, the following part of the matrix needs to be changed:

The matrix (R) gets computed as follows:

Rotation around the x-Axis:
(Rx) =

Rotation around the y-Axis:
(Ry) =

Rotation around the z-Axis:
(Rz) =

Thus, if we want the box to rotate by 45� around the x-Axis, we get:
(Rx) =

and therefore:

<StaticObjects>
<WorldObject>
<ParentTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0"
Value21="0" Value22="1" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="0.707" Value23="-0.707" Value24="0.1"
Value31="0" Value32="0.707" Value33="0.707" Value34="0.1"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.119" Length="0.06" Height="0.06"
Red="200" Green="0" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>
</StaticObjects>

In order to carry out multiple rotations, you need to multiply particular rotation matrices. For instance, in order to rotate around the x-axis first and afterwards around the z-axis, you need to compute the two matrices (Rx) and (Rz) and multiply them then. (Rtotal)=(Rx) x (Rz).
Please pay attention on the order of the matrices (same order like the steps of rotation).
Altering the position of a ChildTransformGroup
Now, the house and its roof are integrated in a ParentTransformGroup. You can easily alter the position of both objects by altering only the matrix of the ParentTransformGroup. In order to rotate the whole house for instance by 90� around the centre of the floor in z-direction, the following change is enough:

Rotation around the z-Axis:
(R) = =

Consequently for the ParentTransformGroup:

<StaticObjects>
<WorldObject>
<ParentTransformGroup
Value11="0" Value12="-1" Value13="0" Value14="0"
Value21="1" Value22="0" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="0.707" Value23="-0.707" Value24="0.1"
Value31="0" Value32="0.707" Value33="0.707" Value34="0.1"
Value41="0" Value42="0"Value43="0" Value44="1">
<Box
Width="0.119" Length="0.06" Height="0.06"
Red="200" Green="0" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>
</StaticObjects>

In so doing, we can multiply reuse created ParentTransformGroups by simple duplicating and adjusting the matrix.

Perspective of the Camera

Under the menu item �View� of the LMS preset perspectives of the camera can be chosen, provided they are defined in the XML file. There are two ways to define these perspectives of the camera: manually or using the LMS.

Defining the Perspective of the Camera using the LMS:

Rotate, drag and zoom the main window into the desired position using the three mouse buttons. Then, click on �View -> Save Camera Pos�.
There, you have defined a camera perspective in the XML file, that from now on you can recall under the menu item �View�.
Due to this simple facility to define camera perspectives, this tutorial merely focuses on the general structure of the camera tag.
As you can see above, multiple perspectives are saved in one camera tag:

<Cameras>
<Camera ...>
<TransformGroup .../>
</Camera>
<Camera ...>
<TransformGroup .../>
</Camera>
</Cameras>

The camera itself has a name (by default �Camera 0�, �Camera 1� and so forth) and a TransformGroup. This TransformGroup is structured in the same way like the ParentTransformGroup and the ChildTransformGroup, that you already know.
The parameters dx, dy and dz specify the position of the camera and the matrix (R) defines the perspective.

<Camera name="Camera 0">
<TransformGroup
Value11="0.8338244" Value12="0.12909822" Value13="-0.53672206"
Value14="-1.4949298" Value21="-0.529671" Value22="0.4610073"
Value23="-0.71198374" Value24="-2.0976896" Value31="0.15551695"
Value32="0.87795556" Value33="0.45277873" Value34="1.1544305"
Value41="0.0" Value42="0.0" Value43="0.0" Value44="1.0"/>
</Camera>

You can carry out the scaling by multiplying the rotation matrix with a scaling matrix (S):
(Rs) =(R) x
Here, z denotes the zoom.

Summary

This tutorial taught you how to create a simple scene for the LMS. This scene integrated a floor with a texture, that can be sensed by the light sensors of the robot, multiple light sources, multiple houses, that are combined in transformation groups and the camera perspective.

Appendix:

The complete scene file �myScene.xml�:

<?xml version="1.0" encoding="UTF-8"?>
<Scene
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../config/Scene/Scene.xsd">
<Floor Length="1.0" Width="1.0"
GifFilename="scenario/myScenario/floor.gif" />

<Lights>
<SpotLight
PositionX="-0.5" PositionY="0.5" PositionZ="1"
DirectionX="0.5" DirectionY="-.5" DirectionZ="-1"
Concentration="40" SpreadAngle="3"
Red="220" Green="50" Blue="50" />
<SpotLight
PositionX="0" PositionY="0" PositionZ="2"
DirectionX="0" DirectionY="0" DirectionZ="-1"
Concentration="100" SpreadAngle="30"
Red="150" Green="150" Blue="150" />
</Lights>

<StaticObjects>

<WorldObject>
<ParentTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0"
Value21="0" Value22="1" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="0.707" Value23="-0.707" Value24="0.1"
Value31="0" Value32="0.707" Value33="0.707" Value34="0.1"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.119" Length="0.06" Height="0.06"
Red="200" Green="0" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>

<WorldObject>
<ParentTransformGroup
Value11="0" Value12="-1" Value13="0" Value14="0"
Value21="1" Value22="0" Value23="0" Value24="0"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="1" Value23="0" Value24="0.1"
Value31="0" Value32="0" Value33="1" Value34="0"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.12" Length="0.08" Height="0.10"
Red="200" Green="200" Blue="0" />
</ChildTransformGroup>
<ChildTransformGroup
Value11="1" Value12="0" Value13="0" Value14="0.5"
Value21="0" Value22="0.707" Value23="-0.707" Value24="0.1"
Value31="0" Value32="0.707" Value33="0.707" Value34="0.1"
Value41="0" Value42="0" Value43="0" Value44="1">
<Box
Width="0.119" Length="0.06" Height="0.06"
Red="200" Green="0" Blue="0" />
</ChildTransformGroup>
</ParentTransformGroup>
</WorldObject>

</StaticObjects>
  <Cameras>
<Camera name="Camera 0">
<TransformGroup
Value11="0.8338244" Value12="0.12909822" Value13="-0.53672206"
Value14="-1.4949298" Value21="-0.529671" Value22="0.4610073"
Value23="-0.71198374" Value24="-2.0976896" Value31="0.15551695"
Value32="0.87795556" Value33="0.45277873" Value34="1.1544305"
Value41="0.0" Value42="0.0" Value43="0.0" Value44="1.0" />
</Camera>
</Cameras>

</Scene>

Imprint | Webmaster | Recent changes: 04.10.2007