nuclear@6: #include nuclear@6: #include "sim.h" nuclear@6: nuclear@6: SimWorld::SimWorld() nuclear@6: : gravity(0, -9, 0) nuclear@6: { nuclear@6: damping = 0.005; nuclear@6: } nuclear@6: nuclear@6: void SimWorld::add_object(GObject *obj) nuclear@6: { nuclear@6: CoRigid *co = COCAST(CoRigid, obj->get_component("phys")); nuclear@6: if(co) { nuclear@6: add_rigid_body(co); nuclear@6: } else { nuclear@6: fprintf(stderr, "SimWorld::add_object: trying to add object without rigid body component\n"); nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: void SimWorld::add_rigid_body(CoRigid *co) nuclear@6: { nuclear@6: if(std::find(rigid.begin(), rigid.end(), co) == rigid.end()) { nuclear@6: rigid.push_back(co); nuclear@6: co->world = this; nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: void SimWorld::remove_object(GObject *obj) nuclear@6: { nuclear@6: CoRigid *co = COCAST(CoRigid, obj->get_component("phys")); nuclear@6: if(co) { nuclear@6: remove_rigid_body(co); nuclear@6: } else { nuclear@6: fprintf(stderr, "SimWorld::remove_object: failed to remove object without rigid body component\n"); nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: void SimWorld::remove_rigid_body(CoRigid *co) nuclear@6: { nuclear@6: std::list::iterator it = std::find(rigid.begin(), rigid.end(), co); nuclear@6: if(it != rigid.end()) { nuclear@6: rigid.erase(it); nuclear@6: } else { nuclear@6: fprintf(stderr, "SimWorld::remove_rigid_body: failed to remove missing rigid body\n"); nuclear@6: } nuclear@6: } nuclear@6: nuclear@6: void SimWorld::set_damping(float damping) nuclear@6: { nuclear@6: this->damping = damping; nuclear@6: } nuclear@6: nuclear@6: float SimWorld::get_damping() const nuclear@6: { nuclear@6: return damping; nuclear@6: } nuclear@6: nuclear@6: void SimWorld::set_gravity(const Vector3 &v) nuclear@6: { nuclear@6: gravity = v; nuclear@6: } nuclear@6: nuclear@6: const Vector3 &SimWorld::get_gravity() const nuclear@6: { nuclear@6: return gravity; nuclear@6: }