本文整理汇总了Java中org.jbox2d.collision.shapes.CircleShape类的典型用法代码示例。如果您正苦于以下问题:Java CircleShape类的具体用法?Java CircleShape怎么用?Java CircleShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CircleShape类属于org.jbox2d.collision.shapes包,在下文中一共展示了CircleShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNewWorld
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的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);
}
示例2: updateSensor
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public void updateSensor(){
Body bsensor = m_sensor.getBody();
CircleShape circle = (CircleShape) m_sensor.getShape();
Vec2 sensor_pos = bsensor.getWorldPoint(circle.m_p);
// iterate through all contacts and apply a force on shapes that overlap the sensor.
for(Contact contact = world.getContactList(); contact != null; contact = contact.m_next){
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
Body body = null;
if(fixtureA == m_sensor) body = fixtureB.getBody();
else if(fixtureB == m_sensor) body = fixtureA.getBody();
else continue;
Vec2 body_pos = body.getPosition();
Vec2 dist = sensor_pos.sub(body_pos);
if (dist.lengthSquared() > Settings.EPSILON * Settings.EPSILON) {
dist.normalize();
Vec2 force = dist.mulLocal(200f);
body.applyForce(force, body_pos);
}
}
}
示例3: collideCircles
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
/**
* Compute the collision manifold between two circles.
*
* @param manifold
* @param circle1
* @param xfA
* @param circle2
* @param xfB
*/
public final void collideCircles(Manifold manifold, final CircleShape circle1, final Transform xfA,
final CircleShape circle2, final Transform xfB) {
manifold.pointCount = 0;
Transform.mulToOut(xfA, circle1.m_p, pA);
Transform.mulToOut(xfB, circle2.m_p, pB);
d.set(pB).subLocal(pA);
float distSqr = Vec2.dot(d, d);
float radius = circle1.m_radius + circle2.m_radius;
if (distSqr > radius * radius) {
return;
}
manifold.type = ManifoldType.CIRCLES;
manifold.localPoint.set(circle1.m_p);
manifold.localNormal.setZero();
manifold.pointCount = 1;
manifold.points[0].localPoint.set(circle2.m_p);
manifold.points[0].id.zero();
}
示例4: set
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
/**
* Initialize the proxy using the given shape. The shape
* must remain in scope while the proxy is in use.
*/
public final void set(final Shape shape){
switch(shape.getType()){
case CIRCLE:
final CircleShape circle = (CircleShape) shape;
m_vertices[0].set(circle.m_p);
m_count = 1;
m_radius = circle.m_radius;
break;
case POLYGON:
final PolygonShape poly = (PolygonShape) shape;
m_count = poly.m_vertexCount;
m_radius = poly.m_radius;
for(int i=0; i<m_count; i++){
m_vertices[i].set(poly.m_vertices[i]);
}
break;
default:
assert(false);
}
}
示例5: keyPressed
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#keyPressed(char, int)
*/
@Override
public void keyPressed(char key, int argKeyCode) {
switch (key)
{
case 'c':
if (m_fixture2 == null)
{
CircleShape shape = new CircleShape();
shape.m_radius = 3.0f;
shape.m_p.set(0.5f, -4.0f);
m_fixture2 = m_body.createFixture(shape, 10.0f);
m_body.setAwake(true);
}
break;
case 'd':
if (m_fixture2 != null)
{
m_body.destroyFixture(m_fixture2);
m_fixture2 = null;
m_body.setAwake(true);
}
break;
}
}
示例6: createCircle
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public void createCircle()
{
float radius = 2.0f;
CircleShape shape = new CircleShape();
shape.m_p.setZero();
shape.m_radius = radius;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.0f;
Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random());
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = p;
//bd.allowSleep = false;
Body body = m_world.createBody(bd);
body.createFixture(fd);
}
示例7: initPhysicsBody
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的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;
}
示例8: keyPressed
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
@Override
public void keyPressed(char key, int argKeyCode) {
switch (key) {
case 'c':
if (m_fixture2 == null) {
CircleShape shape = new CircleShape();
shape.m_radius = 3.0f;
shape.m_p.set(0.5f, -4.0f);
m_fixture2 = m_body.createFixture(shape, 10.0f);
m_body.setAwake(true);
}
break;
case 'd':
if (m_fixture2 != null) {
m_body.destroyFixture(m_fixture2);
m_fixture2 = null;
m_body.setAwake(true);
}
break;
}
}
示例9: createCircle
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public void createCircle()
{
float radius = 2.0f;
CircleShape shape = new CircleShape();
shape.m_p.setZero();
shape.m_radius = radius;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.0f;
Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random());
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = p;
//bd.allowSleep = false;
Body body = getWorld().createBody(bd);
body.createFixture(fd);
}
示例10: keyPressed
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#keyPressed(char, int)
*/
@Override
public void keyPressed(char key, int argKeyCode, ShowcaseSettings settings) {
switch (key)
{
case 'c':
if (m_fixture2 == null)
{
CircleShape shape = new CircleShape();
shape.m_radius = 3.0f;
shape.m_p.set(0.5f, -4.0f);
m_fixture2 = m_body.createFixture(shape, 10.0f);
m_body.setAwake(true);
}
break;
case 'd':
if (m_fixture2 != null)
{
m_body.destroyFixture(m_fixture2);
m_fixture2 = null;
m_body.setAwake(true);
}
break;
}
}
示例11: Ball
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public Ball(World world)
{
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
float x = random.nextFloat() * WIDTH;
float y = HEIGHT + random.nextFloat() * HEIGHT * 2; /* A ball starts above the screen so we can watch it drop. */
bodyDef.position = new Vec2(x, y);
Shape shape = new CircleShape();
shape.m_radius = 0.1f; /* 10cm */
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 1f;
fixtureDef.restitution = 0.6f;
body = world.createBody(bodyDef);
body.createFixture(fixtureDef);
setRadius(SCALE * 0.1);
setFill(Color.rgb(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
updatePosition();
}
示例12: create
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public void create()
{
engineBodyDefinition = new BodyDef();
engineBodyDefinition.position = position.toVec2();
engineBodyDefinition.angle = angle;
engineBodyDefinition.type = BodyType.DYNAMIC;
engineBodyDefinition.angularVelocity = angularVelocity;
engineBodyDefinition.linearVelocity = linearVelocity.toVec2();
engineBodyDefinition.angularDamping = angularDamping;
engineBodyDefinition.linearDamping = linearDamping;
engineFixtureDefinition = new FixtureDef();
engineFixtureDefinition.shape = new CircleShape();
((CircleShape) engineFixtureDefinition.shape).m_radius = size;
engineFixtureDefinition.density = density;
engineFixtureDefinition.friction = 0.0f;
engineFixtureDefinition.restitution = restitution;
}
示例13: newBob
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
/**
* Create a new bob body.
* @param world the world to place the body in
* @param position the starting position of the bob
* @return the new bob
*/
private Body newBob(final World world, final Vec2 position) {
BodyDef def = new BodyDef();
def.type = BodyType.DYNAMIC;
def.position = position;
CircleShape circle = new CircleShape();
circle.m_radius = BOB_RADIUS;
FixtureDef fix = new FixtureDef();
fix.shape = circle;
fix.density = BOB_DENSITY;
fix.friction = 0f;
fix.isSensor = true;
Body mass = world.createBody(def);
mass.createFixture(fix);
return mass;
}
示例14: GameSound
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
public GameSound(File soundFile, boolean isVisible, Vec2 center, int w) throws Exception {
this(soundFile);
if(isVisible)
{
show = true;
bodyDef = new BodyDef();
bodyDef.position.set(center.x, center.y);
bodyDef.type = BodyType.DYNAMIC;
bb = new CircleShape();
fixture = new FixtureDef();
bb.m_p.set(center);
bb.m_radius = w/4; //divide by 4 so that sound circle is contained within object
fixture.shape = bb;
fixture.density = 1.0f;
fixture.friction = 0.8f;
}
}
示例15: setupBox2d
import org.jbox2d.collision.shapes.CircleShape; //导入依赖的package包/类
protected void setupBox2d(){
float box2Dx = (float) (coords.x/Simulation.meterToPixel);
float box2Dy = (float) (coords.y/Simulation.meterToPixel);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2Dx,box2Dy);
CircleShape cs = new CircleShape();
cs.m_radius = 10.0f/Simulation.meterToPixel;
FixtureDef fd = new FixtureDef();
fd.shape = cs;
fd.density = 0.6f;
fd.friction = 0.3f;
fd.restitution = 0.5f;
fd.filter.categoryBits = Collision.TYPE_AGENT;
if(this instanceof Enemy){
fd.filter.maskBits = Collision.TYPE_AGENT | Collision.TYPE_WALL | Collision.TYPE_WALL_AGENT;
}else{
fd.filter.maskBits = Collision.TYPE_AGENT | Collision.TYPE_WALL | Collision.TYPE_WALL_ENEMY;
}
fd.userData = this;
body = world.createBody(bd);
body.createFixture(fd);
}