Workshop 08: Position, angle and scale

If you don't like to write code at all, you will be happy to hear that this workshop will teach us useful stuff without us having to write a single line of script. We will learn quite a few things about the position of the objects in the 3D world, their angles and scale. If you only have lite-C (that does not contain a level editor) you won't be able to do the WED exercises; however, if you read this workshop you will learn a few things about the coordinate system.

If you have A7 Extra Edition or above: Start the WED Level Editor and open the level work08.wmp inside the workshop08 folder.

You can see a decent looking room. I bet it looks better if we run the level so let's do it: Build the level and Run it.

I would say that it doesn't look too bad. Can I see more of it, please?

If we don't write some code to change the position of the camera (our "window" inside the 3D world), the engine will place it in the origin, at x = 0, y = 0 and z = 0 every time when we run a level. Keep the level running and press the F11 key - you will see a lot of figures on the screen. Let's see what some of them do:

The first column shows the screen resolution (800 x 600 pixels), the huge frame rate that I am getting on a regular PC (447 frames per second!) and the number of polygons rendered per second (199,000 polygons). The x y z pan tilt roll figures show the position and the angles of the camera. Press the 0 key to free the camera, then move it using the arrow keys and the mouse. I have moved the camera a little and here's what I have got:

I like this camera position better, because I can see a bigger part of the level. Five values out of six have changed for the "xyz" and "ang" columns; it is clear that the camera has changed its xyz position and two of its angles.

How can we set up a certain position for a certain object? Take a look at the screenshot below:

We can set x and y for any object by changing its position in Wed’s Top (XY) view and we can change the height (z) of the object by changing its position in the Back (XZ) or Side (YZ) view. Of course that you have two possibilities to change x, y and z (take a look at the picture above) but I think that you should use the method I've mentioned.

Right click one of the level blocks in WED, choose Properties then Position and you will see the following image:

The first row gives the coordinates for the level block on x (-375), y (-54) and z (-259.996). Change one of these values and you will see that the selected block (the red rectangle in the image above) will change its position; this way you can use WED to set any object to a certain position in the level.

Tip: You can also change the x coordinates for your objects in WED's "Back" view and the y coordinates in "Side" view.

The second row in the Object Properties window - Rotate - gives the angle of the selected object. What's with these three angles? Their names are pan, tilt and roll and they are Euler angles; if you don't know what that is here's a picture that should clear the fog:

I shouldn't let you play with a big plane in such a small room but Anakin Skywalker did it so why can't we do it? Right click the top view in WED, choose Add Model and then click mig.mdl:

I have told you that this is a big plane in a small room, haven't I? Don't worry, you don't need to fly it; try to place the plane close to the center of the room, like in my picture and then right click it, choose Properties / Position and play with the three Rotate values to change its angles. You will notice that when we place a model in the level, the level editor will give it an initial pan angle of 90 degrees. Make sure that you learn how pan, tilt and roll work because we will use them a lot in our future workshops.

The last row of values in Object Properties is Scale, the scale (the size) of the object. Right click the plane model and scale it using values bigger than 1 to increase its size or values smaller than 1 to decrease its size.

Let's get back to our test level; start Lite-C and open the workshop08 folder. The script08.c file that runs the level has only a few lines of code:

///////////////////////////////////
function main()
{
screen_size.x = 800;
screen_size.y = 600;