Game Development Reference
In-Depth Information
The
ProcessCameraMove()
function updates the camera's left/right rotation around the y axis,
based on the value in
m_DeltaYAxisRotation
and limited by the values
m_MaxCameraAngle
and
m_MinCameraAngle
. (See Listing 7-10.)
Listing 7-10. Processing Player's Camera Movement
void ProcessCameraMove()
{
Vector3 Axis = new Vector3(0,1,0);
// Test Limits
float CameraRotation = m_Camera.GetOrientation().GetRotationAngle();
float NextRotationAngle = CameraRotation + m_DeltaYAxisRotation;
if (NextRotationAngle > m_MaxCameraAngle)
{
m_DeltaYAxisRotation = m_MaxCameraAngle - CameraRotation;
}
else
if (NextRotationAngle < m_MinCameraAngle)
{
m_DeltaYAxisRotation = m_MinCameraAngle - CameraRotation;
}
// Camera Test
// Rotate Camera Around Y Axis
m_Camera.GetOrientation().SetRotationAxis(Axis);
m_Camera.GetOrientation().AddRotation(m_DeltaYAxisRotation);
m_CameraMoved = false;
}
The
onDrawFrame()
function has to be modified to process a change in the player's view by calling
ProcessCameraMove()
if the
m_CameraMoved
has been set to true. (See Listing 7-11.)
Listing 7-11. Modification to
onDrawFrame()
@Override
public void onDrawFrame(GL10 unused)
{
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
// Player Update
if (m_CameraMoved)
{
ProcessCameraMove();
}
m_Camera.UpdateCamera();
// Rest of code
}