Maximize MenuMinimize Menu

 

 

Back | Home

Drawing in 3D with Game Editor Tutorial

In this tutorial you will draw a 3D wireframe cube using "2D" Game Editor. You will be shown how to easily edit the code to change perspective, yaw, pitch, roll, and viewer position. You will also be shown how similar coding for Game Editor can be as traditional C.

The code is based on code from an old C book of mine from 1988, "High-Performance Graphics in C - Animation and Simulation" by Lee Adams.  Amazingly the code was not that hard to convert. It is actually written for pre-Windows CGA/EGA/VGA graphics systems. It was simple to ignore the hardware specific stuff. The core C code worked basically well with very few changes. This is really a good example of how timeless C really is.

Game Editor Similarities to C

The components of a C program are basically organized into 3 parts:

DECLARATIONS Variables are defined
FUNCTIONS Functions are defined
MAIN  ROUTINE Code and Functions are executed

In Game Editor these components reside in these places:

DECLARATIONS Game Editor Global Code
FUNCTIONS Game Editor Global Code
MAIN  ROUTINE Game Editor Actor Code

Be sure to define your global code functions and variables first. The Actor code will want these defined first. Actor code can also have variable definitions but functions must always be defined in the Global section.

I recommend using TextPad to do all of your Game Editor C code editing. It has C code syntax highlighting which is very handy for editing. Also use  the File Load method within Game Editor to load your code.
 

LET'S DRAW A 3D CUBE

1. Start a new project and add an actor of type CANVAS, name it actor.

2. Go to Config | Game Properties and change Game resolution to 240 x 320 Pocket PC (for Pocket PC resolution).

3. Resize your Canvas Actor to the View Size. I make mine look like this.

4. Select Script | Global Code and load the cube3d_global_script.c file. Name it global.

5. Right-Click over your Actor and select Actor Control | Events | Add | Key Down - and Right-Click. Then select Add Action | Script Editor.

6. Load the cube3d_actor_script.c file.

7. Add as immediate action then Close.

8. Right-Click over the actor, select Actor Control | Events Edit | Key Down | Script Editor - and disable Repeat.

9. Select Game Mode to test your cube. Select a key to draw.


3D Cube Drawn with Game Editor


HOW IT WORKS

The program draws a 3D perspective cube by applying 3D math routines to an array of x,y,z coordinates. Key variables which are initialized in the global code such as perspective factor, yaw, pitch, roll, viewpoint position and screen dimensions affect the look of the wireframe. The code is well commented so you can see how each part works.

EXPERIMENT!

Try editing some of the key variables in the global code to change viewer orientation and distance from the cube. See if you can animate the cube by changing the values using a loop.



That's it!
Now get busy on that new 3D game!

 

Radiosity Games
See our new game site

 

 

 

©Copyright TrajectoryLabs.com. All Rights Reserved.