Dalam postingan kali ini, tim “BlenderTok!” akan mempersembahkan sebuah review tentang physic engine dari Blender. Tentunya udah pada tau kan, apa itu Blender? Kalo blom, coba jalan2 ke sini dulu. Kalo udah tau ya, skip aja, langsung baca review dari kami. Review ini dibuat untuk mengabadikan presentasi kami di kuliah Realitas Virtual 2009 Jurusan Informatika ITS, semoga bisa bermanfaat buat yang baca.
Langsung aja, masuk ke pembahasan tentang game engine-nya dulu. Bahas yang umum dulu supaya gak berat di otak : D. Blender Game Engine ini punya kelebihan yang cukup menonjol dibandingkan kompetitornya, yaitu GRATIS! Developer, terutama para hobyist ataupun developer game kecil-kecilan gak perlu menguras kantong buat bisa bikin game yang enjoyable. Fitur-fitur yang ada di Blender Game Engine adalah
Blender Creation Suite

Blender nyediain antarmuka yang lengkap. Kontrol-kontrol untuk animasi ataupun modelling bisa gampang diakses, ditambah lagi dengan gampangnya kostumasi antarmuka. Bentuk antarmuka yang “advanced” ini ditujukan buat mempermudah desainer yang biasa berkarya via GIMP / Photoshop bisa gampang adaptasi dengan Blender.
Blender 3D Modelling

Blender ngedukung banyak operasi modelling 3D. Mau buat polygon, NURBS surface, kurva bezier, b-spline, vector fonts, dll bisa dibuat via Blender, hebatnya lagi, Blender juga nyediakan mode editing model, contohnya extrude, screw, warp, subdivide, noise & smooth.
Blender 3D Animation

Fitur animasi yang ada di blender juga gak bisa dipandang sebelah mata. Blender punya fitur animasi skeleton deformation with forward/inverse kinematics, auto skinning, interactive vertex 3D paint, morphing vertex keyframe, animatable lattice deformation, dan non-linear animation mixing dipadu dengan pathtracking otomatis. Buat animasinya, blender nyediakan mode WYSIWYG (What You See Is What You Get) dan mode scripting via Phyton.
Blender Game Creation

Seperti udah dibilang di atas kalo Blender ini gak bisa dipandang sebelah mata, fitur-fitur buat game creation dikemas bisa dibilang sangat mumpuni. Blender Game Engine punya fitur-fitur
- Graphical Editors (WYSIWYG)
- Collision Detection
- Dynamics Simulation
- Python Scripting
- Scene Multi-Layering
- Overlays
- Game Logic
- Artificial Intelligence
- Physics
- Input
- Output
- 3D Rendering
Setelah bahas fitur-fitur Blender Game Engine, sekarang waktunya bahas tentang Physic Engine yang ada di BGE. BGE punya Physic Engine yang namanya Bullet Physic. Bullet Physic punya beberapa bounding surface, jadi objek yang dibuat bisa lebih variatif & collision boundarynya lebih fleksibel. Bound surface di BP (Bullet Physic) adalah
- Box
- Sphere
- Convex Hull
- Cylinder
- Cone
- Static Triangle Mesh
Untuk deteksi tabrakan / sentuhan dengan benda-benda disekitar objek, BP ngandalin 3 cara collision detection, yaitu
- Ray Sensor
- Near Sensor
- Collision Sensor
Di bawah ini, contoh Phyton script yang dipake buat logic di BGE
cont = GameLogic.getCurrentController( )
player = cont.getOwner()
remote = cont.getActuator("Remote").getOwner()
mousemove = cont.getSensor('mousemove')
remori = remote.getOrientation()
player.setOrientation(remori)
if player.init == 0:
player.initx = mousemove.getXPosition()
player.inity = mousemove.getYPosition()
player.init = 1
player.mousex = 0.0
player.mousey = 0.0
if player.init == 1 and mousemove.isPositive():
from Rasterizer import setMousePosition
shoulderipo = cont.getActuator('shoulderipo')
playerrot = cont.getActuator("Remote")
shoulder = shoulderipo.getOwner()
nmousex = mousemove.getXPosition() - player.initx
nmousey = mousemove.getYPosition() - player.inity
player.mousex= player.mousex + (float(nmousex) - player.mousex) * player.mousefilter
player.mousey= player.mousey + (float(nmousey) - player.mousey) * player.mousefilter
setMousePosition(player.initx, player.inity)
remote.rot -= (player.mousex * player.sensitivity)
shoulder.pitch -= (player.mousey * player.sensitivity)
GameLogic.addActiveActuator(playerrot, 1)
GameLogic.addActiveActuator(shoulderipo, 1)
cont = GameLogic.getCurrentController()
own = cont.getOwner()
camown = GameLogic.getCurrentScene().getObjectList()["OBcamera0"]
lmb = cont.getSensor("fire")
ray_all = cont.getSensor("ray_all")
add_force = cont.getActuator("add_force")
forceobj = add_force.getLastCreatedObject()
if own.force and ray_all.isPositive():
hit_pos = ray_all.getHitPosition()
forceobj.setOrientation(camown.getOrientation())
forceobj.setPosition(hit_pos)
own.force = 0
apply_force = ray_all.isPositive() and lmb.isPositive()
if apply_force:
GameLogic.addActiveActuator(add_force, 1)
own.force = 1
cont = GameLogic.getCurrentController()
own = cont.getOwner()
ownAmmo = GameLogic.getCurrentScene().getObjectList()["OBAmmo"]
ownMags = GameLogic.getCurrentScene().getObjectList()["OBMags"]
endmag = cont.getSensor("endmag")
lclick = cont.getSensor("lclick")
shoot = cont.getSensor("fire")
R = cont.getSensor("R")
recoil = cont.getActuator("recoil")
fire = cont.getActuator("fire")
trigger = cont.getActuator("trigger")
magspawn = cont.getActuator("magspawn")
if endmag.isPositive():
ownMags.Text += 1
if ownAmmo.Text > 0 and lclick.isPositive():
GameLogic.addActiveActuator(trigger, 1)
if shoot.isPositive():
ownAmmo.Text -= 1
GameLogic.addActiveActuator(recoil, 1)
GameLogic.addActiveActuator(fire, 1)
if ownMags.Text > 0 and ownAmmo.Text < 1 and R.isPositive():
ownMags.Text -= 1
ownAmmo.Text = 50
GameLogic.addActiveActuator(recoil, 1)
GameLogic.addActiveActuator(magspawn, 1)
cont = GameLogic.getCurrentController()
own = cont.getOwner()
g1 = cont.getSensor("g1").isPositive()
g2 = cont.getSensor("g2").isPositive()
g3 = cont.getSensor("g3").isPositive()
g4 = cont.getSensor("g4").isPositive()
jump = cont.getSensor("Space")
fwd = cont.getSensor("W")
back = cont.getSensor("S")
slft = cont.getSensor("A")
srght = cont.getSensor("D")
shift = cont.getSensor("shift")
lctrl = cont.getSensor("lctrl")
act = cont.getActuator("floormove")
crouch = cont.getActuator("crouch")
idle = cont.getActuator("idle")
run = cont.getActuator("run")
ownc = crouch.getOwner()
speed = 6
jspeed = 0
sqrt2over2 = 0.70710678
if g1 or g2 or g3 or g4:
if lctrl.isPositive():
speed = 2
if ownc.frame < 20:
ownc.frame += 1
GameLogic.addActiveActuator(crouch, 1)
if not lctrl.isPositive() and ownc.frame > 1:
ownc.frame -= 1
GameLogic.addActiveActuator(crouch, 1)
else:
GameLogic.addActiveActuator(crouch, 0)
if shift.isPositive():
speed = 3
fspeed = speed * (fwd.isPositive() - back.isPositive())
sspeed = speed * (srght.isPositive() - slft.isPositive())
if fspeed and sspeed:
fspeed *= sqrt2over2
sspeed *= sqrt2over2
if own.rel == 0:
fspeed = 0
sspeed = 0
if not jump.isPositive():
own.jstate = 1
if jump.isPositive() and own.jstate == 1:
jspeed = 6
own.jstate = 0
own.rel = 0
act.setLinearVelocity(sspeed, fspeed, jspeed, 1)
if [sspeed, fspeed, jspeed] == [0, 0, 0]:
GameLogic.addActiveActuator(idle, 1)
GameLogic.addActiveActuator(run, 0)
GameLogic.addActiveActuator(act, 0)
else:
if (lctrl.isPositive() + shift.isPositive() + jspeed) == 0:
GameLogic.addActiveActuator(idle, 0)
GameLogic.addActiveActuator(run, 1)
else:
GameLogic.addActiveActuator(idle, 1)
GameLogic.addActiveActuator(run, 0)
GameLogic.addActiveActuator(act, 1)
else:
GameLogic.addActiveActuator(act, 0)
own.rel = 1
from math import sin, cos, sqrt
def VEC_length(x):
return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])
def VEC_normalize(x):
length = VEC_length(x)
return [x[0]/length,x[1]/length,x[2]/length]
def VEC_cross(x, y):
return [x[1]*y[2] - x[2]*y[1],
x[2]*y[0] - x[0]*y[2],
x[0]*y[1] - x[1]*y[0]]
def VEC_min(x, y):
return [x[0] - y[0], x[1] - y[1], x[2] - y[2]]
def MAT_trackvector(fw, y):
if abs(abs(fw[2]) - abs(y[2])) < .001:
y.append(y[0])
del y[0]
right = VEC_normalize(VEC_cross(y, fw))
up = VEC_cross(fw, right)
return [[right[0], up[0], fw[0]],
[right[1], up[1], fw[1]],
[right[2], up[2], fw[2]]]
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
ray_sensor = cont.getSensor("ray_bullet")
lmb_sensor = cont.getSensor("fire")
add_bullet_act = cont.getActuator("add_bullet")
newobj = add_bullet_act.getLastCreatedObject()
if obj.ebhole and ray_sensor.isPositive():
hit_pos = ray_sensor.getHitPosition()
hit_norm = ray_sensor.getHitNormal()
newobj.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
newobj.setPosition(hit_pos)
obj.ebhole = 0
make_bullet = ray_sensor.isPositive() and lmb_sensor.isPositive()
if make_bullet:
GameLogic.addActiveActuator(add_bullet_act, 1)
obj.ebhole = 1
Kalo mau file yang kami pakai demo, bisa download di sini.
Supported by Studio Asiah dot Com & KemasDimas.Com : Catatan Harian Untuk Berbagi
-7.287243
112.739048