03 Primitives Imam Cholissodin imam cholissodingmail com Primitives
- Slides: 9
03 |Primitives Imam Cholissodin| imam. cholissodin@gmail. com
Primitives : 1. 2. 3. 4. 5. 6. 7. 8. 9. What’s Primitives Create Point Create Line Strip Create Line Loop/ Polygon Create Triangle Create Rectangle Create Line Stipple Create Circle, Ellips, Cardioid, Treeleaf, Spiral and Limacon
What’s Primitives • • Titik Garis Segiempat Lingkaran “Objek se-kompleks apapun, dengan mengkombinasikan primitif di atas. ” dapat dibuat bentuk-bentuk
Create Point gl. Color 3 f(1. 0, 0. 0); gl. Point. Size(19); gl. Begin(GL_POINTS); gl. Vertex 2 f(80, 20); gl. Vertex 2 f(300, 50); gl. Vertex 2 f(180, 200); gl. End(); gl. Flush(); =============
Create Line gl. Color 3 f(1. 0, 0. 0, 1. 0); gl. Line. Width(5); gl. Begin(GL_LINES); gl. Vertex 2 f(100, 100); gl. Vertex 2 f(210, 300); gl. Vertex 2 f(320, 100); gl. Vertex 2 f(100, 100); gl. Vertex 2 f(320, 100); gl. End(); gl. Flush(); =============
Vertex Array & Color Array float array_vertex[]= { 150, 10, //vertex 1 280, 250, //vertex 2 20, 250 //vertex 3 }; float array_color[]= { 1, 0, 0, //red 0, 1, 0, //green 0, 0, 1 //blue };
Create Lines GLfloat x 1 = 2, y 1 = 2 ; GLfloat x 2= 100, y 2 = 100 ; gl. Begin(GL_POINTS); gl. Vertex 2 i(x 1, y 1); gl. Vertex 2 i(x 2, y 2); // hitung nilai m GLfloat m = (y 2 -y 1)/(x 2 -x 1); for(float x=2; x<=10; x++){ GLfloat y = m*(x-x 1)+y 1; gl. Vertex 2 i(x, y); } gl. End();
Create Circle GLfloat jari_jari=150; // Titik Pusat GLfloat a = 290, b = 250 ; GLfloat x=a+jari_jari, y=b; gl. Line. Width(7); gl. Begin(GL_LINE_LOOP); for(float teta=0; teta<=360; teta++){ GLfloat x_aksen = (x-a)*cos((teta/180)*(22/7)) - ((y-b)*sin((teta/180)*(22/7))) + a; GLfloat y_aksen = (x-a)*sin((teta/180)*(22/7)) - ((y-b)*cos((teta/180)*(22/7))) + b; gl. Vertex 2 i(x_aksen, y_aksen); } gl. End();
Selesai Imam Cholissodin| imam. cholissodin@gmail. com