Game Development Reference
In-Depth Information
First, we have to add the variable for the new cube, which is m_Cube2 .
private Cube m_Cube2;
Next, we have to create the new cube. The creation of the new cube is similar to the creation of the
first cube. (See Listing 5-20.)
Listing 5-20. Creating the New Cube
void CreateCube2(Context iContext)
{
//Create Cube Shader
Shader Shader = new Shader(iContext, R.raw.vsonelight, R.raw.fsonelight); // ok
MeshEx CubeMesh = new MeshEx(8,0,3,5,Cube.CubeData4Sided, Cube.CubeDrawOrder);
// Create Material for this object
Material Material1 = new Material();
// Create Texture
Texture TexAndroid = new Texture(iContext,R.drawable.ic_launcher);
Texture[] CubeTex = new Texture[1];
CubeTex[0] = TexAndroid;
m_Cube2 = new Cube(iContext,
CubeMesh,
CubeTex,
Material1,
Shader);
// Set Intial Position and Orientation
Vector3 Axis = new Vector3(0,1,0);
Vector3 Position = new Vector3(0.0f, 4.0f, 0.0f);
Vector3 Scale = new Vector3(1.0f,1.0f,1.0f);
m_Cube2.m_Orientation.SetPosition(Position);
m_Cube2.m_Orientation.SetRotationAxis(Axis);
m_Cube2.m_Orientation.SetScale(Scale);
// Gravity
m_Cube2.GetObjectPhysics().SetGravity(true);
}
The onSurfaceCreated() function has to be modified to create the new cube. The changes needed
are listed in bold in Listing 5-21.
Listing 5-21. onSurfaceCreated() Function Changes
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config)
{
m_PointLight = new PointLight(m_Context);
SetupLights();
 
Search WWH ::




Custom Search