Getting started

The file it all begins with

Before you can start using Ultimate 3D, you need some Game Maker file to work in. It's obvious that you can not use an empty project for this purpose. You need the scripts and the basic objects that belong to Ultimate 3D. If you have seen the demo that comes with Ultimate 3D you may want to use this as a base for your game. But I do not recommend that. If you really want to make your own game you should start from scratch, in which case the stuff in the demo will not be of much use to you. If you just want to mod the Demo somehow you can use it. But people will notice that when you release it and they will not like it.

You should start making your first Ultimate 3D project by creating a new folder and copying the BasicGM5.gmd (resp. BasicGM6.gm6 or BasicGM7.gmk) file. This can be obtained from the Ultimate 3D Software Development Kit (U3D SDK) that can be downloaded at Ultimate3D.org. This Game Maker file contains everything you need to get started with Ultimate 3D (apart from the knowledge which is in the tutorials you are reading currently ;) ). There's one example instance of every kind of Ultimate 3D object, as well as the control object that is required to use Ultimate 3D. The only room contains a senseless combination of these objects. When you start making a game, you should delete every object except the control object and the camera object.

There are a few things you should notice about the room. If you create a new room that is to be used with Ultimate 3D, it has to meet these requirements:
- The room uses views and the first view is enabled.
- The background color is disabled. This is not necessary but it's a waste of computing time if you let Game Maker draw its background color.
- The room has to contain exactly one control object and a camera object.

I recommend creating two sub-folders in your project folder. The first one should be called gfx and should be used for saving textures. The second one should be called models and I guess it's obvious what it's supposed to contain. But that's up to you.


The view system

There's one thing about the use of a 3D extension for Game Maker you will not like. When you use Ultimate 3D it will render to the first view of Game Maker. While it does this you can not use Game Maker to draw to this view anymore. It is simply not possible for two totally different programs to render at the same part of the screen simultaneously. For this reason Ultimate 3D does not just have functions for drawing 3D scenes; there's also a couple of functions to draw 2D graphics and text. Also, the first view does not need to cover the whole Game Maker window. You can use multiple views and as long as they do not try to cover the Ultimate 3D view it will be no problem for Game Maker to use them. Another thing is that you cannot switch fullscreen mode while using Ultimate 3D. So if you want to use fullscreen mode you have to enable it in the Game Maker options or in the Ultimate3DOptions() script.


The camera object

So let's get to the first practical thing: the camera object. By default, the camera object has a piece of code for mouse control in its step event and a couple of calls to the Ultimate 3D function Move in its keyboard events. If you do not like that, feel free to remove it. But how impolite. I did not introduce you to the function Move. So have a look at this:

This function moves the object that calls it in 3D space.

Move(
Longitude,
Latitude,
Speed
)

Longitude, Latitude
These two parameters describe the direction the object should move in. It works in the same way as on a globe. Longitude describes how much the object moves up or down. 0 means that it does not change its height, 90 means that it moves straight down and -90 means that it moves straight up. Latitude gives the horizontal direction the object moves in. Note that it differs from the direction variable of Game Maker. To convert a direction value of Game Maker into a Latitude value of Ultimate 3D without changing the direction, you have to use this little formula: Latitude=direction+90.

Speed
This parameter gives the speed the object should move with. Note that you have to call the function every step to make the object move with this speed.


From now on every function that has parameters will be described like this. If you want just a quick information while programming you can also open the script. Every script contains a short description of the function and its parameters.

By the way, you may have noticed that Move(...) is written with a capital letter as are all other functions of Ultimate 3D. This has a couple of reasons. The first one is that I'm used to functions called like this from C++. The second one is that you can see whether a function belongs to Game Maker or to Ultimate 3D easily this way. If there wasn't this difference there would have been a prefix instead. So Move would not be called Move but u3d_move. In my opinion it's much easier to press the shift key sometimes than writing u3d and _ all the time. Besides, it looks better.

But let's get back to the topic... the camera object. In Ultimate 3D every 3D object in the scene must be represented by an instance of a Game Maker object. You can then change the properties of the scene objects by simply changing the variables of their Game Maker objects. An Ultimate 3D function such as MoveCamera() will pass them to Ultimate 3D automatically. Camera objects have the following variables:

x, y, z
These variables give the position of the camera. Since we are in 3D space now there aren't only x and y anymore. They now have a new friend called z. It defines the height of the object. So if you increase z the object will move up, if you decrease it the object will move down. The combination of x, y and z is called a coordinate. You should remember this word. It may appear again.

height
In first person games the camera usually has a particular height above the ground. This height can be implemented using this variable. The actual z-coordinate of the camera (the one Ultimate 3D works with) is not z but z+height.

rotx, roty, rotz
These variables give the rotation of the camera. In short rotx describes the pitch of the object, roty describes the yaw and rotz describes the roll. A more detailed description of what these variables mean is given in the second part of the tutorial "Using primitive objects".

view
This variable defines the double vertical angle of view of the camera. As with any angle in Ultimate 3D it must be in degrees.

min_range, max_range
The camera will only show objects that are farther away than min_range and closer than max_range. All other objects will be invisible. You should use reasonable values for these variables. If min_range is too small or max_range too big you may get strange display errors. Objects may cover other objects that are in front of them.

falling, falling_speed (optional)
If falling is equal to true the z coordinate of the camera will be increased by falling_speed in every step and falling_speed will be decreased by global.gravitation (by decreasing I mean that every step falling_speed will become smaller. Negative speed is down, and positive speed is up). These variables are meant to be used in combination with the premade collision functions CollisionH(), CollisionV(), CollisionZ() and CollisionTerrainModel().

follow, perspective, rotatex, rotatey, distance (optional)
follow can be set to the ID of a Game Maker object to make the camera follow this object. The followed object can hold a value for the variable height to make the camera follow a point above or below the actual position of the object. perspective defines the way the camera will follow the object. It can be 0 for an inertial camera on the ground, 1 for a fixed third person camera or 2 for a flexible third person camera. If perspective is 1 or 2 you can change rotatex and rotatey to give a rotation offset. distance defines how far the camera stays from the object it follows.


So far that's all you need to know about the camera object. Actually there are a few more variables and functions for cameras, but those are described in the tutorials for advanced users.

So now you know how to create a camera object. Unfortunately there's nothing it will show you so far (at least if you have cleaned up the room). But do not worry, that will change very soon.


Loading textures

Before we get to creating the first visible objects there's one other thing you need to know about: loading textures. For those who do not know, here's a short explanation of what a texture is: A texture is (usually) a two-dimensional picture that gets created by an application that uses 3D graphics. Then this picture can be applied to an object. Without textures all objects in 3D graphics would be made up of only one color and that would be really boring. For that reason it's very important to have good textures. They make your games look much more realistic.

To load a texture you only need one very simple function:

LoadTexture(
TextureFile,
TextureIndex,
Width, Height
)

TextureFile
Since Ultimate 3D can not access the resources of Game Maker, the texture has to be saved into an external file. This file can be a bmp, jpg, tga, png, dds, ppm or dib file (NOT gif). I recommend saving textures in a sub folder called gfx. But if you want to hide your textures from the people who play your game you can also attach them to your executable using Game Maker's data files or including mechanism and load them from its temporary directory.

TextureIndex
The index the texture is to be associated with. It can be an arbitrary number in the range from 0 to 998. An index is similar to an id. When you want to use the texture later you have to know the index you associated it with.

Width, Height
Usually you can simply ignore these two parameters. If you enter 0 or nothing for both of them, Ultimate 3D will get the height and the width of the texture from the file. But if you enter values that differ from the actual size of the texture it will be scaled to this size. Note that only powers of two or zero can be passed for these parameters. For more information read on.


There's one important thing you have to know about textures. Most graphics devices work only with textures that have dimensions made up of powers of two. In addition, some graphics devices can work only with quadratic textures, but that's a rare case. Anyway, your textures will be scaled up if they do not have dimensions made up of powers of two, to make them have valid dimensions. To avoid this unnecessary quality loss you should make all your textures use these dimensions. Some examples for valid dimensions are 256*256, 128*512 and 1024*64. A texture with a size of 257*257 would get scaled up to 512*512 and this is a real waste of memory.

Another thing you need to know is how to make textures transparent. There are two ways to do this. The best one is to use a file format that supports transparency such as tga or png. The Gimp (GNU Image Manipulation Program) supports these file formats. It's a great open source image editing program. If you prefer using other file formats you can get transparency anyway. Simply use the transparency color which is (r=0; g=128; b=64). All pixels that have exactly this color will be set to transparent by Ultimate 3D.

I recommend loading all textures in the create event of the control object. This way you can get a list of all textures loaded including their indices. But that's up to you.

Here's a really small code example that demonstrates how to use this function correctly:

LoadTexture("gfx/WallTexture.png",1);


© Christoph Peters. Some rights reserved.

Creative Commons License XHTML 1.0 Transitional