Sabtu, 30 Mei 2015

Membuat Objek Balok Bengkok 3D Solid / Padat

Siang hari disaat cidera ibu jari kaki kanan mulai sembuh...


Selamat Siang rekan-rekan sekalian...
Setelah di artikel sebelumnya aku membahas tentang objek 3D balok bengkok wire / kawat, sekarang  kita ngobrol  cara pemberian tekstur untuk objek tersebut.


Banyak cara yang dapat digunakan untuk memberi tekstur pada balok bengkok, prinsipnya hampir sama dengan tekstur pada balok, hanya pada balok bengkok terdapat polygon yang berbentuk segitiga (prisma). Berikut ini aku akan menerangkan cara sederhana untuk memberi tekstur balok bengkok, rekan-rekan dapat berkreasi sendiri jika ingin mengembangkannya.


Gambar di atas adalah gambar jaring-jaring balok bengkok yang direntangkan dengan sisi-sisi balok bagian atas dihilangkan(semua polygon balok bagian atas tidak digambar pada gambar 1, karena polygon balok bagian atas identik dengan polygon balok bagian bawah).
Aku membagi polygon-polygon balok bengkok menjadi A, B, C, D, E, F, G, H ,I, dan J. Dengan cara yang sama seperti objek 3D sebelumnya masing-masing tekstur koordinat untuk masing-masing polygon dapat dihitung seperti pada tabel berikut:


NB.
Pada tabel di atas nilai JT ditentukan oleh user, tidak dihitung seperti pada objek 3D balok atau pipa.

Setelah masing-masing polygon dihitung tekstur koordinatnya seperti pada tabel di atas maka langkah selanjutnya tinggal menempelkan tekstur koordinat  tersebut ke masing-masing polygon balok bengkok.

Berikut potongan program untuk tekstur balok bengkok:

void load_Balok_Bengkok_TextureKoordinat(float sudut_alpha, float L1, float L2, float L3, float tinggi, float lebar, float JT, Koordinat TK_BalokB[38])
{
    double pi = 3.1415926535;
    double half_pi = pi * 0.5;
    double sudut_half_teta;

    sudut_half_teta = (180 - sudut_alpha) / 4;
    sudut_half_teta = (sudut_half_teta / 180) * pi * 0.5;

    TK_BalokB[0].X = 0;            TK_BalokB[0].Y = 0;
    TK_BalokB[1].X = tinggi / JT;  TK_BalokB[1].Y = 0;
    TK_BalokB[2].X = tinggi / JT;  TK_BalokB[2].Y = lebar / JT;
    TK_BalokB[3].X = 0;            TK_BalokB[3].Y = lebar / JT;

    TK_BalokB[4].X = 0;                                             TK_BalokB[4].Y = 0;
    TK_BalokB[5].X = (2 * tinggi*(float)sin(sudut_half_teta)) / JT; TK_BalokB[5].Y = 0;
    TK_BalokB[6].X = (2 * tinggi*(float)sin(sudut_half_teta)) / JT; TK_BalokB[6].Y = lebar / JT;
    TK_BalokB[7].X = 0;                                             TK_BalokB[7].Y = lebar / JT;

    TK_BalokB[8].X = 0;            TK_BalokB[8].Y = 0;
    TK_BalokB[9].X = L1 / JT;      TK_BalokB[9].Y = 0;
    TK_BalokB[10].X = L1 / JT;     TK_BalokB[10].Y = lebar / JT;
    TK_BalokB[11].X = 0;           TK_BalokB[11].Y = lebar / JT;

    TK_BalokB[12].X = 0;           TK_BalokB[12].Y = 0;
    TK_BalokB[13].X = L2 / JT;     TK_BalokB[13].Y = 0;
    TK_BalokB[14].X = L2 / JT;     TK_BalokB[14].Y = lebar / JT;
    TK_BalokB[15].X = 0;           TK_BalokB[15].Y = lebar / JT;

    TK_BalokB[16].X = 0;           TK_BalokB[16].Y = 0;
    TK_BalokB[17].X = L3 / JT;     TK_BalokB[17].Y = 0;
    TK_BalokB[18].X = L3 / JT;     TK_BalokB[18].Y = lebar / JT;
    TK_BalokB[19].X = 0;           TK_BalokB[19].Y = lebar / JT;

    TK_BalokB[20].X = 0;            TK_BalokB[20].Y = 0;
    TK_BalokB[21].X = L1 / JT;      TK_BalokB[21].Y = 0;
    TK_BalokB[22].X = L1 / JT;      TK_BalokB[22].Y = tinggi / JT;
    TK_BalokB[23].X = 0;            TK_BalokB[23].Y = tinggi / JT;

    TK_BalokB[24].X = 0;            TK_BalokB[24].Y = 0;
    TK_BalokB[25].X = L2 / JT;      TK_BalokB[25].Y = 0;
    TK_BalokB[26].X = L2 / JT;      TK_BalokB[26].Y = tinggi / JT;
    TK_BalokB[27].X = 0;            TK_BalokB[27].Y = tinggi / JT;

    TK_BalokB[28].X = 0;            TK_BalokB[28].Y = 0;
    TK_BalokB[29].X = L3 / JT;      TK_BalokB[29].Y = 0;
    TK_BalokB[30].X = L3 / JT;      TK_BalokB[30].Y = tinggi / JT;
    TK_BalokB[31].X = 0;            TK_BalokB[31].Y = tinggi / JT;

    TK_BalokB[32].X = (tinggi*(float)sin(sudut_half_teta)) / JT;  
    TK_BalokB[32].Y = 0;
    TK_BalokB[33].X = (2 * tinggi*(float)sin(sudut_half_teta)) / JT;
    TK_BalokB[33].Y = (tinggi*(float)cos(sudut_half_teta) / JT);
    TK_BalokB[34].X = 0;                                  
    TK_BalokB[34].Y = (tinggi*(float)cos(sudut_half_teta) / JT);

    TK_BalokB[35].X = 0;                                  
    TK_BalokB[35].Y = 0;
    TK_BalokB[36].X = (2 * tinggi*(float)sin(sudut_half_teta)) / JT;
    TK_BalokB[36].Y = 0;
    TK_BalokB[37].X = (tinggi*(float)sin(sudut_half_teta)) / JT;
    TK_BalokB[37].Y = (tinggi*(float)cos(sudut_half_teta) / JT);
}

void Balok_Bengkok_Solid(Vertex read_BalokB[32], Koordinat TK_BalokB[38], int index_bitmap)
{
    glBindTexture(GL_TEXTURE_2D, texture_merah);

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[20].X, TK_BalokB[20].Y);
    glVertex3f(read_BalokB[0].VX, read_BalokB[0].VY, read_BalokB[0].VZ);

    glTexCoord2f(TK_BalokB[23].X, TK_BalokB[23].Y);
    glVertex3f(read_BalokB[1].VX, read_BalokB[1].VY, read_BalokB[1].VZ);

    glTexCoord2f(TK_BalokB[22].X, TK_BalokB[22].Y);
    glVertex3f(read_BalokB[2].VX, read_BalokB[2].VY, read_BalokB[2].VZ);

    glTexCoord2f(TK_BalokB[21].X, TK_BalokB[21].Y);
    glVertex3f(read_BalokB[3].VX, read_BalokB[3].VY, read_BalokB[3].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[20].X, TK_BalokB[20].Y);
    glVertex3f(read_BalokB[4].VX, read_BalokB[4].VY, read_BalokB[4].VZ);

    glTexCoord2f(TK_BalokB[23].X, TK_BalokB[23].Y);
    glVertex3f(read_BalokB[5].VX, read_BalokB[5].VY, read_BalokB[5].VZ);

    glTexCoord2f(TK_BalokB[22].X, TK_BalokB[22].Y);
    glVertex3f(read_BalokB[6].VX, read_BalokB[6].VY, read_BalokB[6].VZ);

    glTexCoord2f(TK_BalokB[21].X, TK_BalokB[21].Y);
    glVertex3f(read_BalokB[7].VX, read_BalokB[7].VY, read_BalokB[7].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[2].X, TK_BalokB[2].Y);
    glVertex3f(read_BalokB[6].VX, read_BalokB[6].VY, read_BalokB[6].VZ);

    glTexCoord2f(TK_BalokB[3].X, TK_BalokB[3].Y);
    glVertex3f(read_BalokB[7].VX, read_BalokB[7].VY, read_BalokB[7].VZ);

    glTexCoord2f(TK_BalokB[0].X, TK_BalokB[0].Y);
    glVertex3f(read_BalokB[0].VX, read_BalokB[0].VY, read_BalokB[0].VZ);

    glTexCoord2f(TK_BalokB[1].X, TK_BalokB[1].Y);
    glVertex3f(read_BalokB[1].VX, read_BalokB[1].VY, read_BalokB[1].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[8].X, TK_BalokB[8].Y);
    glVertex3f(read_BalokB[1].VX, read_BalokB[1].VY, read_BalokB[1].VZ);

    glTexCoord2f(TK_BalokB[9].X, TK_BalokB[9].Y);
    glVertex3f(read_BalokB[2].VX, read_BalokB[2].VY, read_BalokB[2].VZ);

    glTexCoord2f(TK_BalokB[10].X, TK_BalokB[10].Y);
    glVertex3f(read_BalokB[5].VX, read_BalokB[5].VY, read_BalokB[5].VZ);

    glTexCoord2f(TK_BalokB[11].X, TK_BalokB[11].Y);
    glVertex3f(read_BalokB[6].VX, read_BalokB[6].VY, read_BalokB[6].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[11].X, TK_BalokB[11].Y);
    glVertex3f(read_BalokB[0].VX, read_BalokB[0].VY, read_BalokB[0].VZ);

    glTexCoord2f(TK_BalokB[10].X, TK_BalokB[10].Y);
    glVertex3f(read_BalokB[3].VX, read_BalokB[3].VY, read_BalokB[3].VZ);

    glTexCoord2f(TK_BalokB[9].X, TK_BalokB[9].Y);
    glVertex3f(read_BalokB[4].VX, read_BalokB[4].VY, read_BalokB[4].VZ);

    glTexCoord2f(TK_BalokB[8].X, TK_BalokB[8].Y);
    glVertex3f(read_BalokB[7].VX, read_BalokB[7].VY, read_BalokB[7].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[8].VX, read_BalokB[8].VY, read_BalokB[8].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[2].VX, read_BalokB[2].VY, read_BalokB[2].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[9].VX, read_BalokB[9].VY, read_BalokB[9].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[10].VX, read_BalokB[10].VY, read_BalokB[10].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[11].VX, read_BalokB[11].VY, read_BalokB[11].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[12].VX, read_BalokB[12].VY, read_BalokB[12].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[5].VX, read_BalokB[5].VY, read_BalokB[5].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[13].VX, read_BalokB[13].VY, read_BalokB[13].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[2].VX, read_BalokB[2].VY, read_BalokB[2].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[9].VX, read_BalokB[9].VY, read_BalokB[9].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[12].VX, read_BalokB[12].VY, read_BalokB[12].VZ);

    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[5].VX, read_BalokB[5].VY, read_BalokB[5].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[8].VX, read_BalokB[8].VY, read_BalokB[8].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[10].VX, read_BalokB[10].VY, read_BalokB[10].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[11].VX, read_BalokB[11].VY, read_BalokB[11].VZ);

    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[13].VX, read_BalokB[13].VY, read_BalokB[13].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[14].VX, read_BalokB[14].VY, read_BalokB[14].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[9].VX, read_BalokB[9].VY, read_BalokB[9].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[15].VX, read_BalokB[15].VY, read_BalokB[15].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[16].VX, read_BalokB[16].VY, read_BalokB[16].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[17].VX, read_BalokB[17].VY, read_BalokB[17].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[18].VX, read_BalokB[18].VY, read_BalokB[18].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[12].VX, read_BalokB[12].VY, read_BalokB[12].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[19].VX, read_BalokB[19].VY, read_BalokB[19].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[9].VX, read_BalokB[9].VY, read_BalokB[9].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[15].VX, read_BalokB[15].VY, read_BalokB[15].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[18].VX, read_BalokB[18].VY, read_BalokB[18].VZ);

    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[12].VX, read_BalokB[12].VY, read_BalokB[12].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[14].VX, read_BalokB[14].VY, read_BalokB[14].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[16].VX, read_BalokB[16].VY, read_BalokB[16].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[17].VX, read_BalokB[17].VY, read_BalokB[17].VZ);

    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[19].VX, read_BalokB[19].VY, read_BalokB[19].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[20].VX, read_BalokB[20].VY, read_BalokB[20].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[15].VX, read_BalokB[15].VY, read_BalokB[15].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[21].VX, read_BalokB[21].VY, read_BalokB[21].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[22].VX, read_BalokB[22].VY, read_BalokB[22].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[24].X, TK_BalokB[24].Y);
    glVertex3f(read_BalokB[23].VX, read_BalokB[23].VY, read_BalokB[23].VZ);

    glTexCoord2f(TK_BalokB[27].X, TK_BalokB[27].Y);
    glVertex3f(read_BalokB[24].VX, read_BalokB[24].VY, read_BalokB[24].VZ);

    glTexCoord2f(TK_BalokB[26].X, TK_BalokB[26].Y);
    glVertex3f(read_BalokB[18].VX, read_BalokB[18].VY, read_BalokB[18].VZ);

    glTexCoord2f(TK_BalokB[25].X, TK_BalokB[25].Y);
    glVertex3f(read_BalokB[25].VX, read_BalokB[25].VY, read_BalokB[25].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[15].VX, read_BalokB[15].VY, read_BalokB[15].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[21].VX, read_BalokB[21].VY, read_BalokB[21].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[24].VX, read_BalokB[24].VY, read_BalokB[24].VZ);

    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[18].VX, read_BalokB[18].VY, read_BalokB[18].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[15].X, TK_BalokB[15].Y);
    glVertex3f(read_BalokB[20].VX, read_BalokB[20].VY, read_BalokB[20].VZ);

    glTexCoord2f(TK_BalokB[14].X, TK_BalokB[14].Y);
    glVertex3f(read_BalokB[22].VX, read_BalokB[22].VY, read_BalokB[22].VZ);

    glTexCoord2f(TK_BalokB[13].X, TK_BalokB[13].Y);
    glVertex3f(read_BalokB[23].VX, read_BalokB[23].VY, read_BalokB[23].VZ);

    glTexCoord2f(TK_BalokB[12].X, TK_BalokB[12].Y);
    glVertex3f(read_BalokB[25].VX, read_BalokB[25].VY, read_BalokB[25].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[28].X, TK_BalokB[28].Y);
    glVertex3f(read_BalokB[26].VX, read_BalokB[26].VY, read_BalokB[26].VZ);

    glTexCoord2f(TK_BalokB[31].X, TK_BalokB[31].Y);
    glVertex3f(read_BalokB[21].VX, read_BalokB[21].VY, read_BalokB[21].VZ);

    glTexCoord2f(TK_BalokB[30].X, TK_BalokB[30].Y);
    glVertex3f(read_BalokB[27].VX, read_BalokB[27].VY, read_BalokB[27].VZ);

    glTexCoord2f(TK_BalokB[29].X, TK_BalokB[29].Y);
    glVertex3f(read_BalokB[28].VX, read_BalokB[28].VY, read_BalokB[28].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[0].X, TK_BalokB[0].Y);
    glVertex3f(read_BalokB[27].VX, read_BalokB[27].VY, read_BalokB[27].VZ);

    glTexCoord2f(TK_BalokB[1].X, TK_BalokB[1].Y);
    glVertex3f(read_BalokB[28].VX, read_BalokB[28].VY, read_BalokB[28].VZ);

    glTexCoord2f(TK_BalokB[2].X, TK_BalokB[2].Y);
    glVertex3f(read_BalokB[29].VX, read_BalokB[29].VY, read_BalokB[29].VZ);

    glTexCoord2f(TK_BalokB[3].X, TK_BalokB[3].Y);
    glVertex3f(read_BalokB[30].VX, read_BalokB[30].VY, read_BalokB[30].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[28].X, TK_BalokB[28].Y);
    glVertex3f(read_BalokB[29].VX, read_BalokB[29].VY, read_BalokB[29].VZ);

    glTexCoord2f(TK_BalokB[31].X, TK_BalokB[31].Y);
    glVertex3f(read_BalokB[30].VX, read_BalokB[30].VY, read_BalokB[30].VZ);

    glTexCoord2f(TK_BalokB[30].X, TK_BalokB[30].Y);
    glVertex3f(read_BalokB[24].VX, read_BalokB[24].VY, read_BalokB[24].VZ);

    glTexCoord2f(TK_BalokB[29].X, TK_BalokB[29].Y);
    glVertex3f(read_BalokB[31].VX, read_BalokB[31].VY, read_BalokB[31].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[16].X, TK_BalokB[16].Y);
    glVertex3f(read_BalokB[21].VX, read_BalokB[21].VY, read_BalokB[21].VZ);

    glTexCoord2f(TK_BalokB[17].X, TK_BalokB[17].Y);
    glVertex3f(read_BalokB[27].VX, read_BalokB[27].VY, read_BalokB[27].VZ);

    glTexCoord2f(TK_BalokB[18].X, TK_BalokB[18].Y);
    glVertex3f(read_BalokB[30].VX, read_BalokB[30].VY, read_BalokB[30].VZ);

    glTexCoord2f(TK_BalokB[19].X, TK_BalokB[19].Y);
    glVertex3f(read_BalokB[24].VX, read_BalokB[24].VY, read_BalokB[24].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[19].X, TK_BalokB[19].Y);
    glVertex3f(read_BalokB[26].VX, read_BalokB[26].VY, read_BalokB[26].VZ);

    glTexCoord2f(TK_BalokB[18].X, TK_BalokB[18].Y);
    glVertex3f(read_BalokB[28].VX, read_BalokB[28].VY, read_BalokB[28].VZ);

    glTexCoord2f(TK_BalokB[17].X, TK_BalokB[17].Y);
    glVertex3f(read_BalokB[29].VX, read_BalokB[29].VY, read_BalokB[29].VZ);

    glTexCoord2f(TK_BalokB[16].X, TK_BalokB[16].Y);
    glVertex3f(read_BalokB[31].VX, read_BalokB[31].VY, read_BalokB[31].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[32].X, TK_BalokB[32].Y);
    glVertex3f(read_BalokB[2].VX, read_BalokB[2].VY, read_BalokB[2].VZ);

    glTexCoord2f(TK_BalokB[33].X, TK_BalokB[33].Y);
    glVertex3f(read_BalokB[3].VX, read_BalokB[3].VY, read_BalokB[3].VZ);

    glTexCoord2f(TK_BalokB[34].X, TK_BalokB[34].Y);
    glVertex3f(read_BalokB[8].VX, read_BalokB[8].VY, read_BalokB[8].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[7].X, TK_BalokB[7].Y);
    glVertex3f(read_BalokB[3].VX, read_BalokB[3].VY, read_BalokB[3].VZ);

    glTexCoord2f(TK_BalokB[4].X, TK_BalokB[4].Y);
    glVertex3f(read_BalokB[4].VX, read_BalokB[4].VY, read_BalokB[4].VZ);

    glTexCoord2f(TK_BalokB[5].X, TK_BalokB[5].Y);
    glVertex3f(read_BalokB[13].VX, read_BalokB[13].VY, read_BalokB[13].VZ);

    glTexCoord2f(TK_BalokB[6].X, TK_BalokB[6].Y);
    glVertex3f(read_BalokB[8].VX, read_BalokB[8].VY, read_BalokB[8].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[37].X, TK_BalokB[37].Y);
    glVertex3f(read_BalokB[5].VX, read_BalokB[5].VY, read_BalokB[5].VZ);

    glTexCoord2f(TK_BalokB[36].X, TK_BalokB[36].Y);
    glVertex3f(read_BalokB[4].VX, read_BalokB[4].VY, read_BalokB[4].VZ);

    glTexCoord2f(TK_BalokB[35].X, TK_BalokB[35].Y);
    glVertex3f(read_BalokB[13].VX, read_BalokB[13].VY, read_BalokB[13].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[32].X, TK_BalokB[32].Y);
    glVertex3f(read_BalokB[9].VX, read_BalokB[9].VY, read_BalokB[9].VZ);

    glTexCoord2f(TK_BalokB[33].X, TK_BalokB[33].Y);
    glVertex3f(read_BalokB[10].VX, read_BalokB[10].VY, read_BalokB[10].VZ);

    glTexCoord2f(TK_BalokB[34].X, TK_BalokB[34].Y);
    glVertex3f(read_BalokB[14].VX, read_BalokB[14].VY, read_BalokB[14].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[7].X, TK_BalokB[7].Y);
    glVertex3f(read_BalokB[10].VX, read_BalokB[10].VY, read_BalokB[10].VZ);

    glTexCoord2f(TK_BalokB[4].X, TK_BalokB[4].Y);
    glVertex3f(read_BalokB[11].VX, read_BalokB[11].VY, read_BalokB[11].VZ);

    glTexCoord2f(TK_BalokB[5].X, TK_BalokB[5].Y);
    glVertex3f(read_BalokB[19].VX, read_BalokB[19].VY, read_BalokB[19].VZ);

    glTexCoord2f(TK_BalokB[6].X, TK_BalokB[6].Y);
    glVertex3f(read_BalokB[14].VX, read_BalokB[14].VY, read_BalokB[14].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[37].X, TK_BalokB[37].Y);
    glVertex3f(read_BalokB[12].VX, read_BalokB[12].VY, read_BalokB[12].VZ);

    glTexCoord2f(TK_BalokB[36].X, TK_BalokB[36].Y);
    glVertex3f(read_BalokB[11].VX, read_BalokB[11].VY, read_BalokB[11].VZ);

    glTexCoord2f(TK_BalokB[35].X, TK_BalokB[35].Y);
    glVertex3f(read_BalokB[19].VX, read_BalokB[19].VY, read_BalokB[19].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[32].X, TK_BalokB[32].Y);
    glVertex3f(read_BalokB[15].VX, read_BalokB[15].VY, read_BalokB[15].VZ);

    glTexCoord2f(TK_BalokB[33].X, TK_BalokB[33].Y);
    glVertex3f(read_BalokB[16].VX, read_BalokB[16].VY, read_BalokB[16].VZ);

    glTexCoord2f(TK_BalokB[34].X, TK_BalokB[34].Y);
    glVertex3f(read_BalokB[20].VX, read_BalokB[20].VY, read_BalokB[20].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[7].X, TK_BalokB[7].Y);
    glVertex3f(read_BalokB[16].VX, read_BalokB[16].VY, read_BalokB[16].VZ);

    glTexCoord2f(TK_BalokB[4].X, TK_BalokB[4].Y);
    glVertex3f(read_BalokB[17].VX, read_BalokB[17].VY, read_BalokB[17].VZ);

    glTexCoord2f(TK_BalokB[5].X, TK_BalokB[5].Y);
    glVertex3f(read_BalokB[25].VX, read_BalokB[25].VY, read_BalokB[25].VZ);

    glTexCoord2f(TK_BalokB[6].X, TK_BalokB[6].Y);
    glVertex3f(read_BalokB[20].VX, read_BalokB[20].VY, read_BalokB[20].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[37].X, TK_BalokB[37].Y);
    glVertex3f(read_BalokB[18].VX, read_BalokB[18].VY, read_BalokB[18].VZ);

    glTexCoord2f(TK_BalokB[36].X, TK_BalokB[36].Y);
    glVertex3f(read_BalokB[17].VX, read_BalokB[17].VY, read_BalokB[17].VZ);

    glTexCoord2f(TK_BalokB[35].X, TK_BalokB[35].Y);
    glVertex3f(read_BalokB[25].VX, read_BalokB[25].VY, read_BalokB[25].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[32].X, TK_BalokB[32].Y);
    glVertex3f(read_BalokB[21].VX, read_BalokB[21].VY, read_BalokB[21].VZ);

    glTexCoord2f(TK_BalokB[33].X, TK_BalokB[33].Y);
    glVertex3f(read_BalokB[22].VX, read_BalokB[22].VY, read_BalokB[22].VZ);

    glTexCoord2f(TK_BalokB[34].X, TK_BalokB[34].Y);
    glVertex3f(read_BalokB[26].VX, read_BalokB[26].VY, read_BalokB[26].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[7].X, TK_BalokB[7].Y);
    glVertex3f(read_BalokB[22].VX, read_BalokB[22].VY, read_BalokB[22].VZ);

    glTexCoord2f(TK_BalokB[4].X, TK_BalokB[4].Y);
    glVertex3f(read_BalokB[23].VX, read_BalokB[23].VY, read_BalokB[23].VZ);

    glTexCoord2f(TK_BalokB[5].X, TK_BalokB[5].Y);
    glVertex3f(read_BalokB[31].VX, read_BalokB[31].VY, read_BalokB[31].VZ);

    glTexCoord2f(TK_BalokB[6].X, TK_BalokB[6].Y);
    glVertex3f(read_BalokB[26].VX, read_BalokB[26].VY, read_BalokB[26].VZ);
    glEnd();

    glBegin(GL_POLYGON);
    glTexCoord2f(TK_BalokB[37].X, TK_BalokB[37].Y);
    glVertex3f(read_BalokB[24].VX, read_BalokB[24].VY, read_BalokB[24].VZ);

    glTexCoord2f(TK_BalokB[36].X, TK_BalokB[36].Y);
    glVertex3f(read_BalokB[23].VX, read_BalokB[23].VY, read_BalokB[23].VZ);

    glTexCoord2f(TK_BalokB[35].X, TK_BalokB[35].Y);
    glVertex3f(read_BalokB[31].VX, read_BalokB[31].VY, read_BalokB[31].VZ);
    glEnd();
}

Sampai Ketemu lagi di artikel berikutnya


Heriady
heriady.yoh@gmail.com


Download program tekstur balok bengkok 3D tinggal klik link ini, ngak usah repot-repot ngetik lagi.


Sumber
Artikel ini bersumber dari buku Pemrograman Grafik 3D menggunakan C & OpenGL, karangan Heriady (halaman 130 s/d 144)












Artikel terkait
Program balok 3D solid
Program pipa 3D solid
Program meja 3D
Program tangki air 3D