Package net.phys2d.raw.shapes

Examples of net.phys2d.raw.shapes.Circle


  protected void init(World world) {
    world.setGravity(0,0);
   
    for (int y=0;y<4;y++) {
      for (int x=0;x<y+1;x++) {
        Body body1 = new Body("Ball"+x+","+y, new Circle(20.0f), 1);
        //Body body1 = new Body("Ball"+x+","+y, new Box(40.0f,40.0f), 1);
        body1.setPosition(250.0f+(x*40)-(y*20), 200+(y*35f));
        body1.setRestitution(1.0f);
        body1.setFriction(0);
        world.add(body1);
      }
    }

    Body body5 = new StaticBody("Ground1", new Box(20.0f, 500.0f));
    body5.setPosition(20.0f, 250);
    body5.setRestitution(1.0f);
    world.add(body5);
    Body body6 = new StaticBody("Ground2", new Box(20.0f, 500.0f));
    body6.setPosition(480.0f, 250);
    body6.setRestitution(1.0f);
    world.add(body6);
    Body body1 = new StaticBody("Ground3", new Box(500.0f, 20.0f));
    body1.setPosition(250.0f, 480);
    body1.setRestitution(1.0f);
    world.add(body1);
   
    Body body2 = new Body("Cue", new Circle(20.0f),1);
    //Body body2 = new Body("Cue", new Box(40.0f,40.0f),1);
    body2.setPosition(250,0);
    body2.adjustVelocity(new Vector2f(0,100));
    body2.setRestitution(1.0f);
    body2.setFriction(0);
View Full Code Here


   * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
   */
  protected void init(World world) {
    Body[] bodies = new Body[5];
    for (int x=0;x<4;x++) {
      bodies[x] = new Body("Ball"+x, new Circle(20.0f), 1);
      bodies[x].setPosition(220.0f+(x*20), 200+(x*40f));
      bodies[x].setRestitution(1.0f);
      world.add(bodies[x]);
    }
    for (int x=0;x<4;x++) {
View Full Code Here

    if (!touches) {
      return 0;
    }
   
    Box box = (Box) boxBody.getShape();
    Circle circle = (Circle) circleBody.getShape();
   
    Vector2f[] pts = box.getPoints(boxBody.getPosition(), boxBody.getRotation());
    Line[] lines = new Line[4];
    lines[0] = new Line(pts[0],pts[1]);
    lines[1] = new Line(pts[1],pts[2]);
    lines[2] = new Line(pts[2],pts[3]);
    lines[3] = new Line(pts[3],pts[0]);
   
    float r2 = circle.getRadius() * circle.getRadius();
    int closest = -1;
    float closestDistance = Float.MAX_VALUE;
   
    for (int i=0;i<4;i++) {
      float dis = lines[i].distanceSquared(circleBody.getPosition());
      if (dis < r2) {
        if (closestDistance > dis) {
          closestDistance = dis;
          closest = i;
        }
      }
    }
   
    if (closest > -1) {
      float dis = (float) Math.sqrt(closestDistance);
      contacts[0].setSeparation(dis - circle.getRadius());
     
      // this should really be where the edge and the line
      // between the two elements cross?
      Vector2f contactPoint = new Vector2f();
      lines[closest].getClosestPoint(circleBody.getPosition(), contactPoint);
View Full Code Here

    body.setRotatable(false);
    return init(entity, body);
  }
 
  public Body addBall(Entity entity, float radius) {
    Body body = new Body(new Circle(radius), this.mass);
    body.setPosition(this.position.getX(), this.position.getY());
    return init(entity, body);
  }
View Full Code Here

    a.setSMDPMode(false);
    return a;
  }
 
  protected AgentBody makeAgentBody() {
    Phys2DAgentBody aBody = new Phys2DAgentBody(new Circle(20), 0.5f);
    GridGPSSensor gps = new GridGPSSensor(cellwidth, cellheight);
    gps.setBody(aBody);
    aBody.add(gps);
    return aBody;
  }
View Full Code Here

    a.setInterruptOptions(false);
    return a;
  }
 
  protected AgentBody makeAgentBody() {
    Phys2DAgentBody aBody = new Phys2DAgentBody(new Circle(20), 0.5f);
    GridGPSSensor gps = new GridGPSSensor(cellwidth, cellheight);
    gps.setBody(aBody);
    aBody.add(gps);
    return aBody;
  }
View Full Code Here

      return null;
    Object localObject;
    if ((paramb instanceof a))
    {
      localObject = (a)paramb;
      return new Circle((float)((a)localObject).a());
    }
    if ((paramb instanceof com.a.b.b.c))
    {
      localObject = (com.a.b.b.c)paramb;
      return new Box((float)((com.a.b.b.c)localObject).a(), (float)((com.a.b.b.c)localObject).c());
View Full Code Here

  implements Collider
{
  public strictfp int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Line localLine = (Line)paramBody1.getShape();
    Circle localCircle = (Circle)paramBody2.getShape();
    Vector2f[] arrayOfVector2f = localLine.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f localVector2f1 = arrayOfVector2f[0];
    Vector2f localVector2f2 = arrayOfVector2f[1];
    ROVector2f localROVector2f = paramBody2.getPosition();
    Vector2f localVector2f3 = new Vector2f(localVector2f2);
    localVector2f3.sub(localVector2f1);
    localVector2f3.set(localVector2f3.y, -localVector2f3.x);
    float f1 = localVector2f3.y * (localVector2f2.x - localVector2f1.x);
    f1 -= localVector2f3.x * (localVector2f2.y - localVector2f1.y);
    float f2 = localVector2f3.x * (localVector2f1.y - localROVector2f.getY());
    f2 -= localVector2f3.y * (localVector2f1.x - localROVector2f.getX());
    f2 /= f1;
    Vector2f localVector2f4 = null;
    if (f2 < 0.0F)
      localVector2f4 = localVector2f1;
    else if (f2 > 1.0F)
      localVector2f4 = localVector2f2;
    else
      localVector2f4 = new Vector2f(localVector2f1.x + f2 * (localVector2f2.x - localVector2f1.x), localVector2f1.y + f2 * (localVector2f2.y - localVector2f1.y));
    Vector2f localVector2f5 = localVector2f3;
    localVector2f5.set(localROVector2f);
    localVector2f5.sub(localVector2f4);
    float f3 = localVector2f5.lengthSquared();
    float f4 = localCircle.getRadius() * localCircle.getRadius();
    if (f3 < f4)
    {
      paramArrayOfContact[0].setPosition(localVector2f4);
      paramArrayOfContact[0].setFeature(new FeaturePair());
      localVector2f5.normalise();
      paramArrayOfContact[0].setNormal(localVector2f5);
      float f5 = (float)Math.sqrt(f3) - localCircle.getRadius();
      paramArrayOfContact[0].setSeparation(f5);
      return 1;
    }
    return 0;
  }
View Full Code Here

    float f3 = paramBody2.getPosition().getX();
    float f4 = paramBody2.getPosition().getY();
    boolean bool = paramBody1.getShape().getBounds().touches(f1, f2, paramBody2.getShape().getBounds(), f3, f4);
    if (!bool)
      return 0;
    Circle localCircle1 = (Circle)paramBody1.getShape();
    Circle localCircle2 = (Circle)paramBody2.getShape();
    bool = localCircle1.touches(f1, f2, localCircle2, f3, f4);
    if (!bool)
      return 0;
    Vector2f localVector2f1 = MathUtil.sub(paramBody2.getPosition(), paramBody1.getPosition());
    float f5 = localCircle1.getRadius() + localCircle2.getRadius() - localVector2f1.length();
    localVector2f1.normalise();
    Vector2f localVector2f2 = MathUtil.scale(localVector2f1, localCircle1.getRadius());
    localVector2f2.add(paramBody1.getPosition());
    paramArrayOfContact[0].setSeparation(-f5);
    paramArrayOfContact[0].setPosition(localVector2f2);
View Full Code Here

public class PolygonCircleCollider extends PolygonPolygonCollider
{
  public int collide(Contact[] paramArrayOfContact, Body paramBody1, Body paramBody2)
  {
    Polygon localPolygon = (Polygon)paramBody1.getShape();
    Circle localCircle = (Circle)paramBody2.getShape();
    Vector2f[] arrayOfVector2f = localPolygon.getVertices(paramBody1.getPosition(), paramBody1.getRotation());
    Vector2f localVector2f1 = new Vector2f(localPolygon.getCentroid());
    localVector2f1.add(paramBody1.getPosition());
    int[][] arrayOfInt = getCollisionCandidates(arrayOfVector2f, localVector2f1, localCircle.getRadius(), paramBody2.getPosition());
    int i = 0;
    for (int j = 0; j < arrayOfInt.length; j++)
    {
      if (i >= paramArrayOfContact.length)
        return paramArrayOfContact.length;
      Vector2f localVector2f2 = arrayOfVector2f[arrayOfInt[j][0]];
      Vector2f localVector2f3 = arrayOfVector2f[((arrayOfInt[j][0] + 1) % arrayOfVector2f.length)];
      Line localLine = new Line(localVector2f2, localVector2f3);
      float f1 = localLine.distanceSquared(paramBody2.getPosition());
      float f2 = localCircle.getRadius() * localCircle.getRadius();
      if (f1 < f2)
      {
        Vector2f localVector2f4 = new Vector2f();
        localLine.getClosestPoint(paramBody2.getPosition(), localVector2f4);
        Vector2f localVector2f5 = new Vector2f(paramBody2.getPosition());
        localVector2f5.sub(localVector2f4);
        float f3 = localCircle.getRadius() - localVector2f5.length();
        localVector2f5.normalise();
        paramArrayOfContact[i].setSeparation(-f3);
        paramArrayOfContact[i].setPosition(localVector2f4);
        paramArrayOfContact[i].setNormal(localVector2f5);
        paramArrayOfContact[i].setFeature(new FeaturePair());
View Full Code Here

TOP

Related Classes of net.phys2d.raw.shapes.Circle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.