Game Development Reference
In-Depth Information
float[] UpdateOrientation()
{
// Build Translation Matrix
SetPositionMatrix(m_Position);
// Build Scale Matrix
SetScaleMatrix(m_Scale);
// Then Rotate object around Axis then translate
Matrix.multiplyMM(TempMatrix, 0, m_PositionMatrix, 0, m_RotationMatrix, 0);
// Scale Object first
Matrix.multiplyMM(m_OrientationMatrix, 0, TempMatrix, 0, m_ScaleMatrix, 0);
return m_OrientationMatrix;
}
Adding a Rotation to an Object
Using the “Hello Droid” project from Chapter 2, let's play around with the code to demonstrate how
vectors and matrices work on OpenGL ES 2.0 for Android.
In the onDrawFrame() function in the MyGLRenderer class, make sure the
m_Cube.m_Orientation.AddRotation(1)
statement is uncommented. This will add a rotation of 1 degree every time onDrawFrame() is executed,
which will be continuously (see Listing 3-10).
Listing 3-10. onDrawFrame() Function in MyGLRenderer
@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);
m_Camera.UpdateCamera();
m_Cube.m_Orientation.AddRotation(1);
m_Cube.DrawObject(m_Camera, m_PointLight);
}
The AddRotation() function is part of the Orientation class and is shown in Listing 3-11.
Listing 3-11. AddRotation() Function in the Orientation Class
void AddRotation(float AngleIncrementDegrees)
{
m_RotationAngle += AngleIncrementDegrees;
 
Search WWH ::




Custom Search