Introduction to 3D

Here I'm doing a nice and small tutorial for anyone new to 3D in GM.

For this example you are going to make a 3D block, which is about the most basic 3D thing possible in GM.

Create a new script called "scr_start_3d".

In this script, make this code: ; //enter 3d mode (true); //use perspective projection (used in nearly all 3D games) (true); //removes hidden surfaces (false); //do not use lighting (true,c_white,1,1024); //draw fog starting at a distance of 1 ending at 1024 (false); //switch backface culling off (false); //switch shading off (true); //switch interpolation on

Let's make the next code, the block script. Before you do this, make a background called "back_block".

Make a new script called "scr_block":

(0,0,0,32,32,32,(back_block),1,1);//this makes a block

If you run this script from an object, a block will be drawn at its location.

To see this block, we need a "camera" object. Make another script called "scr_camera". Put this inside it:

(128,96,64,16,16,16,0,0,1); //this makes the camera (click the function for parameter information) (c_white); //use white as the draw colour (1); //set the alpha to 1

Now we need 2 objects to run these scripts from.
 * 1) The block object
 * 2) The camera object

We will start with the camera. Make an object called "obj_camera". In the draw event make an execute script action. In the dialogue simply choose your script "scr_camera".

In the create event, make another execute script action and choose "scr_start_3d".

Now make an object called "obj_block". Make another execute script action in this object's draw event and select "scr_block".

Create a new room, place the camera anywhere and the block at 16x,16y. Run the game, and there should be a block in front of you.

If there a block there, you have finished this tutorial.

Authors:

Dennis Fredriksson - original author

Philip Robinson - correcting grammar