Texturing and positioning

So far we've created a simple package that shows a white plane on top of our target. Let's now look at how to put a picture on the plane, and how to move it around in the scene.

Texturing

The Example - Textured Plane package contains an image - pine.png. Copy it into our SimplePackage folder. Open up the SimpleScene.xml file and change it so that it now reads:

<object type="primitives://plane.aro" skin="pine.png"/>

Saving up and viewing with SceneViewer will show that the plane now displays the wood picture. There are a few technical restrictions on what formats and sizes of images you can use as "skins" on objects - see Images and Textures for details.

We've now met two of the parameters of the object node - type and skin. The node takes a number of other parameters (see the object node reference page for a full list), including positon, scale and rotation.

The position attribute

This attribute allows you to specify the location of the object in the scene.

Open up SimpleScene.xml and change the object so that it now says:

  <object type="primitives://plane.aro" skin="earth.jpg" position="1 0 0"/>

Figure 2.2. Scene coordinate system

Scene coordinate system

Viewing this scene shows the plane located to the right of the target. The position is specified as three numbers, corresponding to the x-coordnate, the y-coordinate and the z-coordnate in turn, separated by spaces. Here we have placed the center of the plane at distance of 1.0 from the center of the target in the x-direction. Figure 2.2, “Scene coordinate system” shows the coordinate system used by scenes. The x-direction is positive to the right of the center of the target; the y-direction is positive towards the top; and the z-coordinate is positive up and out of the target. The coordinate system is arranged so that the top of the target is always at a y-coordinate of 1.0, the bottom is always at a y of -1.0 and the center is at all of the coordinates equaling 0.0.

You may like to try a variety of different values for position of our object in the scene to get a feel for the coordinate system.

The scale and rotation attributes

You can change the scale and rotation of the object in much the same was as the position.

The scale attribute is specified in the same "x y z" format as the position.

The rotation attribute is specified by three numbers representing the yaw, pitch and roll, in degrees, of the object.

Figure 2.3. Yaw, pitch and roll

Yaw, pitch and roll

Grouping objects

The group node allows you to group objects and specify the position, scale, rotation and (and a few other parameters, such as color) of the group as a whole. When objects are grouped, these parameters are relative to their parent group.

Open up SimpleScene.xml again. Change the file to:

<scene>
    <group position="0 1 0">
      <object type="primitives://plane.aro" position="-1 0 0" color="0 1 0 1"/>
      <object type="primitives://plane.aro" position="1 0 0" color="0 0 1 1"/>
    </group>
</scene>

This scene shows two planes - one blue on the left, and one green on the right. Both are positioned at y = 1 via their parent group.

The color attribute takes four numbers - red, green, blue and transparency (also known as alpha). Each ranges from 0 to 1. An alpha value of 0 means fully transparent while a value of 1 means fully opaque. Here are a few examples:

  • 1 1 1 1 - solid white (the default color)

  • 1 0 0 1 - solid red

  • 0 1 0 0.5 - semi-transparent green

  • 1 1 0 1 - solid yellow

  • 1 1 1 0 - invisible