140 likes | 307 Vues
Collition Detection. Agung Toto Wibowo http://gameprogramming.blog.ittelkom.ac.id. Pendahuluan. Collision detection komponen dasar dari game 3D/2D. Tanpa Collision detection, karakter mungkin saja menembus walls atau halangan lain. Aksi yang terjadi setelah collision detection :
E N D
Collition Detection Agung Toto Wibowo http://gameprogramming.blog.ittelkom.ac.id
Pendahuluan • Collision detection komponendasardari game 3D/2D. • Tanpa Collision detection, karaktermungkinsajamenembus walls atauhalangan lain. • Aksi yang terjadisetelah collision detection : • Rule • Collision response
Basic Game Loop while(1){ process_input(); update_objects(); render_world(); } update_objects(){ for (each_object) save_old_position(); calc new_object_position {based on velocity accel. etc.} if (collide_with_other_objects()) new_object_position = old_position(); {or if destroyed object remove it etc.} }
Rectangles collision detection • menggukan bound berbentukpersegi • Objekmemilikiruangkosong yang besardengan bound • Terkadangtidaktabrakandianggaptabrakan • boolIsSeparate( const CBox& box1, const CBox& box2 ) • { • if ( ( box1.xMin > box2.xMax ) || • ( box2.xMin > box1.xMax ) || • ( box1.yMin > box2.yMax ) || • ( box2.yMin > box1.yMax ) ) • { • return true; • } • else • { • return false; • } • }
Reduced size bounding box • kotakbatasnyadiperkecil : mengurangiukuran sprite sebenarnya • ruangkosongdapatdikurangi
Multi Bounding Box • menggunakanbeberapa bounding box secarabersamaanpada sprite atauobjek • ruangkosonglebihdapatdikurangilagi • Konsekuensiwaktulebih lama
Circle collision detection • batasberbentuklingkaran • Membandingkanjarakkeduaobjekdenganjumlah radius masing-masing bound • (ax-bx)2+(ay-by)2 < (ar+br)2
PerpotonganGaris • Note : Atw Issues • Objekakanbertabrakanjikaadagaris yang berpotongan. • Algortima ???
Total Sudut • Perhatikansifatdari point yang adadidalamruangan • Total sudut = 360°
3D Collision Detection • HOW???? • Rectangles collision detection • Reduced size bounding box • Multi Bounding Box • Circle collision detection • PerpotonganGaris • Total Sudut
Collision Response • Rule • Batalkanpergerakan • Object mati/menghilang • Momentum • Kekekalanenergikinetik (hukumnewton) • Elastisitas
Momentum • Contohpadatabrakanmobil/motor/bola • Sumber : http://en.wikipedia.org/wiki/Elastic_collision
Momentum • Untuk 2D/3D
Diskusi • Pseudo code algorithm??? • Problem??? • Answer??? • Dimana collision detection pada game anda?