1. abrie
  2. devderby-may-2013

Commits

abrie  committed 206a7de

create sensor cluster for door bodies

  • Participants
  • Parent commits 0d9cf3a
  • Branches master

Comments (0)

Files changed (1)

File body.js

View file
  • Ignore whitespace
         fixtureDef.set_restitution( 0.5 );
         fixtureDef.set_density( 1.0 );
         var fixture = body.CreateFixture( fixtureDef );
-        //var fixture = body.CreateFixture(shape, 1.0);
         body.SetFixedRotation(false);
         return {body:body, fixture:fixture};
     }
 
     var createDoor = function(world, x, y, userData) {
-        var shape = new Box2D.b2CircleShape();
-        shape.set_m_radius(0.25);
         var bd = new Box2D.b2BodyDef();
         bd.set_type(Box2D.b2_staticBody);
         bd.set_position( new Box2D.b2Vec2(x,y) );
         var body = world.CreateBody(bd);
         body.userData = userData;
-        var fixture = body.CreateFixture(shape, 5.0);
-        fixture.SetSensor(true);
-        return {body:body, fixture:fixture};
+
+        var makeSensor = function(radius,theta) {
+            var shape = new Box2D.b2CircleShape();
+            shape.set_m_p(new Box2D.b2Vec2(radius*Math.cos(theta),radius*Math.sin(theta)));
+            shape.set_m_radius(0.25);
+            var fixture = body.CreateFixture(shape, 5.0);
+            fixture.SetSensor(true);
+        }
+
+        var steps = 5;
+        var radius = 1.50;
+        for(var a=0;a<steps;a++) {
+            var theta = 2*Math.PI/steps*a;
+            makeSensor( radius, theta ); 
+            makeSensor( radius/2, theta ); 
+        }
+
+        return {body:body, fixture:undefined};
     }
 
     return {