Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


    public boolean isRotating(){
      return gravityAngle!=nextGravityAngle;
    }
   
    private void fireGravityChangedEvents(){
      GravityChangedEvent event=new GravityChangedEvent(this,new Vec2(gravity));
      for(int i=listenerList.size()-1;i>=0;i--){
        listenerList.get(i).gravityChanged(event);
      }
     
    }
View Full Code Here


      }
      RotationUnit=delta/Math.abs(delta);
      Settings.velocityThreshold=DEFAULT_VELOCITY_THRESHOLD;
    }
    private static Vec2 getGravityByDegrees(int angleInDegree){
      return new Vec2((float)(GRAVITY_MAGNITUDE*Math.cos(Math.toRadians(angleInDegree))),
               (float)(GRAVITY_MAGNITUDE*Math.sin(Math.toRadians(-angleInDegree))));
    }
 
View Full Code Here

   * @param angle
   */
  public Cross(Point p,double angle) {
    super(0, p, 15*(1+SQRT_2), 15*(1+SQRT_2/2),angle);
   
    Vec2 crossV=CoordinateConverter.vectorPixelToWorld(position.delta(getX(),getTopY()+getWidth()/2));
    Point nwP=this.getPositionAt(PositionType.NORTHWEST);
    Point neP=this.getPositionAt(PositionType.NORTHEAST);
    Point seP=nwP.clone();
    Point swP=neP.clone();
    seP.translate(getHeight(), getHeight());
View Full Code Here

  @Override
  public void update(){
   
    if(!contactShapes.isEmpty()){
      Body body;
      Vec2 imp;
      for(Physical ps:contactShapes){
        if(!ps.isDestroyed()){
          body=ps.getBody();
          imp=body.getLinearVelocity().clone();
         
          imp.mulLocal(IMPULSE_MAGNITUDE);
          body.applyLinearImpulse(imp, body.getWorldCenter());
        }
      }
      contactShapes.clear();
     
View Full Code Here

     
      vecA=CoordinateConverter.coordPixelToWorld(pointA);
      vecB=CoordinateConverter.coordPixelToWorld(pointB);
      vecAToB=vecB.sub(vecA);
      vecBToA=vecAToB.negate();
      forces=new Vec2[]{new Vec2(-vecAToB.y,vecAToB.x),new Vec2(-vecBToA.y,vecBToA.x)};
      for(Vec2 force:forces){
        force.normalize();
        force.mulLocal(FORCE_MAGNITUDE);//force length
      }
     
      float radius=CoordinateConverter.scalerPixelsToWorld(MAGNETIC_FIELD_BOUNDS);
     
      FixtureDef recFixD=new FixtureDef();
      FixtureDef cirFixDA=new FixtureDef();
      FixtureDef cirFixDB=new FixtureDef();
     
      CircleShape cirShapeA=new CircleShape();
      CircleShape cirShapeB=new CircleShape();
      PolygonShape recShape=new PolygonShape();
     
      cirShapeA.m_radius=radius;
      cirShapeB.m_radius=radius;
      cirShapeA.m_p.set(CoordinateConverter.vectorPixelToWorld(position.delta(pointA)));
      cirShapeB.m_p.set(CoordinateConverter.vectorPixelToWorld(position.delta(pointB)));
      recShape.setAsBox(CoordinateConverter.scalerPixelsToWorld(getWidth()/2),radius, new Vec2(),(float)-getAngle());
     
      recFixD.isSensor=true;
      cirFixDA.isSensor=true;
      cirFixDB.isSensor=true;
     
View Full Code Here

  /* (non-Javadoc)
   * @see com.google.gwt.maeglin89273.game.mengine.component.GeneralComponent#update()
   */
  @Override
  public void update(){
    Vec2 shapePos;
    Vec2 pAToShape;
    Vec2 pBToShape;
    Physical dc;
    for(int i=creationsInField.size()-1;i>=0;i--){
      dc=creationsInField.get(i);
      if(dc.isDestroyed()){
        creationsInField.remove(i);
      }else{
        shapePos=dc.getBody().getWorldCenter();
        pAToShape=shapePos.sub(vecA);
        pBToShape=shapePos.sub(vecB);
        if(Vec2.dot(pAToShape, vecAToB)<0){
          if(pAToShape.lengthSquared()>ASBOTXConfigs.E_SQUARE){
            pAToShape.negateLocal();
            pAToShape.normalize();
            pAToShape.mulLocal(FORCE_MAGNITUDE);
            dc.getBody().applyForce(pAToShape,shapePos);
          }
        }else if(Vec2.dot(pBToShape, vecBToA)<0){
          if(pBToShape.lengthSquared()>ASBOTXConfigs.E_SQUARE){
            pBToShape.negateLocal();
            pBToShape.normalize();
            pBToShape.mulLocal(FORCE_MAGNITUDE);
            dc.getBody().applyForce(pBToShape,shapePos);
          }
        }else{
          dc.getBody().applyForce(Vec2.cross(pAToShape,vecAToB)>0?forces[0]:forces[1],shapePos);
        }
View Full Code Here

   * @param h
   * @param a
   */
  public ShapesFountain(Creator creator,Point p,double a,float impulseMag) {
    super(creator, p,a);
    impulse=new Vec2((float)(impulseMag*Math.cos(-a)),(float)(impulseMag*Math.sin(-a)));
    timer=new RepeatingTimer(new TimerTask(){

      @Override
      public void doTask() {
       
View Full Code Here

          break;
        case 2:
          shape=new Polygon(MEngine.getMousePosition());
         
      }*/
      shape.getBody().applyLinearImpulse(new Vec2(0,-1), shape.getBody().getWorldCenter());
    }
   
    worldLayer.update();
   
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.google.gwt.maeglin89273.game.mengine.component.GeneralComponent#update()
   */
  @Override
  public void update() {
    Vec2 v;
    Physical dc;
    for(int i=contentCreations.size()-1;i>=0;i--){
      dc=contentCreations.get(i);
      if(dc.isDestroyed()){
        contentCreations.remove(i);
      }else{
       
        v=center.sub(dc.getBody().getPosition());
        float lengthS=v.lengthSquared();
       
        if(lengthS>ASBOTXConfigs.E_SQUARE){
          v.normalize();
          v.mulLocal((float)radius*K*dc.getBody().getMass());
          dc.getBody().applyForce(v, dc.getBody().getWorldCenter());
        }
      }
    }
  }
View Full Code Here

    aabb=new PixelAABB(this.position,width,height);
   
    BodyDef bodyDef=new BodyDef();
    CircleShape shape=new CircleShape();
    FixtureDef fixtureDef=new FixtureDef();
    Vec2 impulse=CoordinateConverter.vectorPixelsToWorld(new Vector(-30+60*Random.nextDouble(),-(175+50*Random.nextDouble())));
   
    bodyDef.type=BodyType.DYNAMIC;
    bodyDef.position.set(CoordinateConverter.coordPixelsToWorld(position));
   
   
 
View Full Code Here

TOP

Related Classes of org.jbox2d.common.Vec2

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.