package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;
@Override
public void init() {
// TODO Auto-generated method stub
// Setting up default viewport
glViewport(0, 0, width, height);
// Set perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, width / height, 1.0f, 100.0f);
glEnable(GL_TEXTURE_2D);
}
@Override
public void update(int delta) {
// TODO Auto-generated method stub
//glRotatef(30, 10, 10, 10);
}
@Override
public void render() {
// TODO Auto-generated method stub
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
if(wireframe){
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}else{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
glBegin(GL_LINES);
//depan kanan
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-1, 1, -10);
glVertex3f(-1, -3, -10);
//belakang kanan
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(0, 2, -14);
glVertex3f(0, -2, -14);
//belakang kiri
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-4, 2, -14);
glVertex3f(-4, -2, -14);
//depan kiri
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-4, 1, -10);
glVertex3f(-4, -3, -10);
//bawah
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-1, -3, -10);
glVertex3f(-4, -3, -10);
//kanan
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-1, -3, -10);
glVertex3f(0, -2, -14);
//belakang
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-4, -2, -14);
glVertex3f(0, -2, -14);
//kiri
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(-4, -2, -14);
glVertex3f(-4, -3, -10);
glEnd();
glBegin(GL_TRIANGLES);
//depan
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(-4, 1, -10);
glVertex3f(-1, 1, -10);
glVertex3f(-3, 5, -12);
//kanan
glColor3f(0.0f, 1.0f, 1.0f);
glVertex3f(-3, 5, -12);
glVertex3f(-1, 1, -10);
glVertex3f(0, 2, -14);
//belakang
glColor3f(1.0f, 0.0f, 1.0f);
glVertex3f(-3, 5, -12);
glVertex3f(-4, 2, -14);
glVertex3f(0, 2, -14);
//kiri
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-3, 5, -12);
glVertex3f(-4, 2, -14);
glVertex3f(-4, 1, -10);
glEnd();
}
@Override
public void deinit() {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
CG04_3DTransformation app = new CG04_3DTransformation();
app.start(800, 600, false, true, "DemoApp04 - 3D Transformation");
}
}