本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}