Touch Your Coin

Touch Your Coin - Project Pilihan

===

9.5 Touch Your Coin

9.5.1 Konsep

Dalam mengasah konsentrasi sekaligus bermain kami mencip- takan sebuah game yang bisa menjalankan kedua hal tersebut. Game yang terinspirasi dari game guitar hero namun ada beberapa inovasi yaitu dimana terdapat koin yang jatuh dari atas dan user (pemain game) harus menyentuh (touch) koin tersebut ketika sudah berada dalam kotak sentuh. Ketika koin berada pada kotak sentuh dan user berhasil menyentuhnya maka user akan mendapatkan point. Se- baliknya jika user menyentuh kotak sentuh namun tidak ada koin dida- lamnya maka nyawa user akan dikurangi. Selain itu ketika koin jatuh dan user tidak menyentuhnya maka nyawa user juga akan dikurangi.

Game touch your koin pada menu awal terdiri dari empat menu yaitu sebagai berikut :

 Start Menu ini digunakan untuk memulai bermain game tersebut.

Ketika bermain user akan menghadapi dari level pertama sam- pai level 5.

 Help Menu ini berfungsi untuk mengetahui cara bermain dari game touch your koin. Selain itu pada menu ini juga dijelaskan mengenai aturan skore dan nyawa user.

 About Menu ini merupakan profil dari pencipta dari game tersebut yai- tu profil dari kelompok 5 kelas Grafika Komputer I.

 Exit

Menu ini berfungsi untuk keluar dari game touch your coin. Sasaran dari game kami adalah dari segala usia, dari anak-

anak hingga orang dewasa. Karena game tersebut merupakan game untuk mengasah konsentrasi, kecepatan, ketepatan sekaligus ber- main untuk merefreshkan pikiran. Media yang kami gunakan untuk membuat game ini adalah software eclipse berdasarkan bahasa pem- ograman berbasis OpenGL.

Gambar 9.22 Flowchart Touch Your Coin

9.5.2 Fungsi Dasar Pembentuk Objek

Komponen pada game touch your coin ini meliputi berbagai fungsi dalam OpenGL antara lain untuk membuat texture tampilan gambar atau texture mapping-nya. TextRender untuk coin yang disen- tuh. Dan fungsi-fungsi yang ada pada void onDrawFrame(GL10 gl) untuk memindah gambar satu ke gambar lainnya.

Tabel 9.2 Fungsi Dasar Pembentuk Objek

Fungsi Keterangan

// background"" gl.glPushMatrix();

Untuk membuat gl.glDisable(GL10.GL_LIGHTING);

texture mapping gl.glTranslatef(1024.0f, 627.0f, 0.0f);

tempat yang gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f);

fungsinya gl.glScalef(1024.0f, 650.0f,

0.0f); digunakan untuk gl.glRotatef(180, 1, 0, 0);

menampilkan gam- gl.glTranslatef(0, 645, 0);

bg.draw_kotak_texture(gl); bar - gambar back- gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

ground, menu dan

// start gambar koin terse- gl.glPushMatrix();

but. gl.glDisable(GL10.GL_LIGHTING); gl.glTranslatef(600.0f, 290.0f, -20.0f); //gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(70.0f, 20.0f, 0.0f); start.draw_bg(gl); gl.glEnable(GL10.GL_LIGHTING);

gl.glPopMatrix();

// help gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glTranslatef(600.0f, 210.0f, -20.0f); gl.glScalef(70.0f, 20.0f, 0.0f); help.draw_bg(gl); gl.glEnable(GL10.GL_LIGHTING);

gl.glPopMatrix(); // about gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glTranslatef(600.0f, 130.0f, -20.0f); gl.glScalef(70.0f, 20.0f, 0.0f); about.draw_bg(gl); gl.glEnable(GL10.GL_LIGHTING);

gl.glPopMatrix();

// exit gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glTranslatef(600.0f, 50.0f, - 20.0f); gl.glScalef(70.0f, 20.0f, 0.0f); exit.draw_bg(gl); gl.glEnable(GL10.GL_LIGHTING);

gl.glPopMatrix(); if (koin1muncul == true) { Untuk membuat

gl.glPushMatrix(); gambar koin berge- gl.glDisable(GL10.GL_LIGHTING);

gl.glTranslatef(296.0f, 0.0f, rak dari atas ke- 0.0f);

bawah gl.glScalef(22.0f, 22.0f,

22.0f); gl.glTranslatef(0.0f, mlaku1, 0.0f); koin.draw_koin(gl); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix(); }

gl.glPushMatrix();

gl.glDisable (GL10.GL_LIGHTING); Menampilkan gl.glEnable(GL10.GL_TEXTURE_2D);

// Enable Texture Mapping jumlah point dan gl.glEnable(GL10.GL_BLEND); //

tingkatan level. Enable Alpha Blend

gl.glDisable(GL10.GL_DEPTH_TEST) ; // Turn depth testing off (NEW) gl.glBlendFunc(GL10.GL_SRC_ALPHA , GL10.GL_ONE_MINUS_SRC_ALPHA); glText.begin( 0.0f, 0.0f, 0.0f, 1.0f ); // Begin Text Rendering gl.glScalef(1.0f, 1.0f, 1.0f); glText.draw("Nyawa : "+nyawa,

40, 550); // glText.end(); gl.glLoadIdentity(); gl.glEnable (GL10.GL_LIGHTING); gl.glDisable(GL10.GL_BLEND); // Disable Alpha Blend gl.glDisable(GL10.GL_TEXTURE_2); // Disable Texture Mapping

gl.glPopMatrix();

9.5.3 Tampilan Implementasi

OpenGL dalam pembuatan game touch your coin dapat digunakan untuk mengimplementasikan texture mapping dengan tampilan background, menu, koin serta dengan mudah memin- OpenGL dalam pembuatan game touch your coin dapat digunakan untuk mengimplementasikan texture mapping dengan tampilan background, menu, koin serta dengan mudah memin-

Gambar 9.23 Tampilan Loading

Gambar 9.24 Tampilan Menu Utama

Gambar 9.25 Tampilan Help

Gambar 9.26 Tampilan About

Gambar 9.27 Tampilan Memulai Game

9.5.4 Source Code

Source Code 9.5 Code Touch Your Coin MainActivity.java

package com.modelloading;

import android.opengl.GLSurfaceView; import android.os.Bundle; import android.app.Activity; import android.content.pm.ActivityInfo; import android.view.Menu; import android.view.Window; import android.view.WindowManager; import android.opengl.GLSurfaceView; import android.os.Bundle; import android.app.Activity; import android.content.pm.ActivityInfo; import android.view.Menu; import android.view.Window; import android.view.WindowManager;

/** The OpenGL view */ private GLSurfaceView glSurfaceView;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

// Initiate the Open GL view and // create an instance with this activity glSurfaceView = new ESSurfaceView(this);

// set our renderer to be the main renderer with // the current activity context //glSurfaceView.setRenderer(new ESRender()); setContentView(glSurfaceView);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }

/** * Remember to resume the glSurface */

@Override protected void onResume() {

super.onResume(); Music.play(this, R.raw.lagu); glSurfaceView.onResume();

/** * Also pause the glSurface */

@Override protected void onPause() {

super.onPause(); //Music.stop(this); Music.pauseSong(this); glSurfaceView.onPause();

@Override public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to // Inflate the menu; this adds items to

ESRender.java

package com.modelloading;

import java.util.Random;

import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLSurfaceView.Renderer; import android.util.Log;

publicclass ESRender implements Renderer { int miring ;

publicvoid setMiring( int

a) { this . miring = a; }

int nyawa ; private ESText glText ; private PrimitivesObject primob1 ; private PrimitivesObject primob3 ; private ObjectBall objectball2 ; private ObjectBall objectballin ; private ObjectBall objectballout ;

private ObjectBall bg ;

private ObjectBall page_help ; private ObjectBall page_about ; private ObjectBall page_play ; private ObjectBall page_dialog ; private ObjectBall start , help , about , exit ,

koin ; // private ObjectBall objectball3; private ObjectBall objectballstick ; private ObjectBall objectballbgstick ; private PrimitivesObject primob ; private PrimitivesObject primob2 ; private TransObject transobject ; privatefinal MySphere mEarth , mEarth2 , mEarth3 ; String page , dialog ; int ikiX = 0; int ikiY = 0; int point ; koin ; // private ObjectBall objectball3; private ObjectBall objectballstick ; private ObjectBall objectballbgstick ; private PrimitivesObject primob ; private PrimitivesObject primob2 ; private TransObject transobject ; privatefinal MySphere mEarth , mEarth2 , mEarth3 ; String page , dialog ; int ikiX = 0; int ikiY = 0; int point ;

boolean koin1muncul , klik1 , game ; boolean koin2muncul , klik2 ; boolean koin3muncul , klik3 ; boolean koin4muncul , klik4 ;

int Run_Mode = 0; float CurrentAngle = 0.0f; // Angle in degrees float CurrentAngle2 = 0.0f; // Angle in degrees float AnimateStep = 2.0f; // Rotation step per up-

date

float AnimateStep2 = 0.2f; // Rotation step per update float ScaleStep = 1.0f;

float CurrentScale = 1.0f;

float radius = 50.0f; // Ball's radius float x = radius ; // Ball's center (x,y) float y = radius ; float speedX = 5f; // Ball's speed (x,y) float speedY = 3f;

int xMin , xMax , yMin , yMax ; float mlaku1 , mlaku2 , mlaku3 , mlaku4 ; float mudun ; privateint mywidth = 0; privateint myheight = 0; privateint jumlah_pantulan = 0;

privatefloat x_player = 0; privatefloat y_player = 0; float nyawa2 ; privatefloat x_player_end = 0; privatefloat y_player_end = 0; privateint Navigate = 0; privateint positionRow = 0; privateint positionCol = 0; // private inthori[][] = new //

int[2*primob.numberRow*primob.numberCol][2*primob.num berRow*primob.numberCol];

// private intverti[][] = new //

int[2*primob.numberRow*primob.numberCol][2*primob.num berRow*primob.numberCol];

privateint hori [][] = newint [1000][1000]; privateint verti [][] = newint [1000][1000]; privateint numberCol = 0; privateint numberRow = 0; privatefloat WidthObject = 0;

privatefloat x_anim_stick = 0; privatefloat y_anim_stick = 0; float counter1 , counter2 , counter3 , counter4 ; privatefloat x_touch = 0; privatefloat y_touch = 0; privatefloat x_anim_stick = 0; privatefloat y_anim_stick = 0; float counter1 , counter2 , counter3 , counter4 ; privatefloat x_touch = 0; privatefloat y_touch = 0;

privatefloat x_pointer_awal = 0; privatefloat y_pointer_awal = 0;

privatefloat x_lebar_layar = 0; privatefloat y_tinggi_layar = 0;

privatefloat sudut_pointer = 0;

privatefloat jarak_center = 0;

private String arah_joystick = "" ;

boolean get_size_screen = true ;

float black [] = newfloat [] { 0.0f, 0.0f, 0.0f, 1.0f };

float yellow [] = newfloat [] { 1.0f, 1.0f, 0.0f, 1.0f }; float cyan [] = newfloat [] { 0.0f, 1.0f, 1.0f, 1.0f };

float white [] = newfloat [] { 1.0f, 1.0f, 1.0f, 1.0f };

float diffuseMaterial [] = newfloat [] { 0.73f, 0.13f, 0.86f, 1.0f }; // set

float diffuseMaterial2 [] = newfloat [] { 0.5f, 0.5f, 0.5f, 1.0f }; // set

float lightAmbient [] = newfloat [] { 0.2f, 0.3f, 0.6f, 1.0f };

float mat_specular [] = { 1.0f, 1.0f, 1.0f, 1.0f }; float light_position [] = { 0.0f, 0.0f, 1.0f, 0.0f

}; float light_position2 [] = { 0.0f, 0.0f, 1.0f, 0.0f };

/** Constructor to set the handed over context */ public ESRender(Context context) {

// super(); this . context = context; this . primob1 = new PrimitivesObject(); this . primob3 = new PrimitivesObject(); this . objectball2 = new ObjectBall(); this . objectballin = new ObjectBall(); this . objectballout = new ObjectBall();

this . bg = new ObjectBall(); this . start = new ObjectBall(); this . help = new ObjectBall(); this . about = new ObjectBall(); this . exit = new ObjectBall(); page_help = new ObjectBall(); page_about = new ObjectBall(); page_play = new ObjectBall(); page_dialog = new ObjectBall(); this . koin = new ObjectBall(); // this.objectball3 = new ObjectBall(); this . objectballstick = new ObjectBall(); this . objectballbgstick = new Object-

Ball(); this . primob = new PrimitivesObject(); this . primob2 = new PrimitivesObject(); this . mEarth = new MySphere(5, 3); this . mEarth2 = new MySphere(5, 3); this . mEarth3 = new MySphere(5, 3); this . transobject = new TransObject();

// mengambilnilaixyx (posisiawal) labirin player this . x_player = primob . x_player ; this . y_player = primob . y_player ; this . x_player_end = primob . x_player_end ; this . y_player_end = primob . y_player_end ; this . positionRow = primob . positionRow ; this . positionCol = primob . positionCol ; this . hori = primob . hori ; this . verti = primob . verti ; this . numberCol = primob . numberCol ; this . numberRow = primob . numberRow ; this . WidthObject = primob . WidthObject ;

@Override publicvoid onDrawFrame(GL10 gl) {

// menangkapukuranlayar if ( get_size_screen ){

this . x_lebar_layar = mywidth ; this . y_tinggi_layar = myheight ; get_size_screen = false ; page = "awal" ; dialog = "" ; mlaku1 = 100; mlaku2 = 75; mlaku3 = 120; mlaku4 = 40; point = 0; koin1muncul = true ; this . x_lebar_layar = mywidth ; this . y_tinggi_layar = myheight ; get_size_screen = false ; page = "awal" ; dialog = "" ; mlaku1 = 100; mlaku2 = 75; mlaku3 = 120; mlaku4 = 40; point = 0; koin1muncul = true ;

// Draw background color gl.glClear(GL10. GL_COLOR_BUFFER_BIT |

GL10. GL_DEPTH_BUFFER_BIT ); // gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glEnable(GL10. GL_DEPTH_TEST ); gl.glEnable(GL10. GL_NORMALIZE );

// gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT_AND_DIFFUSE, // makeFloatBuffer(cyan)); gl.glMaterialfv(GL10. GL_FRONT ,

GL10. GL_SPECULAR , white , 0);

gl.glMaterialfv(GL10. GL_FRONT ,

GL10. GL_SHININESS , white , 0);

gl.glMaterialfv(GL10. GL_FRONT ,

GL10. GL_DIFFUSE , white , 0);

if ( page .equalsIgnoreCase( "awal" )) {

// background"" gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(1024.0f, 627.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(1024.0f, 650.0f, 0.0f); gl.glRotatef(180, 1, 0, 0); gl.glTranslatef(0, 645, 0);

bg .draw_kotak_texture(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// start gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(600.0f, 290.0f, -

20.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(70.0f, 20.0f, 0.0f); // gl.glRotatef(180, 1, 0, 0); // gl.glTranslatef(0, 300, 0); start .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// help gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(600.0f, 210.0f, -

20.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(70.0f, 20.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); help .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// about gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(600.0f, 130.0f, -

20.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(70.0f, 20.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); about .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// exit gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(600.0f, 50.0f, -

20.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(70.0f, 20.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); exit .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// render text gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING );

gl.glEnable(GL10. GL_TEXTURE_2D ); // Enable Tex- ture Mapping gl.glEnable(GL10. GL_BLEND ); // En- able Alpha Blend gl.glDisable(GL10. GL_DEPTH_TEST ); // Turn depth testing off (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA ); // Set

// Alpha

// Blend

// Function

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

// Color // WHITE) // glText.draw("JumlahPantulan :

(" + jumlah_pantulan + ")", 450,

// 10); // Draw // // Test // // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(1.0f, 1.0f, 1.0f, 1.0f); // Begin Text Rendering (Set

// Color

// WHITE)

// glText.draw("PosisiBola : ("

// + x + "," + y + ")", 150,

// 10); // Draw // // Test // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

// Color

// WHITE) glText .draw( "Posisi Touch : (" + x_touch + ","

+( myheight - y_touch )+ ")" , 450, 400); // Draw // Test // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

// Color

// WHITE)

// glText.draw("Posisi Player : ("

// + ((400*x_player)+50) +

// "," + ((400*y_player)+50)

50, 400); // Draw // // Test // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

glText .end(); // End Text Render- ing glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 0.0f, 1.0f, 0.5f); // Begin Text

// Rendering (Set

// Color

// WHITE) // gl.glTranslatef(((400*x_player_end)+50)+50, // ((400*y_player_end)+50), 0.f);

gl.glTranslatef( mywidth / 2, - myheight / 2, 0.f); gl.glScalef(2.5f, 2.5f, 1.0f);

gl.glTranslatef(5.f, 140.f, 0.f); // gl.glRotatef(CurrentAngle, 0.1f, 1.0f, 0.2f); // Ro- tate

gl.glTranslatef(-

50.f, 0.f, 0.f);

gl.glRotatex( miring , 1, 0, 0);

glText .end(); // End Text Rendering // flag_win=1;

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f);

glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); glText .begin(0.0f, 1.0f, 0.0f, 1.0f);

gl.glLoadIdentity();

glText .begin(.0f, 1.0f, 0.0f, 1.0f);

glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

// Color

// WHITE)

// glText.draw("Posisi xy_pointer : ("

// + x_pointer + "," +

// y_pointer + ")", 50,

// 440); // Draw // // Test // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set

// Color

// WHITE)

// glText.draw("Posisi xy_pointer awal : ("

// + x_pointer_awal + "," +

// y_pointer_awal + ")", 50,

// 420); // Draw // // Test // String //

textview.setText(String.valueOf(x)); // glText.draw( "Line 1", -2, 2 ); // Draw Test String // glText.draw( "Line 2", 0, 0 ); // Draw Test String glText .end(); // End Text Render- ing

gl.glLoadIdentity();

gl.glEnable(GL10. GL_LIGHTING );

// disable texture + alpha gl.glDisable(GL10. GL_BLEND ); //

Disable Alpha Blend gl.glDisable(GL10. GL_TEXTURE_2D ); // Disable Texture Mapping gl.glPopMatrix();

} elseif ( page .equalsIgnoreCase( "help" )) {

// background"" gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(1024.0f, 627.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(1024.0f, 650.0f, 0.0f); gl.glRotatef(180, 1, 0, 0); gl.glTranslatef(0, 645, 0); page_help .draw_kotak_texture(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); // tombol zoom in gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(25.0f, 20.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(20.0f, 10.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); 0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(20.0f, 10.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1);

} elseif ( page .equalsIgnoreCase( "about" )) {

// background"" gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(1024.0f, 627.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(1024.0f, 650.0f, 0.0f); gl.glRotatef(180, 1, 0, 0); gl.glTranslatef(0, 645, 0); page_about .draw_kotak_texture(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); // tombol zoom in gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(25.0f, 20.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(20.0f, 10.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); objectballin .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

} elseif ( page .equalsIgnoreCase( "play" )) {

if ( dia- log .equalsIgnoreCase( "muncul" )) { game = false ; gl.glPushMatrix();

gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(295.0f, 20.0f, 1.0f);

gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f);

gl.glScalef(50.0f, 30.0f, 40.0f); //gl.glRotatef(180, 1, 0, 0);

page_dialog .draw_koin(gl);

gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); } // background"" gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(1024.0f, 627.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(1024.0f, 650.0f, 0.0f); gl.glRotatef(180, 1, 0, 0); gl.glTranslatef(0, 645, 0); page_play .draw_kotak_texture(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); // tombol zoom in

gl.glPushMatrix(); gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(25.0f, 20.0f,

0.0f); // gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f); gl.glScalef(20.0f, 10.0f, 0.0f); // gl.glRotatef(180, 0, 0, 1); objectballin .draw_bg(gl); gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix();

// koin1 if ( koin1muncul == true ){

gl.glPushMatrix();

gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(296.0f, 0.0f, 0.0f);

gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f);

gl.glScalef(22.0f, 22.0f, 22.0f); // gl.glRotatef(180, 0, 0, 1);

koin.draw_segitiga_texture(gl); // object- ballin.draw_segitiga_texture(gl);

koin.draw_circle_color(gl); gl.glTranslatef(0.0f, mlaku1 , 0.0f); koin .draw_koin(gl);

gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); } // koin2 if ( koin2muncul == true ){

gl.glPushMatrix();

gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(404.0f, 0.0f, 0.0f);

gl.glScalef(22.0f, 22.0f, 22.0f); // gl.glRotatef(180, 0, 0, 1);

koin.draw_segitiga_texture(gl); // object- ballin.draw_segitiga_texture(gl);

koin.draw_circle_color(gl); gl.glTranslatef(0.0f, mlaku2 , 0.0f); koin .draw_koin(gl);

gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); } // koin3 if ( koin3muncul == true ){

gl.glPushMatrix();

gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(511.0f, 0.0f, 0.0f);

gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f);

gl.glScalef(22.0f, 22.0f, 22.0f); // gl.glRotatef(180, 0, 0, 1);

koin.draw_segitiga_texture(gl); // object- ballin.draw_segitiga_texture(gl);

koin.draw_circle_color(gl); gl.glTranslatef(0.0f, mlaku3 , 0.0f); koin .draw_koin(gl);

gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); } if ( koin4muncul == true ){

// koin4 gl.glPushMatrix();

gl.glDisable(GL10. GL_LIGHTING ); gl.glTranslatef(618.0f, 0.0f, 0.0f);

gl.glScalef(CurrentScale*5.0f, CurrentScale*5.0f, 1.0f);

gl.glScalef(22.0f, 22.0f, 22.0f); // gl.glRotatef(180, 0, 0,

koin.draw_segitiga_texture(gl); // object- ballin.draw_segitiga_texture(gl);

koin.draw_circle_color(gl); gl.glTranslatef(0.0f, mlaku4 , 0.0f); koin .draw_koin(gl);

gl.glEnable(GL10. GL_LIGHTING ); gl.glPopMatrix(); } // point gl.glPushMatrix(); gl.glEnable(GL10. GL_TEXTURE_2D );

// Enable Texture Mapping gl.glEnable(GL10. GL_BLEND ); // En- able Alpha Blend gl.glDisable(GL10. GL_DEPTH_TEST ); // Turn depth testing off (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA ); // Set glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set // Color // WHITE) glText .draw( "Point :" +( point ),

50, 575); // Draw

glText .end(); gl.glEnable(GL10. GL_LIGHTING ); gl.glDisable(GL10. GL_BLEND ); gl.glDisable(GL10. GL_TEXTURE_2D ); gl.glPopMatrix(); // level gl.glPushMatrix(); gl.glEnable(GL10. GL_TEXTURE_2D );

// Enable Texture Mapping gl.glEnable(GL10. GL_BLEND ); // En- able Alpha Blend gl.glDisable(GL10. GL_DEPTH_TEST ); // Turn depth testing off (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA ); // Set glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set // Color // WHITE) glText .draw( "Level :" + level , 50,

540); // Draw

glText .end(); gl.glEnable(GL10. GL_LIGHTING ); gl.glDisable(GL10. GL_BLEND ); gl.glDisable(GL10. GL_TEXTURE_2D ); gl.glPopMatrix(); // nyawa glText .end(); gl.glEnable(GL10. GL_LIGHTING ); gl.glDisable(GL10. GL_BLEND ); gl.glDisable(GL10. GL_TEXTURE_2D ); gl.glPopMatrix(); // nyawa

// Enable Texture Mapping gl.glEnable(GL10. GL_BLEND ); // En- able Alpha Blend gl.glDisable(GL10. GL_DEPTH_TEST ); // Turn depth testing off (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA ); // Set glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set // Color // WHITE) glText .draw( "Nyawa :" + nyawa + "

---- " + nyawa2 + " --- " + counter1 , 50, 500); // Draw

glText .end(); gl.glEnable(GL10. GL_LIGHTING ); gl.glDisable(GL10. GL_BLEND ); gl.glDisable(GL10. GL_TEXTURE_2D ); gl.glPopMatrix();

gl.glPushMatrix(); gl.glEnable(GL10. GL_TEXTURE_2D );

// Enable Texture Mapping gl.glEnable(GL10. GL_BLEND ); // En- able Alpha Blend gl.glDisable(GL10. GL_DEPTH_TEST ); // Turn depth testing off (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE_MINUS_SRC_ALPHA ); // Set glText .begin(0.0f, 1.0f, 0.0f, 1.0f); // Begin Text Rendering (Set // Color // WHITE) glText .draw( "Posisi Touch : (" +

x_touch + "," +( point )+ ")" + mlaku1 , 450, 400); // Draw

glText .end(); gl.glEnable(GL10. GL_LIGHTING ); gl.glDisable(GL10. GL_BLEND ); gl.glDisable(GL10. GL_TEXTURE_2D ); gl.glPopMatrix();

CurrentAngle += AnimateStep ; if ( CurrentAngle > 360.0) {

// CurrentAngle -= 360.0*Math.floor(CurrentAngle/360.0); CurrentAngle = 0.0f; CurrentAngle += AnimateStep ;

CurrentAngle2 += AnimateStep2 ; if ( CurrentAngle2 > 360.0) {

// CurrentAngle -= 360.0*Math.floor(CurrentAngle/360.0); CurrentAngle2 = 0.0f; CurrentAngle2 += AnimateStep2 ;

// pengkondisian penghitungan pantulan mulai dari nol /* * if(Run_ModeScale==0){ this.CurrentScale-=ScaleStep;

* this.Run_ModeScale=1; } */

if ( game == true ){ if ( mlaku1 <= 3 && mlaku1 >= -2 && koin1muncul == true && klik1 == true ){ koin1muncul = false ; point += 10;

if ( mlaku2 <= 3 && mlaku2 >= -2 && koin2muncul == true && klik2 == true ){ koin2muncul = false ; point += 10;

} if ( mlaku3 <= 3 && mlaku3 >= -2

&& koin3muncul == true && klik3 == true ){ koin3muncul = false ; point += 10;

} if ( mlaku4 <= 3 && mlaku4 >= -2

&& koin4muncul == true && klik4 == true ){ koin4muncul = false ; point += 10;

} // reset counter if ( mlaku1 <= 10 && mlaku1 >= 5) {

counter1 = 0; } if ( mlaku2 <= 10 && mlaku2 >= 5) {

counter2 = 0; } if ( mlaku3 <= 10 && mlaku3 >= 5) {

counter3 = 0; } if ( mlaku4 <= 10 && mlaku4 >= 5) {

counter4 = 0; }

if ( point >= 0 && point <= 50) { level = 1; mudun = 0.1f;

} elseif ( point >= 50 && point <= 100) { level = 2; } elseif ( point >= 50 && point <= 100) { level = 2;

} elseif ( point >= 120 && point <= 160) { level = 4; mudun = 0.18f;

if ( nyawa >= 1) {

mlaku1 -= mudun ; if ( mlaku1 <= -3 && mlaku1 >=

-6) { if ( koin1muncul == true ){ counter1 += 1; }

} if ( mlaku1 <= -10) {

klik1 = false ; mlaku1 = 46; koin1muncul = true ;

mlaku2 -= mudun ; if ( mlaku2 <= -3 && mlaku2 >=

-6) { if ( koin2muncul == true ){ counter2 += 1; }

} if ( mlaku2 <= -10) {

klik2 = false ; mlaku2 = 52; koin2muncul = true ;

mlaku3 -= mudun ; if ( mlaku3 <= -3 && mlaku3 >=

-6) { if ( koin3muncul == true ){ counter3 += 1; }

} if ( mlaku3 <= -10) {

klik3 = false ; mlaku3 = 58; koin3muncul = true ;

mlaku4 -= mudun ; if ( mlaku4 <= -3 && mlaku4 >=

-6) { if ( koin4muncul == true ){ counter4 += 1; }

} if ( mlaku4 <= -10) {

klik4 = false ; mlaku4 = 40; koin4muncul = true ;

} } else { page = "awal" ; //dialog="muncul";

point =0; level =0; nyawa = 5;

if ( counter1 == 1) { nyawa2 += 0.25;

} if ( counter2 == 1) {

nyawa2 += 0.25;

} if ( counter3 == 1) {

nyawa2 += 0.25;

} if ( counter4 == 1) {

nyawa2 += 0.25;

} if ( nyawa2 == 1) {

nyawa -= nyawa2 ; nyawa2 = 0;

} CurrentScale += ScaleStep ; if ( CurrentScale % 10.0f == 0) {

ScaleStep = -1 * ScaleStep ; } } }

publicfloat getX_touch() { return x_touch ; }

publicvoid setX_touch( float x_touch) { this . x_touch = x_touch; }

publicfloat getY_touch() { return y_touch ; publicfloat getY_touch() { return y_touch ;

public String getArah_joystick() { return arah_joystick ; }

publicvoid setArah_joystick(String arah_joystick) { this . arah_joystick = arah_joystick; }

publicfloat getJarak_center() { return jarak_center ; }

publicvoid setJarak_center( float jarak_center) { this . jarak_center = jarak_center; }

publicfloat getSudut_pointer() { return sudut_pointer ; }

publicvoid setSudut_pointer( float sudut_pointer) { this . sudut_pointer = sudut_pointer; }

publicfloat getX_lebar_layar() { return x_lebar_layar ; }

publicvoid setX_lebar_layar( float x_lebar_layar) { this . x_lebar_layar = x_lebar_layar; }

publicfloat getY_tinggi_layar() { return y_tinggi_layar ; }

publicvoid setY_tinggi_layar( float y_tinggi_layar) { this . y_tinggi_layar = y_tinggi_layar; }

publicfloat getX_pointer_awal() { return x_pointer_awal ; }

publicvoid setX_pointer_awal( float x_pointer_awal) { this . x_pointer_awal = x_pointer_awal; } publicvoid setX_pointer_awal( float x_pointer_awal) { this . x_pointer_awal = x_pointer_awal; }

publicvoid setY_pointer_awal( float y_pointer_awal) { this . y_pointer_awal = y_pointer_awal; }

publicfloat getX_pointer() { return x_pointer ; }

publicvoid setX_pointer( float x_pointer) { this . x_pointer = x_pointer;

publicfloat getY_pointer() { return y_pointer ; }

publicvoid setY_pointer( float y_pointer) { this . y_pointer = y_pointer;

publicfloat getX_anim_stick() { return x_anim_stick ; }

publicvoid setX_anim_stick( float x_anim_stick) { this . x_anim_stick = x_anim_stick; }

publicfloat getY_anim_stick() { return y_anim_stick ; }

publicvoid setY_anim_stick( float y_anim_stick) { this . y_anim_stick = y_anim_stick; }

publicfloat getRadius() { return radius ; }

publicvoid setRadius( float radius) { this . radius = radius; }

publicint getMywidth() { return mywidth ; }

publicvoid setMywidth( int mywidth) { this . mywidth = mywidth; }

publicint getMyheight() { return myheight ; publicint getMyheight() { return myheight ;

publicint getNumberRow() { return numberRow ; }

publicvoid setNumberRow( int numberRow) {

this . numberRow = numberRow;

publicfloat getWidthObject() { return WidthObject ; }

publicvoid setWidthObject( float widthObject) {

WidthObject = widthObject; }

publicfloat getX_player() { return x_player ; }

publicvoid setX_player( float x_player) { this . x_player = x_player; }

publicfloat getY_player() { return y_player ; }

publicvoid setY_player( float y_player) { this . y_player = y_player; }

publicint getNavigate() { return Navigate ; }

publicvoid setNavigate( int navigate) { Navigate = navigate; }

publicboolean goForward() { if ( Navigate == 0 && positionRow >0

&& hori [ positionRow ][ positionCol ] == 0) returntrue ; if ( Navigate == 1 && positionCol <( num- berCol - 1)

&& verti [ positionRow ][ positionCol + 1] == 0)

returntrue ; if ( Navigate == 2 && positionRow <( number- Row - 1) && hori [ positionRow +

1][ positionCol ] == 0) returntrue ; if ( Navigate == 3 && positionCol >0

&& verti [ positionRow ][ positionCol ] == 0) returntrue ; returnfalse ; }

publicint getPositionRow() { return positionRow ; }

publicvoid setPositionRow( int positionRow) {

this . positionRow = positionRow; }

publicint getPositionCol() { return positionCol ; }

publicvoid setPositionCol( int positionCol) {

this . positionCol = positionCol; }

publicvoid setPage(String x) { this . page = x; }

public String getPage() { returnthis . page ; }

@Override publicvoid onSurfaceCreated(GL10 gl, EGLConfig

config) { gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // Set color's clear-value to // gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set color's clear-value // to // black // gl.glClearColor(0.0f, 0.0f, 0.0f,

1.0f); // Set color's clear-value // to

gl.glClearDepthf(1.0f); // Set depth's clear-value to farthest gl.glEnable(GL10. GL_DEPTH_TEST ); // Ena- bles depth-buffer for hidden // surface removal gl.glDepthFunc(GL10. GL_LEQUAL ); // The

type of depth testing to do

gl.glHint(GL10. GL_PERSPECTIVE_CORRECTION_HINT , GL10. GL_NICEST ); // nice // perspective // view gl.glShadeModel(GL10. GL_SMOOTH ); // Ena- gl.glHint(GL10. GL_PERSPECTIVE_CORRECTION_HINT , GL10. GL_NICEST ); // nice // perspective // view gl.glShadeModel(GL10. GL_SMOOTH ); // Ena-

// Create the GLText glText = new ESText(gl, con-

text .getAssets());

// Load the font from file (set size + padding), creates the texture // NOTE: after a successful call to this the font is ready for // rendering! glText .load( "Roboto-Regular.ttf" , 14, 2,

2); // Create Font (Height: 14

// Pixels / X+Y Padding

// 2 Pixels)

// gl.glDisable(GL10.GL_DITHER); // Disa- ble dithering for better // performance

// Setup Blending (NEW) gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); //

Full brightness, 50% alpha

// (NEW) gl.glBlendFunc(GL10. GL_SRC_ALPHA , GL10. GL_ONE ); // Select blending

// function (NEW)

// Setup Texture, each time the surface is created (NEW) primob3 .loadBallTexture(gl, context , 1); primob1 .loadBallTexture(gl, context , 4); objectball2 .loadBallTexture(gl, context ); objectballstick .loadBallTexture(gl, con-

text , 2); objectballbgstick .loadBallTexture(gl, context , 3); mEarth .loadGLTexture(gl, context , 2); // mEarth2.loadGLTexture(gl, context,6); mEarth3 .loadGLTexture(gl, context , 4); objectballin .loadBallTexture(gl, context ,

5); objectballout .loadBallTexture(gl, con- text , 6);

bg .loadBallTexture(gl, context , 7); start .loadBallTexture(gl, context , 8); bg .loadBallTexture(gl, context , 7); start .loadBallTexture(gl, context , 8);

14); page_about .loadBallTexture(gl, context , 15); page_play .loadBallTexture(gl, context , 12); page_dialog .loadBallTexture(gl, context , 16); koin .loadBallTexture(gl, context , 13); gl.glEnable(GL10. GL_TEXTURE_2D ); // Ena-

ble texture (NEW)

@Override publicvoid onSurfaceChanged(GL10 gl, int width,

int height) { mywidth = width; myheight = height;

gl.glViewport(0, 0, width, height);

// Setup orthographic projection gl.glMatrixMode(GL10. GL_PROJECTION ); //

Activate Projection Matrix gl.glLoadIdentity(); // Load Identity Ma- trix gl.glOrthof( // Set Ortho Projection (Left,Right,Bottom,Top,Front,Back)

0, width, 0, height, 500.0f, -500.0f);

// Save width and height // this.width = width; // Save Current

Width // this.height = height; // Save Current Height

gl.glMatrixMode(GL10. GL_MODELVIEW ); // Select model-view matrix

gl.glLoadIdentity(); // Reset

publicfloat getxMax() { return xMax ; }

publicvoid setxMax( int xmax) { xMax = xmax; }

publicfloat getxMin() { return xMin ; } publicfloat getxMin() { return xMin ; }

publicfloat getyMax() { return yMax ; }

publicvoid setyMax( int ymax) { yMax = ymax; }

publicfloat getyMin() { return yMin ; }

publicvoid setyMin( int ymin) { yMin = ymin; }

publicfloat getspeedX() { return speedX ; }

publicvoid setspeedX( float speedX_) { speedX = speedX_; }

publicfloat getspeedY() { return speedY ; }

publicvoid setspeedY( float speedY_) { speedY = speedY_; }

publicvoid moveWithCollisionDetection(ESRender esRender) { // Get new (x,y) position x += speedX ; y += speedY ; // Detect collision and react if ( x + radius > esRender.getxMax()) {

speedX =- speedX ; x = esRender.getxMax() - radius ; this . jumlah_pantulan += 1;

} elseif ( x - radius < esRender.getxMin()) { speedX =- speedX ; x = esRender.getxMin() + radius ; this . jumlah_pantulan += 1;

} if ( y + radius > esRender.getyMax()) {

speedY =- speedY ; y = esRender.getyMax() - radius ; this . jumlah_pantulan += 1;

} elseif ( y - radius < esRender.getyMin()) { speedY =- speedY ; } elseif ( y - radius < esRender.getyMin()) { speedY =- speedY ;

// pengkondisian penghitungan pantulan mulai dari nol if ( Run_Mode == 0) { this . jumlah_pantulan -= 4; this . Run_Mode = 1;

publicvoid set( int x, int y, int width, int height) { xMin = x; // xMax = x + width - 1; xMax = x + width; yMin = y; // yMax = y + height - 1; yMax = y + height;

publicint getIkiX() { returnthis . ikiX ; }

publicint getIkiY() { returnthis . ikiY ; }

publicvoid setIkiX( int baru) { this . ikiX = baru; }

publicvoid setIkiY( int baru) { this . ikiY = baru; }

int skalaX = 25; int skalaY ;

publicint getSkalaX() { returnthis . skalaX ; }

publicvoid setSkalaX( int baru) { this . skalaX = baru; }

publicvoid setKlik1() { // TODO Auto-generated method stub klik1 = true ;

publicfloat getPosKoin1() { // TODO Auto-generated method stub returnthis . mlaku1 ; publicfloat getPosKoin1() { // TODO Auto-generated method stub returnthis . mlaku1 ;

publicfloat getPosKoin2() { // TODO Auto-generated method stub returnthis . mlaku2 ;

publicvoid setKlik3() { // TODO Auto-generated method stub klik3 = true ;

publicfloat getPosKoin3() { // TODO Auto-generated method stub returnthis . mlaku3 ;

publicvoid setKlik4() { // TODO Auto-generated method stub klik4 = true ;

publicfloat getPosKoin4() { // TODO Auto-generated method stub returnthis . mlaku4 ;

publicvoid setMati() { // TODO Auto-generated method stub nyawa -= 1;

publicvoid setDialog(String s) { this . dialog = s;

publicvoid setgame() { this . game = true ; }

ESSurfeceView.java ESSurfeceView.java

import android.content.Context; import android.graphics.Point; import android.opengl.GLSurfaceView; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent;

/** * A view container where OpenGL ES graphics can be drawn on screen. This view * can also be used to capture touch events, such as

a user interacting with * drawn objects. */

public class ESSurfaceView extends GLSurfaceView {

private final ESRender esRender; private float previousX; private float previousY;

/* * public float initx_stick = 425; public float inity_stick = 267; public * Point _touchingPoint = new Point(425,267); public Point _pointerPosition * = new Point(220,150); */

public float initx_stick = 1013; public float inity_stick = 500; public Point _touchingPoint = new Point(1013,

500); public Point _pointerPosition = new Point(220,150); private Boolean _dragging = false; private int flag_first=0;

private float mypointer_awal_x=0; private float mypointer_awal_y=0;

public ESSurfaceView(Context context) { super(context);

// Set the Renderer for drawing on the GLSurfaceView esRender = new ESRender(context); setRenderer(esRender);

// To enable keypad this.setFocusable(true); this.requestFocus();

// To enable touch mode this.setFocusableInTouchMode(true);

// Render the view only when there is a // Render the view only when there is a

@Override public boolean onTouchEvent(MotionEvent v) {

// MotionEvent reports input details from the touch screen // and other input controls. In this case, we are only // interested in events where the touch position changed.

/* * initx_stick = esRen- der.getWidthObject()-esRender.getRadius(); * inity_stick = 0.0f; _touchingPoint.x = (int) initx_stick; * _touchingPoint.y= (int) inity_stick; * * _pointerPosition.x = (int) in-

itx_stick; _pointerPosition.y= (int) * inity_stick; */

// update(v);

float currentX = v.getX(); float currentY = v.getY(); float deltaX, deltaY;

// float scalingFactor = 0.50f / ((esRen- der.xMax > esRender.yMax) ? // esRender.yMax // : esRender.xMax);

switch (v.getAction()) { case MotionEvent.ACTION_DOWN:

Log.v("Test Action Down", "action down working");

// esRender.setX_anim_stick(- esRender.getRadius()); // esRender.setY_anim_stick(0.0f);

//membuat touch tombol _touchingPoint.x = (int) v.getX(); _touchingPoint.y = (int) v.getY(); esRen-

der.setX_touch(_touchingPoint.x); esRen- der.setY_touch(esRender.getMyheight()-

_touchingPoint.y); /////// tombol min plus

if(_touchingPoint.x>=600&&_touchingPoint.x<=950&& esRender.getPage().equalsIgnoreCase("awal")){ Log.v("masuk x X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

if(_touchingPoint.y>=248 && _touchingPoint.y <=306){//out - esRen- der.setPage("play"); Mu- sic.playOnce(esRender.context, R.raw.zoom);

}else

if(_touchingPoint.y>=330 && _touchingPoint.y <=390){

esRen- der.setPage("help"); Mu- sic.playOnce(esRender.context, R.raw.zoom); Log.v("click min X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

}else

if(_touchingPoint.y>=400 && _touchingPoint.y <=469){ esRen- der.setPage("about"); Log.v("click min X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

}else

if(_touchingPoint.y>=488 && _touchingPoint.y <=549){ int awal =esRender.getSkalaX(); esRen- der.setSkalaX(awal-4); Mu- sic.playOnce(esRender.context, R.raw.zoom); Log.v("click min X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

} if(_touchingPoint.y>=514 &&

_touchingPoint.y <=600&& esRen- der.getPage().equalsIgnoreCase("play")){

if(_touchingPoint.x>=296&&_touchingPoint.x<=404 && esRender.getPosKoin1()>=-2 && esRen- der.getPosKoin1() <=2){//out -

esRen- der.setKlik1(); Mu- sic.playOnce(esRender.context, R.raw.zoom); } else if(_touchingPoint.x>=296&&_touchingPoint.x<=404){//ou t-

esRender.setMati(); Mu- esRender.setMati(); Mu-

if(_touchingPoint.x>=404&&_touchingPoint.x<=511 && esRender.getPosKoin2()>=-2 && esRen- der.getPosKoin2() <=2){//out -

esRen- der.setKlik2(); Mu- sic.playOnce(esRender.context, R.raw.zoom);

}else

if(_touchingPoint.x>=404&&_touchingPoint.x<=511 ){//out -

esRender.setMati(); Mu-

sic.playOnce(esRender.context, R.raw.fb);

if(_touchingPoint.x>=511&&_touchingPoint.x<=618 && esRender.getPosKoin3()>=-2 && esRen- der.getPosKoin3() <=2){//out -

esRen- der.setKlik3(); Mu- sic.playOnce(esRender.context, R.raw.zoom);

}else

if(_touchingPoint.x>=511&&_touchingPoint.x<=618 ){//out -

esRender.setMati(); Mu-

sic.playOnce(esRender.context, R.raw.fb);

if(_touchingPoint.x>=618&&_touchingPoint.x<=726 && esRender.getPosKoin4()>=-2 && esRen- der.getPosKoin4() <=2){//out -

esRen- der.setKlik4(); Mu- sic.playOnce(esRender.context, R.raw.zoom);

}else

if(_touchingPoint.x>=618&&_touchingPoint.x<=726 ){//out -

esRender.setMati(); Mu-

sic.playOnce(esRender.context, R.raw.fb);

if(_touchingPoint.x>=50&&_touchingPoint.x<=130 && (esRen- der.getPage().equalsIgnoreCase("play")||esRender.getP age().equalsIgnoreCase("help")||esRender.getPage().eq ualsIgnoreCase("about"))){

if(_touchingPoint.y>=esRender.getMyheight()-

80&&_touchingPoint.y<=esRender.getMyheight()- 20){//out -

if(esRender.getPage().equalsIgnoreCase("play")){

//esRender.setDialog("muncul"); esRen- der.setPage("awal");

}else{ esRen- der.setPage("awal"); }

} //deteksi klik dialog

if(_touchingPoint.y>=50&&_touchingPoint.y<=130 && esRender.getPage().equalsIgnoreCase("play")){

if(_touchingPoint.x>=99&&_touchingPoint.x<=99){// out - esRen- der.setDialog("hilang"); esRen- der.setgame();

}else if (_touchingPoint.x>=99&&_touchingPoint.x<=99){ esRen- der.setPage("awal"); }

// membuat animasi pergerakan tom- bol joystick

// bound to a box disekitar joy- stick /* * if( currentX >= _touchingPoint.x-esRender.getRadius() && currentX * <= _touchingPoint.x+esRender.getRadius()){ * * if( currentY >=

_touchingPoint.y-esRender.getRadius() && currentY * <= _touchingPoint.y+esRender.getRadius()){ * * // lakukan pergerakan pada

stick * esRen- der.setX_anim_stick(esRender.getRadius()); * esRen- stick * esRen- der.setX_anim_stick(esRender.getRadius()); * esRen-

break; // requestRender(); // case Motion-

Event.ACTION_POINTER_DOWN: // Log.v("Test Action ACTION_POINTER_DOWN", "action working"); // esRender.setX_anim_stick(- esRender.getRadius()); // esRender.setY_anim_stick(- esRender.getRadius());

// membuat animasi pergerakan tom- bol joystick

// bound to a box disekitar joy- stick /* * if( currentX >= _touchingPoint.x-esRender.getRadius() && currentX * <= _touchingPoint.x+esRender.getRadius()){ * * if( currentY >=

_touchingPoint.y-esRender.getRadius() && currentY * <= _touchingPoint.y+esRender.getRadius()){ * * // lakukan pergerakan pada

stick * esRen- der.setX_anim_stick(esRender.getRadius()); * esRen- der.setY_anim_stick(esRender.getRadius()); * *} * *} */

// requestRender(); case MotionEvent.ACTION_UP: Log.v("Test Action ACTION_UP", "action working"); // esRender.setX_anim_stick(0.0f); // esRender.setY_anim_stick(-

esRender.getRadius()); // requestRender(); // case MotionEvent.ACTION_MOVE: // Log.v("Test Action

ACTION_POINTER_DOWN", "action working"); // requestRender(); // case MotionEvent.ACTION_UP: // Log.v("Test Action Up", "action

up working");

// requestRender(); case MotionEvent.ACTION_MOVE:

// Modify rotational angles ac- cording to movement deltaX = currentX - previousX; deltaY = currentY - previousY;

// esRen- der.setspeedX(esRender.getspeedX()+ (del- taX/getWidth()));

// esRen- der.setspeedY(esRender.getspeedY()+ (del- taY/getHeight()));

esRen- der.setspeedX(esRender.getspeedX() + deltaX / 100); esRen- der.setspeedY(esRender.getspeedY() + deltaY / 100);

requestRender();

// Save current x, y previousX = currentX; previousY = currentY; return true; // Event handled // break;

private MotionEvent lastEvent;

public void update(MotionEvent event) {

//initx_stick = 1066.0f- 1.5f*esRender.getRadius(); //inity_stick =0.5f*esRender.getRadius();

if (event == null && lastEvent == null) { return; } else if (event == null && lastEvent != null) { event = lastEvent; } else { lastEvent = event; } // drag drop if (event.getAction() == Motion-

Event.ACTION_DOWN) { _dragging = true; flag_first=0;

} else if (event.getAction() == Motion- Event.ACTION_UP) { _dragging = false; }

// penanda untuk menyimpan koordinat yang pertama kali diklik // penanda untuk menyimpan koordinat yang pertama kali diklik

// get the pos _touchingPoint.x = (int)

event.getX(); _touchingPoint.y = (int) event.getY();

/////// tombol min plus

if(_touchingPoint.x>=99&&_touchingPoint.x<=150){ Log.v("masuk x X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

if(_touchingPoint.y>=464&&_touchingPoint.y<=514){ //out - int awal =esRender.getSkalaX(); esRen- der.setSkalaX(awal-4); Mu- sic.playOnce(esRender.context, R.raw.zoom); Log.v("click min X : Y ", _touchingPoint.x+" : "+_touchingPoint.y); }else if (_touchingPoint.y>=398&&_touchingPoint.y<=445){ // in +

int awal =esRender.getSkalaX(); esRen- der.setSkalaX(awal+4); Mu- sic.playOnce(esRender.context, R.raw.zoom); Log.v("click plus X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

Log.v("Pos X : Y ", _touchingPoint.x+" : "+_touchingPoint.y);

esRen- der.setX_touch(_touchingPoint.x); esRen- der.setY_touch(esRender.getMyheight()- _touchingPoint.y);

esRender.setJarak_center((float) ((Math.pow(_touchingPoint.x-(esRender.getMywidth()- 2*esRender.getRadius()), 2))+

(Math.pow(esRender.getMyheight()- _touchingPoint.y-2*esRender.getRadius(), 2))));

// membuat radius touch screen // membuat radius touch screen

&& (((Math.pow(_touchingPoint.x-(esRender.getMywidth()- 2*esRender.getRadius()), 2))+

(Math.pow(esRender.getMyheight()- _touchingPoint.y-2*esRender.getRadius(), 2)))>

Math.pow(0.5*esRender.getRadius(), 2)) ){

Mu-

sic.playOnce(esRender.context, R.raw.fb);

//membuat penanda untuk mendapatkan point awal touch if(flag_first==0){ esRen- der.setX_pointer_awal(_touchingPoint.x); mypointer_awal_x = esRender.getX_pointer_awal(); esRen- der.setY_pointer_awal(_touchingPoint.y); mypointer_awal_y = esRender.getY_pointer_awal();

flag_first=1;

//kodisi jika titik awal sama dengan titik pointer

if((mypointer_awal_x==_touchingPoint.x) && (my- pointer_awal_y==_touchingPoint.y)){ mypoint- er_awal_x=esRender.getMywidth()-100; mypoint- er_awal_y=esRender.getMyheight()-100;

esRen- der.setX_pointer(_touchingPoint.x); esRen- der.setY_pointer(_touchingPoint.y);

esRen- der.setX_lebar_layar(esRender.getMywidth()); esRen- der.setY_tinggi_layar(esRender.getMyheight());

// get the angle double myangle = -

Math.atan2(_touchingPoint.y - mypointer_awal_y,

_touchingPoint.x - mypointer_awal_x) / (Math.PI / 180);

esRen- der.setSudut_pointer((float) myangle);

esRen- der.setX_anim_stick((float) (26.0f*Math.cos(myangle * (Math.PI / 180))));

esRen- der.setY_anim_stick((float) (26.0f*Math.sin(myangle * (Math.PI / 180))));

//set arah joystick if((float) myangle>=45 &&

(float) myangle<=135){ esRen- der.setArah_joystick("Atas"); int awal =esRender.getIkiY(); esRen- der.setIkiY(awal+10);

if (esRen- der.getNavigate() == 0 && esRender.goForward()) esRen- der.setPositionRow(esRender.getPositionRow() - 1); else if (esRen- der.getNavigate() == 1 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() + 1); else if (esRen- der.getNavigate() == 2 && esRender.goForward()) esRen- der.setPositionRow(esRender.getPositionRow() + 1); else if (esRen- der.getNavigate() == 3 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() - 1); Log.v("Test Action KEYCODE_T", "action working");

esRen- der.setX_player((esRender.getPositionCol() * esRender

.getWidthObject()) + (esRender.getWidthObject() / 2)); esRen- der.setY_player(((esRender.getNumberRow() - esRender.getPositionRow() - 1) * esRender

.getWidthObject()) + (esRender.getWidthObject() / 2));

}else if( ((float) myan- gle>=0 && (float) myangle<45) || ((float) myangle>=-

44 && (float) myangle<=0)){ esRen- der.setArah_joystick("Kanan"); int awal =esRender.getIkiX(); esRen- der.setIkiX(awal+10);

esRen- der.setNavigate(esRender.getNavigate() + 1); }else if ( (float) myan- gle>=135 && (float) myangle<225){ esRen- der.setArah_joystick("Kiri"); int awal =esRender.getIkiX(); esRen- der.setIkiX(awal-10); esRen- der.setNavigate(esRender.getNavigate() - 1); }else{ int awal =esRender.getIkiY(); esRen- der.setIkiY(awal-10);

//reset Navigate if (esRender.getNavigate()

< 0){ esRen- der.setNavigate(3);

} esRen-

der.setNavigate(esRender.getNavigate() % 4);

/* //membuat penanda if(flag_first==0){

esRen- der.setX_pointer_awal(_touchingPoint.x); esRen- der.setY_pointer_awal(_touchingPoint.y); flag_first=1; }

esRen- der.setX_pointer(_touchingPoint.x); esRen- der.setY_pointer(_touchingPoint.y); esRen- der.setX_pointer(_touchingPoint.x); esRen- der.setY_pointer(_touchingPoint.y);

esRen- der.setX_anim_stick(_touchingPoint.x); esRen- der.setY_anim_stick(_touchingPoint.y);

// bound to a box if (_touchingPoint.x < 400) {

_touchingPoint.x = 400; } if (_touchingPoint.x > 450) {

_touchingPoint.x = 450; } if (_touchingPoint.y < 240) {

_touchingPoint.y = 240; } if (_touchingPoint.y > 290) {

_touchingPoint.y = 290; }

// get the angle double angle =

Math.atan2(_touchingPoint.y - inity_stick, _touchingPoint.x - initx_stick) / (Math.PI / 180);

// Move the beetle in proportion to how far // the joystick is dragged from its center _pointerPosition.y += Math.sin(angle * (Math.PI / 180)) * (_touchingPoint.x / 70); _pointerPosition.x += Math.cos(angle * (Math.PI / 180)) * (_touchingPoint.x / 70);

//esRender.setX_anim_stick(_touchingPoint.x);

//esRender.setY_anim_stick(_touchingPoint.y);

// make the pointer go thru if (_pointerPosition.x > 480) {

_pointerPosition.x = 0; } _pointerPosition.x = 0; }

if (_pointerPosition.y > 320) { _pointerPosition.y = 0; } if (_pointerPosition.y < 0) {

_pointerPosition.y = 320; }

} else if (!_dragging) {

flag_first=0;

// Snap back to center when the joystick is released _touchingPoint.x = (int) in- itx_stick; _touchingPoint.y = (int) ini- ty_stick;

esRender.setX_anim_stick(0.0f); esRender.setY_anim_stick(0.0f);

// shaft.alpha = 0; } }

// Key-up event handler @Override public boolean onKeyUp(int keyCode, KeyEvent

event) { switch (keyCode) { case KeyEvent.KEYCODE_A: // mengurangi

kecepatan object if ((esRender.getspeedX() - 0.05f > 0)) { esRen- der.setspeedX(esRender.getspeedX() - 0.05f); } if ((esRender.getspeedX() - 0.05f

< 0)) { esRender.setspeedX(0.0f); } if ((esRender.getspeedY() - 0.05f

>= 0)) { esRen- der.setspeedY(esRender.getspeedY() - 0.05f); } if ((esRender.getspeedY() - 0.05f

< 0)) { esRender.setspeedY(0.0f); } Log.v("Test Action KEYCODE_A",

"action working"); break; case KeyEvent.KEYCODE_T: // up "action working"); break; case KeyEvent.KEYCODE_T: // up

1 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() + 1); else if (esRender.getNavigate() ==

2 && esRender.goForward()) esRen- der.setPositionRow(esRender.getPositionRow() + 1); else if (esRender.getNavigate() ==

3 && esRender.goForward()) esRen- der.setPositionCol(esRender.getPositionCol() - 1); Log.v("Test Action KEYCODE_T", "action working");

esRen- der.setX_player((esRender.getPositionCol() * esRender .getWidthObject()) + (esRender.getWidthObject() / 2)); esRen- der.setY_player(((esRender.getNumberRow() - esRen- der.getPositionRow() - 1) * esRender

.getWidthObject()) + (esRender.getWidthObject() / 2)); break; case KeyEvent.KEYCODE_G: Log.v("Test Action KEYCODE_G", "action working"); break; case KeyEvent.KEYCODE_H: // right esRen- der.setNavigate(esRender.getNavigate() + 1); Log.v("Test Action KEYCODE_H", "action working"); break; case KeyEvent.KEYCODE_F: // left esRen- der.setNavigate(esRender.getNavigate() - 1); Log.v("Test Action KEYCODE_F", "action working"); break; }

if (esRender.getNavigate() < 0)

esRender.setNavigate(3); esRen- der.setNavigate(esRender.getNavigate() % 4);

return true; // Event handled

ObjModel.java

package com.modelloading;

import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLUtils; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.StringTokenizer; import javax.microedition.khronos.opengles.GL10;

public class ObjModel {

public void bindTextures(Context context, GL10 gl) { Bitmap bitmap;

try { InputStream is = context.getAssets().open("textures/"+mTextureName); bitmap = BitmapFactory.decodeStream(is); if (bitmap == null) {

Log.v("ObjModel", "err loading bitmap!"); } } catch (java.io.IOException e) {

Log.v("ObjModel", "err loading tex: "+e.toString()); return; }

mTextures = new int[1]; gl.glGenTextures(1, mTextures, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D,

mTextures[0]); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);

gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,

Log.v("ObjModel", "loaded texture: "+mTextureName+" = "+mTextures[0]);

bitmap.recycle(); }

public void draw(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

for (Model model : mModels) {

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, model.v); if (model.vt != null && mTextures != null) { gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[0]);

gl.glTexCoordPointer(2,

GL10.GL_FLOAT, 0, model.vt); } if (model.vn != null) {

gl.glNormalPointer(GL10.GL_FLOAT, 0, model.vn); } gl.glDrawArrays(GL10.GL_TRIANGLES, 0,

model.v_size);

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

public static ObjModel loadFromStream(InputStream is, String texture_name) throws IOException { ObjModel obj = ObjLoader.loadFromStream(is); obj.mTextureName = texture_name; return obj;

/* private */

private Model mModels[]; private int mTextures[]; private String mTextureName;

private static class ObjLoader { private static class ObjLoader {

BufferedReader reader = new

BufferedReader(new InputStreamReader(is));

ObjModel obj = new ObjModel(); ArrayList<Point3> v = new

ArrayList<Point3>(); ArrayList<Point3> vt = new ArrayList<Point3>(); ArrayList<Point3> vn = new ArrayList<Point3>(); ArrayList<Face> f = new ArrayList<Face>();

ArrayList<Model> o = new ArrayList<Model>();

boolean o_pending=false;

while(reader.ready()) {

String line = reader.readLine(); if (line == null)

break;

StringTokenizer tok = new StringTokenizer(line); String cmd = tok.nextToken();

if (cmd.equals("o")) {

if (o_pending) { Model model = new Model(); model.fill(f, vt.size() > 0,

vn.size() > 0); o.add(model); } else {

o_pending=true; } } else if (cmd.equals("v")) {

v.add(read_point(tok)); } else if (cmd.equals("vn")) {

vn.add(read_point(tok)); } else if (cmd.equals("vt")) {

vt.add(read_point(tok)); } else if (cmd.equals("f")) {

if (tok.countTokens() != 3) throw new UnsupportedOperationException("Only triangles if (tok.countTokens() != 3) throw new UnsupportedOperationException("Only triangles

Face face = new Face(3); while (tok.hasMoreTokens()) {

StringTokenizer face_tok = new StringTokenizer(tok.nextToken(), "/");

int v_idx = -1; int vt_idx = -1; int vn_idx = -1; v_idx =

Integer.parseInt(face_tok.nextToken()); if (face_tok.hasMoreTokens()) vt_idx = Integer.parseInt(face_tok.nextToken()); if (face_tok.hasMoreTokens()) vn_idx = Integer.parseInt(face_tok.nextToken());

//Log.v("objmodel", "face: "+v_idx+"/"+vt_idx+"/"+vn_idx);

face.addVertex( v.get(v_idx-1), vt_idx == -1 ? null :

vt.get(vt_idx-1), vn_idx == -1 ? null : vn.get(vn_idx-1)

} f.add(face);

} /* else if (cmd.equals("usemtl")) {

// lets not bother parsing material file // just use the name as an asset path obj.mTextureName = tok.nextToken(); } */

if (o_pending) { Model model = new Model(); model.fill(f, vt.size() > 0,

vn.size() > 0); o.add(model); }

obj.mModels = new Model[o.size()]; o.toArray(obj.mModels);

return obj; }

private static Point3 private static Point3

ret.x = Float.parseFloat(tok.nextToken()); if (tok.hasMoreTokens()) { ret.y = Float.parseFloat(tok.nextToken()); if (tok.hasMoreTokens()) {

ret.z =

Float.parseFloat(tok.nextToken()); } } } return ret;

private static class Face {

Point3 v[]; Point3 vt[]; Point3 vn[]; int size; int count;

public Face(int size) {

this.size = size; this.count = 0; this.v = new Point3[size]; this.vt = new Point3[size]; this.vn = new Point3[size];

} public boolean addVertex(Point3 v, Point3 vt,

Point3 vn) { if (count >= size) return false; this.v[count] = v; this.vt[count] = vt; this.vn[count] = vn; count++; return true;

public void pushOnto(FloatBuffer v_buffer, FloatBuffer vt_buffer, FloatBuffer vn_buffer) { int i; for (i=0; i<size; i++) {

v_buffer.put(v[i].x);

v_buffer.put(v[i].y); v_buffer.put(v[i].z);

if (vt_buffer != null && vt[i] != null) { vt_buffer.put(vt[i].x); if (vt_buffer != null && vt[i] != null) { vt_buffer.put(vt[i].x);

if (vn_buffer != null && vn[i] != null) { vn_buffer.put(vn[i].x); vn_buffer.put(vn[i].y); vn_buffer.put(vn[i].z); } } } }

private static class Model {

public FloatBuffer v; public FloatBuffer vt; public FloatBuffer vn; public int v_size;

public void fill(ArrayList<Face> faces, boolean has_tex, boolean has_normals) { int f_len = faces.size();

this.v_size = f_len * 3; this.v =

FloatBuffer.allocate(this.v_size*3);

if (has_tex) this.vt = FloatBuffer.allocate(this.v_size*2); if (has_normals) this.vn = FloatBuffer.allocate(this.v_size*3);

int i; for (i=0; i < f_len; i++) {

Face face = faces.get(i); face.pushOnto(this.v, this.vt,

this.vn); }

this.v.rewind(); if (this.vt != null)

this.vt.rewind(); if (this.vn != null)

this.vn.rewind(); } }

ObjectBall.java ObjectBall.java

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLES20; import android.opengl.GLUtils;

public class ObjectBall {

private float textCoord_Triagle[]={ 1.0f, 1.0f, 0.0f,

V3 0.0f, 1.0f, 0.0f,

V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) }; //yang tak tambah

private float textCoord_kotak[] = { // Vertices for the square -1.0f, 0.0f, 0.0f, // 0. left-bottom 1.0f, 0.0f, 0.0f, // 1. right-bottom 1.0f, 1.0f, 0.0f, // 2. left-top -1.0f, 1.0f, 0.0f, // 3. right-top

private float[] texCoordsbg = { // Tex- ture coords for the above face (NEW) 0.0f, 1.0f, // A. left- bottom (NEW) 1.0f, 1.0f, // B. right- bottom (NEW) 0.0f, 0.0f, // C. left-top (NEW) 1.0f, 0.0f // D. right-top (NEW) }; private int[] imageFileIDs = { // Image file IDs R.drawable.nature, R.drawable.mule, R.drawable.joystick, R.drawable.joystick_bg, R.drawable.meow, R.drawable.plus, //5 R.drawable.min, R.drawable.bg,

R.drawable.start, R.drawable.help, R.drawable.about, R.drawable.exit, R.drawable.play, //12 R.drawable.koin, R.drawable.helping, R.drawable.abouting, R.drawable.dialog

private float vertices_circle[]={0.0f,0.0f,0.0f}; private float verti-

ces_circle_color[]={0.0f,0.0f,0.0f,0.5f}; private float textCoord[]; private float vertices_circle1[];

int[] textures_indek = new int[1];

private int batas_sudut=360; float jari_jari; float a,b; float x,y; float step=3.0f,step_line=0.2f; float x1,y1; float x2,y2; float teta; private int loop,loop_color;

private float[] verticesbg = { // Vertices for a face 0.0f, 0.0f, 0.0f, // 0. left- bottom-front 5.0f, 0.0f, 0.0f, // 1. right- bottom-front 0.0f, 3.0f, 0.0f, // 2. left-top- front 5.0f, 3.0f, 0.0f // 3. right-top- front };

private float[] verticeskoin = { // Vertices for

a face 0.0f, 0.0f, 0.0f, // 0. left- bottom-front 5.0f, 0.0f, 0.0f, // 1. right- bottom-front 0.0f, 5.0f, 0.0f, // 2. left-top- front 5.0f, 5.0f, 0.0f // 3. right-top- front }; private FloatBuffer vertexBuffer; // Buffer for

vertex-array private FloatBuffer texBuffer; private FloatBuffer vertexBuffer2; // Buffer for

vertex-array private FloatBuffer texBuffer2; vertex-array private FloatBuffer texBuffer2;

float. An float has 4 bytes ByteBuffer vbb = ByteBuff- er.allocateDirect(verticesbg.length * 4);

vbb.order(ByteOrder.nativeOrder()); // Use native byte order vertexBuffer = vbb.asFloatBuffer(); // Convert from byte to float vertexBuff- er.put(verticesbg); // Copy data into buffer vertexBuffer.position(0); // Rewind // Setup texture-coords- array buffer, in float. An float has 4 bytes // (NEW) ByteBuffer tbb = ByteBuff-

er.allocateDirect(texCoordsbg.length * 4);

tbb.order(ByteOrder.nativeOrder()); texBuffer = tbb.asFloatBuffer(); texBuff- er.put(texCoordsbg); texBuffer.position(0);

ByteBuffer vbb2 = ByteBuffer.allocateDirect(verticeskoin.length * 4);

vbb2.order(ByteOrder.nativeOrder()); // Use na- tive byte order vertexBuffer2 = vbb2.asFloatBuffer(); // Convert from byte to float vertexBuff- er2.put(verticeskoin); // Copy data into buffer vertexBuffer2.position(0); // Rewind // Setup texture-coords- array buffer, in float. An float has 4 bytes // (NEW) ByteBuffer tbb2 =

ByteBuffer.allocateDirect(texCoordsbg.length * 4);

tbb2.order(ByteOrder.nativeOrder()); texBuffer2 = tbb2.asFloatBuffer(); texBuff- er2.put(texCoordsbg); texBuffer2.position(0); // ============ start to generate stetch texture coordinat ========================== //Inisialisasi jari_jari=0.5f;

// Titik Pusat

a = 0.5f; b = 0.5f ;

//x=a+jari_jari; y=b; teta = 0;

// generate stretch texture coordinat teta=0; textCoord = new float[batas_sudut * 3]; for (int ii = 0; ii < batas_sudut * 3; ii

+= 3) { // membentuk textCoord textCoord[ii] =

(jari_jari*((float) Math.cos(-teta)))+a; textCoord[ii + 1] = (jari_jari*((float) Math.sin(-teta)))+b; textCoord[ii + 2] = 0.0f;

teta += Math.PI / 90;

// ============ start to generate verti- ces to circle (Cara 1) ========================== //Inisialisasi jari_jari=50.0f;

// Titik Pusat

a = 50.0f; b = 50.0f ;

vertices_circle1 = new float[batas_sudut * 3]; for (int ii = 0; ii < batas_sudut * 3; ii += 3) { // membentuk vertices_circle1 vertices_circle1[ii] =

(jari_jari*((float) Math.cos(teta)))+a; vertices_circle1[ii + 1] = (jari_jari*((float) Math.sin(teta)))+b; vertices_circle1[ii + 2] = 0.0f;

teta += Math.PI / 90;

// ============ start to generate verti- ces to circle (Cara 2) ========================== //Inisialisasi jari_jari=50.0f;

// Titik Pusat

a = 50.0f; b = 50.0f ; x=a+jari_jari; y=b;

loop=0; loop_color=0; vertices_circle=new

float[(int)(3*batas_sudut/step)*3]; vertices_circle_color=new float[(int)(3*batas_sudut/step)*4]; for(teta=0;teta<=2*batas_sudut;teta+=step){ vertices_circle[loop] = (float) ((x- float[(int)(3*batas_sudut/step)*3]; vertices_circle_color=new float[(int)(3*batas_sudut/step)*4]; for(teta=0;teta<=2*batas_sudut;teta+=step){ vertices_circle[loop] = (float) ((x-

vertices_circle[loop+1] = (float) ((x- a)*Math.sin((teta/180)*(22/7)) - ((y- b)*Math.cos((teta/180)*(22/7))) + b);

vertices_circle[loop+2]=0; loop+=3;

//mengenerate warna untuk setiap vertex //vertices_circle_color[loop_color]=(float) ((x-

a)*Math.cos((teta/180)*(22/7)) - ((y- b)*Math.sin((teta/180)*(22/7))) + a);

//vertices_circle_color[loop_color+1]=(float) ((x-a)*Math.sin((teta/180)*(22/7)) - ((y- b)*Math.cos((teta/180)*(22/7))) + b);

vertices_circle_color[loop_color]=(float) (Math.cos((teta/180)*(22/7)) );

vertices_circle_color[loop_color+1]=(float) (Math.sin((teta/180)*(22/7)));

vertices_circle_color[loop_color+2]=0.5f; vertices_circle_color[loop_color+3]=0.5f; loop_color+=4;

} // ============= end for generate vertices to circle ====================

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb;

// Setup index-array buffer. Indices in byte. public static ByteBuffer makeByteBuffer(byte[]

arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length); bb.put(arr); bb.position(0); return bb;

/** The draw method for the primitive object with the GL context */ public void draw_circle(GL10 gl) { /** The draw method for the primitive object with the GL context */ public void draw_circle(GL10 gl) {

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the object circle //gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle));

//memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0, make-

FloatBuffer(vertices_circle_color));

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1,

(int) ((int) 2*batas_sudut/step));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINES, 1, (int) ((int) 2*batas_sudut/step)); gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_circle_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// set the colour edge for the object circle //gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle1));

//memetakan warna untuk setiap vertex //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_circle_color));

//menempelkan tekstur ke objek //menempelkan tekstur ke objek

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // 4 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

1, makeFloatBuffer(vertices_circle)); // 5 gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord)); // 5

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

//GL11ExtensionPack gl_ = (GL11ExtensionPack) gl; //GL11 gl11 = (GL11) gl; //gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

// Set the face rotation //gl.glFrontFace(GL10.GL_CW);

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,

(int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, (int) ((int) 2*batas_sudut/step)); gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, ba- tas_sudut); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1, 120);

//Log.i("Nilai 2*batas_sudut/step : ", ""+2*batas_sudut/step);

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawElements(GL10.GL_TRIANGLES, (int) ((int) 2*batas_sudut/step), // GL10.GL_UNSIGNED_SHORT, makeFloat- Buffer(vertices_circle));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARR AY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping }

public void draw_circle_color(GL10 gl,float red_in, float green_in,float blue_in, float alpha_in) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour edge for the object circle gl.glColor4f(red_in, green_in, blue_in, 0.33f); //gl.glColor4f(red_in, green_in, blue_in, alpha_in);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle1));

//memetakan warna untuk setiap vertex //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_circle_color));

//menempelkan tekstur ke objek //gl.glEnable(GL10.GL_TEXTURE_2D);

//gl.glEnable(GL10.GL_BLEND); //gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

//gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_indek[0]); // 4 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

1, makeFloatBuffer(vertices_circle)); // 5 //gl.glTexCoordPointer(3, GL10.GL_FLOAT,

0, makeFloatBuffer(textCoord)); // 5

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY);

//GL11ExtensionPack gl_ = (GL11ExtensionPack) gl;

//GL11 gl11 = (GL11) gl; //gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

// Set the face rotation //gl.glFrontFace(GL10.GL_CW);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0,

(int) ((int) 2*batas_sudut/step));

gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, batas_sudut); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, batas_sudut); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1, 120);

//Log.i("Nilai 2*batas_sudut/step : ", ""+2*batas_sudut/step);

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawElements(GL10.GL_TRIANGLES, (int) ((int) 2*batas_sudut/step), // GL10.GL_UNSIGNED_SHORT, makeFloat- Buffer(vertices_circle));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

//gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping }

public void draw_segitiga(GL10 gl) { public void draw_segitiga(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle //gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] {

1.0f, 1.0f, 0.0f, // V3 0.0f, 1.0f, 0.0f, // V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) }));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek //gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

public void draw_segitiga_texture(GL10 gl) {

gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle (menghilangkan effect dari warna objek sebelumnya) gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V3 0.0f, 1.0f, 0.0f, // V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) }));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord_Triagle)); //

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping

public void draw_koin(GL10 gl) {

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY); // Enable // set the colour edge for the object circle // gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // create VBO from buffer with glBuffer-

Data()

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer2);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y); // Enable

// texture-coords-array

// (NEW) gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuffer2);

// menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // 4 // gl.glTexCoordPointer(3, GL10.GL_FLOAT, 1, // makeFloatBuffer(vertices_circle)); //

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARR AY); // Disable

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glDisable(GL10.GL_BLEND); // Disable Alpha Blend gl.glDisable(GL10.GL_TEXTURE_2D); // Dis- able Texture Mapping } public void draw_bg(GL10 gl) {

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

//gl.glEnableClientState(GL10.GL_TEXTURE_COORD_AR RAY); // Enable // set the colour edge for the object circle // gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// create VBO from buffer with glBuffer- Data()

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y); // Enable

// texture-coords-array

// (NEW) gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuffer);

// menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // 4 // gl.glTexCoordPointer(3, GL10.GL_FLOAT, 1, // makeFloatBuffer(vertices_circle)); //

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARR AY); // Disable

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glDisable(GL10.GL_BLEND); // Disable Alpha Blend gl.glDisable(GL10.GL_TEXTURE_2D); // Dis- able Texture Mapping } public void draw_start(GL10 gl) {

gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle

(menghilangkan effect dari warna objek sebelumnya) gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

gl.glVertexPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { -1.0f, 0.0f, 0.0f, // 0. left-bottom 1.0f, 0.0f, 0.0f, // 1. right-bottom 1.0f, 1.0f, 0.0f, // 2. left-top -1.0f, 1.0f, 0.0f, // 3. right-top }));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // gl.glTexCoordPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord_kotak)); //

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping

public void draw_kotak_texture(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle (menghilangkan effect dari warna objek sebelumnya) // set the colour for the triangle (menghilangkan effect dari warna objek sebelumnya)

gl.glVertexPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { -1.0f, 0.0f, 0.0f, // 0. left-bottom 1.0f, 0.0f, 0.0f, // 1. right-bottom 1.0f, 1.0f, 0.0f, // 2. left-top -1.0f, 1.0f, 0.0f, // 3. right-top }));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- tures_indek[0]); // gl.glTexCoordPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(textCoord_kotak)); //

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping

public void loadBallTexture(GL10 gl, Context con- text) {

// Bitmap bitmap = BitmapFacto-

ry.decodeResource(context.getResources(), // resource);

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(R.drawable.nature)); .openRawResource(R.drawable.nature));

tures_indek[0]);

/*gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); */

//gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE ); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );

gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT );

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT );

///gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, //GL10.GL_NEAREST); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, //GL10.GL_LINEAR);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

public void loadBallTexture(GL10 gl, Context con- text,int index_Texture) {

// Bitmap bitmap = BitmapFacto-

ry.decodeResource(context.getResources(), // resource);

/*Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(R.drawable.nature));*/

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs[index_Texture]));

gl.glGenTextures(1, textures_indek, 0); gl.glGenTextures(1, textures_indek, 0);

/*gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); */

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT );

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT );

///gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, //GL10.GL_NEAREST); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, //GL10.GL_LINEAR);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

Vertices.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; import java.nio.ShortBuffer;

import javax.microedition.khronos.opengles.GL10;

public class Vertices {

//--Constants--// final static int POSITION_CNT_2D = 2;

// Number of Components in Vertex Position for 2D

final static int POSITION_CNT_3D = 3; // Number of Components in Vertex Position for 3D

final static int COLOR_CNT = 4; // Number of Components in Vertex Color final static int TEXCOORD_CNT = 2; // Number of Components in Vertex Texture Coords

final static int NORMAL_CNT = 3; // Number of Components in Vertex Normal

final static int INDEX_SIZE = Short.SIZE / 8; // Index Byte Size (Short.SIZE = bits)

//--Members--// // NOTE: all members are constant, and initialized

in constructor! final GL10 gl; // GL Instance final boolean hasColor; // Use Color in Vertices final boolean hasTexCoords; // Use Texture Coords in Vertices final boolean hasNormals; // Use Normals in Vertices public final int positionCnt; // Number of Position Components (2=2D, 3=3D) public final int vertexStride; // Vertex Stride (Element Size of a Single Vertex)

public final int vertexSize; // Bytesize of a Single Vertex final IntBuffer vertices; // Vertex Buffer final ShortBuffer indices; // Index Buffer public int numVertices; // Number of Vertices in Buffer public int numIndices; // Number of Indices in Buffer final int[] tmpBuffer; // Temp Buffer for Vertex Conversion

//--Constructor--// // D: create the vertices/indices as specified

(for 2d/3d) // A: gl - the gl instance to use // maxVertices - maximum vertices allowed in

buffer // maxIndices - maximum indices allowed in buffer // hasColor - use color values in vertices // hasTexCoords - use texture coordinates in

vertices // hasNormals - use normals in vertices // use3D - (false, default) use 2d positions

(ie. x/y only)

// (true) use 3d positions (ie. x/y/z) public Vertices(GL10 gl, int maxVertices, int max-

Indices, boolean hasColor, boolean hasTexCoords, boolean hasNormals) {

this( gl, maxVertices, maxIndices, hasColor, hasTexCoords, hasNormals, false ); // Call Overload-

ed Constructor } public Vertices(GL10 gl, int maxVertices, int max-

Indices, boolean hasColor, boolean hasTexCoords, boolean hasNormals, boolean use3D) {

this.gl = gl; // Save GL Instance this.hasColor = hasColor; // Save Color Flag this.hasTexCoords = hasTexCoords; // Save Texture Coords Flag this.hasNormals = hasNormals; // Save Normals Flag this.positionCnt = use3D ? POSITION_CNT_3D : POSITION_CNT_2D; // Set Position Component Count this.vertexStride = this.positionCnt + ( has- Color ? COLOR_CNT : 0 ) + ( hasTexCoords ? TEXCOORD_CNT : 0 ) + ( hasNormals ? NORMAL_CNT : 0 ); // Calculate Vertex Stride

this.vertexSize = this.vertexStride * 4; // Calculate Vertex Byte Size

ByteBuffer buffer = ByteBuffer.allocateDirect( maxVertices * vertexSize ); // Allocate Buffer for Vertices (Max)

buffer.order( ByteOrder.nativeOrder() ); // Set Native Byte Order this.vertices = buffer.asIntBuffer(); // Save Vertex Buffer

if ( maxIndices > 0 ) { // IF Indices Required buffer = ByteBuffer.allocateDirect( max- Indices * INDEX_SIZE ); // Allocate Buffer for Indi- ces (MAX)

buffer.order( ByteOrder.nativeOrder() ); // Set Native Byte Order this.indices = buffer.asShortBuffer(); // Save Index Buffer

} else

// ELSE Indices Not Required indices = null; // No Index Buffer

numVertices = 0; // Zero Vertices in Buffer numIndices = 0; // Zero Indices in Buffer

this.tmpBuffer = new int[maxVertices * ver- texSize / 4]; // Create Temp Buffer }

//--Set Vertices--// // D: set the specified vertices in the vertex

buffer // NOTE: optimized to use integer buffer! // A: vertices - array of vertices (floats) to set // offset - offset to first vertex in array // length - number of floats in the vertex ar-

ray (total)

// for easy setting use: vtx_cnt * (this.vertexSize / 4) // R: [none] public void setVertices(float[] vertices, int off-

set, int length) { this.vertices.clear(); // Remove Existing Vertices int last = offset + length; // Calculate Last Element for ( int i = offset, j = 0; i < last; i++, j++ ) // FOR Each Specified Vertex tmpBuffer[j] = Float.floatToRawIntBits( ver- tices[i] ); // Set Vertex as Raw Integer Bits in Buffer

this.vertices.put( tmpBuffer, 0, length ); // Set New Vertices this.vertices.flip(); // Flip Vertex Buffer this.numVertices = length / this.vertexStride; // Save Number of Vertices //this.numVertices = length / ( this.vertexSize / 4 ); // Save Number of Vertices }

//--Set Indices--// // D: set the specified indices in the index buff-

er

// A: indices - array of indices (shorts) to set // offset - offset to first index in array // length - number of indices in array (from

offset) // R: [none] public void setIndices(short[] indices, int off-

set, int length) { this.indices.clear(); // Clear Existing Indices set, int length) { this.indices.clear(); // Clear Existing Indices

//--Bind--// // D: perform all required binding/state changes

before rendering batches.

// USAGE: call once before calling draw() mul- tiple times for this buffer. // A: [none] // R: [none] public void bind() {

gl.glEnableClientState( GL10.GL_VERTEX_ARRAY ); // Enable Position in Vertices vertices.position( 0 ); // Set Vertex Buffer to Position gl.glVertexPointer( positionCnt, GL10.GL_FLOAT, vertexSize, vertices ); // Set Vertex Pointer

if ( hasColor ) { // IF Vertices Have Color gl.glEnableClientState( GL10.GL_COLOR_ARRAY ); // Enable Color in Vertices

vertices.position( positionCnt ); // Set Vertex Buffer to Color gl.glColorPointer( COLOR_CNT, GL10.GL_FLOAT, vertexSize, vertices ); // Set Color Pointer }

if ( hasTexCoords ) { // IF Vertices Have Texture Coords gl.glEnableClientState( GL10.GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coords in Vertices

vertices.position( positionCnt + ( hasColor ? COLOR_CNT : 0 ) ); // Set Vertex Buffer to Texture Coords (NOTE: position based on whether color is also specified)

gl.glTexCoordPointer( TEXCOORD_CNT, GL10.GL_FLOAT, vertexSize, vertices ); // Set Tex- ture Coords Pointer

if ( hasNormals ) { gl.glEnableClientState( GL10.GL_NORMAL_ARRAY ); // Enable Normals in Vertices vertices.position( positionCnt + ( hasColor ? COLOR_CNT : 0 ) + ( hasTexCoords ? TEXCOORD_CNT : 0 ) ); // Set Vertex Buffer to Normals (NOTE: position based on whether color/texcoords is also specified)

gl.glNormalPointer( GL10.GL_FLOAT, ver- texSize, vertices ); // Set Normals Pointer } }

//--Draw--// // D: draw the currently bound vertices in the

vertex/index buffers // USAGE: can only be called after calling bind() for this buffer.

// A: primitiveType - the type of primitive to draw // offset - the offset in the vertex/index buffer to start at

// numVertices - the number of vertices (indi- ces) to draw // R: [none] public void draw(int primitiveType, int offset,

int numVertices) { if ( indices != null ) { // IF Indices Exist indices.position( offset ); // Set Index Buffer to Specified Offset gl.glDrawElements( primitiveType, numVerti- ces, GL10.GL_UNSIGNED_SHORT, indices ); // Draw In- dexed

} else {

// ELSE No Indices Exist gl.glDrawArrays( primitiveType, offset, numVertices ); // Draw Direct (Array) } }

//--Unbind--// // D: clear binding states when done rendering

batches.

// USAGE: call once before calling draw() mul- tiple times for this buffer. // A: [none] // R: [none] public void unbind() {

if ( hasColor ) // IF Vertices Have Color gl.glDisableClientState( GL10.GL_COLOR_ARRAY ); // Clear Color State

if ( hasTexCoords ) // IF Vertices Have Texture Coords gl.glDisableClientState( GL10.GL_TEXTURE_COORD_ARRAY ); // Clear Texture Coords State

if ( hasNormals ) // IF Vertices Have Normals gl.glDisableClientState( GL10.GL_NORMAL_ARRAY ); // Clear Normals State }

//--Draw Full--// // D: draw the vertices in the vertex/index buff-

ers // NOTE: unoptimized version! use bind()/draw()/unbind() for batches

// A: primitiveType - the type of primitive to draw // offset - the offset in the vertex/index buffer to start at

// numVertices - the number of vertices (indi- ces) to draw // R: [none] public void drawFull(int primitiveType, int off-

set, int numVertices) { gl.glEnableClientState( GL10.GL_VERTEX_ARRAY ); // Enable Position in Vertices vertices.position( 0 ); // Set Vertex Buffer to Position gl.glVertexPointer( positionCnt, GL10.GL_FLOAT, vertexSize, vertices ); // Set Vertex Pointer

if ( hasColor ) { // IF Vertices Have Color gl.glEnableClientState( GL10.GL_COLOR_ARRAY ); // Enable Color in Vertices

vertices.position( positionCnt ); // Set Vertex Buffer to Color gl.glColorPointer( COLOR_CNT, GL10.GL_FLOAT, vertexSize, vertices ); // Set Color Pointer }

if ( hasTexCoords ) { // IF Vertices Have Texture Coords gl.glEnableClientState( GL10.GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coords in Vertices

vertices.position( positionCnt + ( hasColor ? COLOR_CNT : 0 ) ); // Set Vertex Buffer to Texture Coords (NOTE: position based on whether color is also specified)

gl.glTexCoordPointer( TEXCOORD_CNT, GL10.GL_FLOAT, vertexSize, vertices ); // Set Tex- ture Coords Pointer

if ( indices != null ) { // IF Indices Exist indices.position( offset ); // Set Index Buffer to Specified Offset gl.glDrawElements( primitiveType, numVerti- ces, GL10.GL_UNSIGNED_SHORT, indices ); // Draw In- dexed

} else {

// ELSE No Indices Exist gl.glDrawArrays( primitiveType, offset, numVertices ); // Draw Direct (Array) }

if ( hasTexCoords ) // IF Vertices Have Texture Coords gl.glDisableClientState( GL10.GL_TEXTURE_COORD_ARRAY ); // Clear Texture Coords State if ( hasTexCoords ) // IF Vertices Have Texture Coords gl.glDisableClientState( GL10.GL_TEXTURE_COORD_ARRAY ); // Clear Texture Coords State

//--Set Vertex Elements--// // D: use these methods to alter the values (posi-

tion, color, textcoords, normals) for vertices

// WARNING: these do NOT validate any values, ensure that the index AND specified // elements EXIST before using!! // A: x, y, z - the x,y,z position to set in buff-

er

// r, g, b, a - the r,g,b,a color to set in buffer // u, v - the u,v texture coords to set in buffer // nx, ny, nz - the x,y,z normal to set in buffer // R: [none] void setVtxPosition(int vtxIdx, float x, float y)

{ int index = vtxIdx * vertexStride; // Calculate Actual Index vertices.put( index + 0, Float.floatToRawIntBits( x ) ); // Set X vertices.put( index + 1, Float.floatToRawIntBits( y ) ); // Set Y } void setVtxPosition(int vtxIdx, float x, float y,

float z) { int index = vtxIdx * vertexStride; // Calculate Actual Index vertices.put( index + 0, Float.floatToRawIntBits( x ) ); // Set X vertices.put( index + 1, Float.floatToRawIntBits( y ) ); // Set Y vertices.put( index + 2, Float.floatToRawIntBits( z ) ); // Set Z } void setVtxColor(int vtxIdx, float r, float g,

float b, float a) { int index = ( vtxIdx * vertexStride ) + posi- tionCnt; // Calculate Actual Index vertices.put( index + 0, Float.floatToRawIntBits( r ) ); // Set Red vertices.put( index + 1, Float.floatToRawIntBits( g ) ); // Set Green vertices.put( index + 2, Float.floatToRawIntBits( b ) ); // Set Blue vertices.put( index + 3, Float.floatToRawIntBits( a ) ); // Set Alpha } void setVtxColor(int vtxIdx, float r, float g,

float b) { int index = ( vtxIdx * vertexStride ) + posi- tionCnt; // Calculate Actual Index float b) { int index = ( vtxIdx * vertexStride ) + posi- tionCnt; // Calculate Actual Index

int index = ( vtxIdx * vertexStride ) + posi- tionCnt; // Calculate Actual Index vertices.put( index + 3, Float.floatToRawIntBits( a ) ); // Set Alpha } void setVtxTexCoords(int vtxIdx, float u, float v)

{ int index = ( vtxIdx * vertexStride ) + posi- tionCnt + ( hasColor ? COLOR_CNT : 0 ); // Calculate Actual Index

vertices.put( index + 0, Float.floatToRawIntBits( u ) ); // Set U vertices.put( index + 1, Float.floatToRawIntBits( v ) ); // Set V } void setVtxNormal(int vtxIdx, float x, float y,

float z) { int index = ( vtxIdx * vertexStride ) + posi- tionCnt + ( hasColor ? COLOR_CNT : 0 ) + ( hasTex- Coords ? TEXCOORD_CNT : 0 ); // Calculate Actual In- dex

vertices.put( index + 0, Float.floatToRawIntBits( x ) ); // Set X vertices.put( index + 1, Float.floatToRawIntBits( y ) ); // Set Y vertices.put( index + 2, Float.floatToRawIntBits( z ) ); // Set Z } }

TransObject.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLES20;

public class TransObject {

private float vertices[] = { -0.5f, -0.5f, 0.0f,

// V1 - first vertex (x,y,z) -0.5f, 0.5f, 0.0f,

V2

0.5f, 0.5f, 0.0f, //

V3 0.5f, -0.5f, 0.0f,

// V4 -0.5f, -0.5f, 0.0f

V5 };

private float vertices_color[] = { 1.0f, 0.0f, 0.0f, 1.0f,

// CV1 - first color (red,green,blue) 0.0f, 1.0f, 0.0f, 1.0f,

// CV2 0.0f, 0.0f, 1.0f, 1.0f,

// CV3 0.0f, 1.0f, 0.0f, 1.0f,

// CV4 1.0f, 0.0f, 0.0f, 1.0f // CV5 };

// list vertices kubus private float vertices_kubus[]= {

0.0f,0.0f,1.0f, 1.0f,0.0f,1.0f, 0.0f,1.0f,1.0f, 1.0f,1.0f,1.0f, 0.0f,0.0f,0.0f, 1.0f,0.0f,0.0f, 0.0f,1.0f,0.0f, 1.0f,1.0f,0.0f

// list color (kombinasi angka nol dan satu) private float colors_kubus[] = {

0.0f,0.0f,0.0f,1.0f, 1.0f,0.0f,0.0f,1.0f, 1.0f,1.0f,0.0f,1.0f, 0.0f,1.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,1.0f, 1.0f,0.0f,1.0f,1.0f, 1.0f,1.0f,1.0f,1.0f, 0.0f,1.0f,1.0f,1.0f

}; private byte[] indices_kubus = {

0,1,3, // depan 1 3,2,0, // depan 2

4,5,7, // belakang 1 7,6,4, // belakang 2

2,3,7, // atas 1 7,6,2, // atas 2

0,1,5, // bawah 1 5,4,0, // bawah 2

1,5,7, // kanan 1 7,3,1, // kanan 2

0,4,6, // kiri 1 6,4,0, // kiri 2

0,2,6, // kiri 3 6,2,0 // kiri 4

private float vertices_circle[]={0.0f,0.0f,0.0f}; private float verti-

ces_circle_color[]={0.0f,0.0f,0.0f,0.5f}; private float vertices_line[]={0.0f,0.0f,0.0f}; private float verti-

ces_line_color[]={0.0f,0.0f,0.0f,1.0f}; private int batas_sudut=360; float jari_jari; float a,b; float x,y; float step=3.0f,step_line=0.2f; float x1,y1; float x2,y2; private int

loop,loop_color,loop_line,loop_line_color;

public TransObject() {

// ============ start to generate verti- ces to circle ========================== //Inisialisasi jari_jari=1.0f;

// Titik Pusat

a = 0.0f; b = 0.0f ; x=a+jari_jari; y=b;

loop=3; loop_color=4; vertices_circle=new

float[(int)(3*batas_sudut/step)*3]; vertices_circle_color=new float[(int)(3*batas_sudut/step)*4]; for(float teta=0;teta<=2*batas_sudut;teta+=step){ vertices_circle[loop] = (float) ((x- a)*Math.cos((teta/180)*(22/7)) - ((y- b)*Math.sin((teta/180)*(22/7))) + a);

vertices_circle[loop+1] = (float) ((x- a)*Math.sin((teta/180)*(22/7)) - ((y- b)*Math.cos((teta/180)*(22/7))) + b);

vertices_circle[loop+2]=0; loop+=3;

//mengenerate warna untuk setiap vertex vertices_circle_color[loop_color]=(float) ((x-

a)*Math.cos((teta/180)*(22/7)) - ((y- b)*Math.sin((teta/180)*(22/7))) + a);

vertices_circle_color[loop_color+1]=(float) ((x- a)*Math.sin((teta/180)*(22/7)) - ((y- vertices_circle_color[loop_color+1]=(float) ((x- a)*Math.sin((teta/180)*(22/7)) - ((y-

} // ============= end for generate vertices to circle ====================

// ============ start to generate vertices to line ========================== x1 = -1.0f; y1 = -1.0f; x2= 1.0f; y2 = 1.0f;

loop_line=3; loop_line_color=4; vertices_line=new float[(int)(2*(x2-

x1)/step_line)*3]; vertices_line_color=new float[(int)(2*(x2- x1)/step_line)*4];

float m = (y2-y1)/(x2-x1); for(x=x1;x<=x2;x+=step_line){

vertices_line[loop_line] = (float) (x); vertices_line[loop_line+1] = (float) (m*(x-

x1)+y1); vertices_line[loop_line+2]=0; loop_line+=3;

//mengenerate warna untuk setiap vertex vertices_line_color[loop_line_color]=(float)

(0.5*x);

vertices_line_color[loop_line_color+1]=(float) (0.5*m*(x-x1)+y1);

vertices_line_color[loop_line_color+2]=1.0f; vertices_line_color[loop_line_color+3]=1.0f; loop_line_color+=4;

} // ============= end for generate vertices to line ==================== }

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb;

// Setup index-array buffer. Indices in byte. public static ByteBuffer makeByteBuffer(byte[]

arr){ ByteBuffer bb = ByteBuff- arr){ ByteBuffer bb = ByteBuff-

/** The draw method for the primitive object with the GL context */

public void draw_kubus(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

// orientation // Enable arrays and define their buffers

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_kubus));

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(colors_kubus)); gl.glDrawElements(GL10.GL_TRIANGLES, in- dices_kubus.length, GL10.GL_UNSIGNED_BYTE, makeByteBuffer(indices_kubus)); //gl.glDrawElements(GL10.GL_LINE_STRIP, indices_kubus2.length, //GL10.GL_UNSIGNED_BYTE, makeByteBuffer(indices_kubus2));

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_points(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the points (pem- berian warna untuk titik) gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) 1.0f, 0.8f, 0.0f, // V2 1.0f, 0.6f, 0.0f, // V3 1.0f, 0.4f, 0.0f,

// V4 1.0f, 0.2f, 0.0f, // V5 1.0f, 0.0f, 0.0f, // V6 1.0f, -0.2f, 0.0f, // V7 1.0f, -0.4f, 0.0f, // V8 1.0f, -0.6f, 0.0f, // V9 1.0f, -0.8f, 0.0f, // V10 1.0f, -1.0f, 0.0f, // V11

0.8f, -1.0f, 0.0f, // V12 0.6f, -1.0f, 0.0f, // V13 0.4f, -1.0f, 0.0f, // V14 0.2f, -1.0f, 0.0f, // V15 0.0f, -1.0f, 0.0f, // V16 -0.2f, -1.0f, 0.0f,

// V17 -0.4f, -1.0f, 0.0f,

// V18 -0.6f, -1.0f, 0.0f,

// V19 -0.7f, -1.0f, 0.0f,

// V20 -0.8f, -1.0f, 0.0f,

// V21 -1.0f, -1.0f, 0.0f,

// V22 }));

// Draw the vertices as points (menggam- bar titik-titik) gl.glDrawArrays(GL10.GL_POINTS, 0, 22);

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

} public void draw_line(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the line (pemberian // set the colour for the line (pemberian

// Point to our vertex buffer (mendata nilai lokasi/posisi titik yang menyusun garis) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) -1.0f, -1.0f, 0.0f,

// V2 - second vertex }));

// Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINES, 0, 2); /*gl.glDrawElements(GL10.GL_LINES, 2,

GL10.GL_UNSIGNED_SHORT, makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) -1.0f, -1.0f, 0.0f,

// V2 - second vertex }));*/

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_line_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the line (pemberian warna untuk garis) gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik yang menyusun garis) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_line));

//memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_line_color));

// Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) (2*(x2-x1)/step_line)); /*gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, makeFloatBuffer(new // Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) (2*(x2-x1)/step_line)); /*gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, makeFloatBuffer(new

// V2 - second vertex }));*/

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_circle(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the object circle gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle));

//draw circle as filled shape //gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1,

(int) ((int) 2*batas_sudut/step));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

gl.glDrawArrays(GL10.GL_LINES, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_circle_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour edge for the object // set the colour edge for the object

//create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, make- FloatBuffer(vertices_circle));

//memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0, make-

FloatBuffer(vertices_circle_color));

//draw circle as filled shape gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 1,

(int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawElements(GL10.GL_TRIANGLES, (int) ((int) 2*batas_sudut/step), // GL10.GL_UNSIGNED_SHORT, makeFloat- Buffer(vertices_circle));

//draw circle contours //gl.glDrawArrays(GL10.GL_LINES, 1, (int)

((int) 2*batas_sudut/step)); // membuat garis putus- putus pada tepi lingkaran

//gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) 2*batas_sudut/step)); //gl.glDrawArrays(GL10.GL_POINTS, 1, (int) ((int) 2*batas_sudut/step));

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_kotak(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices));

// Draw the vertices as square

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3);

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_segitiga(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { -0.5f, -0.5f, 0.0f,

// V1 - first vertex (x,y,z) 0.5f, -0.5f, 0.0f,

// V2 - second vertex 0.0f, 0.5f, 0.0f // V3 - third vertex

// Draw the vertices as triangle gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color)); gl.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

TextureRegion.java TextureRegion.java

class TextureRegion {

//--Members--// publicfloat u1 , v1 ;

// Top/Left U,V Coordinates publicfloat u2 , v2 ;

// Bottom/Right U,V Coordinates

//--Constructor--// // D: calculate U,V coordinates from specified tex- ture coordinates // A: texWidth, texHeight - the width and height of the texture the region is for // x, y - the top/left (x,y) of the region on the texture (in pixels) // width, height - the width and height of the re- gion on the texture (in pixels) public TextureRegion( float texWidth, float texHeight, float x, float y, float width, float height) { this . u1 = x / texWidth;

// Calculate U1 this . v1 = y / texHeight;

// Calculate V1 this . u2 = this . u1 + ( width / texWidth );

// Calculate U2 this . v2 = this . v1 + ( height / texHeight );

// Calculate V2 } }

SpriteBatch.java

package com.modelloading;

import javax.microedition.khronos.opengles.GL10;

publicclass SpriteBatch {

//--Constants--// finalstaticint VERTEX_SIZE = 4;

// Vertex Size (in Components) ie. (X,Y,U,V) finalstaticint VERTICES_PER_SPRITE = 4;

// Vertices Per Sprite finalstaticint INDICES_PER_SPRITE = 6;

// Indices Per Sprite

//--Members--// GL10 gl ; // GL Instance

Vertices vertices ; // Vertices Instance Used for Rendering float [] vertexBuffer ;

// Vertex Buffer int bufferIndex ;

// Vertex Buffer Start Index int maxSprites ;

// Maximum Sprites Allowed in Buffer int numSprites ;

// Number of Sprites Currently in Buffer

//--Constructor--// // D: prepare the sprite batcher for specified maxi- mum number of sprites // A: gl - the gl instance to use for rendering // maxSprites - the maximum allowed sprites per batch public SpriteBatch(GL10 gl, int maxSprites) { this . gl = gl;

// Save GL Instance this . vertexBuffer = newfloat [maxSprites * VERTICES_PER_SPRITE * VERTEX_SIZE ]; // Create Vertex Buffer this . vertices = new Vertices( gl, maxSprites * VERTICES_PER_SPRITE , maxSprites * INDICES_PER_SPRITE , false , true , false ); // Create Rendering Vertices this . bufferIndex = 0;

// Reset Buffer Index this . maxSprites = maxSprites;

// Save Maximum Sprites this . numSprites = 0;

// Clear Sprite Counter

short [] indices = newshort [maxSprites * INDICES_PER_SPRITE ]; // Create Temp Index Buffer int len = indices. length ;

// Get Index Buffer Length short j = 0;

// Counter

for ( int

i = 0; i < len; i+= INDICES_PER_SPRITE ,j += VERTICES_PER_SPRITE ) {

// FOR Each Index Set (Per Sprite)

indices[i + 0] = ( short )( j + 0 ); // Calculate Index 0

indices[i + 1] = ( short )( j + 1 ); // Calculate Index 1

indices[i + 2] = ( short )( j + 2 ); // Calculate Index 2

indices[i + 3] = ( short )( j + 2 ); // Calculate Index 3

indices[i + 4] = ( short )( j + 3 ); // Calculate Index 4

indices[i + 5] = ( short )( j + 0 ); // Calculate Index 5 } vertices .setIndices( indices, 0, len );

// Set Index Buffer for Rendering }

//--Begin Batch--// // D: signal the start of a batch. set the texture and clear buffer // NOTE: the overloaded (non-texture) version as- sumes that the texture is already bound! // A: textureId - the ID of the texture to use for the batch // R: [none] publicvoid beginBatch( int textureId) { gl .glBindTexture( GL10. GL_TEXTURE_2D , textureId ); // Bind the Texture numSprites = 0;

// Empty Sprite Counter bufferIndex = 0;

// Reset Buffer Index (Empty) } publicvoid beginBatch() { numSprites = 0;

// Empty Sprite Counter bufferIndex = 0;

// Reset Buffer Index (Empty) }

//--End Batch--// // D: signal the end of a batch. render the batched sprites // A: [none] // R: [none] publicvoid endBatch() { if ( numSprites >0) {

// IF Any Sprites to Render vertices .setVertices( vertexBuffer , 0, bufferIndex ); // Set Vertices from Buffer vertices .bind();

// Bind Vertices vertices .draw( GL10. GL_TRIANGLES , 0, numSprites * INDICES_PER_SPRITE ); // Render Batched Sprites vertices .unbind();

// Un- bind Vertices } }

//--Draw Sprite to Batch--// // D: batch specified sprite to batch. adds vertices for sprite to vertex buffer // NOTE: MUST be called after beginBatch(), and before endBatch()! // NOTE: if the batch overflows, this will render the current batch, restart it, // and then batch this sprite. // A: x, y - the x,y position of the sprite (center) // width, height - the width and height of the sprite // region - the texture region to use for sprite // R: [none] publicvoid drawSprite( float x, float y, float width, float height, TextureRegion region) { if ( numSprites == maxSprites ) {

// IF Sprite Buffer is Full // IF Sprite Buffer is Full

// Empty Sprite Counter bufferIndex = 0;

// Reset Buffer Index (Empty) }

float halfWidth = width / 2.0f; // Calculate Half Width float halfHeight = height / 2.0f;

// Calculate Half Height float x1 = x - halfWidth;

// Calculate Left X float y1 = y - halfHeight;

// Calculate Bottom Y float x2 = x + halfWidth;

// Calculate Right X float y2 = y + halfHeight;

// Calculate Top Y

vertexBuffer [ bufferIndex ++] = x1; // Add X for Vertex 0 vertexBuffer [ bufferIndex ++] = y1;

// Add Y for Vertex 0 vertexBuffer [ bufferIndex ++] = region. u1 ;

// Add U for Vertex 0 vertexBuffer [ bufferIndex ++] = region. v2 ;

// Add V for Vertex 0

vertexBuffer [ bufferIndex ++] = x2; // Add X for Vertex 1 vertexBuffer [ bufferIndex ++] = y1;

// Add Y for Vertex 1 vertexBuffer [ bufferIndex ++] = region. u2 ;

// Add U for Vertex 1 vertexBuffer [ bufferIndex ++] = region. v2 ;

// Add V for Vertex 1

vertexBuffer [ bufferIndex ++] = x2; // Add X for Vertex 2 vertexBuffer [ bufferIndex ++] = y2;

// Add Y for Vertex 2 vertexBuffer [ bufferIndex ++] = region. u2 ;

// Add U for Vertex 2 vertexBuffer [ bufferIndex ++] = region. v1 ;

// Add V for Vertex 2

vertexBuffer [ bufferIndex ++] = x1; // Add X for Vertex 3 vertexBuffer [ bufferIndex ++] = y2;

// Add Y for Vertex 3 vertexBuffer [ bufferIndex ++] = region. u1 ;

// Add U for Vertex 3 vertexBuffer [ bufferIndex ++] = region. v1 ;

// Add V for Vertex 3

numSprites ++; //

Increment Sprite Count } }

SplashScreen5.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen5 extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 5;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash5);

//@Override // protected void onCreate(final Bundle savedInstance) { // super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen5.this, SplashScreen4.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

SplashScreen4.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen4 extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 5;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash4);

//@Override // protected void onCreate(final Bundle savedInstance) { // super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen4.this, SplashScreen3.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

SplashScreen3.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen3 extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 5;

@Override protected void onCreate(Bundle savedInstanceS-

tate) {

super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash3);

//@Override // protected void onCreate(final Bundle savedInstance) { // super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen3.this, SplashScreen2.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

SplashScreen2.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen2 extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 5;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash2);

//@Override // protected void onCreate(final Bundle savedInstance) { // super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen2.this, SplashScreen1.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

SplashScreen1.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen1 extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 100;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_splash1);

//@Override // protected void onCreate(final Bundle savedInstance) {

// super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen1.this, MainActivity.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

SplashScreen.java

package com.modelloading;

import android.app.Activity; import android.content.Intent; import android.content.pm.ActivityInfo; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

public class SplashScreen extends Activity {

// Splash screen timer private static int SPLASH_TIME_OUT = 3000;

@Override protected void onCreate(Bundle savedInstanceS-

tate) { super.onCreate(savedInstanceState);

// requesting to turn the title OFF requestWindowFea- ture(Window.FEATURE_NO_TITLE); // making it full screen getWin- dow().setFlags(WindowManager.LayoutParams.FLAG_FULLSC REEN,

WindowManag- er.LayoutParams.FLAG_FULLSCREEN);

setRequestedOrienta- tion(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setContentView(R.layout.activity_splash);

//@Override // protected void onCreate(final Bundle savedInstance) { // super.onCreate(savedInstance);

//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTA TION_LANDSCAPE);

new Handler().postDelayed(new Runnable() {

/* * Showing splash screen with a timer. This will be useful when you * want to show case your app logo / com- pany */

@Override public void run() {

// This method will be executed once the timer is over // Start your app main activity Intent i = new In-

tent(SplashScreen.this, SplashScreen5.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

PrimitivesObject.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10;

import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.opengl.GLES20; import android.opengl.GLUtils; import android.util.Log;

public class PrimitivesObject {

private int[] imageFileIDs = { // Image file IDs R.drawable.nature, R.drawable.mule, R.drawable.joystick, R.drawable.joystick_bg,

R.drawable.meow};

private float vertices[] = { -0.5f, -0.5f, 0.0f, // V1 - first vertex

// (x,y,z) -0.5f, 0.5f, 0.0f, // V2 0.5f, 0.5f, 0.0f, // V3 0.5f, -0.5f, 0.0f, // V4

-0.5f, -0.5f, 0.0f // V5 };

private float textCoord_Triagle[]={ 1.0f, 1.0f, 0.0f,

V3 0.0f, 1.0f, 0.0f,

V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) };

int[] textures_indek = new int[1];

private float[] vertices_quad = { // Vertices for the square -1.0f, -1.0f, 0.0f, // 0. left-bottom 1.0f, -1.0f, 0.0f, // 1. right- bottom -1.0f, 1.0f, 0.0f, // 2. left-top 1.0f, 1.0f, 0.0f // 3. right-top

private float vertices_color[] = { 1.0f, 0.0f, 0.0f, 1.0f, // CV1 - first

// color

// (red,green,blue) 0.0f, 1.0f, 0.0f, 1.0f, // CV2 0.0f, 0.0f, 1.0f, 1.0f, // CV3 0.0f, 1.0f, 0.0f, 1.0f, // CV4 1.0f, 0.0f, 0.0f, 1.0f // CV5

//private float vertices_horizontal[] = { 0.0f, 0.0f, 0.0f };

private float vertices_horiverti[] = { 0.0f, 0.0f, 0.0f }; private float vertices_labirin_player[] = { 0.0f, 0.0f, 0.0f }; private float vertices_circle[] = { 0.0f, 0.0f, 0.0f }; private float vertices_circle_color[] = { 0.0f, 0.0f, 0.0f, 0.5f };

private float vertices_line[] = { 0.0f, 0.0f, 0.0f };

private float vertices_line_color[] = { 0.0f, 0.0f, 0.0f, 1.0f }; private float verti- ces_fractal_mandelbrot[]={0.0f, 0.0f, 0.0f}; private float verti- ces_color_fractal_mandelbrot[]={0.0f, 0.0f, 0.0f, 0.0f};

private int batas_sudut = 360; float jari_jari; private int batas_sudut = 360; float jari_jari;

loop_line_color;

float WidthObject=0.08f; int numberRow=5,numberCol=5; int positionRow; int positionCol; int positionRow_end; int positionCol_end; int Navigate; int draw=1; float x_player=0; // posisi start float y_player=0; float x_player_end=0; // posisi end float y_player_end=0;

// menyimpan inisialisasi array untuk labirin int hori[][] = new

int[2*numberRow*numberCol][2*numberRow*numberCol]; int verti[][] = new int[2*numberRow*numberCol][2*numberRow*numberCol]; private int maze[][] = new int[2*numberRow*numberCol][2*numberRow*numberCol];

public PrimitivesObject() {

// ============ start to generate verti- ces to circle

// ========================== // Inisialisasi jari_jari = 1.0f;

// Titik Pusat

a = 0.0f;

b = 0.0f; x = a + jari_jari; y = b;

loop = 3; loop_color = 4; vertices_circle = new float[(int) (3 *

batas_sudut / step) * 3]; vertices_circle_color = new float[(int) (3 * batas_sudut / step) * 4]; for (float teta = 0; teta <= 2 * ba- tas_sudut; teta += step) { vertices_circle[loop] = (float) ((x - a) * Math.cos((teta / 180) * (22 / 7)) - ((y - b) * Math.sin((teta / 180) * (22 / 7))) + a); vertices_circle[loop + 1] = (float) ((x - a)

* Math.sin((teta / 180) * (22 / 7)) - ((y - b) * Math.cos((teta / 180) * (22 / 7))) + b); vertices_circle[loop + 2] = 0; loop += 3;

// mengenerate warna untuk setiap vertex vertices_circle_color[loop_color] = (float) ((x - a) * Math.cos((teta / 180) * (22 / 7)) - ((y - b) * Math.sin((teta / 180) * (22 / 7))) + a); vertices_circle_color[loop_color + 1] = (float) ((x - a) * Math.sin((teta / 180) * (22 / 7)) - ((y - b) * Math.cos((teta / 180) * (22 / 7))) + b); vertices_circle_color[loop_color + 2] = 0.5f; vertices_circle_color[loop_color + 3] = 0.5f;

loop_color += 4;

} // ============= end for generate verti-

ces to circle // ====================

// ============ start to generate verti- ces to line

// ========================== x1 = -1.0f; y1 = -1.0f; x2 = 1.0f; y2 = 1.0f;

loop_line = 3; loop_line_color = 4; vertices_line = new float[(int) (2 * (x2

- x1) / step_line) * 3]; vertices_line_color = new float[(int) (2 * (x2 - x1) / step_line) * 4];

float m = (y2 - y1) / (x2 - x1); for (x = x1; x <= x2; x += step_line) {

vertices_line[loop_line] = (float) (x); vertices_line[loop_line + 1] = (float) (m * (x - x1) + y1); vertices_line[loop_line + 2] = 0; loop_line += 3;

// mengenerate warna untuk setiap vertex verti- ces_line_color[loop_line_color] = (float) (0.5 * x); // mengenerate warna untuk setiap vertex verti- ces_line_color[loop_line_color] = (float) (0.5 * x);

* (x - x1) + y1); verti- ces_line_color[loop_line_color + 2] = 1.0f; verti- ces_line_color[loop_line_color + 3] = 1.0f; loop_line_color += 4; } // ============= end for generate verti-

ces to line ====================

int i, j; vertices_horiverti = new

float[2*numberRow*numberCol*6];

vertices_labirin_player = new

float[2*3*3]; // start generate jaring-jaring labirin

////////////////////////////////////////// generateMaze();

//Log.v("ii Test get numberRow : ", "" + numberRow); //Log.v("ii Test get numberCol : ", "" + num- berCol);

//line horizontal int loop_vertices_horiverti=0; float y = (WidthObject * numberRow); for(i = 0; i < numberRow+1; i++) {

for(j = 0; j < numberCol; j++){ if (hori[i][j] == 1) {

// menampung vertex yang terbentuk verti- ces_horiverti[loop_vertices_horiverti]=j*WidthObject; verti- ces_horiverti[loop_vertices_horiverti+1]=y; verti- ces_horiverti[loop_vertices_horiverti+2]=0;

verti- ces_horiverti[loop_vertices_horiverti+3]=j*WidthObjec t + WidthObject;

verti- ces_horiverti[loop_vertices_horiverti+4]=y; verti- ces_horiverti[loop_vertices_horiverti+5]=0;

loop_vertices_horiverti+=6;

} y -= WidthObject;

//line vertical float x = 0; for(j = 0; j < numberCol+1; j++) {

for(i = 0; i < numberRow; i++){ if (verti[i][j] == 1){ // menampung vertex yang terbentuk

verti-

ces_horiverti[loop_vertices_horiverti]=x;

verti-

ces_horiverti[loop_vertices_horiverti+1]=(numberRow- i)*WidthObject;

verti-

ces_horiverti[loop_vertices_horiverti+2]=0;

verti- ces_horiverti[loop_vertices_horiverti+3]=x; verti- ces_horiverti[loop_vertices_horiverti+4]=(numberRow- i)*WidthObject-WidthObject;

verti- ces_horiverti[loop_vertices_horiverti+5]=0;

loop_vertices_horiverti+=6;

} } x += WidthObject;

//triagle vertices_labirin_player[0]=(positionCol * WidthObject) + (WidthObject/2); vertices_labirin_player[1]=(numberRow - po- sitionRow - 1)*WidthObject + (WidthObject * 3 / 4); vertices_labirin_player[2]=0;

vertices_labirin_player[3]=(positionCol * WidthObject) + (WidthObject/4); vertices_labirin_player[4]=(numberRow - po- sitionRow - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[5]=0;

vertices_labirin_player[6]=(positionCol * WidthObject) + (WidthObject*3/4); vertices_labirin_player[7]=(numberRow - po- sitionRow - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[8]=0;

x = (positionCol * WidthObject) + (WidthOb- ject/2); y = (numberRow - positionRow - 1)*WidthObject + (WidthObject / 2); this.x_player=x; this.y_player=y;

this.x_player_end=(positionCol_end * WidthObject) - (WidthObject/2);;

this.y_player_end=(numberRow- posi- this.y_player_end=(numberRow- posi-

Log.v("Test get x_player : ", "" + x); Log.v("Test get y_player : ", "" + y);

Log.v("Test get x_player_end : ", "" + x_player_end); Log.v("Test get y_player_end : ", "" + y_player_end);

// ============ start to generate verti- ces to fractal mandelbrot int k; float x0,y0,xn,yn,xn1,yn1,c1,c2,thrd;

x0=-2f; y0=-2f; c1=-2f; c2=-2f;

// start counter length array int up_bound_1=479; int up_bound_2=639; int up_bound_3=1024; up_bound_1=479; up_bound_2=639; up_bound_3=1024; int length_fractal_mandelbrot=0; int step_=9; for(i=0;i<up_bound_1;i+= step_){

for(j=0;j<up_bound_2;j+= step_){ xn = x0 + ( j * 0.00625f ); // moving from pixel to pixel horizon- tally..

yn = y0 + ( i * 0.00833f ); // moving from pixel to pixel vertical- ly..

c1=-2+(j*0.00625f); // incrementing the value of C1 c2=-2+(i*0.00833f); // incrementing the value of C2

for(k=0;k<up_bound_3;k+=step_){

xn1=(xn*xn)-(yn*yn)+c1; // finding the value of next X

yn1=(2*xn*yn)+c2; // finding the value of next Y

thrd=(xn1*xn1)+(yn1*yn1); // Checking the abso- lute value of X+Y if( thrd >= 64.0f ){

//if( thrd >= 32.0f && thrd <= 150.0f ){ //if( thrd >= 32.0f && thrd <= 150.0f ){

k=up_bound_3; } xn=xn1; yn=yn1;

length_fractal_mandelbrot += 1;

} // end counter length array Log.v("Test get

length_fractal_mandelbrot : ", "" + length_fractal_mandelbrot);

Log.v("Test get

length_fractal_mandelbrot*3 : ", "" + length_fractal_mandelbrot*3);

Log.v("Test get

length_fractal_mandelbrot*4 : ", "" + length_fractal_mandelbrot*4);

x0=-2f; y0=-2f; c1=-2f; c2=-2f; int loop_fractal_mandelbrot=0; int

loop_color_fractal_mandelbrot=0; vertices_fractal_mandelbrot=new float[(length_fractal_mandelbrot) * 3]; verti- ces_color_fractal_mandelbrot=new float[(length_fractal_mandelbrot) * 4];

for(i=0;i<up_bound_1;i+=step_){

for(j=0;j<up_bound_2;j+=step_){ xn = x0 + ( j * 0.00625f ); // moving from pixel to pixel horizon- tally..

yn = y0 + ( i * 0.00833f ); // moving from pixel to pixel vertical- ly..

c1=- 2.0f+(j*0.00625f); // incrementing the value of C1 c2=- 2.0f+(i*0.00833f); // incrementing the value of C2

for(k=0;k<up_bound_3;k+=step_){

xn1=(xn*xn)-(yn*yn)+c1; // finding the value of next X

yn1=(2.0f*xn*yn)+c2; // finding the value of next Y yn1=(2.0f*xn*yn)+c2; // finding the value of next Y

//if( thrd >= 32.0f && thrd <= 150.0f ){

//glColor3f(1.0, 0.0, 0.0);

//glVertex2f(xn,yn);

verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot] = xn;

verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot + 1] = yn;

verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot + 2] = 0;

loop_fractal_mandelbrot += 3;

// mengenerate warna untuk setiap vertex

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot] = 1.0f*yn;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 1] = 1.0f*xn;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 2] = 0.5f;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 3] = 1.0f;

loop_color_fractal_mandelbrot += 4;

k=up_bound_3; }

xn=xn1; yn=yn1;

//glColor3f(0,1,0);

//glVertex2f(xn,yn);

verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot] = xn; verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot + 1] = yn;

verti- ces_fractal_mandelbrot[loop_fractal_mandelbrot + 2] = 0;

loop_fractal_mandelbrot += 3;

// mengenerate warna untuk setiap vertex verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot] = 0.5f*xn;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 1] = 1.0f;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 2] = 0.5f*yn;

verti- ces_color_fractal_mandelbrot[loop_color_fractal_mande lbrot + 3] = 1.0f;

loop_color_fractal_mandelbrot += 4;

// ============ end to generate vertices to fractal mandelbrot

// membuat inisialisasi jaring-jaring (generate Maze) public void generateMaze() {

//inisialisasi maze int i,j; Log.v("Test get numberRow : ", "" + number-

Row); Log.v("Test get numberCol : ", "" + num- berCol); for (i = 0; i < numberRow; i++){ for (j = 0; j < numberCol; j++) {

maze[i][j] = 0; verti[i][j] = 1; hori[i][j] = 1;

} } for (i = 0; i < numberRow; i++){ ver- } } for (i = 0; i < numberRow; i++){ ver-

for (j = 0; j < numberCol; j++){ ho- ri[numberRow][j] = 1;}

//random cell

i = (int) (Math.random()*10%numberRow); j = (int) (Math.random()*10%numberCol); track(i,j);

//create in & out door

i = (int) (Math.random()*10%numberRow); j = (int) (Math.random()*10%numberRow);

verti[i][0] = 0; verti[j][numberCol] = 0;

// first position triangle positionRow = i; positionCol = 0; positionRow_end = j; positionCol_end = numberCol; Navigate = 0;

//rekursif public void track(int RowTrack, int ColTrack) {

int i,j; while (CheckNeighbor(RowTrack,ColTrack)) {

do { //random cell to check neighbor

that not yet visit

i = RowTrack; j = ColTrack; //int k = rand()%4; int k = (int)

(Math.random()*10%4); if (k==0) j = ColTrack-1; else if (k==1) i = RowTrack-1; else if (k==2) j = ColTrack+1; else i = RowTrack+1;

}while(i<0 || i>=numberRow || j<0 || j>=numberCol || maze[i][j]==1);

maze[i][j] = 1; //mark cell that has been visit RemoveLine(RowTrack,ColTrack,i,j); track(i,j);

public boolean CheckNeighbor(int i, int j) {

if ((i-1 >=0) && (maze[i-1][j]==0)) return true; if ((i+1 <numberRow) && (maze[i+1][j]==0)) return true; if ((j-1 >=0) && (maze[i][j-1]==0)) return true; if ((j+1 <numberCol) && (maze[i][j+1]==0)) if ((i-1 >=0) && (maze[i-1][j]==0)) return true; if ((i+1 <numberRow) && (maze[i+1][j]==0)) return true; if ((j-1 >=0) && (maze[i][j-1]==0)) return true; if ((j+1 <numberCol) && (maze[i][j+1]==0))

//remove line between 2 cell public void RemoveLine(int a1,int b1, int a2, int

b2) { if(a1==a2) {

//this.x_player_end=a1-(WidthObject/2);

if(b1 > b2) { verti[a1][b1] = 0; //this.y_player_end=b2-(WidthObject/2); } else { verti[a1][b2] = 0; //this.y_player_end=b1-(WidthObject/2); }

} else if(b1==b2) {

if(a1 > a2) hori[a1][b1] = 0; else hori[a2][b1] = 0;

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr) { ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb;

/** The draw method for the primitive object with the GL context */ public void draw_points(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the points (pem- berian warna untuk titik) gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 1.0f, 1.0f, 0.0f, // V1 - // Point to our vertex buffer (mendata nilai lokasi/posisi titik) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { 1.0f, 1.0f, 0.0f, // V1 -

0.8f, -1.0f, 0.0f, // V12 0.6f, -1.0f, 0.0f, // V13 0.4f, -1.0f, 0.0f, // V14 0.2f, -1.0f, 0.0f, // V15 0.0f, -1.0f, 0.0f, // V16 -0.2f, -1.0f, 0.0f, // V17 -0.4f, -1.0f, 0.0f, // V18 -0.6f, -1.0f, 0.0f, // V19 -0.7f, -1.0f, 0.0f, // V20 -0.8f, -1.0f, 0.0f, // V21 -1.0f, -1.0f, 0.0f, // V22

// Draw the vertices as points (menggam- bar titik-titik) gl.glDrawArrays(GL10.GL_POINTS, 0, 22);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_fractal_mandelbrot(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the points (pem- berian warna untuk titik) //gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_fractal_mandelbrot));

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color_fractal_mandelbrot)); // Draw the vertices as points (menggam- bar titik-titik) gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color_fractal_mandelbrot)); // Draw the vertices as points (menggam- bar titik-titik)

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_line_maze_horiverti(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the line (pemberian warna untuk garis) gl.glColor4f(0.5f, 0.1f, 0.3f, 1.0f); //gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_horiverti)); gl.glDrawArrays(GL10.GL_LINES,0, (int) (vertices_horiverti.length/3));

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_segitiga_labirin_player(GL10 gl, int positionCol_in, int positionRow_in) {

verti- ces_labirin_player[0]=(positionCol_in * WidthObject) + (WidthObject/2);

vertices_labirin_player[1]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject * 3 / 4);

vertices_labirin_player[2]=0;

vertices_labirin_player[3]=(positionCol_in * WidthObject) + (WidthObject/4); vertices_labirin_player[4]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[5]=0;

vertices_labirin_player[6]=(positionCol_in * WidthObject) + (WidthObject*3/4); vertices_labirin_player[7]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[8]=0;

//x = (positionCol * WidthObject) + (WidthObject/2);

//y = (numberRow - positionRow - 1)*WidthObject + (WidthObject / 2);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle //gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_labirin_player));

// Draw the vertices as triangle gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color)); gl.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_segitiga_labirin_player(GL10 gl ){

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle //gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_labirin_player));

// Draw the vertices as triangle gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color)); gl.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

verti- ces_labirin_player[0]=(positionCol_in * WidthObject) + (WidthObject/2);

vertices_labirin_player[1]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject * 3 / 4);

vertices_labirin_player[2]=0;

vertices_labirin_player[3]=(positionCol_in * WidthObject) + (WidthObject/4); vertices_labirin_player[4]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[5]=0;

vertices_labirin_player[6]=(positionCol_in * WidthObject) + (WidthObject*3/4); vertices_labirin_player[7]=(numberRow - po- sitionRow_in - 1)*WidthObject + (WidthObject / 4); vertices_labirin_player[8]=0;

// set the colour for the triangle (menghilangkan effect dari warna objek sebelumnya) gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

/*gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V3 0.0f, 1.0f, 0.0f, // V2 0.5f, 0.0f, 0.0f,

// V1 - first vertex (x,y,z) }));*/

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_labirin_player));

// Draw the vertices as triangle //gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color));

//menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA); GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisable( GL10.GL_BLEND );

// Disable Alpha Blend

gl.glDisable( GL10.GL_TEXTURE_2D ); // Disable Texture Mapping

public void draw_line(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the line (pemberian warna untuk garis) gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik yang // menyusun garis) gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(new float[] { 1.0f, 1.0f, 0.0f, // V1 - first vertex (x,y,z) -1.0f, -1.0f, 0.0f, // V2 - second vertex }));

// Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINES, 0, 2); /*

* gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, * makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V1 - first vertex * (x,y,z) -1.0f, -1.0f, 0.0f, // V2 - second vertex })); */

// Disable the client state before leav- ing // Disable the client state before leav- ing

// gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_line_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the line (pemberian warna untuk garis) gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik yang // menyusun garis) gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_line));

// memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuff- er(vertices_line_color));

// Draw the vertices as lines (menggambar garis dari titik-titik) gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, (int) (2 * (x2 - x1) / step_line)); /* * gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, * makeFloatBuffer(new float [] { 1.0f, 1.0f, 0.0f, // V1 - first vertex * (x,y,z) -1.0f, -1.0f, 0.0f, // V2 - second vertex })); */

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_circle(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the object circle // set the colour for the object circle

// create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_circle));

// draw circle as filled shape // gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,

1, (int) ((int) // 2*batas_sudut/step));

// draw circle contours // gl.glDrawArrays(GL10.GL_LINES, 1,

(int) ((int) 2*batas_sudut/step)); // // membuat garis putus-putus pada tepi lingkaran gl.glDrawArrays(GL10.GL_LINES, 1, (int) ((int) 2 * batas_sudut / step)); // gl.glDrawArrays(GL10.GL_LINE_STRIP, 1, (int) ((int) // 2*batas_sudut/step)); // gl.glDrawArrays(GL10.GL_POINTS, 1,

(int) ((int) 2*batas_sudut/step));

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_circle_color(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour edge for the object circle gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);

// create VBO from buffer with glBuffer- Data() gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_circle));

// memetakan warna untuk setiap vertex gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuff- er(vertices_circle_color));

// draw circle as filled shape // gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,

1, (int) ((int) // 2*batas_sudut/step)); 1, (int) ((int) // 2*batas_sudut/step));

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY); }

public void draw_kotak(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices));

// Draw the vertices as square gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_segitiga(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// set the colour for the triangle gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(new float[] { -0.5f, -0.5f, 0.0f, // V1 - first vertex (x,y,z) 0.5f, -0.5f, 0.0f, // V2 - second vertex 0.0f, 0.5f, 0.0f // V3 - third vertex

// Draw the vertices as triangle gl.glColorPointer(4, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices_color)); gl.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

// Render the shape quad public void draw_quad(GL10 gl) {

// Enable vertex-array and define its buffer

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_quad)); // Draw the primitives from the vertex- array directly

gl.glPolygonOffset(0.0f, 1.0f); gl.glScalef(0.5f, 0.5f, 0.5f); gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f); //

Set the current color (NEW) gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,

0, vertices_quad.length / 3); //gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertices_quad.length / 3); //gl.glDrawArrays(GL10.GL_LINES, 0, ver- tices_quad.length / 3);

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); }

public void loadBallTexture(GL10 gl, Context con- text,int index_Texture) {

// Bitmap bitmap = BitmapFacto-

ry.decodeResource(context.getResources(), // resource);

/*Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(R.drawable.nature));*/

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs[index_Texture]));

gl.glGenTextures(1, textures_indek, 0); gl.glGenTextures(1, textures_indek, 0);

/*gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); */

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );

//gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

gl.glTexParameterf(GLES20.GL_TEXTURE_2D,

GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT );

//gl.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT );

///gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, //GL10.GL_NEAREST); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, //GL10.GL_LINEAR);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

Point3.java Point3.java

publicclass Point3 extends Object { publicfloat x ; publicfloat y ; publicfloat z ;

public Point3() { x = 0.0f; y = 0.0f; z = 0.0f;

} public Point3( float x, float y, float z) { set(x,y,z); } public Point3(Point3 src) { set(src. x , src. y , src. z ); }

publicfinalboolean equals( float x, float y, float z) { return (( this . x == x) && ( this . y == y) && ( this . z == z));

publicvoid set( float x, float y, float z) { this . x = x; this . y = y; this . z = z;

publicvoid minmax( float minx, float miny, float minz, float maxx, float maxy, float maxz)

{ this . x = Math.min(Math.max( this . x , minx), maxx); this . y = Math.min(Math.max( this . y , miny), maxy); this . z = Math.min(Math.max( this . z , minz), maxz);

@Override publicboolean equals(Object o) { if ( this == o) returntrue ;

if (!(o instanceof Point3)) returnfalse ;

Point3 obj = (Point3)o; returnthis .equals(obj. x , obj. y , obj. z ); }

@Override public String toString() { @Override public String toString() {

ObjectArena.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.opengles.GL10;

public class ObjectArena { private float vertices[] = { -0.5f, -0.5f, 0.0f,

// V1 - first vertex (x,y,z) -0.5f, 0.5f, 0.0f,

V2 0.5f, 0.5f, 0.0f,

V3 0.5f, -0.5f, 0.0f,

// V4 -0.5f, -0.5f, 0.0f

V5 };

private float vertices_color[] = { 1.0f, 0.0f, 0.0f, 1.0f,

// CV1 - first color (red,green,blue) 0.0f, 1.0f, 0.0f, 1.0f,

// CV2 0.0f, 0.0f, 1.0f, 1.0f,

// CV3 0.0f, 1.0f, 0.0f, 1.0f,

// CV4 1.0f, 0.0f, 0.0f, 1.0f // CV5 };

public ObjectArena() {

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4);

bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); return fb;

/** The draw method for the primitive object with the GL context */ public void draw_kotak(GL10 gl) {

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

// Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuffer(vertices));

// Draw the vertices as square

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuffer(vertices_color)); gl.glDrawArrays(GL10.GL_TRIANGLES, 2, 3);

//Disable the client state before leaving

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

MySphere.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import java.util.ArrayList; import java.util.List;

import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.opengl.GLUtils;

/** * Render a sphere. * * @author Jim Cornmell re-edit by XTech * @since July 2013 */

public class MySphere { /** Maximum allowed depth. */ private static final int MAXIMUM_ALLOWED_DEPTH = 5;

/** Used in vertex strip calculations, related to properties of a icosahedron. */

private static final int VERTEX_MAGIC_NUMBER = 5;

/** Each vertex is a 2D coordinate. */ private static final int NUM_FLOATS_PER_VERTEX = 3;

/** Each texture is a 2D coordinate. */ private static final int NUM_FLOATS_PER_TEXTURE =

/** Each vertex is made up of 3 points, x, y, z. */ private static final int

AMOUNT_OF_NUMBERS_PER_VERTEX_POINT = 3;

/** Each texture point is made up of 2 points, x, y (in reference to the texture being a 2D image). */ private static final int AMOUNT_OF_NUMBERS_PER_TEXTURE_POINT = 2;

/** Buffer holding the vertices. */ private final List<FloatBuffer> mVertexBuffer = new

ArrayList<FloatBuffer>();

/** The vertices for the sphere. */ private final List<float[]> mVertices = new Ar-

rayList<float[]>();

/** Buffer holding the texture coordinates. */ private final List<FloatBuffer> mTextureBuffer =

new ArrayList<FloatBuffer>();

/** Mapping texture coordinates for the vertices. */ private final List<float[]> mTexture = new Ar- rayList<float[]>();

/** The texture pointer. */ private final int[] mTextures = new int[1];

/** Total number of strips for the given depth. */ private final int mTotalNumStrips;

private int[] imageFileIDs = { // Image file IDs

R.drawable.nature, R.drawable.mule, R.drawable.earth, R.drawable.basketballcolor,

R.drawable.soccerballadidas };

/** * Sphere constructor. * @param depth integer representing the split of

the sphere. * @param radius The spheres radius. */

public MySphere(final int depth, final float radi- us) { // Clamp depth to the range 1 to MAXIMUM_ALLOWED_DEPTH; final int d = Math.max(1, Math.min(MAXIMUM_ALLOWED_DEPTH, depth));

// Calculate basic values for the sphere. this.mTotalNumStrips = Maths.power(2, d - 1) *

VERTEX_MAGIC_NUMBER; final int numVerticesPerStrip = Maths.power(2, d) * 3; final double altitudeStepAngle = Maths.ONE_TWENTY_DEGREES / Maths.power(2, d); final double azimuthStepAngle = Maths.THREE_SIXTY_DEGREES / this.mTotalNumStrips; double x, y, z, h, altitude, azimuth;

for (int stripNum = 0; stripNum < this.mTotalNumStrips; stripNum++) {

// Setup arrays to hold the points for this strip. final float[] vertices = new float[numVerticesPerStrip * NUM_FLOATS_PER_VERTEX]; // NOPMD

final float[] texturePoints = new float[numVerticesPerStrip * NUM_FLOATS_PER_TEXTURE]; // NOPMD

int vertexPos = 0; int texturePos = 0;

// Calculate position of the first vertex in this strip. altitude = Maths.NINETY_DEGREES; azimuth = stripNum * azimuthStepAngle;

// Draw the rest of this strip. for (int vertexNum = 0; vertexNum < numVerti-

cesPerStrip; vertexNum += 2) { // First point - Vertex. y = radius * Math.sin(altitude);

h = radius * Math.cos(altitude); z = h * Math.sin(azimuth); h = radius * Math.cos(altitude); z = h * Math.sin(azimuth);

// First point - Texture. texturePoints[texturePos++] = (float) (1 -

azimuth / Maths.THREE_SIXTY_DEGREES); texturePoints[texturePos++] = (float) (1 - (altitude + Maths.NINETY_DEGREES) / Maths.ONE_EIGHTY_DEGREES);

// Second point - Vertex. altitude -= altitudeStepAngle; azimuth -= azimuthStepAngle / 2.0; y = radius * Math.sin(altitude);

h = radius * Math.cos(altitude); z = h * Math.sin(azimuth); x = h * Math.cos(azimuth); vertices[vertexPos++] = (float) x; vertices[vertexPos++] = (float) y; vertices[vertexPos++] = (float) z;

// Second point - Texture. texturePoints[texturePos++] = (float) (1 -

azimuth / Maths.THREE_SIXTY_DEGREES); texturePoints[texturePos++] = (float) (1 - (altitude + Maths.NINETY_DEGREES) / Maths.ONE_EIGHTY_DEGREES);

azimuth += azimuthStepAngle; }

this.mVertices.add(vertices); this.mTexture.add(texturePoints);

ByteBuffer byteBuffer = ByteBuff- er.allocateDirect(numVerticesPerStrip * NUM_FLOATS_PER_VERTEX * Float.SIZE);

byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer fb = byteBuffer.asFloatBuffer(); fb.put(this.mVertices.get(stripNum)); fb.position(0); this.mVertexBuffer.add(fb);

// Setup texture. byteBuffer = ByteBuff-

er.allocateDirect(numVerticesPerStrip * NUM_FLOATS_PER_TEXTURE * Float.SIZE);

byteBuffer.order(ByteOrder.nativeOrder());

fb = byteBuffer.asFloatBuffer(); fb.put(this.mTexture.get(stripNum)); fb.position(0); this.mTextureBuffer.add(fb);

/** * Load the texture for the square.

* * @param gl Handle. * @param context Handle. * @param texture Texture map for the sphere. */

public void loadGLTexture(final GL10 gl, final Con- text context, final int index_Texture) {

//public void loadGLTexture(final GL10 gl, final Context context, final int texture) { // final Bitmap bitmap = BitmapFacto- ry.decodeResource(context.getResources(), texture);

final Bitmap bitmap = BitmapFacto- ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs[index_Texture]));

// flip method, untuk membalik texture yang ku- rang sesuai Matrix flip = new Matrix(); flip.postScale(-1f, 1f); final Bitmap bmp = Bitmap.createBitmap(bitmap, 0,

0, bitmap.getWidth(), bitmap.getHeight(), flip, true);

// Generate one texture pointer, and bind it to the texture array. gl.glGenTextures(1, this.mTextures, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D,

this.mTextures[0]);

// Create nearest filtered texture. gl.glTexParameterf(GL10.GL_TEXTURE_2D,

GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

// Use Android GLUtils to specify a two- dimensional texture image from our bitmap. //GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bit- map, 0);

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp,

// Tidy up. //bitmap.recycle(); bmp.recycle();

* The draw method for the square with the GL con- text. * * @param gl Graphics handle. */

public void draw(final GL10 gl) { //menempelkan tekstur ke objek gl.glEnable(GL10.GL_TEXTURE_2D);

// bind the previously generated texture. gl.glBindTexture(GL10.GL_TEXTURE_2D,

this.mTextures[0]);

// Point to our buffers. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

// Set the face rotation, clockwise in this case. gl.glFrontFace(GL10.GL_CCW);

// Point to our vertex buffer. for (int i = 0; i < this.mTotalNumStrips; i++) {

gl.glVertexPointer(AMOUNT_OF_NUMBERS_PER_VERTEX_POINT , GL10.GL_FLOAT, 0, this.mVertexBuffer.get(i));

gl.glNormalPointer(GL10.GL_FLOAT, 0, this.mVertexBuffer.get(i));

gl.glTexCoordPointer(AMOUNT_OF_NUMBERS_PER_TEXTURE_PO INT, GL10.GL_FLOAT, 0, this.mTextureBuffer.get(i));

// Draw the vertices as triangle strip. gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0,

this.mVertices.get(i).length / AMOUNT_OF_NUMBERS_PER_VERTEX_POINT);

// Disable the client state before leaving. gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); gl.glDisable( GL10.GL_TEXTURE_2D );

// Disable Texture Mapping } }

Music.java

package com.modelloading;

import android.content.Context; import android.media.MediaPlayer;

public class Music { private static MediaPlayer mp = null; private static MediaPlayer mpOnce = null;

/** Stop old song and start new one */ /** Stop old song and start new one */

source);

mpOnce.setLooping(false); mpOnce.start();

public static void play(Context context, int re- source) { stop(context); mp = MediaPlayer.create(context, re-

source); mp.setLooping(true); mp.start();

/** Stop the music */ public static void stop(Context context) {

if (mp != null) {

mp.stop(); mp.release(); mp = null;

public static void pauseSong(Context context) { if (mp != null) {

mp.pause(); //mp.start(); //mp.play(this, resource); //mp.release(); //mp = null;

public static void stopOnce(Context context) { if (mpOnce != null) { mpOnce.stop(); mpOnce.release(); mpOnce = null;

Maths.java Maths.java

/** * @author JimCornmell re - edit by XTech * */

publicfinalclass Maths {

/** 180 in radians. */ publicstaticfinaldouble ONE_EIGHTY_DEGREES = Math. PI ;

/** 360 in radians. */ publicstaticfinaldouble THREE_SIXTY_DEGREES =

ONE_EIGHTY_DEGREES * 2;

/** 120 in radians. */ publicstaticfinaldouble ONE_TWENTY_DEGREES = THREE_SIXTY_DEGREES / 3;

/** 90 degrees, North pole. */ publicstaticfinaldouble NINETY_DEGREES = Math. PI / 2;

/** Used by power. */ privatestaticfinallong POWER_CLAMP = 0x00000000ffffffffL;

/** * Constructor, although not used at the moment. */

private Maths() { }

/** * Quick integer power function. * * @param base * number to raise. * @param raise * to this power. * @return base ^ raise. */

publicstaticint power( finalint base, finalint raise) { int p = 1;

long

b = raise & POWER_CLAMP ;

// bits in b correspond to values of powerN // so start with p=1, and for each set bit in b, multiply corresponding // table entry

long powerN = base;

while (b != 0) { if ((b & 1) != 0) {

p *= powerN; }

b >>>= 1; powerN = powerN * powerN; }

return p; }

MathHelper.java

package com.modelloading;

publicclass MathHelper

publicstaticfloat angle_of_vector( float x, float y) { double angle = Math.atan(x / y) * 180 / Math. PI ; angle = y > 0 ? 90 + angle : 270 + angle; return 270f - ( float ) angle;

FitObject.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

public class FitObject {

// Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff- er.allocateDirect(arr.length * 4);

bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0); bb.order(ByteOrder.nativeOrder()); FloatBuffer fb = bb.asFloatBuffer(); fb.put(arr); fb.position(0);

public void draw_bola(GL10 gl, float[] mat_diff, int shiness) {

// mengaktifkan pencahayaan //float[] mat_amb = {0.2f * 1.0f, 0.2f *

0.4f, 0.2f * 0.4f, 1.0f,}; float[] mat_amb = {0.0f * 1.0f, 0.0f * 0.4f, 0.0f * 0.4f, 1.0f,}; //float[] mat_diff = {1.0f, 0.4f, 0.4f, 0.5f,}; //float[] mat_diff = {1.0f, 0.8f, 0.04f, 1.0f}; float[] mat_spec = {1.0f, 1.0f, 1.0f, 1.0f};

/*gl.glEnable(GL10.GL_DEPTH_TEST); gl.glEnable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_SMOOTH);

gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0); */

gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0);

// set the colour edge for the object circle //gl.glColor4f(1.0f, 0.8f, 0.04f, 1.0f);

gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, makeFloatBuffer(mat_amb)); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, makeFloatBuffer(mat_diff)); gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, makeFloatBuffer(mat_spec)); gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, shiness); //gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, 128.0f);

float theta, pai; float

co, si; float

r1, r2; float

h1, h2; float

step = 2.0f; float[][] v = new float[32][3]; ByteBuffer vbb; FloatBuffer vBuf;

vbb = ByteBuffer.allocateDirect(v.length * v[0].length * 4);

vbb.order(ByteOrder.nativeOrder()); vBuf = vbb.asFloatBuffer();

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

for (pai = -90.0f; pai < 90.0f; pai += step) { for (pai = -90.0f; pai < 90.0f; pai += step) {

r1 = (float)Math.cos(pai * Math.PI / 180.0); r2 = (float)Math.cos((pai + step) * Math.PI / 180.0); h1 = (float)Math.sin(pai * Math.PI / 180.0); h2 = (float)Math.sin((pai + step) * Math.PI / 180.0);

for (theta = 0.0f; theta <= 360.0f; theta += step) { co = (float)Math.cos(theta * Math.PI / 180.0); si = -(float)Math.sin(theta * Math.PI / 180.0);

v[n][0] = (r2 * co); v[n][1] = (h2); v[n][2] = (r2 * si); v[n + 1][0] = (r1 * co); v[n + 1][1] = (h1); v[n + 1][2] = (r1 * si);

vBuf.put(v[n]); vBuf.put(v[n + 1]);

n += 2;

if(n>31){ vBuf.position(0);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuf); gl.glNormalPointer(GL10.GL_FLOAT,

0, vBuf);

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, n);

n = 0; theta -= step;

} vBuf.position(0);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vBuf); gl.glNormalPointer(GL10.GL_FLOAT, 0, vBuf);

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, n); } gl.glDisable(GL10.GL_LIGHTING); gl.glDisable(GL10.GL_LIGHT0); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); }

ESText.java

// This is a OpenGL ES 1.0 dynamic font rendering system. It loads actual font // files, generates a font map (texture) from them, and allows rendering of // text strings. // // NOTE: the rendering portions of this class uses a sprite batcher in order // provide decent speed rendering. Also, rendering assumes a BOTTOM-LEFT // origin, and the (x,y) positions are relative to that, as well as the // bottom-left of the string to render.

package com.modelloading;

import javax.microedition.khronos.opengles.GL10;

import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Typeface; import android.opengl.GLUtils;

public class ESText {

//--Constants--// public final static int CHAR_START = 32;

// First Character (ASCII Code)

public final static int CHAR_END = 126; // Last Character (ASCII Code) public final static int CHAR_CNT = ( ( ( CHAR_END - CHAR_START ) + 1 ) + 1 ); // Character Count (In- cluding Character to use for Unknown)

public final static int CHAR_NONE = 32; // Character to Use for Unknown (ASCII Code) public final static int CHAR_UNKNOWN = ( CHAR_CNT - 1 ); // Index of the Unknown Character

public final static int FONT_SIZE_MIN = 6; // Minumum Font Size (Pixels) public final static int FONT_SIZE_MAX = 180; // Maximum Font Size (Pixels)

public final static int CHAR_BATCH_SIZE = 100; // Number of Characters to Render Per Batch

//--Members--//

GL10 gl; // GL10 Instance AssetManager assets; // Asset Manager SpriteBatch batch; // Batch Renderer

int fontPadX, fontPadY; // Font Padding (Pixels; On Each Side, ie. Doubled on Both X+Y Axis)

float fontHeight; // Font Height (Actual; Pixels) float fontAscent; // Font Ascent (Above Baseline; Pixels) float fontDescent; // Font Descent (Below Baseline; Pixels)

int textureId; // Font Texture ID [NOTE: Public for Testing Purposes Only!]

int textureSize; // Texture Size for Font (Square) [NOTE: Public for Testing Purposes Only!]

TextureRegion textureRgn; // Full Texture Region

float charWidthMax; // Character Width (Maximum; Pixels) float charHeight; // Character Height (Maximum; Pixels) final float[] charWidths; // Width of Each Character (Actual; Pixels) TextureRegion[] charRgn; // Region of Each Character (Texture Coordinates) int cellWidth, cellHeight; // Character Cell Width/Height int rowCnt, colCnt; // Number of Rows/Columns

float scaleX, scaleY; // Font Scale (X,Y Axis) float spaceX; // Additional (X,Y Axis) Spacing (Unscaled)

//--Constructor--// // D: save GL instance + asset manager, create ar-

rays, and initialize the members // A: gl - OpenGL ES 10 Instance public ESText(GL10 gl, AssetManager assets) {

this.gl = gl; // Save the GL10 Instance this.assets = assets; // Save the Asset Manager Instance

batch = new SpriteBatch( gl, CHAR_BATCH_SIZE ); // Create Sprite Batch (with Defined Size) batch = new SpriteBatch( gl, CHAR_BATCH_SIZE ); // Create Sprite Batch (with Defined Size)

// initialize remaining members fontPadX = 0; fontPadY = 0;

fontHeight = 0.0f; fontAscent = 0.0f; fontDescent = 0.0f;

textureId = -1; textureSize = 0;

charWidthMax = 0; charHeight = 0;

cellWidth = 0; cellHeight = 0; rowCnt = 0; colCnt = 0;

scaleX = 1.0f; // Default Scale = 1 (Unscaled) scaleY = 1.0f; // Default Scale = 1 (Unscaled) spaceX = 0.0f; }

//--Load Font--// // description // this will load the specified font file, cre-

ate a texture for the defined // character range, and setup all required val- ues used to render with it. // arguments: // file - Filename of the font (.ttf, .otf) to

use. In 'Assets' folder. // size - Requested pixel size of font (height) // padX, padY - Extra padding per character

(X+Y Axis); to prevent overlapping characters.

public boolean load(String file, int size, int padX, int padY) {

// setup requested values fontPadX = padX;

// Set Requested X Axis Padding fontPadY = padY; // Set Requested Y Axis Padding

// load the font and setup paint instance for drawing Typeface tf = Typeface.createFromAsset( assets, file ); // Create the Typeface from Font File Paint paint = new Paint(); // Create Android Paint Instance paint.setAntiAlias( true );

// Enable Anti Alias paint.setTextSize( size ); // Set Text Size paint.setColor( 0xffffffff ); // Set ARGB (White, Opaque) paint.setTypeface( tf ); // Set Typeface

// get font metrics Paint.FontMetrics fm = paint.getFontMetrics();

// Get Font Metrics

fontHeight = (float)Math.ceil( Math.abs( fm.bottom ) + Math.abs( fm.top ) ); // Calculate Font Height

fontAscent = (float)Math.ceil( Math.abs( fm.ascent ) ); // Save Font Ascent

fontDescent = (float)Math.ceil( Math.abs( fm.descent ) ); // Save Font Descent

// determine the width of each character (in- cluding unknown character) // also determine the maximum character width char[] s = new char[2];

// Create Character Array charWidthMax = charHeight = 0; // Reset Character Width/Height Maximums float[] w = new float[2]; // Working Width Value int cnt = 0; // Array Counter for ( char c = CHAR_START; c <= CHAR_END; c++ ) { // FOR Each Character s[0] = c; // Set Character

paint.getTextWidths( s, 0, 1, w ); // Get Character Bounds charWidths[cnt] = w[0]; // Get Width

if ( charWidths[cnt] > charWidthMax ) // IF Width Larger Than Max Width

charWidthMax = charWidths[cnt];

// Save New Max Width cnt++; // Advance Array Counter } s[0] = CHAR_NONE;

// Set Unknown Character paint.getTextWidths( s, 0, 1, w ); // Get Character Bounds charWidths[cnt] = w[0]; // Get Width if ( charWidths[cnt] > charWidthMax ) // IF Width Larger Than Max Width charWidthMax = charWidths[cnt]; // Save New Max Width cnt++; // Advance Array Counter

// set character height to font height // set character height to font height

// find the maximum size, validate, and setup cell sizes cellWidth = (int)charWidthMax + ( 2 * fontPadX ); // Set Cell Width cellHeight = (int)charHeight + ( 2 * fontPadY ); // Set Cell Height int maxSize = cellWidth > cellHeight ? cell- Width : cellHeight; // Save Max Size (Width/Height)

if ( maxSize < FONT_SIZE_MIN || maxSize > FONT_SIZE_MAX ) // IF Maximum Size Outside Valid Bounds

return false; // Return Error

// set texture size based on max font size (width or height) // NOTE: these values are fixed, based on the defined characters. when // changing start/end characters (CHAR_START/CHAR_END) this will need adjustment too! if ( maxSize <= 24 ) // IF Max Size is 18 or Less textureSize = 256; // Set 256 Texture Size else if ( maxSize <= 40 ) // ELSE IF Max Size is 40 or Less textureSize = 512; // Set 512 Texture Size else if ( maxSize <= 80 ) // ELSE IF Max Size is 80 or Less textureSize = 1024; // Set 1024 Texture Size else // ELSE IF Max Size is Larger Than 80 (and Less than FONT_SIZE_MAX)

textureSize = 2048; // Set 2048 Texture Size

// create an empty bitmap (alpha only) Bitmap bitmap = Bitmap.createBitmap( texture-

Size, textureSize, Bitmap.Config.ALPHA_8 ); // Cre- ate Bitmap

Canvas canvas = new Canvas( bitmap ); // Create Canvas for Rendering to Bitmap bitmap.eraseColor( 0x00000000 ); // Set Transparent Background (ARGB)

// calculate rows/columns // NOTE: while not required for anything, these

may be useful to have :) colCnt = textureSize / cellWidth; // Calculate Number of Columns

rowCnt = (int)Math.ceil( (float)CHAR_CNT / (float)colCnt ); // Calculate Number of Rows

// render each of the characters to the canvas

(ie. build the font map) float x = fontPadX; // Set Start Position (X) float y = ( cellHeight - 1 ) - fontDescent - fontPadY; // Set Start Position (Y) for ( char c = CHAR_START; c <= CHAR_END; c++ ) { // FOR Each Character s[0] = c; // Set Character to Draw canvas.drawText( s, 0, 1, x, y, paint ); // Draw Character x += cellWidth; // Move to Next Character if ( ( x + cellWidth - fontPadX ) > texture- Size ) { // IF End of Line Reached x = fontPadX; // Set X for New Row y += cellHeight; // Move Down a Row } } s[0] = CHAR_NONE;

// Set Character to Use for NONE

canvas.drawText( s, 0, 1, x, y, paint ); // Draw Character

// generate a new texture int[] textureIds = new int[1];

// Array to Get Texture Id gl.glGenTextures( 1, textureIds, 0 ); // Generate New Texture textureId = textureIds[0]; // Save Texture Id

// setup filters for texture gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId

); // Bind Texture gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST ); // Set Minification Filter

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR ); // Set Magnification Filter

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE ); // Set U Wrapping

gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE ); // Set V Wrapping

// load the generated bitmap onto the texture GLUtils.texImage2D( GL10.GL_TEXTURE_2D, 0, bit-

map, 0 ); // Load Bitmap to Texture

gl.glBindTexture( GL10.GL_TEXTURE_2D, 0 ); // Unbind Texture

// release the bitmap bitmap.recycle();

// Release the Bitmap

// setup the array of character texture regions x = 0;

// Initialize X y = 0; // Initialize Y

for ( int c = 0; c < CHAR_CNT; c++ ) { // FOR Each Character (On Texture) charRgn[c] = new TextureRegion( textureSize, textureSize, x, y, cellWidth-1, cellHeight-1 ); // Create Region for Character

x += cellWidth; // Move to Next Char (Cell)

if ( x + cellWidth > textureSize ) {

x = 0; // Reset X Position to Start y += cellHeight; // Move to Next Row (Cell) } }

// create full texture region textureRgn = new TextureRegion( textureSize,

textureSize, 0, 0, textureSize, textureSize ); // Create Full Texture Region

// return success return true;

// Return Success }

//--Begin/End Text Drawing--// // D: call these methods before/after (respective-

ly all draw() calls using a text instance // NOTE: color is set on a per-batch basis, and fonts should be 8-bit alpha only!!!

// A: red, green, blue - RGB values for font (de- fault = 1.0)

// alpha - optional alpha value for font (de- fault = 1.0) // R: [none] public void begin() {

begin( 1.0f, 1.0f, 1.0f, 1.0f ); // Begin with White Opaque } public void begin(float alpha) {

begin( 1.0f, 1.0f, 1.0f, alpha ); // Begin with White (Explicit Alpha) } public void begin(float red, float green, float

blue, float alpha) {

gl.glColor4f( red, green, blue, alpha ); // Set Color+Alpha gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId ); // Bind the Texture batch.beginBatch(); // Begin Batch } public void end() { gl.glColor4f( red, green, blue, alpha ); // Set Color+Alpha gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId ); // Bind the Texture batch.beginBatch(); // Begin Batch } public void end() {

gl.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); // Restore Default Color/Alpha }

//--Draw Text--// // D: draw text at the specified x,y position // A: text - the string to draw // x, y - the x,y position to draw text at

(bottom left of text; including descent) // R: [none] public void draw(String text, float x, float y) {

float chrHeight = cellHeight * scaleY; // Calculate Scaled Character Height float chrWidth = cellWidth * scaleX; // Calculate Scaled Character Width int len = text.length(); // Get String Length x += ( chrWidth / 2.0f ) - ( fontPadX * scaleX ); // Adjust Start X y += ( chrHeight / 2.0f ) - ( fontPadY * scaleY ); // Adjust Start Y for ( int i = 0; i < len; i++ ) { // FOR Each Character in String int c = (int)text.charAt( i ) - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

if ( c < 0 || c >= CHAR_CNT ) // IF Character Not In Font

c = CHAR_UNKNOWN; // Set to Unknown Character Index batch.drawSprite( x, y, chrWidth, chrHeight, charRgn[c] ); // Draw the Character x += ( charWidths[c] + spaceX ) * scaleX; // Advance X Position by Scaled Character Width } }

//--Draw Text Centered--// // D: draw text CENTERED at the specified x,y po-

sition // A: text - the string to draw // x, y - the x,y position to draw text at

(bottom left of text)

// R: the total width of the text that was drawn public float drawC(String text, float x, float y)

{ float len = getLength( text ); // Get Text Length draw( text, x - ( len / 2.0f ), y - ( getChar- Height() / 2.0f ) ); // Draw Text Centered return len; // Return Length } public float drawCX(String text, float x, float y)

{ float len = getLength( text ); // Get Text Length { float len = getLength( text ); // Get Text Length

{ draw( text, x, y - ( getCharHeight() / 2.0f ) ); // Draw Text Centered (Y-Axis Only) }

//--Set Scale--// // D: set the scaling to use for the font // A: scale - uniform scale for both x and y axis

scaling // sx, sy - separate x and y axis scaling fac- tors // R: [none] public void setScale(float scale) {

scaleX = scaleY = scale; // Set Uniform Scale } public void setScale(float sx, float sy) {

scaleX = sx; // Set X Scale scaleY = sy; // Set Y Scale }

//--Get Scale--// // D: get the current scaling used for the font // A: [none] // R: the x/y scale currently used for scale public float getScaleX() {

return scaleX; // Return X Scale } public float getScaleY() {

return scaleY; // Return Y Scale }

//--Set Space--// // D: set the spacing (unscaled; ie. pixel size)

to use for the font // A: space - space for x axis spacing // R: [none] public void setSpace(float space) {

spaceX = space; // Set Space }

//--Get Space--// // D: get the current spacing used for the font // A: [none] // R: the x/y space currently used for scale public float getSpace() {

return spaceX; // Return X Space

//--Get Length of a String--// // D: return the length of the specified string if

rendered using current settings // A: text - the string to get length for // R: the length of the specified string (pixels) public float getLength(String text) {

float len = 0.0f; // Working Length int strLen = text.length(); // Get String Length (Characters) for ( int i = 0; i < strLen; i++ ) { // For Each Character in String (Except Last int c = (int)text.charAt( i ) - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

len += ( charWidths[c] * scaleX ); // Add Scaled Character Width to Total Length } len += ( strLen > 1 ? ( ( strLen - 1 ) * spaceX

) * scaleX : 0 ); // Add Space Length return len; // Return Total Length }

//--Get Width/Height of Character--// // D: return the scaled width/height of a charac-

ter, or max character width // NOTE: since all characters are the same height, no character index is required! // NOTE: excludes spacing!! // A: chr - the character to get width for // R: the requested character size (scaled) public float getCharWidth(char chr) {

int c = chr - CHAR_START; // Calculate Character Index (Offset by First Char in Font)

return ( charWidths[c] * scaleX ); // Return Scaled Character Width } public float getCharWidthMax() {

return ( charWidthMax * scaleX ); // Return Scaled Max Character Width } public float getCharHeight() {

return ( charHeight * scaleY ); // Return Scaled Character Height }

//--Get Font Metrics--// // D: return the specified (scaled) font metric // A: [none] // R: the requested font metric (scaled) public float getAscent() {

return ( fontAscent * scaleY ); // Return Font Ascent } public float getDescent() { return ( fontAscent * scaleY ); // Return Font Ascent } public float getDescent() {

return ( fontHeight * scaleY ); // Return Font Height (Actual) }

//--Draw Font Texture--// // D: draw the entire font texture (NOTE: for

testing purposes only)

// A: width, height - the width and height of the area to draw to. this is used

// to draw the texture to the top-left corner. public void drawTexture(int width, int height) {

batch.beginBatch( textureId ); // Begin Batch (Bind Texture) batch.drawSprite( textureSize / 2, height - ( textureSize / 2 ), textureSize, textureSize, textur- eRgn ); // Draw

batch.endBatch(); // End Batch } }