Apa kabar nih...
Oke deh, kali ini aku mau share Kode Basic4GL Membuat Truk. Yaa itung-itung tugasku kuliah Desain Grafis.
Maklum yaa kalo masih sangat minim, soalnya aku masih newbie ngambil desain grafis ini. OKe langsung disimak aja yaa
Kodenya :
dim a#, b#
dim x1#(1),y1#,z1#(1),x2#(1),y2#,z2#(1)
dim tex1,tex2,tex3,tex4
dim angle#
dim sd#(3)
dim i#,j#
dim n#,n2#
dim xx#(1),yy#(1)
dim texture(3)
dim r#,rk#(1)
dim rkk#(1)
dim phi#
phi#=3.14
gosub main
Bola:
n# = 30
n2#=n#/2
glBegin(GL_quads)
for i#=0 to n#-1
for j# = 0 to n#-1
rk#(0)=r#*Cos(-(PHI#/2)+i#/n2#*PHI#/2)
rk#(1)=r#*Cos(-(PHI#/2)+(i#+1)/n2#*PHI#/2)
y1#= r#*sin(-(PHI#/2)+i#/n2#*PHI#/2)
y2#= r#*sin(-(PHI#/2)+(i#+1)/n2#*PHI#/2)
x1#(0)= rk#(0)*sin(j#/n2#*PHI#) 'theta/(2*phi)
x1#(1)= rk#(0)*sin((j#+1)/n2#*PHI#) 'theta/(2*phi)
x2#(0)= rk#(1)*sin(j#/n2#*PHI#) 'theta/(2*phi)
x2#(1)= rk#(1)*sin((j#+1)/n2#*PHI#) 'theta/(2*phi)
z1#(0)= rk#(0)*cos(j#/n2#*PHI#) 'theta/(2*phi)
z1#(1)= rk#(0)*cos((j#+1)/n2#*PHI#) 'theta/(2*phi)
z2#(0)= rk#(1)*cos(j#/n2#*PHI#) 'theta/(2*phi)
z2#(1)= rk#(1)*cos((j#+1)/n2#*PHI#) 'theta/(2*phi)
glTexCoord2f(xx#(0), yy#(0)) 'koordinat penempatan tekstur bola(x,y)
glVertex3f( x1#(0), y1#,z1#(0)) 'p(0,y)=(rsin0,y,rcos0)
glTexCoord2f(xx#(1), yy#(0)) 'koordinat penempatan tekstur(x,y)
glVertex3f(x1#(1),y1#,z1#(1))
glTexCoord2f(xx#(1), yy#(1)) 'koordinat penempatan tekstur(x,y)
glVertex3f( x2#(1), y2#,z2#(1))
glTexCoord2f(xx#(0), yy#(1)) 'koordinat penempatan tekstur(x,y)
glVertex3f(x2#(0),y2#,z2#(0))
next
next
glEnd()
Return
main:
while true
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity ()
glTranslatef (-20, 0, -30)
glRotatef (0, 0, 0, 1)
glBegin (GL_QUADS)
glcolor3f (1, 1, 1)
glVertex2f (-0.8, -2): 'lampu
glVertex2f (3, -2):
glVertex2f (3, 4):
glVertex2f (-0.8, 4)
glend()
glLoadIdentity ()
glTranslatef (-20, 0, -30)
glRotatef (0, 0, 0, 1)
glcolor3f (1, 0, 0)
glBegin (GL_QUADS) 'bemper
glVertex2f (-1, 1):
glVertex2f (-1, -2):
glVertex2f (0, -3):
glVertex2f (0, 0)
glVertex2f (0, -3):
glVertex2f (0, 0)
glVertex2f (2, 0):
glVertex2f (2, -3)
glEnd ()
glLoadIdentity ()
glTranslatef (-20, 0, -30)
glRotatef (0, 0, 0, 1)
glbegin(gl_triangles) 'kcdpan
glvertex2f (-0.8, 4)
glvertex2f (5.8, 4)
glvertex2f (1, 10)
glend()
glLoadIdentity ()
glTranslatef (-20, 0, -30)
glRotatef (0, 0, 0, 1)
glBegin (GL_QUADS)
glVertex2f (1, 10):
glVertex2f (10, 11.8): 'atap
glVertex2f (10, 0):
glVertex2f (1, 0)
glend ()
glLoadIdentity ()
glTranslatef (-19, 0, -30)
glRotatef (0, 0, 0, 1)
glcolor3f(0, 0, 0)
glbegin(gl_triangles) 'kc smping
glvertex2f (-0.8, 4)
glvertex2f (2.8, 5)
glvertex2f (0.8, 9.8)
glend()
glLoadIdentity ()
glTranslatef (-19, 0, -30)
glRotatef (0, 0, 0, 1)
glBegin (GL_QUADS)
glvertex2f (-0.8, 4)
glvertex2f (0.8, 9.8) 'kcsmping
glVertex2f (8, 10.5):
glVertex2f (8, 6.5)
glend ()
glLoadIdentity ()
glTranslatef (-8, 0, -30)
glRotatef (0, 0, 0, 1)
glBegin (GL_QUADS)
glcolor3f (1, 1, 1)
glvertex2f (-1, -1):
glvertex2f (27, -1): 'bak miring 1
glvertex2f (28, 2):
glvertex2f (1, 2)
glvertex2f (-1, -1):
glvertex2f (1, 2): 'bak miring 2
glvertex2f (1, 14):
glvertex2f (-1, 11)
glcolor3f (1,0,0)
glVertex2f (-1, 14):
glVertex2f (-1, -1): 'bak berdiri
glVertex2f (0, -1):
glVertex2f (0, 14)
glvertex2f (1, 2):
glvertex2f (2, 2): 'bak berdiri2
glvertex2f (2, 17):
glvertex2f (1, 17)
glvertex2f (-1, -1):
glvertex2f (27, -1):
glvertex2f (27, 0): 'bak memnjng1
glvertex2f (-1,0)
glvertex2f (27, -1):
glvertex2f (27,0):
glvertex2f (28, 3):
glvertex2f (28, 2) 'bakmemnjng2
glvertex2f (28, 3):
glvertex2f (28, 2): 'bak memnjg3
glvertex2f (2, 2):
glvertex2f (2, 3)
glEnd ()
glLoadIdentity ()
glTranslatef (0, b#+0.5, -13)
glRotatef (0, 0, 0, 1)
glcolor3f (0.3, 0.1, 0)
glBegin (GL_QUADS)
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5): 'balok 1
glVertex2f (5, -0.5):
glVertex2f (5, 0.5):
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5):
glvertex2f (-0.5, 0):
glvertex2f (-0.5, 1):
glvertex2f (-0.5, 0):
glvertex2f (-0.5, 1):
glvertex2f (5.5, 1):
glvertex2f (5.5, 0):
glvertex2f (5.5, 1):
glvertex2f (5.5, 0):
glvertex2f (5, -0.5):
glvertex2f (5, 0.5):
glvertex2f (5, -0.5):
glvertex2f (5, 0.5):
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5):
glEnd ()
glLoadIdentity ()
glTranslatef (0, a#+2, -13)
glRotatef (0, 0, 0, 0)
glcolor3f (0.3, 0.1, 0)
glBegin (GL_QUADS)
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5): 'balok 2
glVertex2f (5, -0.5):
glVertex2f (5, 0.5):
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5):
glvertex2f (-0.5, 0):
glvertex2f (-0.5, 1):
glvertex2f (-0.5, 0):
glvertex2f (-0.5, 1):
glvertex2f (5.5, 1):
glvertex2f (5.5, 0):
glvertex2f (5.5, 1):
glvertex2f (5.5, 0):
glvertex2f (5, -0.5):
glvertex2f (5, 0.5):
glvertex2f (5, -0.5):
glvertex2f (5, 0.5):
glVertex2f (-1, 0.5):
glVertex2f (-1, -0.5):
glEnd ()
glLoadIdentity()
glTranslatef(-2.4,-0.7,-5.5)
glRotatef (0, 0, 1, 0) 'ban1
glcolor3f (1, 1, 1)
r#=.5
gosub bola
glLoadIdentity()
glTranslatef(2,-0.7,-5.5)
glRotatef (0, 0, 1, 0) 'ban2
glcolor3f (1, 1, 1)
r#=.5
gosub bola
SwapBuffers ()
angle# = angle# + 0.1
while SyncTimer (10)
if ScanKeyDown (VK_LEFT) then a# = a# + 0.1 : endif
if ScanKeyDown (VK_RIGHT) then a# = a# - 1: endif
if scankeydown (VK_up) then b# = b# + 0.1: endif
if scankeydown (VK_down) then b# = b# - 1 : endif
wend
wend
Kode diatas udah beserta tombol geraknya, jadi kalo ditekan tombol kebawah, dan tombol kekanan, maka balok yang ada diatas truk akan jatuh kebawah.
Dan kalo ditekan tombol keatas dan kekiri, maka balok itu bisa kembali keatas truk lagi..
ini penampakannya:
Silahkan yang mau soft filenya, klik Disini sobat
Tata Cara Berkomentar yang Baik dan Benar :
1. Gunakan Bahasa yang Sopan.
2. Biasakanlah berkomentar sebelum meninggalkan.
3. Usahakan jangan menggunakan anonymous
4. Saya sangat berterima kasih atas komentar yang kalian berikan
5. Admin selalu berusaha melakukan yang terbaik untuk para pengunjung ConversionConversion EmoticonEmoticon