Package net.phys2d.math

Examples of net.phys2d.math.Vector2f


  public Vector2f[] getPoints(ROVector2f pos, float rotation) {
    Matrix2f R = new Matrix2f(rotation);
    Vector2f[] pts = new Vector2f[4];
    ROVector2f h = MathUtil.scale(getSize(),0.5f);

    pts[0] = MathUtil.mul(R, new Vector2f(-h.getX(), -h.getY()));
    pts[0].add(pos);
    pts[1] = MathUtil.mul(R, new Vector2f(h.getX(), -h.getY()));
    pts[1].add(pos);
    pts[2] = MathUtil.mul(R, new Vector2f( h.getX(),  h.getY()));
    pts[2].add(pos);
    pts[3] = MathUtil.mul(R, new Vector2f(-h.getX(),  h.getY()));
    pts[3].add(pos);

    return pts;
  }
View Full Code Here


      throw new IllegalArgumentException("A polygon can not have fewer than 3 edges!");
   
    this.vertices = new Vector2f[vertices.length];
   
    for ( int i = 0; i < vertices.length; i++ ) {
      this.vertices[i] = new Vector2f(vertices[i]);
    }
   
    if ( !super.isConvex() )
      throw new IllegalArgumentException("The supplied vertices do not represent a convex polygon!");
   
View Full Code Here

   */
  public boolean contains(Vector2f p) {
    // p is in the polygon if it is left of all the edges
    int l = vertices.length;
    for ( int i = 0; i < vertices.length; i++ ) {
      Vector2f x = vertices[i];
      Vector2f y = vertices[(i+1)%l];
      Vector2f z = p;
     
      // does the 3d cross product point up or down?
      if ( (z.x-x.x)*(y.y-x.y)-(y.x-x.x)*(z.y-x.y) >= 0 )
        return false;
    }
View Full Code Here

   */
  public ROVector2f getNearestPoint(ROVector2f p) {
    // TODO: this can be done with a kind of binary search
    float r = Float.MAX_VALUE;
    float l;
    Vector2f v;
    int m = -1;
   
    for ( int i = 0; i < vertices.length; i++ ) {
      v = new Vector2f(vertices[i]);
      v.sub(p);
      l = v.x * v.x + v.y * v.y;
     
      if ( l < r ) {
        r = l;
        m = i;
      }
    }
   
    // the closest point could be on one of the closest point's edges
    // this happens when the angle between v[m-1]-v[m] and p-v[m] is
    // smaller than 90 degrees, same for v[m+1]-v[m]
    int length = vertices.length;
    Vector2f pm = new Vector2f(p);
    pm.sub(vertices[m]);
    Vector2f l1 = new Vector2f(vertices[(m-1+length)%length]);
    l1.sub(vertices[m]);
    Vector2f l2 = new Vector2f(vertices[(m+1)%length]);
    l2.sub(vertices[m]);
   
    Vector2f normal;
    if ( pm.dot(l1) > 0 ) {
      normal = MathUtil.getNormal(vertices[(m-1+length)%length], vertices[m]);
    } else if ( pm.dot(l2) > 0 ) {
      normal = MathUtil.getNormal(vertices[m], vertices[(m+1)%length]);
    } else {
      return vertices[m];
    }
   
    normal.scale(-pm.dot(normal));
    normal.add(p);
    return normal;
  }
View Full Code Here

    }
    if(this.rightBorder != null && this.body.getPosition().getX() >= this.rightBorder) {
      this.dir = LEFT;
    }
    if(this.body.getVelocity().getX() * this.dir < TARGET_VELOCITY) {
      this.body.addForce(new Vector2f(240.0f * this.dir, 0.0f));
    }
  }
View Full Code Here

  private Vector2f position;
 
  private ParticleEmitterFactory factory;
 
  public ParticleEffect(ROVector2f position, ParticleEmitterFactory factory) {
    this.position = new Vector2f(position);
    this.factory = factory;
  }
View Full Code Here

    addAxisAlignedWall(new Stone(), startX, startY, x, y);
  }
 
  public Body addFigure(float footX, float footY) {
    float oldMass = setMass(Figure.MASS);
    ROVector2f oldPosition = setPosition(new Vector2f(footX + Figure.WIDTH / 2.0f, footY - Figure.HEIGHT / 2.0f));
    Body figure = addAxisAlignedBox(new Figure(), Figure.WIDTH, Figure.HEIGHT);
    setMass(oldMass);
    setPosition(oldPosition);
    return figure;
  }
View Full Code Here

    return figure;
  }
 
  public Body addSimpleFootSoldier(float footX, float footY, short dir, Float leftBorder, Float rightBorder) {
    float oldMass = setMass(SimpleFootSoldier.MASS);
    ROVector2f oldPosition = setPosition(new Vector2f(footX + SimpleFootSoldier.WIDTH / 2.0f, footY - SimpleFootSoldier.HEIGHT / 2.0f));
    Body soldier = addAxisAlignedBox(new SimpleFootSoldier(dir, leftBorder, rightBorder), SimpleFootSoldier.WIDTH, SimpleFootSoldier.HEIGHT);
    setMass(oldMass);
    setPosition(oldPosition);
    return soldier;
  }
View Full Code Here

    return addSimpleFootSoldier(footX, footY, SimpleFootSoldier.LEFT, null, null);
  }
 
  public Body addArmouredFootSoldier(float footX, float footY, short dir, Float leftBorder, Float rightBorder) {
    float oldMass = setMass(SimpleFootSoldier.MASS);
    ROVector2f oldPosition = setPosition(new Vector2f(footX + SimpleFootSoldier.WIDTH / 2.0f, footY - SimpleFootSoldier.HEIGHT / 2.0f));
    Body soldier = addAxisAlignedBox(new ArmouredFootSoldier(dir, leftBorder, rightBorder), SimpleFootSoldier.WIDTH, SimpleFootSoldier.HEIGHT);
    setMass(oldMass);
    setPosition(oldPosition);
    return soldier;
  }
View Full Code Here

    return soldier;
  }
 
  public Body addVerticalSlider(float footX, float footY, float x, float y, float upperBorder, float lowerBorder) {
    float oldMass = setMass(VerticalSlider.MASS);
    ROVector2f oldPosition = setPosition(new Vector2f(footX + x / 2.0f, footY + y / 2.0f));
    Body slider = addAxisAlignedBox(new VerticalSlider(upperBorder, lowerBorder), x, y);
    setMass(oldMass);
    setPosition(oldPosition);
    return slider;
  }
View Full Code Here

TOP

Related Classes of 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.