Package eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math

Examples of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f


    private Joint j1, j2;
   
    @Override
    public Phys3Env[] generateRunnables(ParCollection params) {
        Phys3Env[] envs = new Phys3Env[1];
        final Phys3Env env = new Phys3Env(0, params, new Vector2f(0, 5), 1000);
        envs[0] = env;
       
        env.addAgent(new Phys3Agent(0, env, "Agent0", 10, params), new Vector2D(0, -5), 180);
        env.addAgent(new Phys3JetAgent(1, env, "Agent1", 10, params), new Vector2D(-3, 1), 180);
        env.addAgent(new Phys3JetAgent(2, env, "Agent2", 10, params), new Vector2D(3, 1), 180);
View Full Code Here


    @Override
    public PhysicsEnvironment2D<PhysicsAgent2D<?>>[] generateRunnables(ParCollection params) {
        @SuppressWarnings("unchecked")
        PhysicsEnvironment2D<PhysicsAgent2D<?>>[] envs = new PhysicsEnvironment2D[1];
        PhysicsEnvironment2D<PhysicsAgent2D<?>> env = new PhysicsEnvironment2D<PhysicsAgent2D<?>>(0, params, new Vector2f(0, 0), 500);
        envs[0] = env;
       
        for (int i = 0; i < 200; i += 30) {
            for (int j = 0; j < 200; j += 30) {
                env.addAgent(new PhysicsAgent2(j * 10 + i, env, 5, params), new Vector2D(i, j), 0);
            }           
        }
       
        PhysicsAgent3 p = new PhysicsAgent3(10000, env, 200, params);
        env.addAgent(p, new Vector2D(-200, 100), 0);
//        p.adjustVelocity(new Vector2f(100, 0));
       
        env.addAgent(new StaticBody(10001, env, params), new Vector2D(10, -80), 0);
        env.addAgent(new StaticBody(10002, env, params), new Vector2D(125, -80), 0);
        env.addAgent(new StaticBody(10003, env, params), new Vector2D(250, -80), 0);
        env.addAgent(new StaticBody(10004, env, params), new Vector2D(10, 250), 0);
        env.addAgent(new StaticBody(10005, env, params), new Vector2D(125, 250), 0);
        env.addAgent(new StaticBody(10006, env, params), new Vector2D(250, 250), 0);
        env.addAgent(new StaticBody(10007, env, params), new Vector2D(325, -40), 90);
        env.addAgent(new StaticBody(10008, env, params), new Vector2D(325, 85), 90);
        env.addAgent(new StaticBody(10009, env, params), new Vector2D(325, 210), 90);
       
        env.add(new ForceSource<PhysicsAgent2D<?>>() {
            private static final long serialVersionUID = 7669888473552046204L;

            @Override
            public void apply(PhysicsAgent2D<?> body, float dt) {
                if (body.id() == 10000) {
                    body.addForce(new Vector2f(3500, -150));
                }
            }
        });
       
        return envs;
View Full Code Here

  @Override
  public PhysEnvSimple[] generateRunnables(ParCollection params) {
      PhysEnvSimple env = new PhysEnvSimple(
                0,
                params,
                new Vector2f(0, 0),
                5);
    fillEnv(params, env);
   
    return new PhysEnvSimple[] {env};
  }
View Full Code Here

          } else {
                agent = new PhysAgentCircleSimple((int) w.getLastTick(), umg, 10, params);
          }
         
          umg.addAgent(agent, new Vector2D(15, 113), 90);
          agent.addForce(new Vector2f(-100000, 0));
      }
     
      if (insertAgent && w.getLastTick() % 1 == 0) {
            PhysicsAgent2D<PhysEnvSimple> agent;
            if (new Random().nextBoolean()) {
                agent = new PhysAgentRectangleSimple((int) w.getLastTick(), umg, 10, params);
            } else {
                agent = new PhysAgentCircleSimple((int) w.getLastTick(), umg, 10, params);
            }
           
            umg.addAgent(agent, new Vector2D(-70, 70), 0);
            agent.addForce(new Vector2f(0, 1000));
      }

        if (insertAgent2 && w.getLastTick() % 1 == 0) {
            PhysicsAgent2D<PhysEnvSimple> agent;
            if (new Random().nextBoolean()) {
                agent = new PhysAgentRectangleSimple((int) w.getLastTick(),
                        umg, 10, params);
            } else {
                agent = new PhysAgentCircleSimple((int) w.getLastTick(),
                        umg, 10, params);
            }

            umg.addAgent(agent, new Vector2D(-100, -30), 0);
            agent.addForce(new Vector2f(0, 1000));
        }

        if (insertAgent3 && w.getLastTick() % 1 == 0) {
            PhysicsAgent2D<PhysEnvSimple> agent;
            if (new Random().nextBoolean()) {
                agent = new PhysAgentRectangleSimple((int) w.getLastTick(),
                        umg, 10, params);
            } else {
                agent = new PhysAgentCircleSimple((int) w.getLastTick(),
                        umg, 10, params);
            }

            try {
                AllroundVideoPlugin vid = (AllroundVideoPlugin) umg.getSimTime().getPluginObject(new AllroundVideoPlugin().id());
                umg.addAgent(agent, umg.getAgentPosition(vid.getMarkedAgentId()), 0);
                agent.addForce(new Vector2f(0, 1000));
            } catch (Exception e) {
            }
           
        }
View Full Code Here

        PhysicsEnvironment2D<PhysicsAgent2D<?>> env = new PhysicsEnvironment2D<PhysicsAgent2D<?>>(
                "Physics-Environment",
                0,
                null,
                params,
                new Vector2f(0, 50),
                500,
                new BruteCollisionStrategy());
       
        envs[0] = env;
        env.addAgent(new PhysicalObstacle(0, env, params, 10), new Vector2D(13, -150), 26);
View Full Code Here

  @Override
  public PhysEnv[] generateRunnables(ParCollection params) {
      PhysEnv env = new PhysEnv(
                0,
                params,
                new Vector2f(0, 0),
                150);
    int max = params.getParValueInt("numBoxes");
    int numSpheres = params.getParValueInt("numSpheres");

    fillEnv(params, env, max, numSpheres);
View Full Code Here

   * @param vertsA The vertices of polygon A
   * @param vertsB The vertices of polygon B
   * @return the maximum penetration depth along the given normal
   */
  public static float getPenetrationDepth(Intersection in, Intersection out, Vector2f normal, Vector2f[] vertsA, Vector2f[] vertsB) {
    Vector2f sweepdir = new Vector2f(out.position);
    sweepdir.sub(in.position);
   
    PenetrationSweep ps = new PenetrationSweep(normal, sweepdir, in.position, out.position);

    //TODO: most penetrations are very simple, similar to:
    // \               +       |       
View Full Code Here

   *
   * @return True if the joint is holding the bodies together
   */
  public boolean isActive() {
    if (body1.getPosition().distanceSquared(body2.getPosition()) < distance) {
      Vector2f to2 = new Vector2f(body2.getPosition());
      to2.sub(body1.getPosition());
      to2.normalise();
      Vector2f vel = new Vector2f(body1.getVelocity());
      vel.normalise();
      if (body1.getVelocity().dot(to2) < 0) {
        return true;
      }
    }
   
View Full Code Here

   
    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];
    ROVector2f startB = bodyB.getPosition();
    Vector2f endB = new Vector2f(endA);
    endB.sub(startA);
    endB.set(endB.y, -endB.x);
//    endB.add(startB);// TODO: inline endB into equations below, this last operation will be useless..
   
    //TODO: reuse mathutil.intersect
//    float d = (endB.y - startB.getY()) * (endA.x - startA.x);
//    d -= (endB.x - startB.getX()) * (endA.y - startA.y);
//   
//    float uA = (endB.x - startB.getX()) * (startA.y - startB.getY());
//    uA -= (endB.y - startB.getY()) * (startA.x - startB.getX());
//    uA /= d;
    float d = endB.y * (endA.x - startA.x);
    d -= endB.x * (endA.y - startA.y);
   
    float uA = endB.x * (startA.y - startB.getY());
    uA -= endB.y * (startA.x - startB.getX());
    uA /= d;
   
    Vector2f position = null;
   
    if ( uA < 0 ) { // the intersection is somewhere before startA
      position = startA;
    } else if ( uA > 1 ) { // the intersection is somewhere after endA
      position = endA;
    } else {
      position = new Vector2f(
          startA.x + uA * (endA.x - startA.x),
          startA.y + uA * (endA.y - startA.y));
    }
   
    Vector2f normal = endB; // reuse of vector object
    normal.set(startB);
    normal.sub(position);
    float distSquared = normal.lengthSquared();
    float radiusSquared = circle.getRadius() * circle.getRadius();
   
    if ( distSquared < radiusSquared ) {
      contacts[0].setPosition(position);
      contacts[0].setFeature(new FeaturePair());
     
      normal.normalise();
      contacts[0].setNormal(normal);
     
      float separation = (float) Math.sqrt(distSquared) - circle.getRadius();
      contacts[0].setSeparation(separation);
     
View Full Code Here

    Polygon polyB = (Polygon) bodyB.getShape();

    Vector2f[] vertsA = polyA.getVertices(bodyA.getPosition(), bodyA.getRotation());
    Vector2f[] vertsB = polyB.getVertices(bodyB.getPosition(), bodyB.getRotation());
   
    Vector2f centroidA = new Vector2f(polyA.getCentroid());
    centroidA.add(bodyA.getPosition());
    Vector2f centroidB = new Vector2f(polyB.getCentroid());
    centroidB.add(bodyB.getPosition());
   
    int[][] collEdgeCands = getCollisionCandidates(vertsA, vertsB, centroidA, centroidB);
    Intersection[][] intersections = getIntersectionPairs(vertsA, vertsB, collEdgeCands);   
    return populateContacts(contacts, vertsA, vertsB, intersections);
  }
View Full Code Here

TOP

Related Classes of eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f

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.