Package eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.shapes

Examples of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.shapes.Line


      if ( noContacts >= contacts.length )
        return contacts.length;
     
      Vector2f lineStartA = vertsA[collPairs[i][0]];
      Vector2f lineEndA = vertsA[(collPairs[i][0]+1) % vertsA.length ];
      Line line = new Line(lineStartA, lineEndA);
           
      float dis2 = line.distanceSquared(bodyB.getPosition());
      float r2 = circle.getRadius() * circle.getRadius();

      if ( dis2 < r2 ) {
        Vector2f pt = new Vector2f();
       
        line.getClosestPoint(bodyB.getPosition(), pt);
        Vector2f normal = new Vector2f(bodyB.getPosition());
        normal.sub(pt);
        float sep = circle.getRadius() - normal.length();
        normal.normalise();
       
View Full Code Here


   */
  @Override
    public int collide(Contact[] contacts, PhysicsAgent2D<?> bodyA, PhysicsAgent2D<?> bodyB) {
    int numContacts = 0;
   
    Line line = (Line) bodyA.getBodyShape();
    Box box = (Box) bodyB.getBodyShape();
   
    Vector2f lineVec = new Vector2f(line.getDX(), line.getDY());
    lineVec.normalise()
    Vector2f axis = new Vector2f(-line.getDY(), line.getDX());
    axis.normalise();
   
    Vector2f res = new Vector2f();
    line.getStart().projectOntoUnit(axis, res);
    float linePos = getProp(res,axis);
   
    Vector2f c = MathUtil.sub(bodyB.getPosition(),bodyA.getPosition());
    c.projectOntoUnit(axis,res);
    float centre = getProp(res, axis);
   
    Vector2f[] pts = box.getPoints(bodyB.getPosition(), bodyB.getRotation());
    float[] tangent = new float[4];
    float[] proj = new float[4];
   
    int outOfRange = 0;
   
    for (int i=0;i<4;i++) {
      pts[i].sub(bodyA.getPosition());
      pts[i].projectOntoUnit(axis, res);
      tangent[i] = getProp(res, axis);
      pts[i].projectOntoUnit(lineVec, res);
      proj[i] = getProp(res, new Vector2f(line.getDX(), line.getDY()));
     
      if ((proj[i] >= 1) || (proj[i] <= 0)) {
        outOfRange++;
      }
    }
    if (outOfRange == 4) {
      return 0;
    }
   
    Vector2f normal = new Vector2f(axis);
   
    if (centre < linePos) {
      if (!line.blocksInnerEdge()) {
        return 0;
      }
     
      normal.scale(-1);
      for (int i=0;i<4;i++) {
        if (tangent[i] > linePos) {
          if (proj[i] < 0) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left > 0) && (right > 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getStart());
             
              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else if (proj[i] > 1) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left > 0) && (right > 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getEnd());

              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else {
            pts[i].projectOntoUnit(lineVec, res);
            res.add(bodyA.getPosition());
            contacts[numContacts].setSeparation(-(tangent[i]-linePos));
            contacts[numContacts].setPosition(new Vector2f(res));
            contacts[numContacts].setNormal(normal);
            contacts[numContacts].setFeature(new FeaturePair(i))
            numContacts++;
          }
        }
      }
    } else {
      if (!line.blocksOuterEdge()) {
        return 0;
      }
     
      for (int i=0;i<4;i++) {
        if (tangent[i] < linePos) {
          if (proj[i] < 0) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left < 0) && (right < 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getStart());

              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else if (proj[i] > 1) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left < 0) && (right < 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
View Full Code Here

    Vector2f end = new Vector2f(start);
    end.add(norm);
   
    rightLine.move(bodyA.getPosition());
    leftLine.move(bodyA.getPosition());
    Line normLine = new Line(start,end);
    Vector2f rightPoint = normLine.intersect(rightLine);
    Vector2f leftPoint = normLine.intersect(leftLine);
   
    float dis1 = Float.MAX_VALUE;
    if (rightPoint != null) {
      dis1 = rightPoint.distance(start) - norm.length();
    }
View Full Code Here

    Box box = (Box) boxBody.getBodyShape();
    Circle circle = (Circle) circleBody.getBodyShape();
   
    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;
   
View Full Code Here

    /**
   * @see eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.collide.Collider#collide(eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Contact[], eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body, eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body)
   */
  @Override
    public int collide(Contact[] contacts, PhysicsAgent2D<?> bodyA, PhysicsAgent2D<?> bodyB) {
    Line line = (Line) bodyA.getBodyShape();
    Circle circle = (Circle) bodyB.getBodyShape();
   
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
View Full Code Here

    /**
   * @see eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.collide.Collider#collide(eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Contact[], eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body, eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body)
   */
  @Override
    public int collide(Contact[] contacts, PhysicsAgent2D<?> bodyA, PhysicsAgent2D<?> bodyB) {
    Line line = (Line) bodyA.getBodyShape();
    Polygon poly = (Polygon) bodyB.getBodyShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only one shape
    // specifically the line, because it has only two vertices
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = poly.getVertices(bodyB.getPosition(), bodyB.getRotation());

    Vector2f pos = poly.getCentroid(bodyB.getPosition(), bodyB.getRotation());
   
    // using the z axis of a 3d cross product we determine on what side B is
View Full Code Here

    /**
   * @see eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.collide.Collider#collide(eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Contact[], eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body, eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body)
   */
  @Override
    public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Line line = (Line) bodyA.getShape();
    Circle circle = (Circle) bodyB.getShape();
   
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
   
    // compute intersection of the line A and a line parallel to
    // the line A's normal passing through the origin of B
    Vector2f startA = vertsA[0];
    Vector2f endA = vertsA[1];
View Full Code Here

    /**
   * @see eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.collide.Collider#collide(eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Contact[], eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body, eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.Body)
   */
  @Override
    public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    Line line = (Line) bodyA.getShape();
    Polygon poly = (Polygon) bodyB.getShape();
   
    // TODO: this can be optimized using matrix multiplications and moving only one shape
    // specifically the line, because it has only two vertices
    Vector2f[] vertsA = line.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = poly.getVertices(bodyB.getPosition(), bodyB.getRotation());

    Vector2f pos = poly.getCentroid(bodyB.getPosition(), bodyB.getRotation());
   
    // using the z axis of a 3d cross product we determine on what side B is
View Full Code Here

      if ( noContacts >= contacts.length )
        return contacts.length;
     
      Vector2f lineStartA = vertsA[collPairs[i][0]];
      Vector2f lineEndA = vertsA[(collPairs[i][0]+1) % vertsA.length ];
      Line line = new Line(lineStartA, lineEndA);
           
      float dis2 = line.distanceSquared(bodyB.getPosition());
      float r2 = circle.getRadius() * circle.getRadius();

      if ( dis2 < r2 ) {
        Vector2f pt = new Vector2f();
       
        line.getClosestPoint(bodyB.getPosition(), pt);
        Vector2f normal = new Vector2f(bodyB.getPosition());
        normal.sub(pt);
        float sep = circle.getRadius() - normal.length();
        normal.normalise();
       
View Full Code Here

   */
  @Override
    public int collide(Contact[] contacts, Body bodyA, Body bodyB) {
    int numContacts = 0;
   
    Line line = (Line) bodyA.getShape();
    Box box = (Box) bodyB.getShape();
   
    Vector2f lineVec = new Vector2f(line.getDX(), line.getDY());
    lineVec.normalise()
    Vector2f axis = new Vector2f(-line.getDY(), line.getDX());
    axis.normalise();
   
    Vector2f res = new Vector2f();
    line.getStart().projectOntoUnit(axis, res);
    float linePos = getProp(res,axis);
   
    Vector2f c = MathUtil.sub(bodyB.getPosition(),bodyA.getPosition());
    c.projectOntoUnit(axis,res);
    float centre = getProp(res, axis);
   
    Vector2f[] pts = box.getPoints(bodyB.getPosition(), bodyB.getRotation());
    float[] tangent = new float[4];
    float[] proj = new float[4];
   
    int outOfRange = 0;
   
    for (int i=0;i<4;i++) {
      pts[i].sub(bodyA.getPosition());
      pts[i].projectOntoUnit(axis, res);
      tangent[i] = getProp(res, axis);
      pts[i].projectOntoUnit(lineVec, res);
      proj[i] = getProp(res, new Vector2f(line.getDX(), line.getDY()));
     
      if ((proj[i] >= 1) || (proj[i] <= 0)) {
        outOfRange++;
      }
    }
    if (outOfRange == 4) {
      return 0;
    }
   
    Vector2f normal = new Vector2f(axis);
   
    if (centre < linePos) {
      if (!line.blocksInnerEdge()) {
        return 0;
      }
     
      normal.scale(-1);
      for (int i=0;i<4;i++) {
        if (tangent[i] > linePos) {
          if (proj[i] < 0) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left > 0) && (right > 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getStart());
             
              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else if (proj[i] > 1) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left > 0) && (right > 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getEnd());

              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else {
            pts[i].projectOntoUnit(lineVec, res);
            res.add(bodyA.getPosition());
            contacts[numContacts].setSeparation(-(tangent[i]-linePos));
            contacts[numContacts].setPosition(new Vector2f(res));
            contacts[numContacts].setNormal(normal);
            contacts[numContacts].setFeature(new FeaturePair(i))
            numContacts++;
          }
        }
      }
    } else {
      if (!line.blocksOuterEdge()) {
        return 0;
      }
     
      for (int i=0;i<4;i++) {
        if (tangent[i] < linePos) {
          if (proj[i] < 0) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getStart(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left < 0) && (right < 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
              pos.add(line.getStart());

              resolveEndPointCollision(pos,bodyA,bodyB,normal,leftLine,rightLine,contacts[numContacts],i);
              numContacts++;
            }
          } else if (proj[i] > 1) {
            Vector2f onAxis = new Vector2f();
            Line leftLine = new Line(getPt(pts,i-1),pts[i]);
            Line rightLine = new Line(getPt(pts,i+1),pts[i]);
            leftLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float left = getProp(onAxis, axis);
            rightLine.getClosestPoint(line.getEnd(),res);
            res.projectOntoUnit(axis, onAxis);
            float right = getProp(onAxis, axis);
           
            if ((left < 0) && (right < 0)) {
              Vector2f pos = new Vector2f(bodyA.getPosition());
View Full Code Here

TOP

Related Classes of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.raw.shapes.Line

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.