c++ - Writing 'ON' Events for Physics Engine -


i'm writing 2d physics engine in oop. , wondering how can create sort of "ontouchstart" or "ontouchend" event system physical objects in space?

and yes know there box2d , others, want in house since game going basic collision checking. plus see way learn new.

anyway, have code....

void phphysics::step(float delta) {     int objectcount = m_objects.size();      (int = 0; < objectcount; ++i)     {         phphysicsobject* obj = m_objects.at(i);          /* update positon of object. */         obj->update(delta);          if(!obj->issleep())             checkforcollisions(obj);     } }  void phphysics::checkforcollisions(phphysicsobject* object) {     int objectcount = m_objects.size();      (int = 0; < objectcount; ++i)     {         phphysicsobject* obj = m_objects.at(i);          if(object == obj)             continue;          if(iscolliding(object, obj))             obj->ontouchstart(object);     } } 

as can see have ontouchstart event, of course going continuously trigger on "ontouchstart". how have trigger 'once' on collision , once on touch end? thought of doing array of objects touching each other, don't know if works well.

i think works well. in phphysicsobject can have array of objects (or id if have one, save memory), everytime ontouchstart called, can check if object in it, if not, have new object colliding. if is, stop, because function called object. , ontouchend remove object array.


Comments