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


Java PolygonShape.set方法代码示例

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


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

示例1: initPhysicsBody

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

示例2: initPhysicsBody

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

示例3: initPhysicsBody

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

示例4: initPhysicsBody

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

示例5: initPhysicsBody

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

示例6: initPhysicsBody

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

示例7: initPhysicsBody

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

示例8: initPhysicsBody

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

示例9: createBody

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
/**
 * �������������
 */
private void createBody() {
	//�����������״�Ƕ������״
	PolygonShape shape = new PolygonShape();
	shape.set(vecs, edge);
	
	//���ö���������һЩ�̶�����������
	FixtureDef fd = new FixtureDef();
	fd.shape = shape;
	//�̶����ò���
	fd.density = 5.0f; 					// �ܶ�
	fd.friction = 0.3f;   					//Ħ��ϵ��
	fd.restitution = restitution;		//�ָ�ϵ��
	
	BodyDef bd = new BodyDef();
	bd.position.set(x, y);
	bd.type = BodyType.DYNAMIC;
	bd.angle = angle;
	bd.allowSleep = true;
	bd.setAwake(true);
	
	//����bodyDef�������嵽������
	body = world.createBody(bd);
	//���ú�����Ĺ̶�����
	body.createFixture(fd);
}
 
开发者ID:Jvaeyhcd,项目名称:Cut-Polygon,代码行数:29,代码来源:Polygon.java

示例10: onBodyCreation

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
public void onBodyCreation(Body _body){

        body = _body;

        PolygonShape shape = new PolygonShape();
        Vec2[] verts = new Vec2[vertices.length/3];

        int vertIndex = 0;
        for(int i = 0; i < vertices.length; i+=3){
            verts[vertIndex] = new Vec2(vertices[i] / Renderer.getPPM(), vertices[i + 1] / Renderer.getPPM());
            vertIndex++;
        }

        shape.set(verts,verts.length);

        //attach fixture
        FixtureDef fd = new FixtureDef();
        fd.shape =shape;
        fd.density = density;
        fd.friction = friction;
        fd.restitution = restitution;

        body.createFixture(fd);
    }
 
开发者ID:fokkedekker,项目名称:Eindproject,代码行数:25,代码来源:BaseObject.java

示例11: initReel

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private void initReel() {
    BodyDef reelDef = new BodyDef();
    reelDef.type = BodyType.DYNAMIC;
    reelDef.position = new Vec2(3, 3);
    reel = world.createBody(reelDef);

    FixtureDef fixture = new FixtureDef();
    fixture.friction = 0.5f;
    fixture.restitution = 0.4f;
    fixture.density = 1;

    int parts = 30;
    for (int i = 0; i < parts; ++i) {
        PolygonShape shape = new PolygonShape();
        double angle1 = i / (double) parts * 2 * Math.PI;
        double x1 = 2.7 * Math.cos(angle1);
        double y1 = 2.7 * Math.sin(angle1);
        double angle2 = (i + 1) / (double) parts * 2 * Math.PI;
        double x2 = 2.7 * Math.cos(angle2);
        double y2 = 2.7 * Math.sin(angle2);
        double angle = (angle1 + angle2) / 2;
        double x = 0.01 * Math.cos(angle);
        double y = 0.01 * Math.sin(angle);

        shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2),
                new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4);
        fixture.shape = shape;
        reel.createFixture(fixture);
    }
}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:31,代码来源:JBox2DSimulation.java

示例12: initReel

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
private void initReel() {
    BodyDef reelDef = new BodyDef();
    reelDef.type = BodyType.DYNAMIC;
    reelDef.position = new Vec2(3, 3);
    reel = world.createBody(reelDef);

    FixtureDef fixture = new FixtureDef();
    fixture.friction = 0.5f;
    fixture.restitution = 0.4f;
    fixture.density = 1;

    int parts = 30;
    for (int i = 0; i < parts; ++i) {
        System.out.println("New reel part");
        PolygonShape shape = new PolygonShape();
        double angle1 = i / (double) parts * 2 * Math.PI;
        double x1 = 2.7 * Math.cos(angle1);
        double y1 = 2.7 * Math.sin(angle1);
        double angle2 = (i + 1) / (double) parts * 2 * Math.PI;
        double x2 = 2.7 * Math.cos(angle2);
        double y2 = 2.7 * Math.sin(angle2);
        double angle = (angle1 + angle2) / 2;
        double x = 0.01 * Math.cos(angle);
        double y = 0.01 * Math.sin(angle);

        shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2),
                new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4);
        fixture.shape = shape;
        reel.createFixture(fixture);
    }
}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:32,代码来源:JBox2DTest.java

示例13: mouseDragged

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
@Override
public void mouseDragged(MouseEvent e) {
	Point mouse = e.getPoint();
	Vec2 point = new Vec2(mouse.x, mouse.y);

	synchronized (lines) {
		LinkedList<Vec2> lastLine = lines.getLast();

		if (lastLine.size() > 0) {
			Vec2 last = lastLine.getLast();
			if (last.sub(point).length() < LINE_LENGTH)
				return;

			BodyDef bd = new BodyDef();
			bd.position.set(0, 0);
			bd.type = BodyType.STATIC;

			PolygonShape shape = new PolygonShape();
			shape.set(new Vec2[] {last, point}, 2);

			FixtureDef fd = new FixtureDef();
			fd.shape = shape;

			Body body = world.createBody(bd);
			body.createFixture(fd);
		}

		lastLine.add(point);
	}
}
 
开发者ID:TomTasche,项目名称:lineracer,代码行数:31,代码来源:Main.java

示例14: createFixture

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
protected void createFixture(int index)
{
    PolygonShape shape = new PolygonShape();
    Vector2[] vertices = triangles.get(index);
    Vec2[] engineVertices = new Vec2[3];
    for (int i = 0; i < 3; i++)
        engineVertices[i] = new Vec2(offset.x + vertices[i].x, offset.y + vertices[i].y);
    shape.set(engineVertices, engineVertices.length);
    
    FixtureDef def = new FixtureDef();
    def.shape = shape;
    def.userData = this;
    
    engineFixtures[index] = engineBody.createFixture(def);
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:16,代码来源:PhysicsShapeTriangleGroup.java

示例15: UssTriangle

import org.jbox2d.collision.shapes.PolygonShape; //导入方法依赖的package包/类
public UssTriangle(Body ussTriangleBody) {
	super(ussTriangleBody);

	
	// original swing shape dimensions
	//
	//double x2Points[] = {0, -10, 0, 10};			
	//double y2Points[] = {0, 35, 25, 35};
	
	Vec2[] verticiesRight = new Vec2[3];
	verticiesRight[0] = new Vec2(0, 0);
	verticiesRight[1] = new Vec2(0.5f, -1.75f);
	verticiesRight[2] = new Vec2(0, -1.25f);

	PolygonShape triangleShapeRight = new PolygonShape();
	triangleShapeRight.set(verticiesRight, verticiesRight.length);		
	
	
	Vec2[] verticiesLeft = new Vec2[3];
	verticiesLeft[0] = new Vec2(0, 0);
	verticiesLeft[1] = new Vec2(-0.5f, -1.75f);
	verticiesLeft[2] = new Vec2(0, -1.25f);

	PolygonShape triangleShapeLeft = new PolygonShape();
	triangleShapeLeft.set(verticiesLeft, verticiesLeft.length);			

	m_body.createFixture(triangleShapeRight, 1);
	m_body.createFixture(triangleShapeLeft, 1);	
	
	m_body.setUserData(this);
}
 
开发者ID:davidholiday,项目名称:ALTk,代码行数:32,代码来源:UssTriangle.java


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