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


Java CircleShape类代码示例

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

}
 
开发者ID:mirkosertic,项目名称:Bytecoder,代码行数:19,代码来源:JBox2DTest.java

示例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);
    }
  }
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:27,代码来源:box2d_Collisions_SensorTest.java

示例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();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:Collision.java

示例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);
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:26,代码来源:Distance.java

示例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;
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:29,代码来源:ShapeEditing.java

示例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);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:22,代码来源:ConfinedTest.java

示例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;
}
 
开发者ID:playn,项目名称:playn-samples,代码行数:21,代码来源:Pea.java

示例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;
  }
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:23,代码来源:ShapeEditing.java

示例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);
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:22,代码来源:ConfinedTest.java

示例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;
	}
}
 
开发者ID:dragome,项目名称:dragome-examples,代码行数:29,代码来源:ShapeEditing.java

示例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();
}
 
开发者ID:svanimpe,项目名称:fx-game-loops,代码行数:26,代码来源:Ball.java

示例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;
}
 
开发者ID:LoDoMa,项目名称:Lime,代码行数:19,代码来源:PhysicsParticleDefinition.java

示例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;
}
 
开发者ID:marik332000,项目名称:double-pendulum,代码行数:22,代码来源:Pendulum.java

示例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;
	}
}
 
开发者ID:col726,项目名称:game-engine-CMZ,代码行数:23,代码来源:GameSound.java

示例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);
       
}
 
开发者ID:RuthRainbow,项目名称:anemone,代码行数:27,代码来源:Agent.java


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