Skip to content

Instantly share code, notes, and snippets.

@initrunlevel0
Created November 28, 2013 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save initrunlevel0/7691093 to your computer and use it in GitHub Desktop.
Save initrunlevel0/7691093 to your computer and use it in GitHub Desktop.
Huawei EC306-2 dengan OpenGL (Tugas 4 Mata Kuliah Grafkom)
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
#define PI 3.14
const float DEG2RAD = 3.14159/180;
double rotate_x=0, rotate_y=0;
void display() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(1.0, 0.9, 0.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef( rotate_x, 1.0, 0.0, 0.0 );
glRotatef( rotate_y, 0.0, 1.0, 0.0 );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15.0, 15.0, -15.0, 15.0, -30.0, 30.0);
// glBegin(GL_LINE_STRIP);
// glColor3f(1.0,1.0,1.0);
// glVertex3f(-9.0, 9.0, -9.0);
// glVertex3f(9.0, 9.0, -9.0);
// glVertex3f(9.0, -9.0, 9.0);
// glVertex3f(-9.0, -9.0, 9.0);
// glEnd();
// glPointSize(10);
// glBegin(GL_POINTS);
// glColor3f(1.0,0.0,0.0);
// glVertex3f(0.0, 0.0, 0.0);
// glEnd();
// glBegin(GL_POINTS);
// glColor3f(0.0,1.0,0.0);
// glVertex3f(0.1, 0.1, -0.1);
// glEnd();
// glPointSize(10);
// for (int a = 270; a < 450; a += 360 / 50)
// {
// double heading = a * 3.1415926535897932384626433832795 / 180;
// //glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 10.0, 9.0);
// glBegin(GL_POINTS);
// glColor3f(0.0,0.0,1.0);
// glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 5.0, 9.0);
// glEnd();
// }
// Polygon untuk Rangka depan hitam (yang ada logo Smartfrennya)
glBegin(GL_POLYGON);
glColor3f(0.1, 0.1, 0.1); // Hitam
glVertex3f(-9.0, -5.0, 9.0);
for (int a = 270; a < 450; a += 360 / 100)
{
double heading = a * 3.1415926535897932384626433832795 / 180;
glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 5.0, 9.0);
}
glVertex3f(-9.0, 5.0, 9.0);
glEnd();
// Batas kiri dengan rangka depan
glBegin(GL_POLYGON);
glColor3f(0.9, 0.9, 0.9);
glVertex3f(-9.0, 5.0, 9.0);
glVertex3f(-9.0, 4.5, 5.0);
glVertex3f(-9.0, -4.5, 5.0);
glVertex3f(-9.0, -4.5, 9.0);
glEnd();
// Kotak Lampu LED
glBegin(GL_POLYGON);
glColor3f(0.0,0.0,1.0);
glVertex3f(-0.5, 0.5, 9.1);
glVertex3f(-0.5, -0.5, 9.1);
glVertex3f(0.5, -0.5, 9.1);
glVertex3f(0.5, 0.5, 9.1);
glEnd();
// Pembatas port USB
// Tampak atas
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(-9.0, 5.0, 8.0);
glVertex3f(-10.0, 5.0, 8.0);
glVertex3f(-10.0, -5.0, 8.0);
glVertex3f(-9.0, -5.0, 8.0);
glEnd();
// Tampak samping bawah
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(-10.0, -5.0, 8.0);
glVertex3f(-9.0, -5.0, 8.0);
glVertex3f(-9.0, -4.5, 6.0);
glVertex3f(-10.0, -4.5, 6.0);
glEnd();
// Tampak samping atas
glBegin(GL_POLYGON);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(-10.0, 5.0, 8.0);
glVertex3f(-9.0, 5.0, 8.0);
glVertex3f(-9.0, 4.5, 6.0);
glVertex3f(-10.0, 4.5, 6.0);
glEnd();
// Tampak batas kiri dengan USB
glBegin(GL_POLYGON);
glColor3f(0.9, 0.9, 0.9);
glVertex3f(-10.0, 5.0, 8.0);
glVertex3f(-10.0, -5.0, 8.0);
glVertex3f(-10.0, -4.5, 6.0);
glVertex3f(-10.0, 4.5, 6.0);
glEnd();
// Port USB nya itu sendiri
glBegin(GL_POLYGON);
glColor3f(0.6, 0.6, 0.6);
glVertex3f(-10.0, 3.0, 7.5);
glVertex3f(-14.0, 3.0, 7.5);
glVertex3f(-14.0, -3.0, 7.5);
glVertex3f(-10.0, -3.0, 7.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.6, 0.6, 0.6);
glVertex3f(-10.0, 3.0, 6.5);
glVertex3f(-14.0, 3.0, 6.5);
glVertex3f(-14.0, -3.0, 6.5);
glVertex3f(-10.0, -3.0, 6.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.6, 0.6, 0.6);
glVertex3f(-14.0, 3.0, 7.5);
glVertex3f(-10.0, 3.0, 7.5);
glVertex3f(-10.0, 3.0, 6.5);
glVertex3f(-14.0, 3.0, 6.5);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.6, 0.6, 0.6);
glVertex3f(-14.0, -3.0, 7.5);
glVertex3f(-10.0, -3.0, 7.5);
glVertex3f(-10.0, -3.0, 6.5);
glVertex3f(-14.0, -3.0, 6.5);
glEnd();
// Sisi samping dan Belakang (The hardest part)
//glBegin(GL_LINES);
//for (int a = 180; a < 360; a += 360 / 100)
//{
// double heading = a * 3.1415926535897932384626433832795 / 180;
// glVertex3f(0.0, cos(heading) * 5.0, sin(heading) * 4.0 + 9.0);
//}
//glEnd();
// Pakai cara cupu dulu
glBegin(GL_POLYGON);
glColor3f(0.7, 0.7, 0.7);
glVertex3f(-9.0, -4.5, 5.0);
for (int a = 270; a < 450; a += 360 / 100)
{
double heading = a * 3.1415926535897932384626433832795 / 180;
glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 4.5, 5.0);
}
glVertex3f(-9.0, 4.5, 5.0);
glEnd();
// Samping atas
glBegin(GL_POLYGON);
glColor3f(0.9, 0.9, 0.9);
glVertex3f(-9.0, 5.0, 9.0);
glVertex3f(8.0, 5.0, 9.0);
glVertex3f(8.0, 4.5, 5.0);
glVertex3f(-9.0, 4.5, 5.0);
glEnd();
// Samping bawah
glBegin(GL_POLYGON);
glColor3f(0.9, 0.9, 0.9);
glVertex3f(-9.0, -5.0, 9.0);
glVertex3f(8.0, -5.0, 9.0);
glVertex3f(8.0, -4.5, 5.0);
glVertex3f(-9.0, -4.5, 5.0);
glEnd();
glBegin(GL_QUAD_STRIP);
glColor3f(0.9, 0.9, 0.9);
glVertex3f(8.0, 5.0, 9.0);
glVertex3f(8.0, 4.5, 5.0);
for (int a = 270; a < 450; a += 360 / 100)
{
double heading = a * 3.1415926535897932384626433832795 / 180;
glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 5.0, 9.0);
glVertex3f(cos(heading) * 2.0 + 8.0, sin(heading) * 4.5, 5.0);
}
glEnd();
glFlush();
glutSwapBuffers();
}
void specialKeys( int key, int x, int y ) {
// Right arrow - increase rotation by 5 degree
if (key == GLUT_KEY_RIGHT)
rotate_y += 5;
// Left arrow - decrease rotation by 5 degree
else if (key == GLUT_KEY_LEFT)
rotate_y -= 5;
else if (key == GLUT_KEY_UP)
rotate_x += 5;
else if (key == GLUT_KEY_DOWN)
rotate_x -= 5;
// Request display update
glutPostRedisplay();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("Smartfren EC306-2");
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glutDisplayFunc(display);
glutSpecialFunc(specialKeys);
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment