Persegi terpotong oleh lingkaran OpenGL (Square Cut Off By Circle OpenGL)

Persegi terpotong oleh lingkaran OpenGL (Square Cut Off By Circle OpenGL)

Hay presser, di post kali ini aku bakal ceritain nih bagaimana cara membuat suatu persegi dimana persegi tersebut terpotong sebagian oleh lingkaran . Oke langsung aja….

public static void kubusTerpotong(GL gl,double sudutAwal,double sudutAkhir, double length,double radius,double height){
        //height disini adalah ketebalan
        double XsudutAwal,YsudutAwal,XsudutAkhir,YsudutAkhir;
        double DerajaSudutAwal=sudutAwal*phi/180,DerajaSudutAkhir=sudutAkhir*phi/180;
        XsudutAwal=Math.cos(DerajaSudutAwal)*radius;
        YsudutAwal=Math.sin(DerajaSudutAwal)*radius+radius;

        XsudutAkhir=Math.cos(DerajaSudutAkhir)*radius;
        YsudutAkhir=Math.sin(DerajaSudutAkhir)*radius+radius;
        //penutup atas bawah
        gl.glPushMatrix();
           gl.glTranslated(0,Math.abs(YsudutAwal-YsudutAkhir),0);//translated ke atas
           gl.glRotated(90,1,0,0);
            gl.glColor3d(1,0,1);
            gl.glTranslated(XsudutAwal,0,0);
            persegi(gl, length-XsudutAwal, height);//persegi atas
            gl.glTranslated(-XsudutAwal,0,0);

            gl.glColor3d(1,0.3,0);
            gl.glTranslated(0,0,Math.abs(YsudutAwal-YsudutAkhir));
            gl.glTranslated(XsudutAkhir,0,0);
            persegi(gl, length-XsudutAkhir, height);//persegi atas
            gl.glTranslated(-XsudutAkhir,0,0);
        gl.glTranslated(0,0,length);
        gl.glPopMatrix();

    // penutup belakang
        gl.glPushMatrix();
            gl.glColor3d(0,0.3,1);

            gl.glTranslated(length,0,0);
            gl.glRotated(-90,0,1,0);
            persegi(gl,height,Math.abs(YsudutAwal-YsudutAkhir));
        gl.glPopMatrix();

        gl.glColor3d(0,0.3,0);
        persegiPotong(gl, sudutAwal, sudutAkhir, length, radius);
        gl.glTranslated(0,0,height);
        persegiPotong(gl, sudutAwal, sudutAkhir, length, radius);
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s