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


Java PolygonShape.setAsBox方法代码示例

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


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

示例1: makeBody

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
void makeBody(Vec2 center, float w_, float h_) {
    // Define a polygon (this is what we use for a rectangle)
    PolygonShape sd = new PolygonShape();
    float box2dW = box2d.scalarPixelsToWorld(w_ / 2);
    float box2dH = box2d.scalarPixelsToWorld(h_ / 2);
    sd.setAsBox(box2dW, box2dH);

    // Define a fixture
    FixtureDef fd = new FixtureDef();
    fd.shape = sd;
    // Parameters that affect physics
    fd.density = 1;
    fd.friction = 0.3F;
    fd.restitution = 0.5F;

    // Define the body and make it from the shape
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(box2d.coordPixelsToWorld(center));

    body = box2d.createBody(bd);
    body.createFixture(fd);

    // Give it some initial random velocity
    shake();
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:27,代码来源:Box.java

示例2: Ground

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
public Ground(Texture texture) {
	super(new Vec2(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2),texture);
	//Body def
   	BodyDef bd = new BodyDef();
   	bd.type = BodyType.STATIC;
   	bd.position.set(Public.box2d.coordPixelsToWorld(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2) );
   	bd.setUserData("PhysicalGameObject,Ground");
   	//Create body
       body = Public.box2d.createBody(bd);
   	//Creat Shape
       PolygonShape ps = new PolygonShape();
       ps.setAsBox(Public.box2d.scalarPixelsToWorld(Public.p.width*100),-Public.box2d.scalarPixelsToWorld(-texture.getTexture().height/2) );
       //Fixture
       FixtureDef fd = new FixtureDef();
       fd.shape = ps;
       fd.density = 1f;
       fd.friction = 0.3f;
       fd.restitution = 0.15f;
       body.createFixture(fd);
       
}
 
开发者ID:Error1000,项目名称:processingGameEngine,代码行数:22,代码来源:Ground.java

示例3: Create

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void Create()
{
	BodyDef def = new BodyDef();
	def.position.set(new Vec2(x, y));
	def.type = type;
	def.angle = 0;
	this.body = Game.world.createBody(def);
	PolygonShape shape = new PolygonShape();
	shape.setAsBox(w/2, h/2);
	FixtureDef fixture = new FixtureDef();
	Filter filter = new Filter();
	filter.groupIndex = 1;
	fixture.density = 0.1f;
	fixture.setShape(shape);
	fixture.setFilter(filter);
	fixture.isSensor = false;
	fixture.setFriction(0.5f);
	fixture.friction = 1;
	fixture.setUserData(box);
	//Physics.SetPhysicsAccordingly(this.body, fixture, information);
	body.createFixture(fixture);
}
 
开发者ID:Joshuagollaher,项目名称:HawkEngine,代码行数:24,代码来源:BoxPhysics.java

示例4: makeDomino

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的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

示例5: initTest

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
   public void initTest() {
      setTitle("Couple of Things Test");
      
      m_world.setGravity(new Vec2());

      for (int i = 0; i < 2; i++)
      {
//         CircleShape circleShape = new CircleShape();
//         circleShape.m_radius = 1;
//         Shape shape = circleShape;
         PolygonShape polygonShape = new PolygonShape();
         polygonShape.setAsBox(1, 1);
         Shape shape = polygonShape;

         BodyDef bodyDef = new BodyDef();
         bodyDef.type = BodyType.DYNAMIC;
         bodyDef.position.set(5 * i, 0);
         bodyDef.angle = (float) (Math.PI / 4 * i);
         bodyDef.allowSleep = false;
         Body body = m_world.createBody(bodyDef);
         body.createFixture(shape, 5.0f);
         
         body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
      }
   }
 
开发者ID:mleoking,项目名称:PhET,代码行数:27,代码来源:MJWTest.java

示例6: init

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);


	eshape = new EdgeShape();
	eshape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
	shape = new PolygonShape();
	shape.setAsBox(0.6f, 0.125f);
	fixtureDef = new FixtureDef();
	fixtureDef.shape = shape;
	fixtureDef.density = 20.0f;
	fixtureDef.friction = 0.2f;
	bodyDef = new BodyDef();
	anchor = new Vec2(0, 0);
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:17,代码来源:ChainHighVP.java

示例7: init

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);
	gravity = new Vec2(0.0f, -10.0f);
	platformFixtureDef = new FixtureDef();
	PolygonShape platformPolygonShape = new PolygonShape();
	platformPolygonShape.setAsBox(15.0f, 0.1f);
	platformFixtureDef.shape = platformPolygonShape;

	dominoFixtureDef = new FixtureDef();
	PolygonShape dominoPolygonShape = new PolygonShape();
	dominoPolygonShape.setAsBox(0.2f, 2.5f);
	dominoFixtureDef.shape = dominoPolygonShape;
	dominoFixtureDef.density = 25.0f;
	dominoFixtureDef.friction = .5f;
	dominoBody = new BodyDef();
	dominoBody.type = BodyType.DYNAMIC;
	
	floorFixtureDef = new FixtureDef();
	PolygonShape floorPolygonShape = new PolygonShape();
	floorPolygonShape.setAsBox(60.0f, 5.0f);
	floorFixtureDef.shape = floorPolygonShape;
	floor = new BodyDef();
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:25,代码来源:DominoBullet.java

示例8: makeDomino

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的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 = getWorld().createBody(bd);
    myBody.createFixture(fd);
  }
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:17,代码来源:DominoTower.java

示例9: step

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public synchronized void step(TestbedSettings settings) {
  super.step(settings);

  if (m_count < MAX_NUM) {
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DYNAMIC;
    bd.position.set(0.0f, 10.0f);
    Body body = m_world.createBody(bd);

    PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.125f, 0.125f);
    body.createFixture(shape, 1.0f);

    ++m_count;
  }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:18,代码来源:Tumbler.java

示例10: createTopAndBottomBounds

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private void createTopAndBottomBounds() {
    int boundSize = Math.round(boundsSize);
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.STATIC;
    PolygonShape box = new PolygonShape();
    int boxWidth = (int) pixelsToMeters(width);
    int boxHeight = (int) pixelsToMeters(boundSize);
    box.setAsBox(boxWidth, boxHeight);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = box;
    fixtureDef.density = 0.5f;
    fixtureDef.friction = 0.3f;
    fixtureDef.restitution = 0.5f;

    fixtureDef.userData = R.id.physics_layout_bound_top;
    bodyDef.position.set(0, -boxHeight);
    Body topBody = world.createBody(bodyDef);
    topBody.createFixture(fixtureDef);
    bounds.add(topBody);

    fixtureDef.userData = R.id.physics_layout_body_bottom;
    bodyDef.position.set(0, pixelsToMeters(height) + boxHeight);
    Body bottomBody = world.createBody(bodyDef);
    bottomBody.createFixture(fixtureDef);
    bounds.add(bottomBody);
}
 
开发者ID:Jawnnypoo,项目名称:PhysicsLayout,代码行数:27,代码来源:Physics.java

示例11: createLeftAndRightBounds

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private void createLeftAndRightBounds() {
    int boundSize = Math.round(boundsSize);
    int boxWidth = (int) pixelsToMeters(boundSize);
    int boxHeight = (int) pixelsToMeters(height);
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.STATIC;
    PolygonShape box = new PolygonShape();
    box.setAsBox(boxWidth, boxHeight);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = box;
    fixtureDef.density = 0.5f;
    fixtureDef.friction = 0.3f;
    fixtureDef.restitution = 0.5f;

    fixtureDef.userData = R.id.physics_layout_body_left;
    bodyDef.position.set(-boxWidth, 0);
    Body leftBody = world.createBody(bodyDef);
    leftBody.createFixture(fixtureDef);
    bounds.add(leftBody);

    fixtureDef.userData = R.id.physics_layout_body_right;
    bodyDef.position.set(pixelsToMeters(width) + boxWidth, 0);
    Body rightBody = world.createBody(bodyDef);
    rightBody.createFixture(fixtureDef);
    bounds.add(rightBody);
}
 
开发者ID:Jawnnypoo,项目名称:PhysicsLayout,代码行数:27,代码来源:Physics.java

示例12: initTest

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void initTest(boolean argDeserialized) {
  this.getWorld().setGravity(new Vec2());

  for (int i = 0; i < 2; i++) {
    PolygonShape polygonShape = new PolygonShape();
    polygonShape.setAsBox(1, 1);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;
    bodyDef.position.set(5 * i, 0);
    bodyDef.angle = (float) (Math.PI / 4 * i);
    bodyDef.allowSleep = false;
    
    Body body = this.getWorld().createBody(bodyDef);
    body.createFixture(polygonShape, 5.0f);
    body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
  }
}
 
开发者ID:davidholiday,项目名称:ALTk,代码行数:20,代码来源:MJWTest2.java

示例13: initTest

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void initTest(boolean argDeserialized)
{
	setTitle("This is a Title");
	
	getWorld().setGravity(new Vec2());
	
	for (int i = 0; i < 2; i++) {
	      PolygonShape polygonShape = new PolygonShape();
	      polygonShape.setAsBox(1, 1);
	      
	      BodyDef bodyDef = new BodyDef();
	      bodyDef.type = BodyType.DYNAMIC;
	      bodyDef.position.set(5 * i, 0);
	      bodyDef.angle = (float) (Math.PI / 4 * i);
	      bodyDef.allowSleep = false;
	      Body body = getWorld().createBody(bodyDef);
	      body.createFixture(polygonShape, 5.0f);

	      body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:23,代码来源:ColinTest.java

示例14: initTest

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
   public void initTest(boolean argDeserialized) {
      setTitle("Couple of Things Test");
      
      getWorld().setGravity(new Vec2());

      for (int i = 0; i < 2; i++)
      {
//         CircleShape circleShape = new CircleShape();
//         circleShape.m_radius = 1;
//         Shape shape = circleShape;
         PolygonShape polygonShape = new PolygonShape();
         polygonShape.setAsBox(1, 1);
         Shape shape = polygonShape;

         BodyDef bodyDef = new BodyDef();
         bodyDef.type = BodyType.DYNAMIC;
         bodyDef.position.set(5 * i, 0);
         bodyDef.angle = (float) (Math.PI / 4 * i);
         bodyDef.allowSleep = false;
         Body body = getWorld().createBody(bodyDef);
         body.createFixture(shape, 5.0f);
         
         body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
      }
   }
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:27,代码来源:MJWTest.java

示例15: createShape

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
protected static Shape createShape(PhysicsBodyShape shape, float width, float height, float x, float y, float rotation) {
	switch( shape ) {
		case BOX:
			PolygonShape box = new PolygonShape();
			box.setAsBox(width / 2f * BOX2D_SCALE_FACTOR, height / 2f * BOX2D_SCALE_FACTOR, toBox2dCS(x,y), rotation);
			return box;
			
		case CIRCLE:
			assert( Math.abs(height-width)<0.00001 );
			CircleShape circle = new CircleShape();
			circle.setRadius(height/2 * BOX2D_SCALE_FACTOR);
			circle.m_p.x = x*BOX2D_SCALE_FACTOR;
			circle.m_p.y = y*BOX2D_SCALE_FACTOR;
			return circle;
			
		default:
			throw new RuntimeException("Unsupported Shape-Type: "+shape);
	}
}
 
开发者ID:lowkey42,项目名称:java-jumpandrun-dev,代码行数:20,代码来源:Box2dPhysicsBody.java


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