Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.BodyDef


    mouseTracing = false;
    mouseTracerPosition.setZero();
    mouseTracerVelocity.setZero();

    BodyDef bodyDef = new BodyDef();
    groundBody = m_world.createBody(bodyDef);

    init(m_world, false);
  }
View Full Code Here


    if (bomb != null) {
      m_world.destroyBody(bomb);
      bomb = null;
    }
    // todo optimize this
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(position);
    bd.bullet = true;
    bomb = m_world.createBody(bd);
    bomb.setLinearVelocity(velocity);
View Full Code Here

    if (deserialized) {
      return;
    }
    Body bodies[] = new Body[e_count];
    {
      BodyDef bd = new BodyDef();
      Body ground = getWorld().createBody(bd);

      EdgeShape shape = new EdgeShape();
      shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
      ground.createFixture(shape, 0.0f);
    }

    {
      CircleShape shape = new CircleShape();
      shape.m_radius = 1.0f;

      for (int i = 0; i < e_count; ++i) {
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.position.set(0.0f, 4.0f + 3.0f * i);

        bodies[i] = getWorld().createBody(bd);

View Full Code Here

   * @param life
   * @param weapons
   * @param weapon
   */
  public AbstractElement(Vec2 position, int category, int mask) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position = position;
   
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(1.1f, 1.1f);
View Full Code Here

    this.restituion = restitution;
   
    this.setGestureAllowance(ScaleProcessor.class, false);
    this.setGestureAllowance(RotateProcessor.class, false);
   
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(centerPoint.x /(float)worldScale, centerPoint.y /(float)worldScale);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = this.world.createBody(dymBodyDef);
   
    CircleDef circleDef = new CircleDef();
View Full Code Here

   
    Vector3D scaledPos = PhysicsHelper.scaleDown(centerPosition.getCopy(), scale);
//    PhysicsHelper.scaleDown(centerPosition, scale);
//    centerPosition.scaleLocal(1f/scale);
   
    BodyDef dymBodyDef = new BodyDef();
//    dymBodyDef.position = new Vec2(pos.x, pos.y);
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);//FIXME WORKS?
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
View Full Code Here

      pd.friction   = friction;
      pd.restitution   = restituion;
    }

    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);

    this.polyDefB4CreationCallback(pd); //FIXME TEST
   
    int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, body, pd);
    if (success != -1){
      System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
      body.setMassFromShapes();
      body.setUserData(this);
      this.setUserData("box2d", body);
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
    }else{
      System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
      GluTrianglulator triangulator = new GluTrianglulator(applet);
      List<Vertex> physicsTris = triangulator.tesselate(physicsVertices, GLU.GLU_TESS_WINDING_NONZERO);
      Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
      //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);

      //Cap the max triangles - dont use anymore triangles for the physics body..
      int cap = 400;
      if (triangulatedBodyVerts.length > cap){
        //System.err.println("OVER cap! -> capping!");
        Vertex[] tmp = new Vertex[cap];
        System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
        triangulatedBodyVerts = tmp;
      }

      //Create polygon body
      world.destroyBody(body);
      dymBodyDef = new BodyDef();
      dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
      this.bodyDefB4CreationCallback(dymBodyDef);
      body = world.createBody(dymBodyDef);
      for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
        //Create polygon definition
View Full Code Here

      pd.friction   = friction;
      pd.restitution   = restituion;
    }

    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
    this.polyDefB4CreationCallback(pd); //FIXME TEST
   
    int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, body, pd);
    if (success != -1){
      System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
      body.setMassFromShapes();
      body.setUserData(this);
      this.setUserData("box2d", body);
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
    }else{
      System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
      GluTrianglulator triangulator = new GluTrianglulator(this.getRenderer());
      List<Vertex> physicsTris = triangulator.tesselate(bodyVerts, GLU.GLU_TESS_WINDING_NONZERO);
      Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
      //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);

      //Cap the max triangles - dont use anymore triangles for the physics body..
      int cap = 400;
      if (triangulatedBodyVerts.length > cap){
        //System.err.println("OVER cap! -> capping!");
        Vertex[] tmp = new Vertex[cap];
        System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
        triangulatedBodyVerts = tmp;
      }

      //Create polygon body
      world.destroyBody(body);
      dymBodyDef = new BodyDef();
      dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
      this.bodyDefB4CreationCallback(dymBodyDef);
      body = world.createBody(dymBodyDef);
      for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
        //Create polygon definition
View Full Code Here

        pd.friction   = friction;
        pd.restitution   = restituion;
    }
     
    //Create polygon body
    BodyDef dymBodyDef = new BodyDef();
//    dymBodyDef.position = new Vec2(position.x /worldScale, position.y /worldScale);
    dymBodyDef.position = new Vec2(position.x , position.y );
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
//      GluTrianglulator triangulator = new GluTrianglulator(applet);
//    List<Vertex> physicsTris = triangulator.tesselate(vertices, GLU.GLU_TESS_WINDING_NONZERO);
//    Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
//    triangulator.deleteTess();
   
//    //Set the triangulated vertices as the polygons (mesh's) vertices
//    this.setGeometryInfo(new GeometryInfo(applet, triangulatedBodyVerts));
   
    //Decompose poly and add verts to phys body if possible
      int success = org.jbox2d.util.nonconvex.Polygon.decomposeConvexAndAddTo(myPoly, this.body, pd);
     
      if (success != -1){
        System.out.println("-> Ear clipping SUCCESSFUL -> Using triangulated and polygonized shape for b2d.");
        this.body.setMassFromShapes();
        this.body.setUserData(this);
        this.setUserData("box2d", this.body); //TODO rename userData
      //Performance hit! but prevents object from sticking to another sometimes
//      theBody.setBullet(true);
      }else{
        System.out.println("-> Ear clipping had an ERROR - trying again by triangulating shape for b2d with GLU-Triangulator");
//        GluTrianglulator triangulator = new GluTrianglulator(app);
//        List<Vertex> physicsTris = triangulator.tesselate(bodyVerts, GLU.GLU_TESS_WINDING_NONZERO);
//        Vertex[] triangulatedBodyVerts = physicsTris.toArray(new Vertex[physicsTris.size()]);
        //System.out.println("GLU tris created: " + triangulatedBodyVerts.length);
       
        //Cap the max triangles - dont use anymore triangles for the physics body..
        int cap = 400;
        if (triangulatedBodyVerts.length > cap){
          //System.err.println("OVER cap! -> capping!");
          Vertex[] tmp = new Vertex[cap];
          System.arraycopy(triangulatedBodyVerts, 0, tmp, 0, cap);
          triangulatedBodyVerts = tmp;
        }
       
        //Create polygon body
        world.destroyBody(this.body);
        dymBodyDef = new BodyDef();
        dymBodyDef.position = new Vec2(position.x, position.y);
        this.bodyDefB4CreationCallback(dymBodyDef);
        this.body = world.createBody(dymBodyDef);
        for (int i = 0; i < triangulatedBodyVerts.length/3; i++) {
          //Create polygon definition
View Full Code Here

    this.setGestureAllowance(ScaleProcessor.class, false);
    this.setGestureAllowance(RotateProcessor.class, false);
   
    Vector3D scaledPos = PhysicsHelper.scaleDown(centerPosition.getCopy(), scale);
   
    BodyDef dymBodyDef = new BodyDef();
    dymBodyDef.position = new Vec2(scaledPos.x, scaledPos.y);
    this.bodyDefB4CreationCallback(dymBodyDef);
    this.body = world.createBody(dymBodyDef);
   
    CircleDef circleDef = new CircleDef();
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.BodyDef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.