Game Development Reference
In-Depth Information
Listing 7-59. Mapping Window Coordinates to 3D World Coordinates
float[] MapWindowCoordsToWorldCoords(int[] View, float WinX, float WinY, float WinZ)
{
// Set modelview matrix to just camera view to get world coordinates
// Map window coordinates to object coordinates. gluUnProject maps the specified
// window coordinates into object coordinates using model, proj, and view. The result is
// stored in obj.
// view the current view, {x, y, width, height}
float[] ObjectCoords = new float[4];
float realy = View[3] - WinY;
int result = 0;
//public static int gluUnProject (float winX, float winY, float winZ,
// float[] model, int modelOffset,
// float[] project, int projectOffset,
// int[] view, int viewOffset,
// float[] obj, int objOffset)
result = GLU.gluUnProject (WinX, realy, WinZ, m_Camera.GetViewMatrix(), 0, m_Camera.
GetProjectionMatrix(), 0, View, 0, ObjectCoords, 0);
if (result == GLES20.GL_FALSE)
{
Log.e("class Object3d :", "ERROR = GLU.gluUnProject failed!!!");
Log.e("View = ", View[0] + "," + View[1] + ", " + View[2] + ", " + View[3]);
}
return ObjectCoords;
}
The CreatePlayerWeaponSound() function creates a new sound effect for the player's weapon.
(See Listing 7-60.)
Listing 7-60. Creating the Player's Weapon Sound Effects
void CreatePlayerWeaponSound(Context iContext)
{
m_PlayerWeaponSFX = new Sound(iContext, m_SoundPool, R.raw.playershoot2);
}
The PlayPlayerWeaponSound() function plays the weapon sound effects. (See Listing 7-61.)
Listing 7-61. Playing the Weapon's Sound Effect
void PlayPlayerWeaponSound()
{
if (m_SFXOn)
{
m_PlayerWeaponSFX.PlaySound();
}
}
The CheckTouch() function (see Listing 7-62) is called when the user touches the screen and fires the
player's weapon.
Search WWH ::




Custom Search