Package org.jbox2d.common

Examples of org.jbox2d.common.Vec2


    private static void render() {
        glClear(GL_COLOR_BUFFER_BIT);
        for (Body body : bodies) {
            if (body.getType() == BodyType.DYNAMIC) {
                glPushMatrix();
                Vec2 bodyPosition = body.getPosition().mul(30);
                glTranslatef(bodyPosition.x, bodyPosition.y, 0);
                glRotated(Math.toDegrees(body.getAngle()), 0, 0, 1);
                glRectf(-0.75f * 30, -0.75f * 30, 0.75f * 30, 0.75f * 30);
                glPopMatrix();
            }
View Full Code Here


    private static void input() {
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_C:
                        Vec2 bodyPosition = new Vec2(Mouse.getX(), Mouse.getY()).mul(0.5f).mul(1 / 30f);
                        BodyDef boxDef = new BodyDef();
                        boxDef.position.set(bodyPosition);
                        boxDef.type = BodyType.DYNAMIC;
                        PolygonShape boxShape = new PolygonShape();
                        boxShape.setAsBox(0.75f, 0.75f);
                        Body box = world.createBody(boxDef);
                        FixtureDef boxFixture = new FixtureDef();
                        boxFixture.density = 0.1f;
                        boxFixture.shape = boxShape;
                        box.createFixture(boxFixture);
                        bodies.add(box);
                        break;
                }
            }
        }
        for (Body body : bodies) {
            if (body.getType() == BodyType.DYNAMIC) {
                if (Keyboard.isKeyDown(Keyboard.KEY_A) && !Keyboard.isKeyDown(Keyboard.KEY_D)) {
                    body.applyAngularImpulse(+0.01f);
                } else if (Keyboard.isKeyDown(Keyboard.KEY_D) && !Keyboard.isKeyDown(Keyboard.KEY_A)) {
                    body.applyAngularImpulse(-0.01f);
                }
                if (Mouse.isButtonDown(0)) {
                    Vec2 mousePosition = new Vec2(Mouse.getX(), Mouse.getY()).mul(0.5f).mul(1 / 30f);
                    Vec2 bodyPosition = body.getPosition();
                    Vec2 force = mousePosition.sub(bodyPosition);
                    body.applyForce(force, body.getPosition());
                }
            }
        }
    }
View Full Code Here

    private static void render() {
        glClear(GL_COLOR_BUFFER_BIT);
        for (Body body : bodies) {
            if (body.getType() == BodyType.DYNAMIC) {
                glPushMatrix();
                Vec2 bodyPosition = body.getPosition().mul(30);
                glTranslatef(bodyPosition.x, bodyPosition.y, 0);
                glRotated(Math.toDegrees(body.getAngle()), 0, 0, 1);
                glRectf(-0.75f * 30, -0.75f * 30, 0.75f * 30, 0.75f * 30);
                glPopMatrix();
            }
View Full Code Here

                    body.applyAngularImpulse(+0.01f);
                } else if (Keyboard.isKeyDown(Keyboard.KEY_D) && !Keyboard.isKeyDown(Keyboard.KEY_A)) {
                    body.applyAngularImpulse(-0.01f);
                }
                if (Mouse.isButtonDown(0)) {
                    Vec2 mousePosition = new Vec2(Mouse.getX(), Mouse.getY()).mul(0.5f).mul(1 / 30f);
                    Vec2 bodyPosition = body.getPosition();
                    Vec2 force = mousePosition.sub(bodyPosition);
                    body.applyForce(force, body.getPosition());
                }
            }
        }
    }
View Full Code Here

  public static void init(int w,int h){
    width=w;
    height=h;
  }
  public static Vec2 coordPixelToWorld(Point p){
    return new Vec2(scalerPixelsToWorld(p.getX()-width/2.0),scalerPixelsToWorld(height/2.0-p.getY()));
  }
View Full Code Here

  }
  public static Vec2 coordPixelToWorld(Point p){
    return new Vec2(scalerPixelsToWorld(p.getX()-width/2.0),scalerPixelsToWorld(height/2.0-p.getY()));
  }
  public static Vec2 vectorPixelToWorld(Vector v){
    return new Vec2(scalerPixelsToWorld(v.getVectorX()),scalerPixelsToWorld(-v.getVectorY()));
  }
View Full Code Here

      this.checker=new Checker(fixtures);
     
      body.setTransform(body.getPosition(),(float)-angle);
      aabb=new AABB();
      aabb.combine(fixtures[0].getAABB(), fixtures[1].getAABB());
      forceVec=new Vec2((float)(radius*FORCE_MAGNITUDE_FACTOR*Math.cos(-angle)),(float)(radius*FORCE_MAGNITUDE_FACTOR*Math.sin(-angle)));
     
    }else{
      this.forceVec=null;
      this.radius=0;
    }
 
View Full Code Here

    Point brP=bmP.clone();
    blP.translate(-7.5f, 0);
    brP.translate(7.5f, 0);
    points=Point.getRotatedPoint(getPosition(), getAngle(),tlP,trP,crossP,bmP,blP,brP);
   
    Vec2 crossV=CoordinateConverter.vectorPixelToWorld(position.delta(crossP));
   
    BodyDef bodyD=new BodyDef();
    PolygonShape[] edges=new PolygonShape[]{new PolygonShape(),new PolygonShape(),new PolygonShape(),new PolygonShape()};
   
    bodyD.type=BodyType.STATIC;
View Full Code Here

      PolygonShape lineP=new PolygonShape();
     
      this.hL=getWidth()/2;
       
      lineP.setAsBox(CoordinateConverter.scalerPixelsToWorld(getWidth())/2
          ,CoordinateConverter.scalerPixelsToWorld(1),new Vec2(),0);
           
      fixD.density=1.2f;
      fixD.shape=lineP;
      fixD.restitution=0.75f;
      fixD.friction=0.4f;
View Full Code Here

  public void update() {
    if(lastShapesCount>0){
      double angle=lastShapesCount*PORTION_ANGLE;
      Point pos=this.position.clone();
      pos.translate(new Vector(spoutDistance,angle,true));
      Vec2 impulse=new Vec2((float)(this.impulseMag*Math.cos(angle)),(float)(this.impulseMag*Math.sin(angle)));
     
      PhysicalShape shape=generateShape(pos,angle);
      if(shape.isVerified()){
        shape.getBody().applyLinearImpulse(impulse,shape.getBody().getWorldCenter());
        lastShapesCount--;
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.