Math Snail

Math Snail - Project Pilihan

===

9.8 Math Snail

9.8.1 Konsep

Game ini berbeda dari game balap lain karena menghadirkan hewan sebagai karakter utamanya, hewannya pun terbilang lucu ka- rena seekor siput yang notabene berjalan lambat. Game tersebut adalah sebuah games racing yang pesertanya adalah siput –siput lu- cu. Dalam games ini berkonsepkan seekor siput yang balapan lari. Si- put akan melalui beberapa rintangan. Rintangan yang diberikan beru- pa soal-soal matematika. Yang terdiri dari penjumlahan, pengu- rangan, perkalian, dan pembagian. Lari siput itu akan semakin cepat Game ini berbeda dari game balap lain karena menghadirkan hewan sebagai karakter utamanya, hewannya pun terbilang lucu ka- rena seekor siput yang notabene berjalan lambat. Game tersebut adalah sebuah games racing yang pesertanya adalah siput –siput lu- cu. Dalam games ini berkonsepkan seekor siput yang balapan lari. Si- put akan melalui beberapa rintangan. Rintangan yang diberikan beru- pa soal-soal matematika. Yang terdiri dari penjumlahan, pengu- rangan, perkalian, dan pembagian. Lari siput itu akan semakin cepat

Edukasi (Tujuan dan Manfaat)

Edukasi yang kita berikan pada games ini, dengan mem- berikan soal-soal matematika dalam permainannya. Tujuan nya agar yang memainkan games ini lebih cermat, cepat, dan teliti. Sasaran utama yang memainkan games ini lebih ke siswa-siswi dari mulai SD, SMP, dan SMA. Karena terdapat level-levelnya, jadi tingkat kesu- litannya dapat kita pilih. Ditambah dengan adanya timing sehingga, hal tersebut membuat anda berusaha untuk menyelesaikan game dengan cepat sebelum waktunya habis.

Manfaat dari memainkan games ini, diharapkan mampu men- gitung matematika dengan cepat dan teliti. Lalu kita juga dapat mem- buat anak-anak menyukai pelajaran menghitung.

Feature / Menu

Feature game kita ini :  Bias dijalankan di laptop dengan tombol navigasi  Kami berencana game ini dapat dijalankan di gadget berbasis

android  Games ini mendukung jika dimainkan di android touch screen

9.8.2 Fungsi Dasar Pembentuk Objek

Komponen pada pembangunan game edukasi Snail Running ini meliputi berbagai fungsi dalam OpenGL antara lain yang paling utama adalah fungsi GL_BLEND. Yaitu untuk membuat objek agar objek ter- sebut berbentuk seperti tekstur mappingnya. Mayoritas dari pemben- tuk game ini memanfaatkan fungsi tersebut. Mulai dari tampilan siput, soal, rintangan dan score.

Tabel 9.4 Fungsi Dasar Pembentuk Objek

Keterangan Fungsi

// ini siput // create siput with no

Untuk membuat

'if' bullshit this.siput_pos_x =

objek siput dalam

(x_lebar_layar / 10) + siput_next;

permainan, yang

this.siput_pos_y = (y_tinggi_layar / 10) + siput_up; this.siput_pos_y = (y_tinggi_layar / 10) + siput_up;

dimana disini juga

(x_lebar_layar / 16); this.siput_size_y = 2 *

terdapat code untuk

(y_tinggi_layar / 9);

mengontrol ke-

gl.glPushMatrix();

cepatan siput.

gl.glDisable(GL10.GL_LIGHTING);

Selain itu, di code

gl.glBlendFunc(GL10.GL_SRC_ALPHA,

ini juga mengatur

GL10.GL_ONE_MINUS_SRC_ALPHA);

gerakan siput (lon-

gl.glEnable(GL10.GL_BLEND);

cat naik-turun).

// mengatur naik turun

gl.glTranslatef(faktor_naik_turun,

0, 0.0f);

gl.glTranslatef(siput_pos_x, si- put_pos_y, 0.0f); gl.glScalef(siput_size_x, siput_size_y, 1.0f); siput.loadPlayerTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); siput.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); // mengatur naik turun

gl.glTranslatef(faktor_naik_turun,

0, 0.0f);

gl.glTranslatef(siput_pos_x, si- put_pos_y, 0.0f); gl.glScalef(siput_size_x, siput_size_y, 1.0f); siput.loadPlayerTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); siput.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glDisable(GL10.GL_BLEND);

Code ini untuk

Clock.uptimeMillis() / 1000;

mengatur lama

this.timeElapsed = cur- rentTime - beginningTime;

durasi perlombaan

Log.v("timeElapsed", Long.toString(timeElapsed));

siput itu berlang- sung.

// ini npc_icon float sN_pos_x =

Untuk melihat po-

(x_lebar_layar / 16) + npc_next + npc_time;

sisi siput itu dimana

float sN_pos_y = (8.5f *

pada time bar.

y_tinggi_layar / 9);

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(sN_pos_x, sN_pos_y, 0.0f); gl.glScalef(sS_size_y, sS_size_y, 1.0f); npc.loadNPCTexture(gl, con- text, 0); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix(); // ini garis finish

Ini digunakan untuk

if (timeElapsed >= this.endTime) {

jika waktu time bar

sudah habis, dan

Log.v("state","end game");

soal-soal yang

this.finish_pos_x = x_lebar_layar + this.finish_move;

dhadapi sudah

this.finish_pos_y =

selesai, maka siput

(y_tinggi_layar / 9); this.finish_size_x

akan menghadapi

= 4 * x_lebar_layar / 16; this.finish_size_y

garis finish untuk

= 4 * y_tinggi_layar / 9;

menyudahi per-

gl.glPushMatrix();

mainan.

gl.glDisable(GL10.GL_LIGHTING); gl.glDisable(GL10.GL_LIGHTING);

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(finish_pos_x, fin-

ish_pos_y, 0.0f);

gl.glScalef(finish_size_x, fin-

ish_size_y, 1.0f);

// fin- ish.loadPlayerTexture(gl, context, nu-

mIDFrame);

// gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); fin-

ish.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

if (currentTime - gameTime

float start_pos_x =

(x_lebar_layar / 3);

float start_pos_y =

(y_tinggi_layar / 3);

float start_size_x

= 5f * (x_lebar_layar / 16);

float start_size_y

= 5f * (y_tinggi_layar / 9);

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(start_pos_x,

start_pos_y, 0.0f);

gl.glScalef(start_size_x, start_size_y, 1.0f);

getready.loadBallTexture(gl, con-

text, 0);

getready.draw_background(gl); getready.draw_background(gl);

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

this.startRace = false;

} else { this.startRace =

true;

if (this.startQuiz) { Log.v("QUIZ", "Started");

// int rand_jawab =

randomGenerator.nextInt(2);

float quiz_pos_x =

(x_lebar_layar / 3);

float quiz_pos_y =

(2 * y_tinggi_layar / 3);

float quiz_size_x =

1.5f * 4 * (x_lebar_layar / 16);

float quiz_size_y =

1.5f * 1 * (y_tinggi_layar / 9);

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(quiz_pos_x,

quiz_pos_y, 0.0f);

gl.glScalef(quiz_size_x, quiz_size_y, 1.0f);

quiz.loadSoalTexture(gl, context,

this.soal, difficulty);

quiz.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

float ans_pos_x[] = { quiz_pos_x, quiz_pos_x + ans_size_x,

quiz_pos_x + 2 * ans_size_x };

this.setAns_pos_x(ans_pos_x);

// manual this.ans_pos_x0 = ans_pos_x[0]; this.ans_pos_x1 = ans_pos_x[1]; this.ans_pos_x2 = ans_pos_x[2];

// Log.v("blabla", Float.toString(this.getAns_pos_x(0))); shuffleAr- ray(rand_jawab); int ans[] = { this.soal, this.jwb2, this.jwb3 };

// float[] ans_pos_y = { quiz_size_y, quiz_size_y, quiz_size_y }; this.ans_pos_y = (1 * y_tinggi_layar / 3);

this.ans_size_x = quiz_size_x / 3; this.ans_size_y = 1f * (y_tinggi_layar / 9);

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

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(ans_pos_x[rand_jaw ab[i]], ans_pos_y, 0.0f);

gl.glScalef(ans_size_x, ans_size_y, 1.0f);

quiz.loadJwbTexture(gl, context, ans[rand_jawab[i]], difficulty);

quiz.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

gl.glEnable(GL10.GL_LIGHTING);

gl.glPopMatrix();

} } } // jump public void startJump() {

Untuk mengatur

kecepatan_lompat = 20.0f; kecepatan_lompat = 20.0f;

pada siput. Dengan

public void endJump() { kecepatan_lompat = -20.0f;

ketentuan ke-

cepatan yang

public void move(ESRender esRen-

dimilkik saat men-

der) { float kecepatan_ground_tmp;

jawab soal. Lalu disini juga megatur

if (esRen-

der.kecepatan_ground == 0) {

pergerakan siput ke

ke-

cepatan_ground_tmp = 1;

kanan atau ke kiri.

} else { ke-

cepatan_ground_tmp = esRen- der.kecepatan_ground;

int a = (int) (Math.ceil(esRender.x_lebar_layar / ke- cepatan_ground_tmp) * ke- cepatan_ground_tmp);

esRen-

der.setX_lebar_layar_temp(a);

// ground velocity esRender.move_left_right1 - = kecepatan_ground; esRender.move_left_right2 - = kecepatan_ground; esRender.move_left_rightobj -= kecepatan_ground;

if (-

esRender.move_left_right1 == esRen- der.x_lebar_layar_temp) {

esRen-

der.move_left_right1 = esRen- der.x_lebar_layar_temp;

if (-

esRender.move_left_right2 == 2 * esRen- der.x_lebar_layar_temp) {

esRen-

der.move_left_right2 = 0;

if (-

esRender.move_left_rightobj == 2 * esRender.x_lebar_layar_temp) {

esRen-

der.move_left_rightobj = 0;

int random = ran- domGenerator.nextInt(900);

esRen-

der.setRandom(random);

// 1 esRen-

der.randTexture = randomGenera- tor.nextInt(2);

// esRen-

der.startQuiz = false;

// esRen-

der.resetInput();

shuffleAr-

ray(esRender.index);

esRender.soal =

esRender.index[0];

esRender.jwb2 =

esRender.index[1];

esRender.jwb3 =

esRender.index[2];

esRen- der.moveWithCollisionDetection(esRender)

; // move if (esRender.startRace) { esRender.difficulty = false;

this.kecepatan_ground = 50.0f;

// jump siput_up += ke- cepatan_lompat;

if (siput_up <= 0)

siput_up =

ke-

cepatan_lompat = 0.0f;

onGround =

true;

if (siput_pos_y >=

7 * this.y_tinggi_layar / 9) {

siput_pos_y = (7 * this.y_tinggi_layar / 9) - 20; ke-

cepatan_lompat = -20.0f;

onGround =

false;

// jump // jump

5; // game selesai = 20 detik

float timefrag =

(15 * esRender.timebar_size_x / 16)

esRender.endTime;

float currtimefrag

= timefrag * esRender.timeElapsed;

if (esRen- der.timeElapsed <= esRender.endTime) { esRen-

der.npc_time = currtimefrag;

esRen-

der.siput_time = currtimefrag;

esRen-

der.finish_move -= 50;

if (finish_pos_x >=

3 * x_lebar_layar / 4) {

finish_pos_x

= 3 * x_lebar_layar / 4;

} else if (!esRen- der.startRace) {

esRen-

der.kecepatan_ground = 0.0f;

Log.v("stop", "stop");

// y move jump public void move_y(float y) { kecepatan_lompat = 25.0f;

if (y > 0) { this.siput_up +=

kecepatan_lompat;

if

(this.siput_pos_y > 8 * this.y_tinggi_layar / 9) {

this.siput_pos_y = 8 * this.y_tinggi_layar / 9;

ke-

cepatan_lompat = 0;

} if (y < 0) { this.siput_up -=

kecepatan_lompat;

if

(this.siput_pos_y < 0) {

this.siput_pos_y = (this.y_tinggi_layar / 10); this.siput_pos_y = (this.y_tinggi_layar / 10);

public boolean startQuiz(int soal, int jwb2, int jwb3) {

this.startQuiz = true; this.startRace = false;

this.soal = soal; this.jwb2 = jwb2; this.jwb3 = jwb3;

float inY = this.getInputY(); float inX = this.getInputX();

Log.v("touch_position",

Float.toString(inX) + "_,_" + Float.toString(inY));

if (inY != 0 && inX != 0) { if (checkQuiz(inAns(inX, inY))) {

Log.v("answer", "TRUE");

this.resetInput(); return true; } else {

Log.v("answer", "WRONG"); return false; }

return false; }

public int inAns(float x, float y) {

if (y == 0 & x == 0) { return 4; } else if ((this.ans_pos_x0 <= x && x <= this.ans_pos_x0 + if (y == 0 & x == 0) { return 4; } else if ((this.ans_pos_x0 <= x && x <= this.ans_pos_x0 +

return

this.rand_jawab[0]; } else if ((this.ans_pos_x1 <= x && x <= this.ans_pos_x1

this.ans_size_x)) {

return

this.rand_jawab[1]; } else if ((this.ans_pos_x2 <= x && x <= this.ans_pos_x2

this.ans_size_x)) {

return

this.rand_jawab[2];

} else { return 3; }

public boolean checkQuiz(int in- dex) { if (index == 3 || index ==

4) { return false;

if (index == this.soal) { return true;

} else if (index == this.jwb3 || index == this.jwb2) { return false;

return false;

public boolean startQuiz(int soal, int jwb2, int jwb3) {

Fungsi ini untuk

this.startQuiz = true; this.startRace = false;

mengatur soal-soal yang keluar. Dan

this.soal = soal; this.jwb2 = jwb2;

juga berhubungan

this.jwb3 = jwb3;

dengan kecepatan yang dicapai siput,

float inY = this.getInputY();

jika menjawab soal

float inX = this.getInputX();

benar maka ke- cepatan siput akan

Log.v("touch_position",

lebih cepat dari

Float.toString(inX) + "_,_" + Float.toString(inY));

lawannya, tetapi

jika salah maka ke- jika salah maka ke-

if (inY != 0 && inX != 0) {

if

menurun.

(checkQuiz(inAns(inX, inY))) {

Log.v("answer", "TRUE");

this.resetInput(); return true; } else {

Log.v("answer", "WRONG"); return false; }

return false;

public int inAns(float x, float y) {

if (y == 0 & x == 0) {

return 4;

} else if ((this.ans_pos_x0 <= x && x <= this.ans_pos_x0 + this.ans_size_x)) { return this.rand_jawab[0];

} else if ((this.ans_pos_x1 <= x && x <= this.ans_pos_x1 + this.ans_size_x)) { return this.rand_jawab[1];

} else if ((this.ans_pos_x2 <= x && x <= this.ans_pos_x2 + this.ans_size_x)) { return this.rand_jawab[2];

} else {

return 3;

public boolean checkQuiz(int in- dex) { if (index == 3 || index ==

4) { return false; 4) { return false;

} else if (index == this.jwb3 || index == this.jwb2) { return false;

return false;

} // menangkap ukuran layar if (get_size_screen) {

Untuk mengatur

this.x_lebar_layar = mywidth;

ukuran layar per-

this.y_tinggi_layar

mainan.

= myheight; this.ratio = (this.x_lebar_layar / this.y_tinggi_layar);

get_size_screen = false;

// membuat background gl.glPushMatrix();

Fungsi ini untuk

gl.glDisable(GL10.GL_LIGHTING);

membuat objek background pada

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

game ini.

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(move_left_right1,

0.f, 0.f); gl.glTranslatef(0, -45.f, 0.f); gl.glScalef(x_lebar_layar, y_tinggi_layar, 1.0f); bg.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix(); // membuat background 2 gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glTranslatef(move_left_right2,

0.f, 0.f); gl.glTranslatef(0, -45.f, 0.f); gl.glScalef(x_lebar_layar, y_tinggi_layar, 1.0f); bg.draw_background(gl); 0.f, 0.f); gl.glTranslatef(0, -45.f, 0.f); gl.glScalef(x_lebar_layar, y_tinggi_layar, 1.0f); bg.draw_background(gl);

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

// membuat ground 1 gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glTranslatef(move_left_right1,

0.f, 0.f); gl.glTranslatef(0, -40.f, 0.f);

gl.glScalef(x_lebar_layar_temp, 7 * y_tinggi_layar / 10, 1.0f); groud.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

// membuat ground 2 gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glTranslatef(move_left_right2,

0.f, 0.f);

gl.glTranslatef(x_lebar_layar_temp , 0.f, 0.f); gl.glTranslatef(0, -40.f,

0.f);

gl.glScalef(x_lebar_layar_temp, 7 * y_tinggi_layar / 10, 1.0f); groud.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

//ini BATU this.batu_pos_x = (13 *

Membuat rintangan

x_lebar_layar / 13) + move_left_rightobj

batu. Mengatur le-

this.getRandom();

taknya batu, taknya batu,

mengatur kapan

(y_tinggi_layar / 25); this.batu_size_x = 1.5f *

keluarnya batu, dan

(x_lebar_layar / 16); this.batu_size_y = 1.5f *

lain-lain.

(y_tinggi_layar / 9);

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); // keluar di pojok kanan gl.glTranslatef(batu_pos_x, batu_pos_y, 0.0f); gl.glScalef(batu_size_x, batu_size_y, 1.0f); batu.loadRandTexture(gl, context, randTexture); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); batu.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

numFrames2++;

numIDFrame++;

if (numIDFrame >= 1) {

numIDFrame = 0; }

//NPC this.npc_pos_x =

Membuat lawan

(x_lebar_layar / 10) + npc_next; this.npc_pos_y =

siput yaitu dari

(y_tinggi_layar / 4) + npc_up;

permainannya

this.npc_size_x = 2 * (x_lebar_layar / 16);

sendiri. Dengan ke-

this.npc_size_y = 2 * (y_tinggi_layar / 9);

cepatan yang kon- stan.

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

// mengatur naik turun

gl.glTranslatef(faktor_naik_turun,

0, 0.0f);

gl.glTranslatef(npc_pos_x, npc_pos_y, 0.0f); gl.glScalef(npc_size_x, npc_size_y, 1.0f);

npc.loadNPCTexture(gl, con- text, numIDFrame);

// gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

// mengatur naik turun

gl.glTranslatef(faktor_naik_turun,

0, 0.0f);

gl.glTranslatef(npc_pos_x, npc_pos_y, 0.0f); gl.glScalef(npc_size_x, npc_size_y, 1.0f);

npc.loadNPCTexture(gl, con- text, numIDFrame);

// gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND);

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

9.8.3 Tampilan Implementasi

Gambar 9.36 Menu Awal

Gambar 9.37 Get Ready

Gambar 9.38 Soal

Gambar 9.39 Finish

9.8.4 Source Code

Source Code 5.1 ESRender Math Snail ESRender.java

package com.ligthing;

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.GLUtils;

/* * A photo cube with 6 pictures (textures) on its 6 faces. */ public class TextureKubus { private FloatBuffer vertexBuffer; // Vertex Buffer private FloatBuffer texBuffer; // Texture Coords Buffer private int numFaces = 14; private int[] imageFileIDs = { // Image file IDs R.drawable.caldera, // index 0

R.drawable.candice, // index 1 R.drawable.mule, // index 2 R.drawable.glass, // index 3 R.drawable.leonardo, // index 4 R.drawable.tmsk, // index 5 R.drawable.lantai, // index 6 R.drawable.tembok, // index 7 R.drawable.tembokx, // index 8 R.drawable.atap, // index 9 R.drawable.meja,// index 10 R.drawable.imam, // index 11 R.drawable.pintux, // index 12 R.drawable.wallpaper // index 13

}; private int[] textureIDs = new int[numFaces]; private Bitmap[] bitmap = new Bitmap[numFaces]; private float cubeHalfSize = 1.0f;

package com.modelloading;

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; import android.os.SystemClock; import android.content.Context; import android.opengl.GLSurfaceView.Renderer; import android.util.Log; import android.os.SystemClock;

public class ESRender implements Renderer { boolean difficulty; long timeElapsed; private float finish_move; boolean startRace = false; boolean startQuiz = false; float[] ans_pos_x; int[] ans; float ans_pos_y; float ans_size_x; float ans_size_y; float inputY; float inputX; float ans_pos_x0; float ans_pos_x1; float ans_pos_x2; int soal; int jwb2; int jwb3; int[] rand_jawab = { 0, 1, 2 }; int[] index = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // batu private int randTexture; private float batu_pos_x; private float batu_pos_y; private float batu_size_x; private float batu_size_y; Random randomGenerator = new Random(); // siput private float siput_up; private float siput_next; private float siput_pos_x; private float siput_pos_y; private float siput_size_x; private float siput_size_y; private float kecepatan_lompat = 0.0f; private PrimitivesObject siput; private PrimitivesObject npc;

float siput_time; float npc_time; // NPC private float npc_up; private float npc_next; private float npc_pos_x; private float npc_pos_y; private float npc_size_x; private float npc_size_y; // private float kecepatan_lompat = 0.0f;

private PrimitivesObject quiz; // finish private PrimitivesObject finish; private float finish_pos_x; private float finish_pos_y; private float finish_size_x; private PrimitivesObject quiz; // finish private PrimitivesObject finish; private float finish_pos_x; private float finish_pos_y; private float finish_size_x;

boolean onGround = true;

// time long beginningTime; long endTime; long gameTime; private PrimitivesObject timebar; private float timebar_pos_x; private float timebar_pos_y; private float timebar_size_x; private float timebar_size_y; private float barLength;

private float random;

private ESText glText; private PrimitivesObject bg;

private PrimitivesObject groud; private PrimitivesObject primob1; private PrimitivesObject primob3; private PrimitivesObject batu; private PrimitivesObject getready;

// private ObjectBall objectball3;

// private ObjectBall objectballstickdua; private PrimitivesObject primob; // private PrimitivesObject primob2; private TransObject transobject;

Context context; 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

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

private float move_left_right1 = 0.f; private float move_left_right2 = 0.f; private float move_left_rightobj = 0.f;

private float kecepatan_ground; private int faktor_naik_turun = 0; private int flag_naik = 1;

private long startTime; private long fpsStartTime; private long numFrames; private float fps_temp; private long fpsElapsed_temp; private long numFrames_temp; private boolean startTimeInit = true; private long startTime; private long fpsStartTime; private long numFrames; private float fps_temp; private long fpsElapsed_temp; private long numFrames_temp; private boolean startTimeInit = true;

float CurrentScale = 1.0f;

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

int xMin, xMax, yMin, yMax;

private int mywidth = 0; private int myheight = 0; private int jumlah_pantulan = 0;

private float x_player = 0; private float y_player = 0; private float x_player_end = 0; private float y_player_end = 0; private int Navigate = 0; private int positionRow = 0; private int positionCol = 0; // private int hori[][] = new //

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

// private int verti[][] = new //

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

private int hori[][] = new int[1000][1000]; private int verti[][] = new int[1000][1000]; private int numberCol = 0; private int numberRow = 0; private float WidthObject = 0;

private float x_anim_stick = 0; private float y_anim_stick = 0;

private float x_touch = 0; private float y_touch = 0;

private float x_pointer = 0; private float y_pointer = 0;

private float x_pointer_awal = 0; private float y_pointer_awal = 0;

private float x_lebar_layar = 0; private float y_tinggi_layar = 0; private float ratio = 4 / 3;

int x_lebar_layar_temp;

private float sudut_pointer = 0; private float sudut_pointer = 0;

private String arah_joystick = "";

boolean get_size_screen = true;

private float x_graf = 0; private float y_graf = 0;

int[] textures_indek = new int[1];

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

float cyan[] = new float[] { 0.0f, 1.0f, 1.0f, 1.0f }; float white[] = new float[] { 1.0f, 1.0f, 1.0f, 1.0f };

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

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

// cahaya

// warna

// ungu float lightAmbient[] = new float[] { 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.bg = new PrimitivesObject();

this.groud = new PrimitivesObject(); this.primob1 = new PrimitivesObject(); this.groud = new PrimitivesObject(); this.primob1 = new PrimitivesObject();

this.primob = new PrimitivesObject(); // this.primob2 = new PrimitivesObject();

this.siput = new PrimitivesObject(); this.npc = new PrimitivesObject();

this.getready = new PrimitivesObject();

this.batu = new PrimitivesObject(); this.timebar = new PrimitivesObject(); this.finish = new PrimitivesObject(); this.quiz = new PrimitivesObject();

this.gameTime = SystemClock.uptimeMillis() / 1000; this.beginningTime = (SystemClock.uptimeMillis() / 1000) + 3; this.startRace = false; //

@Override public void onDrawFrame(GL10 gl) {

// menangkap ukuran layar if (get_size_screen) {

this.x_lebar_layar = mywidth; this.y_tinggi_layar = myheight; this.ratio = (this.x_lebar_layar /

this.y_tinggi_layar); get_size_screen = false; }

// 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);

// ////////////real SIPUT RACE

BEGIN\\\\\\\\\ // running //

(update)\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\

// moveWithCollisionDetection(this);

move(this);

// create //

(render)\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\

// move_left_right1 -= kecepatan_ground;

// if (-move_left_right1 ==

x_lebar_layar_temp) { // move_left_right1 = x_lebar_layar_temp; // }

// // membuat background gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(move_left_right1, 0.f,

0.f);

gl.glTranslatef(0, -45.f, 0.f); gl.glScalef(x_lebar_layar,

y_tinggi_layar, 1.0f); bg.draw_background(gl); gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// move_left_right2 -= kecepatan_ground;

// if (-move_left_right2 == 2 *

x_lebar_layar_temp) { // move_left_right2 = 0; // }

// membuat background 2 gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(move_left_right2, 0.f,

0.f);

gl.glTranslatef(0, -45.f, 0.f); gl.glScalef(x_lebar_layar,

y_tinggi_layar, 1.0f); bg.draw_background(gl); gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// membuat ground 1 gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(move_left_right1, 0.f,

0.f);

gl.glTranslatef(0, -40.f, 0.f); gl.glScalef(x_lebar_layar_temp, 7 *

y_tinggi_layar / 10, 1.0f); groud.draw_background(gl); gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); y_tinggi_layar / 10, 1.0f); groud.draw_background(gl); gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING);

// membuat ground 2 gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(move_left_right2, 0.f,

0.f); gl.glTranslatef(x_lebar_layar_temp, 0.f, 0.f);

gl.glTranslatef(0, -40.f, 0.f); gl.glScalef(x_lebar_layar_temp, 7 *

y_tinggi_layar / 10, 1.0f); groud.draw_background(gl); gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// ////////////////\\\\\\\\\ // ////ini BATU this.batu_pos_x = (13 * x_lebar_layar /

13) + move_left_rightobj + this.getRandom(); this.batu_pos_y = (y_tinggi_layar / 25); this.batu_size_x = 1.5f * (x_lebar_layar

/ 16); this.batu_size_y = 1.5f * (y_tinggi_layar / 9);

// setBatu_size_y(batu_size_y);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); // keluar di pojok kanan gl.glTranslatef(batu_pos_x, batu_pos_y,

0.0f); gl.glScalef(batu_size_x, batu_size_y, 1.0f); batu.loadRandTexture(gl, context, randTexture); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); batu.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

numFrames2++;

numIDFrame++;

if (numIDFrame >= 1) {

numIDFrame = 0;

// ini NPC // ////NPC this.npc_pos_x = (x_lebar_layar / 10) +

npc_next; this.npc_pos_y = (y_tinggi_layar / 4) + npc_up; this.npc_size_x = 2 * (x_lebar_layar / 16); this.npc_size_y = 2 * (y_tinggi_layar / 9);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);

// mengatur naik turun gl.glTranslatef(faktor_naik_turun, 0,

0.0f);

gl.glTranslatef(npc_pos_x, npc_pos_y, 0.0f); gl.glScalef(npc_size_x, npc_size_y, 1.0f); npc.loadNPCTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);

// mengatur naik turun gl.glTranslatef(faktor_naik_turun, 0,

0.0f);

gl.glTranslatef(npc_pos_x, npc_pos_y, 0.0f); gl.glScalef(npc_size_x, npc_size_y, 1.0f); npc.loadNPCTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// ini siput

// create siput with no 'if' bullshit this.siput_pos_x = (x_lebar_layar / 10) +

siput_next; this.siput_pos_y = (y_tinggi_layar / 10) + siput_up; this.siput_size_x = 2 * (x_lebar_layar / 16); this.siput_size_y = 2 * (y_tinggi_layar / 9);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);

// mengatur naik turun gl.glTranslatef(faktor_naik_turun, 0,

0.0f);

gl.glTranslatef(siput_pos_x, siput_pos_y, 0.0f); gl.glScalef(siput_size_x, siput_size_y, 1.0f); siput.loadPlayerTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); siput.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);

// mengatur naik turun gl.glTranslatef(faktor_naik_turun, 0,

0.0f);

gl.glTranslatef(siput_pos_x, siput_pos_y, 0.0f); gl.glScalef(siput_size_x, siput_size_y, 1.0f); siput.loadPlayerTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); siput.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// ini time bar this.timebar_pos_x = (x_lebar_layar /

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(timebar_pos_x,

timebar_pos_y, 0.0f);

gl.glScalef(timebar_size_x,

timebar_size_y, 1.0f);

timebar.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// calc time bar

// time bar long currentTime =

SystemClock.uptimeMillis() / 1000; this.timeElapsed = currentTime - beginningTime; Log.v("timeElapsed", Long.toString(timeElapsed));

// if (timeElapsed < endTime) { // barLength = timeElapsed * ((14 *

x_lebar_layar / 16) / endTime); // // ga perfect // } else { // barLength = endTime * ((14 *

x_lebar_layar / 16) / endTime);

// float finRL = -20; // if (finRL >= x_lebar_layar/2){ // finRL -= 10; // }

// ini siput_icon float sS_pos_x = (x_lebar_layar / 16) +

siput_next + siput_time; float sS_pos_y = (7.5f * y_tinggi_layar / 9); float sS_size_x = 0.5f * (x_lebar_layar / 16); float sS_size_y = 0.5f * (y_tinggi_layar / 9);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(sS_pos_x, sS_pos_y,

0.0f); gl.glScalef(sS_size_x, sS_size_y, 1.0f); siput.loadPlayerTexture(gl, context, 0); siput.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// ini npc_icon float sN_pos_x = (x_lebar_layar / 16) +

npc_next + npc_time; float sN_pos_y = (8.5f * y_tinggi_layar / 9);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA);

gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(sN_pos_x, sN_pos_y,

0.0f); gl.glScalef(sS_size_y, sS_size_y, 1.0f); npc.loadNPCTexture(gl, context, 0); npc.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

// ini garis finish

if (timeElapsed >= this.endTime) { // Log.v("state","end game");

this.finish_pos_x = x_lebar_layar + this.finish_move; this.finish_pos_y = (y_tinggi_layar / 9); this.finish_size_x = 4 * x_lebar_layar / 16; this.finish_size_y = 4 * y_tinggi_layar / 9;

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(finish_pos_x, finish_pos_y, 0.0f); gl.glScalef(finish_size_x, finish_size_y, 1.0f);

// finish.loadPlayerTexture(gl, context, numIDFrame); // gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); finish.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

if (currentTime - gameTime <= 3) { float start_pos_x = (x_lebar_layar / 3); float start_pos_y = (y_tinggi_layar / 3); float start_size_x = 5f * (x_lebar_layar / 16); float start_size_y = 5f * (y_tinggi_layar / 9);

gl.glPushMatrix(); gl.glDisable(GL10.GL_LIGHTING); gl.glBlendFunc(GL10.GL_SRC_ALPHA,

GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(start_pos_x,

start_pos_y, 0.0f); gl.glScalef(start_size_x, start_size_y, 1.0f); getready.loadBallTexture(gl, context, 0); getready.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

this.startRace = false; } else { this.startRace = true; }

if (this.startQuiz) { Log.v("QUIZ", "Started");

// int rand_jawab = randomGenerator.nextInt(2);

float quiz_pos_x = (x_lebar_layar / 3); float quiz_pos_y = (2 * y_tinggi_layar / 3); float quiz_size_x = 1.5f * 4 * (x_lebar_layar / 16); float quiz_size_y = 1.5f * 1 * (y_tinggi_layar / 9); float quiz_pos_x = (x_lebar_layar / 3); float quiz_pos_y = (2 * y_tinggi_layar / 3); float quiz_size_x = 1.5f * 4 * (x_lebar_layar / 16); float quiz_size_y = 1.5f * 1 * (y_tinggi_layar / 9);

GL10.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL10.GL_BLEND); gl.glTranslatef(quiz_pos_x,

quiz_pos_y, 0.0f); gl.glScalef(quiz_size_x, quiz_size_y, 1.0f); quiz.loadSoalTexture(gl, context, this.soal, difficulty); quiz.draw_background(gl);

gl.glDisable(GL10.GL_BLEND); gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix();

float ans_pos_x[] = { quiz_pos_x, quiz_pos_x + ans_size_x, quiz_pos_x + 2 * ans_size_x }; this.setAns_pos_x(ans_pos_x); // manual this.ans_pos_x0 = ans_pos_x[0]; this.ans_pos_x1 = ans_pos_x[1]; this.ans_pos_x2 = ans_pos_x[2];

// Log.v("blabla", Float.toString(this.getAns_pos_x(0))); shuffleArray(rand_jawab); int ans[] = { this.soal,

this.jwb2, this.jwb3 };

// float[] ans_pos_y = { quiz_size_y, quiz_size_y, quiz_size_y }; this.ans_pos_y = (1 * y_tinggi_layar / 3);

this.ans_size_x = quiz_size_x / 3; this.ans_size_y = 1f *

(y_tinggi_layar / 9);

for (int i = 0; i <= 2; i++) { gl.glPushMatrix();

gl.glDisable(GL10.GL_LIGHTING);

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

gl.glEnable(GL10.GL_BLEND);

gl.glTranslatef(ans_pos_x[rand_jawab[i]], ans_pos_y, 0.0f); gl.glScalef(ans_size_x, ans_size_y, 1.0f); quiz.loadJwbTexture(gl, context, ans[rand_jawab[i]], difficulty); quiz.draw_background(gl); gl.glTranslatef(ans_pos_x[rand_jawab[i]], ans_pos_y, 0.0f); gl.glScalef(ans_size_x, ans_size_y, 1.0f); quiz.loadJwbTexture(gl, context, ans[rand_jawab[i]], difficulty); quiz.draw_background(gl);

gl.glEnable(GL10.GL_LIGHTING); gl.glPopMatrix(); } } }

public float getX_graf() { return x_graf; }

public void setX_graf(float x_graf) { this.x_graf = x_graf; }

public float getY_graf() { return y_graf; }

public void setY_graf(float y_graf) { this.y_graf = y_graf; }

public float getX_touch() { return x_touch; }

public void setX_touch(float x_touch) { this.x_touch = x_touch; }

public float getY_touch() { return y_touch; }

public void setY_touch(float y_touch) { this.y_touch = y_touch; }

public String getArah_joystick() { return arah_joystick; }

public void setArah_joystick(String arah_joystick) { this.arah_joystick = arah_joystick; }

public float getJarak_center() { return jarak_center; }

public void setJarak_center(float jarak_center) { this.jarak_center = jarak_center; }

public float getSudut_pointer() { public float getSudut_pointer() {

public void setSudut_pointer(float sudut_pointer) { this.sudut_pointer = sudut_pointer; }

public float getX_lebar_layar() { return x_lebar_layar; }

public void setX_lebar_layar(float x_lebar_layar) { this.x_lebar_layar = x_lebar_layar; }

public float getY_tinggi_layar() { return y_tinggi_layar; }

public void setY_tinggi_layar(float y_tinggi_layar) { this.y_tinggi_layar = y_tinggi_layar; }

public float getX_pointer_awal() { return x_pointer_awal; }

public void setX_pointer_awal(float x_pointer_awal) { this.x_pointer_awal = x_pointer_awal; }

public float getY_pointer_awal() { return y_pointer_awal; }

public void setY_pointer_awal(float y_pointer_awal) { this.y_pointer_awal = y_pointer_awal; }

public float getX_pointer() { return x_pointer; }

public void setX_pointer(float x_pointer) {

this.x_pointer = x_pointer; }

public float getY_pointer() { return y_pointer; }

public void setY_pointer(float y_pointer) {

this.y_pointer = y_pointer; } this.y_pointer = y_pointer; }

public void setX_anim_stick(float x_anim_stick) { this.x_anim_stick = x_anim_stick; }

public float getY_anim_stick() { return y_anim_stick; }

public void setY_anim_stick(float y_anim_stick) { this.y_anim_stick = y_anim_stick; }

public float getRadius() { return radius; }

public void setRadius(float radius) { this.radius = radius; }

public int getMywidth() { return mywidth; }

public void setMywidth(int mywidth) { this.mywidth = mywidth; }

public int getMyheight() { return myheight; }

public void setMyheight(int myheight) { this.myheight = myheight; }

public int getNumberRow() { return numberRow; }

public void setNumberRow(int numberRow) { this.numberRow = numberRow; }

public float getWidthObject() { return WidthObject; }

public void setWidthObject(float widthObject) {

WidthObject = widthObject; }

public float getX_player() { return x_player; public float getX_player() { return x_player;

public float getY_player() { return y_player; }

public void setY_player(float y_player) { this.y_player = y_player;

public int getNavigate() { return Navigate; }

public void setNavigate(int navigate) {

Navigate = navigate; }

public boolean goForward() { if (Navigate == 0 && positionRow > 0 && hori[positionRow][positionCol] == 0)

return true; if (Navigate == 1 && positionCol < (numberCol - 1) && verti[positionRow][positionCol + 1] == 0)

return true; if (Navigate == 2 && positionRow < (numberRow - 1) && hori[positionRow + 1][positionCol] == 0)

return true; if (Navigate == 3 && positionCol > 0 && verti[positionRow][positionCol] == 0)

return true; return false; }

public int getPositionRow() { return positionRow; }

public void setPositionRow(int positionRow) { this.positionRow = positionRow; }

public int getPositionCol() { return positionCol; }

public void setPositionCol(int positionCol) { this.positionCol = positionCol; }

@Override public void onSurfaceCreated(GL10 gl, EGLConfig

config) { gl.glClearColor(0.93f, 0.99f, 0.99f, 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); // Enables 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); //

Enable smooth shading of color gl.glDisable(GL10.GL_DITHER); // Disable dithering for better // performance gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0); // gl.glEnable(GL10.GL_LIGHT1);

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

context.getAssets());

glText.load("Roboto-Regular.ttf", 24, 5, 5); // gl.glDisable(GL10.GL_DITHER); // Disable dithering for better // performance

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

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); bg.loadBallTexture(gl, context, 5); groud.loadBallTexture(gl, context, 6);

siput.loadPlayerTexture(gl, context, 0); siput.loadPlayerTexture(gl, context, 0);

// batu.loadRandTexture(gl, context, 0); timebar.loadBallTexture(gl, context, 4); finish.loadBallTexture(gl, context, 0);

gl.glEnable(GL10.GL_TEXTURE_2D); // Enable texture (NEW)

@Override public void 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 Matrix 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

public float getxMax() { return xMax; }

public void setxMax(int xmax) { xMax = xmax; }

public float getxMin() { return xMin; }

public void setxMin(int xmin) { xMin = xmin; }

public float getyMax() { return yMax; public float getyMax() { return yMax;

public float getyMin() { return yMin; }

public void setyMin(int ymin) { yMin = ymin; }

public float getspeedX() { return speedX; }

public void setspeedX(float speedX_) { speedX = speedX_; }

public float getspeedY() { return speedY; }

public void setspeedY(float speedY_) { speedY = speedY_; }

public void 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;

public float getsiput_pos_x() { return siput_pos_x; }

public void setsiput_pos_x(float siput_pos_x) { this.siput_pos_x = siput_pos_x; }

public float getsiput_pos_y() { return siput_pos_y; }

public void setsiput_pos_y(float siput_pos_y) { this.siput_pos_y = siput_pos_y; }

public float getbatu_pos_x() { return batu_pos_x; } public float getbatu_pos_x() { return batu_pos_x; }

public float getSiput_up() { return siput_up; }

public void setSiput_up(float siput_up) { this.siput_up = siput_up; }

// collision detector public void moveWithCollisionDetection(ESRender

esRender) { boolean collision = false; boolean result = false; // running float batu_left_bound =

(this.batu_pos_x); float siput_right_bound = getsiput_pos_x()

(esRender.getSiput_size_x());

float batu_right_bound = (this.batu_pos_x + (esRender.getBatu_size_x())); float siput_left_bound = getsiput_pos_x();

float batu_top_bound = (this.batu_pos_y + (esRender.getBatu_size_y())); float siput_bot_bound = getsiput_pos_y();

// Detect collision and react // getbatusize if ((siput_right_bound > batu_left_bound

&& siput_bot_bound < batu_top_bound) && (siput_left_bound < batu_left_bound)) { collision = true; this.kecepatan_ground = 2.0f;

//shuffleArray(index); esRender.soal = index[0]; esRender.jwb2 = index[1]; esRender.jwb3 = index[2];

//shuffleArray(rand_jawab);

result = startQuiz(soal, jwb2, jwb3);

// NPC get next this.npc_next += 5.0f; Log.v("COLLISION", "DETECTED"); Log.v("Ybound",

Float.toString(siput_bot_bound) + "__" + Float.toString(batu_top_bound));

Log.v("Xbound",

Float.toString(siput_right_bound) + "__" + Float.toString(batu_left_bound));

} else { // normal // this.kecepatan_ground = 12.0f; // Log.v("COLLISION", "not

detected"); // Log.v("Ybound", // Float.toString(siput_bot_bound)

+ "__" // + Float.toString(batu_top_bound)); // Log.v("Xbound", //

Float.toString(siput_right_bound) + "__" // + Float.toString(batu_left_bound)); collision = false;

esRender.startQuiz = false; }

if (result == true) { collision = false; esRender.startQuiz = false; esRender.startRace = true; this.siput_next += 100.0f;

} // pengkondisian penghitungan pantulan

mulai dari nol << }

public boolean collDetector(ESRender esRender) { boolean collision; // running float batu_left_bound =

(esRender.batu_pos_x); float siput_right_bound = esRender.getsiput_pos_x()

(esRender.getSiput_size_x());

float batu_right_bound = (esRender.batu_pos_x + (esRender .getBatu_size_x())); float siput_left_bound = esRender.getsiput_pos_x();

float batu_top_bound = (esRender.batu_pos_y + (esRender .getBatu_size_y())); float siput_bot_bound = float batu_top_bound = (esRender.batu_pos_y + (esRender .getBatu_size_y())); float siput_bot_bound =

// Detect collision and react // getbatusize if ((siput_right_bound > batu_left_bound

&& siput_bot_bound < batu_top_bound) && (siput_left_bound < batu_left_bound)) { collision = true; Log.v("COLLISION", "DETECTED");

} else { collision = false; } return collision; // pengkondisian penghitungan pantulan

mulai dari nol << }

// jump public void startJump() {

kecepatan_lompat = 20.0f;

public void endJump() { kecepatan_lompat = -20.0f; }

public void move(ESRender esRender) {

float kecepatan_ground_tmp;

if (esRender.kecepatan_ground == 0) { kecepatan_ground_tmp = 1; } else { kecepatan_ground_tmp = esRender.kecepatan_ground; }

int a = (int) (Math.ceil(esRender.x_lebar_layar / kecepatan_ground_tmp) * kecepatan_ground_tmp);

esRender.setX_lebar_layar_temp(a);

// ground velocity esRender.move_left_right1 -=

kecepatan_ground;

esRender.move_left_right2 -=

kecepatan_ground;

esRender.move_left_rightobj -=

kecepatan_ground; if (-esRender.move_left_right1 == esRender.x_lebar_layar_temp) { esRender.move_left_right1 = esRender.x_lebar_layar_temp; }

if (-esRender.move_left_right2 == 2 * esRender.x_lebar_layar_temp) { if (-esRender.move_left_right2 == 2 * esRender.x_lebar_layar_temp) {

if (-esRender.move_left_rightobj == 2 * esRender.x_lebar_layar_temp) { esRender.move_left_rightobj = 0;

int random = randomGenerator.nextInt(900); esRender.setRandom(random); // 1 esRender.randTexture =

randomGenerator.nextInt(2); // esRender.startQuiz = false; // esRender.resetInput(); // 2

shuffleArray(esRender.index); esRender.soal = esRender.index[0]; esRender.jwb2 = esRender.index[1]; esRender.jwb3 = esRender.index[2];

// if (esRender.collDetector(esRender)) { //

boolean result = startQuiz(soal, jwb2, jwb3); // //

if (result == true) { // //

esRender.startQuiz = false; //

esRender.startRace = true; //

esRender.siput_next += 5.0f; //

if (esRender.siput_next ==

esRender.siput_next += 0.0f; //

// // Log.v("COLLISIONEV", "DETECTED"); //

} else { //

esRender.npc_next += 5.0f; //

esRender.moveWithCollisionDetection(esRender);

// move if (esRender.startRace) {

esRender.difficulty = false;

this.kecepatan_ground = 50.0f;

// jump siput_up += kecepatan_lompat; // jump siput_up += kecepatan_lompat;

onGround = true; }

if (siput_pos_y >= 7 * this.y_tinggi_layar / 9) { siput_pos_y = (7 * this.y_tinggi_layar / 9) - 20; kecepatan_lompat = -20.0f; onGround = false;

// jump esRender.endTime = 5; // game

selesai = 20 detik float timefrag = (15 * esRender.timebar_size_x / 16) / esRender.endTime; float currtimefrag = timefrag * esRender.timeElapsed; if (esRender.timeElapsed <= esRender.endTime) { esRender.npc_time = currtimefrag; esRender.siput_time = currtimefrag; }

esRender.finish_move -= 50; if (finish_pos_x >= 3 *

x_lebar_layar / 4) { finish_pos_x = 3 * x_lebar_layar / 4; } // if (-esRender.finish_move >= 4*

esRender.x_lebar_layar_temp/4) { // //esRender.finish_move = 4* esRender.x_lebar_layar_temp/4; // esRender.finish_move = 0; // }

} else if (!esRender.startRace) { esRender.kecepatan_ground = 0.0f; Log.v("stop", "stop");

// y move jump public void move_y(float y) {

kecepatan_lompat = 25.0f;

if (y > 0) { this.siput_up += kecepatan_lompat; if (this.siput_pos_y > 8 *

this.y_tinggi_layar / 9) { this.siput_pos_y = 8 * this.y_tinggi_layar / 9) { this.siput_pos_y = 8 *

} if (y < 0) {

this.siput_up -= kecepatan_lompat; if (this.siput_pos_y < 0) {

this.siput_pos_y = (this.y_tinggi_layar / 10); kecepatan_lompat = 0; } } // // if (siput_up >= y) { // siput_up = y; // kecepatan_lompat = 0.0f; // }

// this.siput_up += y/80;

public void stop_move_y() { kecepatan_lompat = 0.0f; }

// public int getX_lebar_layar_temp() {

return x_lebar_layar_temp; }

public void setX_lebar_layar_temp(int x_lebar_layar_temp) { this.x_lebar_layar_temp = x_lebar_layar_temp; }

public float getRandom() { return random; }

public void setRandom(float random) { this.random = random; }

public float getBatu_size_x() { return batu_size_x; }

public void setBatu_size_x(float batu_size_x) {

this.batu_size_x = batu_size_x;

public float getBatu_size_y() { return batu_size_y; }

public void setBatu_size_y(float batu_size_y) { public void setBatu_size_y(float batu_size_y) {

public float getSiput_size_x() { return siput_size_x; }

public void setSiput_size_x(float siput_size_x) { this.siput_size_x = siput_size_x; }

public float getSiput_size_y() { return siput_size_y; }

public void setSiput_size_y(float siput_size_y) { this.siput_size_y = siput_size_y; }

public boolean startQuiz(int soal, int jwb2, int jwb3) { this.startQuiz = true; this.startRace = false;

this.soal = soal; this.jwb2 = jwb2; this.jwb3 = jwb3;

// int soal = randomGenerator.nextInt(8); // int jwb2 = randomGenerator.nextInt(8); // int jwb3 = randomGenerator.nextInt(8);

// startQuiz(soal, jwb2, jwb3);

float inY = this.getInputY(); float inX = this.getInputX();

Log.v("touch_position", Float.toString(inX) + "_,_" + Float.toString(inY));

// Log.v("check", Float.toString(esRender.ans_pos_x0));

if (inY != 0 && inX != 0) { if (checkQuiz(inAns(inX, inY))) { Log.v("answer", "TRUE"); // this.siput_next += 100; // // esRender.batu_pos_x

= 0; // // collision = false; // this.startQuiz = false; //this.startRace = true; this.resetInput(); return true;

} else { Log.v("answer", "WRONG"); return false;

// Log.v("index", Integer.toString(inAns(inX, inY))); // Log.v("my_ans",Float.toString(inX)+","+Float.toString (inY));

// Log.v("box

position",Float.toString(this.ans_pos_x0)+","+Float.t oString(this.ans_pos_x1)+","+Float.toString(this.ans_ pos_x2));

} // Log.v("my_touch", Float.toString(inX)

+ "," + Float.toString(inY));

return false; }

public int inAns(float x, float y) {

if (y == 0 & x == 0) { return 4; } else if ((this.ans_pos_x0 <= x && x <= this.ans_pos_x0 + this.ans_size_x)) { return this.rand_jawab[0]; } else if ((this.ans_pos_x1 <= x && x <= this.ans_pos_x1 + this.ans_size_x)) { return this.rand_jawab[1]; } else if ((this.ans_pos_x2 <= x && x <= this.ans_pos_x2 + this.ans_size_x)) { return this.rand_jawab[2]; } else { return 3; } // return (int)this.getAns_pos_x(0);

public boolean checkQuiz(int index) {

if (index == 3 || index == 4) { return false;

if (index == this.soal) {

return true;

} else if (index == this.jwb3 || index == this.jwb2) {

return false;

return false;

public float getInputY() { return inputY; } public float getInputY() { return inputY; }

public float getInputX() { return inputX; }

public void setInputX(float inputX) { this.inputX = inputX; }

public void resetInput() { this.inputX = 0; this.inputY = 0;

static void shuffleArray(int[] ar) {

Random rnd = new Random(); for (int i = ar.length - 1; i > 0; i--) {

int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a;

public float getAns_pos_x(int index) { return ans_pos_x[index];

public void setAns_pos_x(float[] ans_pos_x) { this.ans_pos_x = ans_pos_x; } }

ESSurfaceView.java

package com.modelloading;

import android.content.Context; import android.graphics.Point; import android.opengl.GLSurfaceView; import android.os.SystemClock; 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;

private float x_down = 0; private float y_down = 0; private float y_up = 0; private float y = 0;

/* * 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); // Set the Renderer for drawing on the GLSurfaceView esRender = new ESRender(context);

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

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

// Render the view only when there is a change in the drawing data // merender hanya ketika ada perubahan/ event // setRender- Mode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); }

@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()) {

// default :esRender.setSiput_up(0);break;

case MotionEvent.ACTION_DOWN: // clicked Log.v("Test Action Down", "action down working"); this.y_down = v.getY(); this.x_down = v.getX();

// if (esRender.startRace) {

esRender.startJump(); } if (esRender.startQuiz) {

esRen- der.setInputY(y_down); esRen- der.setInputX(x_down); } // esRender.setX_anim_stick(-

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

// 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 perge- rakan pada stick esRen- der.setX_anim_stick(esRender.getRadius()); esRen- der.setY_anim_stick(esRender.getRadius());

break; case MotionEvent.ACTION_UP: // lepas touch Log.v("Test Action ACTION_UP", "action working"); this.y_up = v.getY();

// esRender.stop_move_y(); if (esRender.startRace) {

esRender.endJump(); }

//esRender.resetInput(); // 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(); break;

case MotionEvent.ACTION_MOVE:

float x = v.getX(); this.y = v.getY();

float kacek = y - y_down; // esRender.move_y(-kacek);

Log.v("touch position", Float.toString(x) + "_,_" + Float.toString(y));

// 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

if (_dragging) {

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

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

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

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

.pow(esRender.getMyheight() - _touchingPoint.y -

2 * esRender.getRadius(), 2))));

// membuat radius touch screen if (_touchingPoint.x >= (esRen-

der.getMywidth() - 200) && _touchingPoint.y >= (esRender.getMyheight() - 200) && (((Math.pow(

_touchingPoint.x

- (esRender.getMywidth() - 2 * esRender

.getRadius()), 2)) + (Math.pow(

esRender.getMyheight() - _touchingPoint.y - 2

* esRender.getRadius(), 2))) > Math.pow(

* esRender.getRadius(), 2))) {

Mu-

sic.playOnce(esRender.context, R.raw.fb); System.out.print("touch detected"); // 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)) { mypointer_awal_x = esRender.getMywidth() - 100; mypointer_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.setX_anim_stick((float) (26.0f * Math.cos(myangle * (Math.PI / 180))));

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

&& (float) myangle <= 135) { esRen- der.setArah_joystick("Atas");

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");

esRen- esRen-

// 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_lebar_layar(esRender.getMywidth()); * esRen- der.setY_tinggi_layar(esRender.getMyheight()); * * 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 // get the 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);

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

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

_pointerPosition.x = 0; }

if (_pointerPosition.x < 0) { _pointerPosition.x = 480; }

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

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

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; .getWidthObject()) + (esRender.getWidthObject() / 2)); break;

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 }

ESText.java

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) float fontHeight; // Font Height (Actual; Pixels) float fontAscent; // Font Ascent (Above Baseline; Pixels) float fontDescent; // Font Descent (Below Baseline; Pixels)

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)

charWidths = new float[CHAR_CNT]; // Create the Array of Character Widths charRgn = new TextureRegion[CHAR_CNT]; // Create the Array of Character Regions

// initialize remaining members fontPadX = 0; fontPadY = 0;

fontHeight = 0.0f; fontAscent = 0.0f; fontDescent = 0.0f;

textureId = -1; textureSize = 0;

charWidthMax = 0; charHeight = 0; charWidthMax = 0; charHeight = 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 charHeight = fontHeight;

// Set Character 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() {

batch.endBatch(); // End Batch

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 draw( text, x - ( len / 2.0f ), y ); // Draw Text Centered (X-Axis Only) return len; // Return Length } public void drawCY(String text, float x, float y)

{ 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] // sx, sy - separate x and y axis scaling fac- tors // R: [none]

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 ( fontDescent * scaleY ); // Return Font Descent } public float getHeight() {

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 - ( batch.beginBatch( textureId ); // Begin Batch (Bind Texture) batch.drawSprite( textureSize / 2, height - (

batch.endBatch(); // End Batch }

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); return fb;

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) {

int n = 0;

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); 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);

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); }

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;

public class MainActivity extends Activity {

/** 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.song); 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 the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }

MathHelper.java

package com.modelloading; public class MathHelper { public static float 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; }

Maths.java

package com.modelloading;

/** * @author Jim Cornmell re-edit by XTech

public final class Maths {

/** 180 in radians. */ public static final double ONE_EIGHTY_DEGREES =

Math.PI;

/** 360 in radians. */ public static final double THREE_SIXTY_DEGREES =

ONE_EIGHTY_DEGREES * 2;

/** 120 in radians. */ public static final double ONE_TWENTY_DEGREES =

THREE_SIXTY_DEGREES / 3;

/** 90 degrees, North pole. */ public static final double NINETY_DEGREES = Math.PI

/** Used by power. */ private static final long 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. */

public static int power(final int base, final int 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;

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 */ public static void playOnce(Context context, int

resource) { //stop(context); mpOnce = MediaPlayer.create(context, re-

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) { public static void stopOnce(Context context) {

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- // Point to our vertex buffer, return buffer holding the vertices public static FloatBuffer makeFloatBuffer(float[] arr){ ByteBuffer bb = ByteBuff-

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);

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 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;

public class ObjModel { public void bindTextures(Context context, GL10 gl)

{ Bitmap bitmap; try { InputStream is = con- text.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, bitmap, 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

{ public static ObjModel loadFromStream(InputStream is) throws IOException

BufferedReader reader = new BufferedReader(new In- putStreamReader(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 else

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 trian- gles supported");

Face face = new Face(3);

while (tok.hasMoreTokens()) {

StringTokenizer face_tok = new StringTokeniz- er(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 = Inte- ger.parseInt(face_tok.nextToken());

if (face_tok.hasMoreTokens()) vn_idx = Inte- ger.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)

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 read_point(StringTokenizer tok) {

Point3 ret = new Point3();

if (tok.hasMoreTokens()) {

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; int count;

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, FloatBuff- er 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); vt_buffer.put(vt[i].y);

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 = FloatBuff- er.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();

Point3.java

package com.modelloading;

public class Point3 extends Object {

public float x; public float y; public float 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); }

public final boolean equals(float x, float y, float z) { return ((this.x == x) && (this.y == y) && (this.z == z)); }

public void set(float x, float y, float z) {

this.x = x; this.y = y; this.z = z;

public void 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 public boolean equals(Object o) {

if (this == o) return true; if (this == o) return true;

Point3 obj = (Point3)o; return this.equals(obj.x, obj.y, obj.z);

} @Override public String toString() {

return "("+x+","+y+","+z+")"; } @Override public int hashCode() { throw new UnsupportedOp-

erationException(); } }

PrimitivesObject.java

package com.modelloading;

import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; //import java.util.Random;

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 {

// MyComplex mycomplex_k;

// MyComplex c = new MyComplex(0.109, 0.603); int width = 100, height = 100; // private int its_loop =0; // private float r_julia_m =0.f; boolean doJuliaSet = true; int idx_vertex = 0; int idx_vertex_color = 0;

private float verticesbackground[] = { 0.0f, 0.0f, 0.0f, // V1 - bottom left 0.0f, 1.0f, 0.0f, // V2 - top left 1.0f, 0.0f, 0.0f, // V3 - bottom

right 1.0f, 1.0f, 0.0f // V4 - top right };

// private FloatBuffer textureBuffer; // buffer holding the texture // coordinates private float texturebackground[] = {

// Mapping coordinates for the vertices 0.0f, 1.0f, 0.0f, // top left (V2) 0.0f, 0.0f, 0.0f, // bottom left

(V1) 1.0f, 1.0f, 0.0f, // top right (V4) 1.0f, 0.0f, 0.0f // bottom right (V3) };

// private int[] imageFileIDs = { // Image file IDs // R.drawable.nature, R.drawable.mule, R.drawable.joystick, // R.drawable.joystick_bg, //

R.drawable.daun,R.drawable.bg,R.drawable.ground,R.dra wable.logo};

private int[] imageFileIDrand = { // Image file IDs

R.drawable.rintangan1, R.drawable.rintangan2, R.drawable.rintangan3 };

private int[] imageFileIDs = { // Image file IDs R.drawable.getready, R.drawable.bg,

R.drawable.joystick, R.drawable.joystick_bg, R.drawable.timebar, R.drawable.bg4, R.drawable.bg2 };

// private int[] imageFileIDs2 = { // Image file IDs // R.drawable.k1, R.drawable.k2, R.drawable.k3, R.drawable.k4, // R.drawable.k5, // R.drawable.k6, R.drawable.k7, R.drawable.k8,

R.drawable.k9, // R.drawable.k10, R.drawable.k11 };

private int[] imageFileIDs2 = { // Image file IDs R.drawable.player, R.drawable.player2 };

private int[] imageFileIDs3 = { // Image file IDs R.drawable.npc, R.drawable.npc2 };

private int[] soaleasy = { // Image file IDs R.drawable.soal1, R.drawable.soal2,

R.drawable.soal3, R.drawable.soal4, R.drawable.soal5, R.drawable.soal6, R.drawable.soal7, R.drawable.soal8, R.drawable.soal9, R.drawable.soal10 };

private int[] soalmed = { R.drawable.med1,

R.drawable.med2, R.drawable.med3, R.drawable.med4, R.drawable.med5, R.drawable.med6, R.drawable.med7, R.drawable.med8, R.drawable.med9, R.drawable.med10 };

private int[] jwbeasy = { // Image file IDs R.drawable.js1, R.drawable.js2, R.drawable.js3,

R.drawable.js4, R.drawable.js5, R.drawable.js6, R.drawable.js7, R.drawable.js8, R.drawable.js9, R.drawable.js10 };

private int[] jwbmed = { // Image file IDs R.drawable.med1, R.drawable.med2,

R.drawable.med3, R.drawable.med4, R.drawable.med5, R.drawable.med6, R.drawable.med7, R.drawable.med8, R.drawable.med9, R.drawable.med10 };

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 vertices_fractal_mandelbrot[] = { 0.0f, 0.0f, 0.0f }; private float vertices_color_fractal_mandelbrot[] = { 0.0f, 0.0f, 0.0f, 0.0f };

private float vertices_fractal_julia[] = { 0.0f, 0.0f, 0.0f }; private float vertices_color_fractal_julia[] = { 0.0f, 0.0f, 0.0f, 0.0f };

private float vertices_fractal_julia_m[] = { 0.0f, 0.0f, 0.0f }; private float vertices_color_fractal_julia_m[] = { 0.0f, 0.0f, 0.0f, 0.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;

float WidthObject = 0.08f; int numberRow = 10, numberCol = 10; 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 // menyimpan inisialisasi array untuk labirin

int verti[][] = new int[2 * numberRow * num- berCol][2 * numberRow

* numberCol]; private int maze[][] = new int[2 * numberRow * numberCol][2 * numberRow

* numberCol];

public PrimitivesObject() {

// this.mycomplex = new My- Complex(WidthObject, WidthObject);

// ============ 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); verti- ces_line_color[loop_line_color + 1] = (float) (0.5 * m

* (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 * num-

berRow * 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 : ", "" + numberCol);

// 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 * WidthObject + 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] = (number- Row - i)

* WidthObject; verti- ces_horiverti[loop_vertices_horiverti + 2] = 0; * WidthObject; verti- ces_horiverti[loop_vertices_horiverti + 2] = 0;

* 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 - positionRow - 1) * WidthObject + (WidthOb- ject * 3 / 4);

vertices_labirin_player[2] = 0;

vertices_labirin_player[3] = (positionCol * WidthObject) + (WidthObject / 4); vertices_labirin_player[4] = (numberRow - positionRow - 1) * WidthObject + (WidthOb- ject / 4);

vertices_labirin_player[5] = 0;

vertices_labirin_player[6] = (positionCol * WidthObject) + (WidthObject * 3 / 4); vertices_labirin_player[7] = (numberRow - positionRow - 1) * WidthObject + (WidthOb- ject / 4);

vertices_labirin_player[8] = 0;

x = (positionCol * WidthObject) + (WidthObject / 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-

tionRow_end - 1) * WidthObject + (WidthObject / 2); ;

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 horizontally.. * yn = y0 + ( i * 0.00833f ); // moving from pixel to pixel * vertically.. * * 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 absolute value of X+Y if( * thrd >= 64.0f ){ //if( thrd >= 32.0f && thrd <= 150.0f ){ * length_fractal_mandelbrot += 1; 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 length_fractal_mandelbrot*4 : ", "" + * length_fractal_mandelbrot*4); * * x0=-2f; y0=-2f; c1=-2f; c2=-2f; int

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 horizontally.. * yn = y0 + ( i * 0.00833f ); // moving from pixel to pixel * vertically.. * * 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 thrd=(xn1*xn1)+(yn1*yn1); // Check- ing the absolute value of X+Y if( * thrd >= 64.0f ){ //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 ver-

tex * 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- * = 0.5f; * verti-

* = 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 ver-

tex * 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

// start fractal set julia /*

* int length_fractal_julia=10000; verti- ces_fractal_julia=new * float[(int) (3*length_fractal_julia) * 3]; * vertices_color_fractal_julia=new float[(int) (3*length_fractal_julia) * * 4]; * * int min_rand = 0; int max_rand = 10;

float my_random;

* * * int idx_vertex = 0; int

idx_vertex_color = 0; float k_julia=0.01f; * * float z0=1; float z_next; z_next=z0; * * //Inisialisasi bilangan komplek untuk

k //mycomplex_k = new * MyComplex(0.3, 0.6); MyComplex k_complex = new MyComplex(0.3, 0.6); * //MyComplex k_complex = new My- Complex(0.01, 1.2); //MyComplex * k_complex = new MyComplex(0.109, 0.603); MyComplex z0_complex = new

* MyComplex(1, 0); MyComplex

znext_complex = new

* MyComplex(z0_complex.re(),

z0_complex.im()); float abs_znext_complex * ; float akar_abs_znext_complex; float teta; float delta=0.01f; //for * (int k=1;k<=length_fractal_julia;k++){ //k_complex = new * MyComplex(1/k, 2/k); for(i=0;i<length_fractal_julia;i++){ z0_complex * = znext_complex; //znext_complex = *

(z0_complex.times(z0_complex)).plus(k_complex); * * Random init_random = new Random();

my_random = * (float)(init_random.nextInt(max_rand - min_rand + 1) + * min_rand)/max_rand; * * if (my_random < 0.5f){

znext_complex=z0_complex.minus(k_complex); * znext_complex = new * My-

Complex(znext_complex.pow(0.5,2).re(),znext_complex

* .pow(0.5,2).im()); }else{

znext_complex=z0_complex.minus(k_complex); * znext_complex = new * MyComplex(-

znext_complex.pow(0.5,2).re(),-znext_complex * .pow(0.5,2).im()); } * * * //Log.v("float znext_complex.im() : ",

""+(float) * znext_complex.im()); //Log.v("float znext_complex.re() : ", * ""+(float) znext_complex.re()); //Log.v("atan yx : ", * ""+Math.atan(1/1)); //Log.v("atan2 yx : ", ""+Math.atan2(1,2)); * * *

//if(Math.pow(abs_znext_complex,2)<=4){ * * //delta=(float)

Math.abs(znext_complex.re()-znext_complex.im()); * * vertices_fractal_julia[idx_vertex++] =

(float) znext_complex.re(); * vertices_fractal_julia[idx_vertex++] = (float) znext_complex.im(); * vertices_fractal_julia[idx_vertex++] = 0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 0.5f; * * * vertices_fractal_julia[idx_vertex++] =

(float) znext_complex.re(); * vertices_fractal_julia[idx_vertex++] = (float) * znext_complex.im()+delta; verti- ces_fractal_julia[idx_vertex++] = 0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 0.5f; * * vertices_fractal_julia[idx_vertex++] =

(float) * znext_complex.re()+delta; verti- ces_fractal_julia[idx_vertex++] = * (float) znext_complex.im()+delta; * vertices_fractal_julia[idx_vertex++] =

0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti-

/*vertices_fractal_julia[idx_vertex++] = (float)

* znext_complex.re(); verti-

ces_fractal_julia[idx_vertex++] = (float)

* znext_complex.im(); verti-

ces_fractal_julia[idx_vertex++] = 0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 0.5f; * * * vertices_fractal_julia[idx_vertex++] =

(float) * znext_complex.re()+delta; verti- ces_fractal_julia[idx_vertex++] = * (float) znext_complex.im(); verti- ces_fractal_julia[idx_vertex++] = 0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 0.5f; * * vertices_fractal_julia[idx_vertex++] =

(float) * znext_complex.re()+delta; verti- ces_fractal_julia[idx_vertex++] = * (float) znext_complex.im()+delta; * vertices_fractal_julia[idx_vertex++] =

0; * * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.re()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = (float) * Math.abs(znext_complex.im()); * verti-

ces_color_fractal_julia[idx_vertex_color++] = 1.f; * verti- ces_color_fractal_julia[idx_vertex_color++] = 0.5f; */

// verti- ces_color_fractal_julia[idx_vertex_color++] = 1/z0; // verti- ces_color_fractal_julia[idx_vertex_color++] = 1/z_next;

// verti- ces_color_fractal_julia[idx_vertex_color++] = 1/(z0- z_next);

// verti- ces_color_fractal_julia[idx_vertex_color++] = 1.f;

// end fractal set julia

// start merget fractal julia & man- delbrot // int length_fractal_julia_m=width*height;

// vertices_fractal_julia_m=new

float[(int) (6*length_fractal_julia_m) * // 3]; // vertices_color_fractal_julia_m=new

float[(int) // (6*length_fractal_julia_m) * 4]; /*

* float left = -2.0f, right = 2.0f, bot- tom = -2.0f;//, top = 1.5f; // * loop over the pixels on the screen float delta = (right - * left)/width; for( float j_l=0; j_l < 100; j_l+=1f ) { for( float * i_l=0; i_l < 100; i_l+=1f ) { // con- vert pixel location to world * coordinates float xf = left + i_l*delta; float yf = bottom + * j_l*delta; * * //float xf = i; //float yf = j; * * // test for convergence //int its = 0;

//float R = 0; MyComplex b_ = * new MyComplex(xf,yf); MyComplex c = new MyComplex(0.109, 0.603); if( * !doJuliaSet ){ julia(b_, c);} else{ mandelbrot(b_);} * * // turn iterations and radius to color * * if( its_loop ==256 ){ * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0;

* verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=1; * * * }else { * * * float r = r_julia_m/(3.f); float g =

its_loop/(128.f); float b =

* r_julia_m/(its_loop+1.f);

//glColor3d(r,g,b); * verti- ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- //glColor3d(r,g,b); * verti- ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=g; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=b; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0.5f; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=g; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=b; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0.5f; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=g; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=b; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0.5f; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=g; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=b; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0.5f; * * verti-

ces_color_fractal_julia_m[idx_vertex_color++]=r; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=g; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=b; * verti- ces_color_fractal_julia_m[idx_vertex_color++]=0.5f; } //delta =

* 0.0001f; * * verti-

ces_fractal_julia_m[idx_vertex++]=xf; * verti- ces_fractal_julia_m[idx_vertex++]=yf; * verti- ces_fractal_julia_m[idx_vertex++]=0;

* * verti-

ces_fractal_julia_m[idx_vertex++]=xf; * verti- ces_fractal_julia_m[idx_vertex++]=yf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=0; * * verti-

ces_fractal_julia_m[idx_vertex++]=xf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=yf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=0; * * verti-

ces_fractal_julia_m[idx_vertex++]=xf; * verti- ces_fractal_julia_m[idx_vertex++]=yf; * verti- ces_fractal_julia_m[idx_vertex++]=0; * * verti-

ces_fractal_julia_m[idx_vertex++]=xf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=yf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=0; * * verti-

ces_fractal_julia_m[idx_vertex++]=xf+delta; * verti- ces_fractal_julia_m[idx_vertex++]=yf; * verti- ces_fractal_julia_m[idx_vertex++]=0; //} * * // draw polygon //glBegin(GL_POLYGON);

//glVertex2d(x, y);

* //glVertex2d(x, y+delta);

//glVertex2d(x+delta, y+delta); * //glVertex2d(x+delta, y); //glEnd(); * * * * } // glFlush(); } */

// end merger fractal julia & mandelbrot

// --- start merger julia & Mandelbrot fractal -- --------------- /* * public void julia( MyComplex p, MyComplex c) { float rSqr = 0; int * maxIterations = 256; for(its_loop=0; its_loop < maxIterations; its_loop++ * ) { //p = p.times(p).plus(c); //Log.v("its_loop julia : ", ""+its_loop);

* p = new My- Com- plex(p.times(p).plus(c).re(),p.times(p).plus(c).im()) ; rSqr

* = (float) (p.re()*p.re() + p.im()*p.im()); //Log.v("rSqr julia : ", * ""+rSqr); if( rSqr > 4 ){ break; } } r_julia_m = (float) Math.sqrt(rSqr); *} * * public void mandelbrot( MyComplex b_) { float

rSqr = 0; int maxIterations

* = 256; MyComplex p = new MyComplex(0,0); for(its_loop=0; its_loop < * maxIterations; its_loop++ ) { //p = p.times(p).plus(c); * //Log.v("its_loop mandelbrot : ", ""+its_loop); p = new * My- Com- plex(p.times(p).plus(b_).re(),p.times(p).plus(b_).im( )); rSqr =

* (float) (p.re()*p.re() + p.im()*p.im()); //Log.v("rSqr mandelbrot : ", * ""+rSqr); if( rSqr > 4 ){ break; } } r_julia_m = (float) Math.sqrt(rSqr); *} */

// ------------- end Julia & Mandelbrol Fractal - -------------------

// membuat inisialisasi jaring-jaring (generate Maze) public void generateMaze() { // inisialisasi maze int i, j; Log.v("Test get numberRow : ", "" + num-

berRow); 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++) {

verti[i][numberCol] = 1; } for (j = 0; j < numberCol; j++) {

hori[numberRow][j] = 1; }

// random cell

i = (int) (Math.random() * 10 % number- Row); j = (int) (Math.random() * 10 % num- i = (int) (Math.random() * 10 % number- Row); j = (int) (Math.random() * 10 % num-

// create in & out door

i = (int) (Math.random() * 10 % number- Row); j = (int) (Math.random() * 10 % number- Row);

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 ((i + 1 < numberRow) && (maze[i + 1][j] == 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_background(GL10 gl) {

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

// bind the previously generated texture gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

// Point to our buffers // Point to our buffers

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

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

// Point to our vertex buffer gl.glVertexPointer(3, GL10.GL_FLOAT, 0,

makeFloatBuff- er(verticesbackground)); gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, makeFloatBuff- er(texturebackground));

// Draw the vertices as triangle strip gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,

0, verticesbackground.length / 3); // Log.v("verticesbackground.length : ", ""+verticesbackground.length); // Log.v("verticesbackground.length / 3 : ", // ""+verticesbackground.length / 3); // gl.glDrawArrays(GL10.GL_TRIANGLE_FAN,

0, verticesbackground.length / // 3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARR AY); gl.glDisable(GL10.GL_TEXTURE_2D); // Dis- able Texture Mapping }

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_julia_m(GL10 gl) {

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

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, 0.5f);

// Point to our vertex buffer (mendata nilai lokasi/posisi titik) gl.glVertexPointer(3, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_fractal_julia_m));

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_color_fractal_julia_m));

// Draw the vertices as points (menggam- bar titik-titik) gl.glDrawArrays(GL10.GL_POINTS, 0, (int) ((idx_vertex - 1) / 3)); // gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (int) ((idx_vertex-1)/3));

// gl.glDrawArrays(GL10.GL_POINTS, 0, 3); //

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (int) // (vertices_fractal_julia_m.length)/3); //

gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 2,3); // gl.glDrawArrays(GL10.GL_LINES, 0, (int) // (vertices_fractal_julia.length)/3);

// gl.glDrawArrays(GLES20.GL_POLYGON_OFFSET_FILL, 0, (int)

// (vertices_fractal_julia.length)/3);

// Disable the client state before leav- ing

gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

public void draw_fractal_julia(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, makeFloatBuff- er(vertices_fractal_julia));

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_color_fractal_julia)); // Draw the vertices as points (menggam- bar titik-titik) gl.glDrawArrays(GL10.GL_POINTS, 0, (int) (verti- ces_fractal_julia.length) / 3); // gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (int) // (vertices_fractal_julia.length)/3);

// gl.glDrawArrays(GL10.GL_LINES, 0, (int) // (vertices_fractal_julia.length)/3);

// gl.glDrawArrays(GLES20.GL_POLYGON_OFFSET_FILL, 0, (int)

// (vertices_fractal_julia.length)/3);

// 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, makeFloatBuff- er(vertices_fractal_mandelbrot));

gl.glColorPointer(4, GL10.GL_FLOAT, 0, makeFloatBuff- er(vertices_color_fractal_mandelbrot)); // Draw the vertices as points (menggam- bar titik-titik) gl.glDrawArrays(GL10.GL_POINTS, 0, (int) (verti- ces_fractal_mandelbrot.length) / 3);

// 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,

makeFloatBuff- er(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) {

vertices_labirin_player[0] = (position- Col_in * WidthObject) + (WidthObject / 2); vertices_labirin_player[1] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject * 3 / 4);

vertices_labirin_player[2] = 0;

vertices_labirin_player[3] = (position- Col_in * WidthObject) + (WidthObject / 4); vertices_labirin_player[4] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject / 4);

vertices_labirin_player[5] = 0;

vertices_labirin_player[6] = (position- Col_in * WidthObject) + (WidthObject * 3 / 4); vertices_labirin_player[7] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject / 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, makeFloatBuff- er(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, makeFloatBuff- er(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_texture(GL10 gl, int positionCol_in, int positionRow_in) { gl.glFrontFace(GL10.GL_CCW); // Front face in counter-clockwise

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

vertices_labirin_player[0] = (position- Col_in * WidthObject) + (WidthObject / 2); vertices_labirin_player[1] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject * 3 / 4);

vertices_labirin_player[2] = 0;

vertices_labirin_player[3] = (position- Col_in * WidthObject) + (WidthObject / 4); vertices_labirin_player[4] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject / 4);

vertices_labirin_player[5] = 0;

vertices_labirin_player[6] = (position- Col_in * WidthObject) + (WidthObject * 3 / 4); vertices_labirin_player[7] = (numberRow - positionRow_in - 1) * WidthObject + (WidthOb- ject / 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, makeFloatBuff- er(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);

gl.glBindTexture(GL10.GL_TEXTURE_2D, tex- gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);

gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,

// Disable the client state before leav- ing

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_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- // Disable the client state before leav-

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,

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 gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);

// 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)); gl.glDrawArrays(GL10.GL_LINE_STRIP, 1,

(int) ((int) 2 * ba- tas_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])); .openRawResource(imageFileIDs[index_Texture]));

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 loadPlayerTexture(GL10 gl, Context context, int index_Texture) {

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs2[index_Texture]));

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

0, bitmap, 0);

bitmap.recycle(); }

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

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(imageFileIDs3[index_Texture]));

gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]); 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); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

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

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources()

.openRawResource(imageFileIDrand[index_Texture])) ; gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

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);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); } bitmap.recycle(); }

raw = soaleasy[index_Texture]; } else {

raw = soalmed[index_Texture]; }

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources() .openRawResource(raw)); gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]); 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);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0); bitmap.recycle(); } public void loadJwbTexture(GL10 gl, Context con-

text, int index_Texture, boolean difficulty) { int raw; if(difficulty == false){

raw = jwbeasy[index_Texture]; } else {

raw = jwbmed[index_Texture]; }

Bitmap bitmap = BitmapFacto-

ry.decodeStream(context.getResources() .openRawResource(raw)); gl.glGenTextures(1, textures_indek, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, tex-

tures_indek[0]);

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);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,

0, bitmap, 0);

bitmap.recycle(); }

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 = 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_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 // This method will be executed once

tent(SplashScreen.this, SplashScreen5.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); }

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 // This method will be executed once

tent(SplashScreen2.this, SplashScreen1.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); }

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 // This method will be executed once

tent(SplashScreen4.this, SplashScreen3.class);

i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);

// close this activity finish();

} }, SPLASH_TIME_OUT); }

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); }

SpriteBatch.java

package com.modelloading;

import javax.microedition.khronos.opengles.GL10;

public class SpriteBatch {

//--Constants--// final static int VERTEX_SIZE = 4;

// Vertex Size (in Components) ie. (X,Y,U,V) final static int VERTICES_PER_SPRITE = 4; // Vertices Per Sprite final static int 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

maximum 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 = new float[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 = new short[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 assumes that the texture is already bound! // A: textureId - the ID of the texture to use for the batch // R: [none] public void beginBatch(int textureId) {

gl.glBindTexture( GL10.GL_TEXTURE_2D, textureId ); // Bind the Texture numSprites = 0; // Empty Sprite Counter bufferIndex = 0; // Reset Buffer Index (Empty) } public void 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] public void endBatch() {

if ( numSprites > 0 ) { // IF Any Sprites to Render vertices.setVertices( vertexBuffer, 0, buff- erIndex ); // Set Vertices from Buffer vertices.bind(); // Bind Vertices

vertices.draw( GL10.GL_TRIANGLES, 0, vertices.draw( GL10.GL_TRIANGLES, 0,

vertices.unbind(); // Unbind Vertices } }

//--Draw Sprite to Batch--// // D: batch specified sprite to batch. adds verti-

ces for sprite to vertex buffer // NOTE: MUST be called after beginBatch(), and before endBatch()! // NOTE: if the batch overflows, this will ren- der the current batch, restart it, // and then batch this sprite. // A: x, y - the x,y position of the sprite (cen-

ter)

// width, height - the width and height of the sprite // region - the texture region to use for sprite // R: [none] public void drawSprite(float x, float y, float

width, float height, TextureRegion region) { if ( numSprites == maxSprites ) { // IF Sprite Buffer is Full endBatch(); // End Batch // NOTE: leave current texture bound!! numSprites = 0;

// 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++] = x2; // Add X 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 } }

TextureRegion.java

package com.modelloading;

class TextureRegion {

//--Members--// public float u1, v1;

// Top/Left U,V Coordinates public float u2, v2; // Bottom/Right U,V Coordinates

//--Constructor--// // D: calculate U,V coordinates from specified

texture 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 region on the texture (in pixels)

public TextureRegion(float texWidth, float texHeight, float x, float y, float width, float public TextureRegion(float texWidth, float texHeight, float x, float y, float width, float

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; loop,loop_color,loop_line,loop_line_color;

// ============ 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- 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 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); x1)+y1);

//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- 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_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 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 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 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_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 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)); //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- ((int) 2*batas_sudut/step)); // membuat garis putus-

//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);

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 in constructor! final GL10 gl; // GL Instance

//--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 this.indices.put( indices, offset, length ); // Set New Indices this.indices.flip(); // Flip Index Buffer this.numIndices = length; // Save Number of 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] // USAGE: call once before calling draw() mul- tiple times for this buffer. // A: [none] // R: [none]

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- gl.glTexCoordPointer( TEXCOORD_CNT, GL10.GL_FLOAT, vertexSize, vertices ); // Set Tex-

// 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 ( hasColor ) // IF Vertices Have Color gl.glDisableClientState( GL10.GL_COLOR_ARRAY ); // Clear Color 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 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 } void setVtxColor(int vtxIdx, float a) {

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 } }

Daftar Pustaka

[EDW-06] Edward Angel., 2006. ”Interactive Computer Graphics ”, 4thed, Addison Wesley, New York.

[HEA-97] Hearn, D. & M. P. Baker., 1997. ”Computer Graphics ”, 3rd ed. Prentice-Hall, New Jersey.

[FOL-93] Foley, J.D. et all., 1993, ”Computer Graphics: Principle and Practice ”, Addison Wesley.

[DAV-09] Dave Shreiner ., 2009. ”OpenGL Programming Guide : The Official Guide to Learning OpenGL ”, Seventh Edition, Addison Wesley.

[EDH-05] Edhi Nugroho., 200

5. ”Teori dan Praktek Grafika Komputer Menggunakan Delphi dan OpenGL ”. Edisi Pertama, Graha Ilmu.

[FAD-07] Fadlisyah.,

Muthmainnah., 2007. ”Pengantar Grafika Komputer”. Edisi Pertama, Yogyakarta : Penerbit ANDI.

Nurlaila.,

[ACH-06] Achmad Basuki., Nana Ramadijanti., 2006. ”Grafika Komputer : Teori dan Implementasi”. Edisi Pertama, Yogyakarta : Penerbit ANDI.

[SIM-07] Janner Simarmata., Tintin Chandra., 2007. ”Grafika Komputer”. Edisi Pertama, Yogyakarta : Penerbit ANDI.

[SUY-03] Suyoto., 2003. ”Teori dan Pemrograman Grafika Komputer dengan Visual C++ V.6 dan OpenGL ”. Edisi Pertama, Yogyakarta : Penerbit Gava Media.

[SYI-10] Nafisah, Syifatun., Effendy, Nazrul. 2010. ”Grafika Komputer

Borland C++ Builder Professional ”. Edisi Pertama, Yogyakarta : Graha Ilmu.

dengan

[GLP-14] GLProgramming., ”OpenGL Programming Guide Chapter

Mapping”, [online], (http://www.glprogramming.com/red/chapter09.htm l, diakses tanggal 8 November 2014)

9 Texture

Biografi Penulis

Imam Cholissodin, lahir di Lamongan pada tanggal 19 Juli 1985, telah menyelesaikan pendidikan S2 di Teknik Informatika FTIF ITS Surabaya pada Tahun 2011. Sejak Tahun 2012 telah aktif sebagai dosen pengajar di jurusan Teknik Informatika Program Teknologi dan Ilmu Komputer (PTIIK) Universitas Brawijaya (UB) Malang pada beberapa mata kuliah, seperti

Information Retrieval, Pengolahan Citra Digital, Probabilitas dan Statatistika, Grafika Komputer, Decision Support System, Kecerdasan Buatan, Data Mining dan Pengenalan Pola. Bidang Keminatan yang ditekuni peneliti adalah Information Retrieval, Artificial Vision, Decision Support System, Image Processing, dan Cryptography. Di samping mengajar, peneliti juga aktif dalam Riset Group Image Processing dan Vision (IMPROV) di dalam Laboratorium Komputasi Cerdas dan Visualisasi. Selain itu peneliti juga telah melakukan beberapa publikasi pada jurnal nasional dan internasional (IEEE). Riset pada tahun 2013-2014 yang sedang dilakukan sekarang bersama dengan beberapa tim dosen dan mahasiswa semester akhir adalah berfokus pada bidang Information Retrieval untuk melakukan analisis dokumen lembaga pendidikan secara Real-time, yaitu

de ngan tema “Groups Decision Sentiment Analysis Untuk Klasifikasi Dokumen E-Complaint Kampus Menggunakan Additive Kernel

SVM” yang merupakan kombinasi dari dua lintas bidang keilmuan antara Decision Support System (DSS) dan Information Retrieval (IR).Motto : “We Are A Code, We Are The Best Code Of God”.

Maya Kurniawati, lahir di Malang pada tang- gal 10 Agustus 1992. Pada tahun 2014 ber- hasil menyelesaikan studi S1 Teknik Informat- ika, Program Teknologi Informasi dan Ilmu Komputer, Universitas Brawijaya Malang dengan tugas akhir yang berjudul “Klasifikasi Dokumen

E-Complaint Kampus Menggunakan Directed Acyclic Graph Multi- Class SVM ”.