当前位置: 首页>>代码示例>>Java>>正文


Java World.createBody方法代码示例

本文整理汇总了Java中org.jbox2d.dynamics.World.createBody方法的典型用法代码示例。如果您正苦于以下问题:Java World.createBody方法的具体用法?Java World.createBody怎么用?Java World.createBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jbox2d.dynamics.World的用法示例。


在下文中一共展示了World.createBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNewWorld

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Test
public void testNewWorld() {
    World world = new World(new Vec2(0, -9.8f));

    BodyDef axisDef = new BodyDef();
    axisDef.type = BodyType.STATIC;
    axisDef.position = new Vec2(3, 3);
    Body axis = world.createBody(axisDef);

    CircleShape axisShape = new CircleShape();
    axisShape.setRadius(0.02f);
    axisShape.m_p.set(0, 0);

    //FixtureDef axisFixture = new FixtureDef();
    //axisFixture.shape = axisShape;
    //axis.createFixture(axisFixture);

}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:19,代码来源:JBox2DTest.java

示例2: makeDomino

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
public void makeDomino(float x, float y, boolean horizontal, World world) {

    	PolygonShape sd = new PolygonShape();
        sd.setAsBox(.5f*dwidth, .5f*dheight);
        FixtureDef fd = new FixtureDef();
        fd.shape = sd;
        fd.density = ddensity;
        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        fd.friction = dfriction;
        fd.restitution = 0.65f;
        bd.position = new Vec2(x, y);
        bd.angle = horizontal? (float)(Math.PI/2.0):0f;
        Body myBody = world.createBody(bd);
        myBody.createFixture(fd);
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:DominoTower.java

示例3: createCollisions

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
/**
 * Cria as colis�es.
 * @param world 		Objeto que representa o mundo do jogo.
 * @param collisions	V�rtices dos pol�gonos de colis�o.
 */
private void createCollisions(World world, List<List<Vec2>> collisions) {
	for (List<Vec2> vertex : collisions) {			
		BodyDef bd = new BodyDef();
		Body b = world.createBody(bd);
		
		for (int i = 0; i < vertex.size() - 1; ++i) {
			PolygonDef sd = new PolygonDef();
			sd.friction = LevelConfiguration.GROUND_FRICTION;
			Utils.createStrokeRect(vertex.get(i), vertex.get(i + 1), LevelConfiguration.STROKE_RADIUS, b, sd);
		}
		
		//Adiciona o v�rtice a user data para posterior colis�o.
		b.setUserData(vertex);
		b.setMassFromShapes();
	}
}
 
开发者ID:intentor,项目名称:telyn,代码行数:22,代码来源:EditorInputProcessor.java

示例4: createCheckpoint

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
/**
 * Cria um checkpoint do jogo.
 * @param world 	Objeto que representa o mundo do jogo.
 * @param position	Posi��o do checkpoint, em unidades do mundo.
 * @param position  Objeto de estado do jogo.
 * @return Corpo do checkpoint.
 */
public static Body createCheckpoint(World world, Vec2 position, LevelState state) {
	BodyDef def = new BodyDef();
	def.position.set(position);
	Body checkpoint = world.createBody(def);
	
	PolygonDef pd = new PolygonDef();
	pd.isSensor = true; //Todo checkpoint � um sensor.
	pd.userData = "checkpoint";
	pd.setAsBox(CHECKPOINT_SIZE.x, CHECKPOINT_SIZE.y);
	
	checkpoint.createShape(pd);
	checkpoint.setMassFromShapes();
	checkpoint.setUserData(state);
	
	return checkpoint;
}
 
开发者ID:intentor,项目名称:telyn,代码行数:24,代码来源:Utils.java

示例5: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  // height of the portal contact box
  float boxHeight = getHeight() / 12f;
  float boxWidth = getWidth() * 0.75f;
  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-boxWidth/2f, getHeight()/2f - boxHeight);
  polygon[1] = new Vec2(boxWidth/2f, getHeight()/2f - boxHeight);
  polygon[2] = new Vec2(boxWidth/2f, getHeight()/2f);
  polygon[3] = new Vec2(-boxWidth/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.8f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:25,代码来源:Portal.java

示例6: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[1] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[2] = new Vec2(getWidth()/2f, getHeight()/2f);
  polygon[3] = new Vec2(-getWidth()/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.8f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:22,代码来源:Block.java

示例7: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.DYNAMIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  CircleShape circleShape = new CircleShape();
  circleShape.m_radius = getRadius();
  fixtureDef.shape = circleShape;
  fixtureDef.density = 0.4f;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.35f;
  circleShape.m_p.set(0, 0);
  body.createFixture(fixtureDef);
  body.setLinearDamping(0.2f);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:21,代码来源:Pea.java

示例8: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[3];
  polygon[0] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[1] = new Vec2(getWidth()/2f, getHeight()/2f);
  polygon[2] = new Vec2(-getWidth()/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.9f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:22,代码来源:BlockLeftRamp.java

示例9: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.DYNAMIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-getWidth() / 2f, -getHeight() / 2f + getTopOffset());
  polygon[1] = new Vec2(getWidth() / 2f, -getHeight() / 2f + getTopOffset());
  polygon[2] = new Vec2(getWidth() / 2f, polygon[0].y + getSpringBoxHeight());
  polygon[3] = new Vec2(-getWidth() / 2f, polygon[1].y + getSpringBoxHeight());
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 1.4f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:22,代码来源:BlockSpring.java

示例10: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[1] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[2] = new Vec2(getWidth()/2f, getHeight()/2f);
  polygon[3] = new Vec2(-getWidth()/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 1.0f;
  fixtureDef.restitution = 0.3f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:23,代码来源:BlockGel.java

示例11: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[3];
  polygon[0] = new Vec2(-getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[1] = new Vec2(getWidth()/2f, getHeight()/2f);
  polygon[2] = new Vec2(-getWidth()/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.9f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:22,代码来源:BlockRightRamp.java

示例12: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  // height of the portal contact box
  float boxHeight = getHeight() / 12f;
  float boxWidth = getWidth() * 0.75f;
  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-boxWidth/2f, getHeight()/2f - boxHeight);
  polygon[1] = new Vec2(boxWidth/2f, getHeight()/2f - boxHeight);
  polygon[2] = new Vec2(boxWidth/2f, getHeight()/2f);
  polygon[3] = new Vec2(-boxWidth/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.8f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:fredsa,项目名称:forplay,代码行数:26,代码来源:Portal.java

示例13: initPhysicsBody

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
  FixtureDef fixtureDef = new FixtureDef();
  BodyDef bodyDef = new BodyDef();
  bodyDef.type = BodyType.STATIC;
  bodyDef.position = new Vec2(0, 0);
  Body body = world.createBody(bodyDef);

  PolygonShape polygonShape = new PolygonShape();
  Vec2[] polygon = new Vec2[4];
  polygon[0] = new Vec2(-getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[1] = new Vec2(getWidth()/2f, -getHeight()/2f + getTopOffset());
  polygon[2] = new Vec2(getWidth()/2f, getHeight()/2f);
  polygon[3] = new Vec2(-getWidth()/2f, getHeight()/2f);
  polygonShape.set(polygon, polygon.length);
  fixtureDef.shape = polygonShape;
  fixtureDef.friction = 0.1f;
  fixtureDef.restitution = 0.8f;
  body.createFixture(fixtureDef);
  body.setTransform(new Vec2(x, y), angle);
  return body;
}
 
开发者ID:fredsa,项目名称:forplay,代码行数:23,代码来源:Block.java

示例14: testSimpleBall

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
@Test
public void testSimpleBall() {
    World world = new World(new Vec2(0, -9.8f));

    float ballRadius = 0.15f;

    BodyDef ballDef = new BodyDef();
    ballDef.type = BodyType.DYNAMIC;
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.friction = 0.3f;
    fixtureDef.restitution = 0.3f;
    fixtureDef.density = 0.2f;
    CircleShape shape = new CircleShape();
    shape.m_radius = ballRadius;
    fixtureDef.shape = shape;

    int i=0;
    int j=0;

    float x = (j + 0.5f) * (ballRadius * 2 + 0.01f);
    float y = (i + 0.5f) * (ballRadius * 2 + 0.01f);
    ballDef.position.x = 3 + x;
    ballDef.position.y = 3 + y;
    Body theBall = world.createBody(ballDef);
    theBall.createFixture(fixtureDef);

    for (int k=0;k<100;k++) {
        world.step(0.01f, 20, 40);
    }

    Vec2 thePosition = theBall.getPosition();
    int theX = (int)(thePosition.x * 1000);
    int theY = (int) (thePosition.y * 1000);

    System.out.println("Finally ended at ");
    System.out.println(theX);
    System.out.println(theY);
}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:39,代码来源:JBox2DTest.java

示例15: Box2DAdapter

import org.jbox2d.dynamics.World; //导入方法依赖的package包/类
public Box2DAdapter( World world, final Compound<SphericalParticle> compound, final ModelViewTransform transform ) {
    this.world = world;
    this.compound = compound;
    this.transform = transform;

    //First create the body def at the right location
    BodyDef bodyDef = new BodyDef() {{
        Vector2D box2DPosition = transform.modelToView( compound.getPosition() );
        position = new Vec2( (float) box2DPosition.getX(), (float) box2DPosition.getY() );
        angle = (float) compound.getAngle();

        //Have to specify the type as dynamic or it won't move
        type = BodyType.DYNAMIC;
    }};
    body = world.createBody( bodyDef );

    //Add a little bit of linear and rotational friction so the system doesn't accelerate out of control
    body.setLinearDamping( 1 );
    body.setAngularDamping( 1 );

    //Add shapes for all of the constituents as rigid fixtures to the box2d shape
    for ( int i = 0; i < compound.numberConstituents(); i++ ) {

        final Constituent<SphericalParticle> constituent = compound.getConstituent( i );
        //Create the shape to add to the body
        final CircleShape shape = new CircleShape() {{
            m_radius = (float) transform.modelToViewDeltaX( constituent.particle.radius );

            //Set the position within the molecule
            Vector2D boxOffset = transform.modelToViewDelta( constituent.relativePosition );
            m_p.set( (float) boxOffset.getX(), (float) boxOffset.getY() );
        }};

        //Add the shape to the body
        Fixture f = body.createFixture( shape, 1 );

        //Add a little bit of bounciness to keep things moving randomly
        f.setRestitution( 0.1f );
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:41,代码来源:Box2DAdapter.java


注:本文中的org.jbox2d.dynamics.World.createBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。