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


Java World类代码示例

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


World类属于org.jbox2d.dynamics包,在下文中一共展示了World类的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: displayParticles

import org.jbox2d.dynamics.World; //导入依赖的package包/类
static public void displayParticles(PGraphics pg, World world) {
  int particle_num = world.getParticleCount();
  if (particle_num != 0) {
    float radius = world.getParticleRadius();
    radius *= PARTICLE_RADIUS_SCALE;
    Vec2[] particle_pos = world.getParticlePositionBuffer();
    pg.beginShape(PConstants.QUADS);
    pg.noFill();
    pg.noStroke();
    pg.textureMode(PConstants.NORMAL);
    pg.texture(PARTICLE_SPRITE);
    for (int i = 0; i < particle_num; i++) {
      Vec2 pos = particle_pos[i];
      pg.vertex(pos.x - radius, pos.y - radius, 0, 0);
      pg.vertex(pos.x + radius, pos.y - radius, 1, 0);
      pg.vertex(pos.x + radius, pos.y + radius, 1, 1);
      pg.vertex(pos.x - radius, pos.y + radius, 0, 1);
    }
    pg.endShape();
  }
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:22,代码来源:DwDebugDraw.java

示例3: DwMouseShootBullet

import org.jbox2d.dynamics.World; //导入依赖的package包/类
public DwMouseShootBullet(World world, DwViewportTransform transform){
  this.world = world;
  this.transform = transform;
  
  // bullet specific settings
  cirlce_shape.m_radius = 0.3f;
  
  fixture_def.shape = cirlce_shape;
  fixture_def.density = 200f;
  fixture_def.restitution = 0.1f;
  
  body_def.type = BodyType.DYNAMIC;
  body_def.bullet = true;
  
  body_dragger = new DwMouseDragBodies(world, transform);
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:17,代码来源:DwMouseShootBullet.java

示例4: create

import org.jbox2d.dynamics.World; //导入依赖的package包/类
public static Joint create(World argWorld, JointDef def) {
	//Joint joint = null;
	switch(def.type){
		case MOUSE:
			return new MouseJoint(argWorld.getPool(), (MouseJointDef) def);
		case DISTANCE:
			return new DistanceJoint(argWorld.getPool(), (DistanceJointDef) def);
		case PRISMATIC:
			return new PrismaticJoint(argWorld.getPool(), (PrismaticJointDef) def);
		case REVOLUTE:
			return new RevoluteJoint(argWorld.getPool(), (RevoluteJointDef) def);
		case WELD:
			return new WeldJoint(argWorld.getPool(), (WeldJointDef) def);
		case FRICTION:
			return new FrictionJoint(argWorld.getPool(), (FrictionJointDef) def);
		case LINE:
			return new LineJoint(argWorld.getPool(), (LineJointDef) def);
		case GEAR:
			return new GearJoint(argWorld.getPool(), (GearJointDef) def);
		case PULLEY:
			return new PulleyJoint(argWorld.getPool(), (PulleyJointDef) def);
		case CONSTANT_VOLUME:
			return new ConstantVolumeJoint(argWorld, (ConstantVolumeJointDef) def);
	}
	return null;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:Joint.java

示例5: 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

示例6: Scene

import org.jbox2d.dynamics.World; //导入依赖的package包/类
public Scene() {
	sun = new DirectionalLight(vec3(-1.0f, -1.0f, 0.2f), vec3(2.0f, 2.0f, 2.0f), Settings.ENABLE_SHADOWS, 30, Settings.SHADOW_RESOLUTION);
	
	//setup bullet
	BroadphaseInterface broadphase = new DbvtBroadphase();
	DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
	CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);

	SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver();

	world = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

	// set the gravity of our world
	world.setGravity(new Vector3f(0, -9.8f, 0));
	
	//setup jbox2D
	world2D = new World(new Vector2(0, -9.8f));	
	world2D.setContactListener(this);
}
 
开发者ID:pianoman373,项目名称:Point-Engine,代码行数:20,代码来源:Scene.java

示例7: 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

示例8: 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

示例9: getBodyAtPosition

import org.jbox2d.dynamics.World; //导入依赖的package包/类
/**
 * Obt�m o corpo presente em uma determinada posi��o do mouse.
 * @param world Mundo f�sico.
 * @param p 	Posi��o do mundo a ser analisada.
 * @param d 	Dimens�es da box de an�lise.
 * @return Corpo na posi��o ou null caso nenhum corpo esteja no ponto informado.
 */
public static Body getBodyAtPosition(World world, Vec2 p, Vec2 d) {
	//Cria uma pequena caixa que representa a posi��o informada.		
	AABB aabb = new AABB(p.sub(d), p.add(d));
	
	//Realiza pesquisa no mundo.
	int k_maxCount = 10;
	Shape shapes[] = world.query(aabb, k_maxCount);

	Body body = null;
       for (int i = 0; i < shapes.length; i++) {
           Body shapeBody = shapes[i].getBody();
           boolean inside = shapes[i].testPoint(shapeBody.getMemberXForm(),p);
           if (inside) {
               body = shapes[i].m_body;
               break;
           }
       }
       
       return body;
}
 
开发者ID:intentor,项目名称:telyn,代码行数:28,代码来源:Utils.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);

  // 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

示例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[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

示例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.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

示例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[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

示例14: 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

示例15: 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


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