[color:#003300][size:17pt]**3D techniques in Multimedia fusion 2 **[/size][/color]

[color:#003300]**Basic 3d**

Before making a 3D game it is essential to comprehend how implementing 3D will effect what you

already know.

Anyone who has used MMF should have a good grasp of 2D; 'X' being left and right and 'Y' being up

and down; here is a simple example including a 'Z' axis acting as forward and backward.

Example: `Please login to see this link.`

In this example we are positioning and scaling each object as such:

[color:#660000]X = "320+(x_( "Active" )/z_( "Active" ))"

Y = "240+(y_( "Active" )/z_( "Active" ))"

Scale = "1.0/z_( "Active" )"[/color][/color]

[color:#003300]

In 2D we consider 0x,0y to be at the top left of the screen,

in 3D '0' is always considered the center of the screen, so by adding half the screens width "320"

to the 'X' position and half the screens height "240" to the 'Y' position we effectively make 0x,0y

the center of the screen.

The second part of positioning;

[/color][color:#660000]

X = "320+(x_( "Active" )/z_( "Active" ))"

Y = "240+(y_( "Active" )/z_( "Active" ))"[/color]

[color:#003300]

Involves taking the 'X' and 'Y' dimensions and dividing them by the 'Z' dimension, remember

that 'Z' in this example represents how far the object is from the camera, and the further an

object is, the closer it is to the center of the screen (0)

The first and final part of scaling;

[/color][color:#660000]

Scale = "1.0/z_( "Active" )"[/color]

[color:#003300]

simply makes the object smaller as it's distance from the camera becomes larger.

**polygons in 3d**

Positioning and scaling objects may give a sense of 3 dimensions, however not all 3D

geometry can be displayed this way.

Polygons are closed shapes (eg. triangle's) which are drawn at runtime, this example uses

polygons and the above principles to draw a cube.

Example: `Please login to see this link.`

In this example the 'X' and 'Y' positing is slightly more complex; now we have included

'CAMX', 'CAMY' and 'CAMZ', the camera can now me manipulated.

This is done by simply subtracting the cameras coordinates from the objects coordinated.

**OpenGL in MMF2**

MMF2's 3d capabilities are currently being expanded on; one example of this is the

integration of OpenGL into mmf2

Information and download link: `Please login to see this link.`

OpenGL is a powerful and widely accepted display engine; capable of drawing polygons in

3D.

Polygons (or polys) are drawn by defining 'vertex's'; points in space.

For example the vertex's:

[/color][color:#660000][x,y,z]

0,0,-3

1,0,-3

1,1,-3[/color]

[color:#003300]

[image]`Please login to see this link.`]

would draw a triangular poly just infront of the camera; to the top right of the screen.

Just as we can move the camera in the previous 'cube' example so too can we move the

camera in OpenGl; this is done by 'Translating' the matrix before drawing.

Whenever performing an action in OpenGL it is necessary to consider the current

matrix state as well as the effect that action will have on the Matrix.

The previous example; using vertex's to draw a triangle, could also be written in OpenGL

like:

[/color][color:#660000]

Translate 0,0,-3

[x,y,z]

0,0,0

1,0,0

1,1,0[/color]

[color:#003300]

Thats because translating 'Z' to -3 effectively makes '0:Z' equivalent to '-3:Z'

OpenGL can keep track of multiple matrices by putting them onto a 'matrix stack'

To avoid losing track or relativity of your matrix; 'push' the matrix stack before

any redundant action then 'pop' the matrix stack after to return to where you last

'push[ed]' it.

Time for a working example.

This OpenGL example generates a shaded and tiled heightmap based on several

bitmaps and imports models into it.

`Please login to see this picture.`

Example `Please login to see this link.`

[/color]