Game Development Reference
In-Depth Information
With IwGx ready to go we next need to set up our projection. We're going to be
using a perspective projection, so we need to be able to specify the perspective
multiplier value that we want to use. The code to do this is as follows:
IwGxSetPerspMul((float) IwGxGetScreenWidth() * 0.5f);
This line of code sets the perspective multiplier up, to provide a 90 degree field of
view. See the section Converting Between Coordinate Systems earlier in this chapter for
more information on how to calculate the required perspective multiplier value.
Next we have to set the far and near clipping planes' distances. For our demo
purposes we'll choose a value of 10 for the near plane and 1000 for the far plane;
these values are set as follows:
IwGxSetFarZNearZ(1000.0f, 10.0f);
These values are in view space units and can be set to any value greater than zero
(the far value should be greater than the near value too!) that works well for the
needs of our game. Normally it is the far clip distance that is most important, as it
needs to be set far enough out that our world is rendered satisfactorily, but not so
far that the frame rate suffers because we are rendering too much.
You may be wondering why these numbers have been written
as 10.0f and not just 10 or 10.0? The reason is to ensure that the
compiler treats these values as a single precision float value. The
latter two forms will both be interpreted as a double and this can
lead to a time consuming conversion from double to float .
Setting lighting information
In order to make our spinning cube look a little more attention grabbing, we'll set up
some lights so that as the cube spins its faces change color accordingly. The lighting
support provided by Marmalade may look a little limited, but is generally adequate
for most mobile games' needs.
Marmalade only allows us to define a single ambient light and a single diffuse light.
Let's start by setting the global ambient lighting value.
The first function we call is IwGxSetLightType , which takes an ID number to
identify the light we wish to modify and a definition describing the type of light we
are specifying. Presumably this API has been chosen so that Marmalade can easily
be made to support more lights in the future, but for now the ID number can only be
zero or one, and the light type must be one of IW_GX_LIGHT_AMBIENT , IW_GX_LIGHT_
DIFFUSE , or IW_GX_LIGHT_UNUSED . The latter value can be used to disable the light.
 
Search WWH ::




Custom Search