User talk:Nopsaka

3Dimensi Bergerak Java
GRAFIKA COMPUTER - E

*Naufal Sakagraha K    - 105060807111095 *Dian Hermansyah       - 105060807111144 *Radyan Ilham C        - 115060807111126 *Akhmad Syururi        - 115060807111096 *Khoirinnisa Fitria Nur - 125150100111021

Transformasi adalah memindahkan objek tanpa merusak bentuk aslinya, meskipun ada perubahan bentuk atau modifikasi pada hasil akhirnya. Tujuan Transformasi :
 * Melihat objek dari sudut pandang yang berbeda.
 * Membuat komposisi pemandangan yang sesuai.
 * Memudahkan membuat objek yang simetris.
 * Memindahkan satu atau beberapa objek dari satu tempat ke tempat lain (animasi).

1. Sebelum memulai membuat program, Anda harus mendeklarasikan library apa saja yang dipakai dalam program Anda, melalui statement import yang ditulis di luar deklarasi class public. Berikut ini beberapa library yang dibutuhkan dalam dasar pembuatan animasi 3D Bergerak Java.

package Tugas3D;

import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.util.glu.GLU.*; import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode;

2. Seteleah library sudah di tentukan apa saja yang dipakai, kemudian buat ketentuan untuk interface program beserta ketentuannya

public class Main extends Kincir{ public static final int DISPLAY_HEIGHT = 480; public static final int DISPLAY_WIDTH = 640; protected boolean wireframe = false; private float dgrRot, dgrxRot, dgryRot; private long lastTime; private int fps; public static void main(String[] args) { Main main = null; try { main = new Main; main.create; main.run; }catch(Exception e){} if(main != null) { main.destroy; }   }

3. Setelah itu agar objek dapat di putar keatas, ke bawah, ke kiri, kekanan dengan method seperti di bawah ini, jika menekan arah atas maka akan ke atas dan seterusnya.

public void processKeyboard { if(Keyboard.isKeyDown(Keyboard.KEY_UP)) { --dgrxRot; /*ketika tombol up di keyboard di tekan, maka semua obyek akan diputar sebanyak -1.0f dengan poros x setiap kali ditekan */       }        if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { ++dgrxRot; /*ketika tombol down di keyboard di tekan, maka semua obyek akan diputar sebanyak 1.0f dengan poros x setiap kali ditekan */       }if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { --dgryRot; /*ketika tombol down di keyboard di tekan, maka semua obyek akan diputar sebanyak -1.0f dengan poros y setiap kali ditekan */       }        if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { ++dgryRot; /*ketika tombol down di keyboard di tekan, maka semua obyek akan diputar sebanyak 1.0f dengan poros y setiap kali ditekan */       }    }

4. Setelah itu buat method untuk menampilkan perspektif sisi dari bangun 3D ini dengan menggunakan glPushMatrix dan glPopMatrix

public void render { Main klas = new Main; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }       glLoadIdentity; gluLookAt(0.0f, 0.0f, 20.0f, 0.0f, 0.0f, 10.0f, 0.0f, 10.0f, 20.0f); glRotatef(dgrxRot,1.0f,0.0f, 0.0f);//rotasi semua obyek dengan poros x       glRotatef(dgryRot,0.0f,1.0f , 0.0f);//rotasi semua obyek dengan poros y        klas.drawQuad1;//limas penyangga glPushMatrix; glRotatef(dgrRot,0.0f,0.0f,1.0f); klas.drawQuadH;//tiang sirip mendatar klas.drawQuadV;//tiang sirip tegak dgrRot += 1.0f; glPopMatrix; }

5. Lalu kita buat class untuk dapat menerima inputan berupa arah atas, bawah, kanan, kiri beserta pengaturan kecepatan kincir sesuai yang kita ingin kan pada coding.

public void run { while(!Display.isCloseRequested && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { if(Display.isVisible) { processKeyboard;//untuk memasukkan proses keyboard input(arah) update; render; }           else { if(Display.isDirty) { render; }               try { Thread.sleep(100); }               catch(InterruptedException ex) { }           }            Display.update; Display.sync(500); //fps --> 60 }   }

6. Untuk menampilkan berapa FPS pada bar windows juga bisa ditambahkan class sebagai berikut.

public void updateFPS{ if(Sys.getTime-lastTime>1000){ Display.setTitle("Kincir Angin fps : "+fps); fps = 0; lastTime = Sys.getTime; }       fps++; } 7. Source code diatas merupakan Main program yang akan kita buat, dimana sebelumnya kita sudah membuat java class untuk menentukan bentuk dari bangun 3D yang akan di bangun. disini ada 3 turunan class yaitu untuk membuat bidang kincir (2 buah yaitu 1 horizontal dan 1 vertical) dan 1 bangun untuk penyangga kincir.

public void drawQuadV // BALING2 VERTIKAL { }

public void drawQuadH //BALING2 HORIZONTAL { }

public void drawQuad1 //LIMAS PENYANGGA { }

3D Java Moving Animation
Transformation is moving objects without damaging the original form, although there is a change or modification to the shape of the end result. Purpose of the transformation :
 * Viewing objects from different viewpoints.
 * Creating landscape composition accordingly.
 * Creating symmetrical objects easier
 * Move one or several objects from one place to another (animation).

1. Before starting a program, you must declare any library that is used in your program, through the import statement is written outside the class declaration public. Here is some basic libraries needed tp making the Java 3D moving animation.

package Tugas3D;

import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.util.glu.GLU.*; import org.lwjgl.LWJGLException; import org.lwjgl.Sys; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode;

2. After determining what is in use, then make a provision for the interface of the program with its provisions

public class Main extends Kincir{ public static final int DISPLAY_HEIGHT = 480; public static final int DISPLAY_WIDTH = 640; protected boolean wireframe = false; private float dgrRot, dgrxRot, dgryRot; private long lastTime; private int fps; public static void main(String[] args) { Main main = null; try { main = new Main; main.create; main.run; }catch(Exception e){} if(main != null) { main.destroy; }   }

3. Then to make the object turned up, down, to the left, to the right we need this following method if pressing top button it will be up and so on

public void processKeyboard { if(Keyboard.isKeyDown(Keyboard.KEY_UP)) { --dgrxRot; /*when top button in the keyboard is pressed All of the objects will be rotated as much -1.0f the x axis of each press */ }       if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { ++dgrxRot; /*when down button in the keyboard is pressed All of the objects will be rotated as much 1.0f the x axis of each press */ }        if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { --dgryRot; /*when down button in the keyboard is pressed All of the objects will be rotated as much -1.0f the y axis of each press */ }       if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { ++dgryRot; /*when down button in the keyboard is pressed All of the objects will be rotated as much 1.0f the y axis of each press*/ }

4. After that, create a method to displaying 3D perspective from the 3D shapes using glPushMatrix and glPopMatrix

public void render { Main klas = new Main; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); }       glLoadIdentity; gluLookAt(0.0f, 0.0f, 20.0f, 0.0f, 0.0f, 10.0f, 0.0f, 10.0f, 20.0f); glRotatef(dgrxRot,1.0f,0.0f, 0.0f);// rotation for all objects with the x axis glRotatef(dgryRot,0.0f,1.0f, 0.0f);// rotation for all objects with the y axis klas.drawQuad1;// pyramid buffer glPushMatrix; glRotatef(dgrRot,0.0f,0.0f,1.0f); klas.drawQuadH;//horizontal fins pole klas.drawQuadV;//vertical fins pole dgrRot += 1.0f; glPopMatrix; }

5. Then we create a class to accept in the form of directions up, down, right, left, along with wheel speed settings according to what we want. public void run { while(!Display.isCloseRequested && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { if(Display.isVisible) { processKeyboard;//process of inputting the direction from the keyboard update; render; }           else { if(Display.isDirty) { render; }               try { Thread.sleep(100); }               catch(InterruptedException ex) { }           }            Display.update; Display.sync(500); //fps --> 60 }   }

6. To showing several of FPS on the windows bar, we can also adding new class use this following way public void updateFPS{ if(Sys.getTime-lastTime>1000){ Display.setTitle("Kincir Angin fps : "+fps); fps = 0; lastTime = Sys.getTime; }       fps++; }

7. That source code is the program what will be create where previously we've made a java class to determine the shape of the 3D will be built. Here there are 3 derived class is to create a field of windmills (2 pieces which is 1 horizontal and 1 vertical) and 1 shape up for a buffer wheel. public void drawQuadV // vertical wheel { }

public void drawQuadH //horizontal wheel { }

public void drawQuad1 //pyramid buffer{ }