Exemplo n.º 1
0
 STARTDECL(ph_particlecontacts) (VM &vm, Value &id) {
     CheckPhysics();
     auto &po = GetObject(vm, id);
     if (!po.particle_contacts) po.particle_contacts = new vector<int>();
     auto numelems = (int)po.particle_contacts->size();
     auto v = vm.NewVec(numelems, numelems, TYPE_ELEM_VECTOR_OF_INT);
     for (int i = 0; i < numelems; i++) v->At(i) = Value((*po.particle_contacts)[i]);
     return Value(v);
 }
Exemplo n.º 2
0
 STARTDECL(ph_raycast) (VM &vm, Value &p1, Value &p2, Value &n) {
     CheckPhysics();
     auto p1v = ValueDecToB2(vm, p1);
     auto p2v = ValueDecToB2(vm, p2);
     auto v = vm.NewVec(0, max(n.ival(), (intp)1), TYPE_ELEM_VECTOR_OF_INT);
     if (!particlesystem) return Value(v);
     struct callback : b2RayCastCallback {
         LVector *v;
         VM &vm;
         float ReportParticle(const b2ParticleSystem *, int i, const b2Vec2 &, const b2Vec2 &,
                              float) {
             v->Push(vm, Value(i));
             return v->len == v->maxl ? -1.0f : 1.0f; 
         }
         float ReportFixture(b2Fixture *, const b2Vec2 &, const b2Vec2 &, float) {
             return -1.0f;
         }
         callback(LVector *_v, VM &vm) : v(_v), vm(vm) {}
     } cb(v, vm);
     particlesystem->RayCast(&cb, p1v, p2v);
     return Value(v);
 }