Monday 15 June 2015

collision detection - physics engine - phase order and other general information -



collision detection - physics engine - phase order and other general information -

i want build own 2d mini-physics engine, include(for now) stiff bodys, , constraints (joints, contacts, springs...). , i've tried figure out right order of phases, when start timestep, when the general phases are: broadphase, narrow phase(collision detection, , contact generation), resolution (constraints solver), , integration - hope can tell me right order.

i allso have general questions each phase:

narrow phase - when i've found collision need seperate bodies after i've found collision or apply impulse velocities in resolution phase?

and if i'm using ccd(continuous collision detection) bodies, happand if i've found collision (the earliest object a) of fast moving object other object b, , found object b collide other object c before object collide object a, need go object , looking other collisions after first collision i've found him?

and if i'm using contact solver in engine (in constraints solver, i'll generat contact constraints each collision, , i'll solve in resolution phase, or i'll solve each contact right after i've found them in narrow phase?

resolution - using constaints solver resolution phase ok? , if solving 1 constraint i'll solve other constraints or create more constraints? (do need check after each constraints solving if solves other constraints or create more?

intefration - part take info gathered (impulses, forces..) , intefrate them velocity , position integration method chose?

a symplectic euler integration plenty physics engine?

and alsso saw in many physics engines, box2d, utilize iterations , allow me chose frequncy here (notice can alter iteration count (10) , frequency (60.0 hz)):

what variables means? iterations how many times recall physics update(all phases above) in each frame, or recall 1 phase narrow phase or somthing that? , frequency variable allow me chose how many frames there in 1 second? right me if i'm worng please.

all qeustions above me stack learning because basics things, , didnt found place explain things in clean , strait forward

so read of that, , help me of questions :)

the order of phases not important. yes mess each other dis-function can corrected adjusting constants ...

getting started

you should start object representation , visualization prior simulation code. need able visualize stuff can see if ok or not

object classes

so create class(es) object types want back upwards , add together few basic interface functions (virtual base of operations class thought future implementation) like:

load(file,ini,stream...),save(file,ini,stream...) draw(screen or render context),update(dt),bool colide(object),etc...

in time see need add together ... empty (instead draw need code...). can prepare few mutual physics variables (also virtual) position, speed, temperature,...

base class

it should encapsulation of engine. hold lists of objects/stuff. main interface gui/app. more insight of mean here drag&drop editor in c++ can utilize start point add together physics iteration/update it. not forget implement object interface main class like:

load(filename) ... load objects draw(...) ... draws objects ...

simulation

start if above working. need take business relationship accuracy , response time want achieve. more fast object/processes higher simulation loop frequency need. mine simulations utilize 1-100 ms per iteration. fast simulation can n iterations per 1 timer call. meaning of count , frequency. frequency timer phone call speed iteration loop called , count (n) time step dt partition if n=10 , f=60hz means iterate 10 times every 1/60 seconds same n=1 f=600hz @ to the lowest degree in windows timer resolution 1 ms , not precise ether. frequencies above 100 hz unreliable. if want more precise can measure time via performancecounter or rdtsc or precise plenty time api have @ disposal.

you can utilize d'lambert principle (simple integration) simulation of motions rest compute known equations (do not know of want simulate). illustration here simple mass points gravity simulation in 3d (c++)

if code written can parallelize iteration loop have take in mind can create few troubles double collision reaction,etc

collisions

there tons of stuff here on so/se search it. think should here: simulation of particle collisions thought of multiple collisions handling.

to thought here illustration of how 1 of mine simulations looks like

it uses stuff wrote here , in add-on uses special class bonds springs or joints. how looks like:

struct _bond { physics_point *pnt0,*pnt1; double l0,l1; int _beg0,_end0; int _beg1,_end1; list<int> depend0,depend1; int _computed; _bond() {} _bond(_bond& a) { *this=a; } ~_bond() {} _bond* operator = (const _bond *a) { *this=*a; homecoming this; } //_bond* operator = (const _bond &a) { ...copy... homecoming this; } }; list<_bond> bnds;

i cover whole book stuff behind lazy , site not right place in hurry of import stuff each bond has start , end object pointer (pnt0,pnt1) , during computations filled dependency lists (depend0,depend1).

depend0 consequential bonds pnt0 side depend1 consequential bonds pnt1 side.

then during each iteration recursively updated bonds match bond/collision conditions when positions updated @ 1 time of them.

_computed flag announce bond ok (conditions met).

the rest temp variables ease burden on recursion heap/stack trashing

collision-detection game-engine physics game-physics physics-engine

No comments:

Post a Comment