當前位置: 首頁>>代碼示例>>Java>>正文


Java Vec2類代碼示例

本文整理匯總了Java中org.jbox2d.common.Vec2的典型用法代碼示例。如果您正苦於以下問題:Java Vec2類的具體用法?Java Vec2怎麽用?Java Vec2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Vec2類屬於org.jbox2d.common包,在下文中一共展示了Vec2類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setTransform

import org.jbox2d.common.Vec2; //導入依賴的package包/類
/**
 * Set the position of the body's origin and rotation. This breaks any contacts and wakes the
 * other bodies. Manipulating a body's transform may cause non-physical behavior. Note: contacts
 * are updated on the next call to World.step().
 * 
 * @param position the world position of the body's local origin.
 * @param angle the world rotation in radians.
 */
public final void setTransform(Vec2 position, float angle) {
  assert (m_world.isLocked() == false);
  if (m_world.isLocked() == true) {
    return;
  }

  m_xf.q.set(angle);
  m_xf.p.set(position);

  // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
  Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c);
  m_sweep.a = angle;

  m_sweep.c0.set(m_sweep.c);
  m_sweep.a0 = m_sweep.a;

  BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
  for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
    f.synchronize(broadPhase, m_xf, m_xf);
  }
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:30,代碼來源:Body.java

示例2: Ground

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public Ground(Texture texture) {
	super(new Vec2(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2),texture);
	//Body def
   	BodyDef bd = new BodyDef();
   	bd.type = BodyType.STATIC;
   	bd.position.set(Public.box2d.coordPixelsToWorld(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2) );
   	bd.setUserData("PhysicalGameObject,Ground");
   	//Create body
       body = Public.box2d.createBody(bd);
   	//Creat Shape
       PolygonShape ps = new PolygonShape();
       ps.setAsBox(Public.box2d.scalarPixelsToWorld(Public.p.width*100),-Public.box2d.scalarPixelsToWorld(-texture.getTexture().height/2) );
       //Fixture
       FixtureDef fd = new FixtureDef();
       fd.shape = ps;
       fd.density = 1f;
       fd.friction = 0.3f;
       fd.restitution = 0.15f;
       body.createFixture(fd);
       
}
 
開發者ID:Error1000,項目名稱:processingGameEngine,代碼行數:22,代碼來源:Ground.java

示例3: computeEdgeSeparation

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public void computeEdgeSeparation(EPAxis axis) {
  axis.type = EPAxis.Type.EDGE_A;
  axis.index = m_front ? 0 : 1;
  axis.separation = Float.MAX_VALUE;
  float nx = m_normal.x;
  float ny = m_normal.y;

  for (int i = 0; i < m_polygonB.count; ++i) {
    Vec2 v = m_polygonB.vertices[i];
    float tempx = v.x - m_v1.x;
    float tempy = v.y - m_v1.y;
    float s = nx * tempx + ny * tempy;
    if (s < axis.separation) {
      axis.separation = s;
    }
  }
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:18,代碼來源:Collision.java

示例4: initScene

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public void initScene()   {
  Body ground = null;
  {
    BodyDef bd = new BodyDef();
    bd.position.set(0.0f, 20.0f);
    ground = world.createBody(bd);
  }

  float a = 0.5f;
  Vec2 h = new Vec2(0.0f, a);

  colorMode(HSB, 1f);
  
  Body root = AddNode(ground, new Vec2(), 0, 3.0f, a);
  
  colorMode(RGB, 255);

  RevoluteJointDef jointDef = new RevoluteJointDef();
  jointDef.bodyA = ground;
  jointDef.bodyB = root;
  jointDef.localAnchorA.setZero();
  jointDef.localAnchorB = h;
  world.createJoint(jointDef);
  
  world.bodies.addAll();
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:27,代碼來源:box2d_MobileBalanced.java

示例5: raycast

import org.jbox2d.common.Vec2; //導入依賴的package包/類
@Override
public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
  assert (childIndex < m_count);

  final EdgeShape edgeShape = pool0;

  int i1 = childIndex;
  int i2 = childIndex + 1;
  if (i2 == m_count) {
    i2 = 0;
  }
  Vec2 v = m_vertices[i1];
  edgeShape.m_vertex1.x = v.x;
  edgeShape.m_vertex1.y = v.y;
  Vec2 v1 = m_vertices[i2];
  edgeShape.m_vertex2.x = v1.x;
  edgeShape.m_vertex2.y = v1.y;

  return edgeShape.raycast(output, input, xf, 0);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:21,代碼來源:ChainShape.java

示例6: computeAABB

import org.jbox2d.common.Vec2; //導入依賴的package包/類
@Override
public void computeAABB(AABB aabb, Transform xf, int childIndex) {
  assert (childIndex < m_count);
  final Vec2 lower = aabb.lowerBound;
  final Vec2 upper = aabb.upperBound;

  int i1 = childIndex;
  int i2 = childIndex + 1;
  if (i2 == m_count) {
    i2 = 0;
  }

  final Vec2 vi1 = m_vertices[i1];
  final Vec2 vi2 = m_vertices[i2];
  final Rot xfq = xf.q;
  final Vec2 xfp = xf.p;
  float v1x = (xfq.c * vi1.x - xfq.s * vi1.y) + xfp.x;
  float v1y = (xfq.s * vi1.x + xfq.c * vi1.y) + xfp.y;
  float v2x = (xfq.c * vi2.x - xfq.s * vi2.y) + xfp.x;
  float v2y = (xfq.s * vi2.x + xfq.c * vi2.y) + xfp.y;

  lower.x = v1x < v2x ? v1x : v2x;
  lower.y = v1y < v2y ? v1y : v2y;
  upper.x = v1x > v2x ? v1x : v2x;
  upper.y = v1y > v2y ? v1y : v2y;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:27,代碼來源:ChainShape.java

示例7: createLoop

import org.jbox2d.common.Vec2; //導入依賴的package包/類
/**
 * Create a loop. This automatically adjusts connectivity.
 * 
 * @param vertices an array of vertices, these are copied
 * @param count the vertex count
 */
public void createLoop(final Vec2[] vertices, int count) {
  assert (m_vertices == null && m_count == 0);
  assert (count >= 3);
  m_count = count + 1;
  m_vertices = new Vec2[m_count];
  for (int i = 1; i < count; i++) {
    Vec2 v1 = vertices[i - 1];
    Vec2 v2 = vertices[i];
    // If the code crashes here, it means your vertices are too close together.
    if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
      throw new RuntimeException("Vertices of chain shape are too close together");
    }
  }
  for (int i = 0; i < count; i++) {
    m_vertices[i] = new Vec2(vertices[i]);
  }
  m_vertices[count] = new Vec2(m_vertices[0]);
  m_prevVertex.set(m_vertices[m_count - 2]);
  m_nextVertex.set(m_vertices[1]);
  m_hasPrevVertex = true;
  m_hasNextVertex = true;
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:29,代碼來源:ChainShape.java

示例8: updateBodyContacts

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public void updateBodyContacts() {
  final AABB aabb = temp;
  aabb.lowerBound.x = Float.MAX_VALUE;
  aabb.lowerBound.y = Float.MAX_VALUE;
  aabb.upperBound.x = -Float.MAX_VALUE;
  aabb.upperBound.y = -Float.MAX_VALUE;
  for (int i = 0; i < m_count; i++) {
    Vec2 p = m_positionBuffer.data[i];
    Vec2.minToOut(aabb.lowerBound, p, aabb.lowerBound);
    Vec2.maxToOut(aabb.upperBound, p, aabb.upperBound);
  }
  aabb.lowerBound.x -= m_particleDiameter;
  aabb.lowerBound.y -= m_particleDiameter;
  aabb.upperBound.x += m_particleDiameter;
  aabb.upperBound.y += m_particleDiameter;
  m_bodyContactCount = 0;

  ubccallback.system = this;
  m_world.queryAABB(ubccallback, aabb);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:21,代碼來源:ParticleSystem.java

示例9: updateSensor

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public void updateSensor(){
  
  Body bsensor = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 sensor_pos = bsensor.getWorldPoint(circle.m_p);

  // iterate through all contacts and apply a force on shapes that overlap the sensor.
  for(Contact contact = world.getContactList(); contact != null; contact = contact.m_next){

    Fixture fixtureA = contact.getFixtureA();
    Fixture fixtureB = contact.getFixtureB();
    
    Body body = null;
         if(fixtureA == m_sensor) body = fixtureB.getBody();
    else if(fixtureB == m_sensor) body = fixtureA.getBody();
    else continue;

    Vec2 body_pos = body.getPosition();
    Vec2 dist = sensor_pos.sub(body_pos);
    if (dist.lengthSquared() > Settings.EPSILON * Settings.EPSILON) {
      dist.normalize();
      Vec2 force = dist.mulLocal(200f);
      body.applyForce(force, body_pos);
    }
  }
}
 
開發者ID:diwi,項目名稱:LiquidFunProcessing,代碼行數:27,代碼來源:box2d_Collisions_SensorTest.java

示例10: applyLinearImpulse

import org.jbox2d.common.Vec2; //導入依賴的package包/類
/**
 * Apply an impulse at a point. This immediately modifies the velocity. It also modifies the
 * angular velocity if the point of application is not at the center of mass. This wakes up the
 * body if 'wake' is set to true. If the body is sleeping and 'wake' is false, then there is no
 * effect.
 * 
 * @param impulse the world impulse vector, usually in N-seconds or kg-m/s.
 * @param point the world position of the point of application.
 * @param wake also wake up the body
 */
public final void applyLinearImpulse(Vec2 impulse, Vec2 point, boolean wake) {
  if (m_type != BodyType.DYNAMIC) {
    return;
  }

  if (!isAwake()) {
    if (wake) {
      setAwake(true);
    } else {
      return;
    }
  }

  m_linearVelocity.x += impulse.x * m_invMass;
  m_linearVelocity.y += impulse.y * m_invMass;

  m_angularVelocity +=
      m_invI * ((point.x - m_sweep.c.x) * impulse.y - (point.y - m_sweep.c.y) * impulse.x);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:30,代碼來源:Body.java

示例11: drawJoint

import org.jbox2d.common.Vec2; //導入依賴的package包/類
private void drawJoint(Joint joint) {
  Body bodyA = joint.getBodyA();
  Body bodyB = joint.getBodyB();
  Transform xf1 = bodyA.getTransform();
  Transform xf2 = bodyB.getTransform();
  Vec2 x1 = xf1.p;
  Vec2 x2 = xf2.p;
  Vec2 p1 = pool.popVec2();
  Vec2 p2 = pool.popVec2();
  joint.getAnchorA(p1);
  joint.getAnchorB(p2);

  color.set(0.5f, 0.8f, 0.8f);

  switch (joint.getType()) {
  // TODO djm write after writing joints
    case DISTANCE:
      m_debugDraw.drawSegment(p1, p2, color);
      break;

    case PULLEY: {
      PulleyJoint pulley = (PulleyJoint) joint;
      Vec2 s1 = pulley.getGroundAnchorA();
      Vec2 s2 = pulley.getGroundAnchorB();
      m_debugDraw.drawSegment(s1, p1, color);
      m_debugDraw.drawSegment(s2, p2, color);
      m_debugDraw.drawSegment(s1, s2, color);
    }
      break;
    case CONSTANT_VOLUME:
    case MOUSE:
      // don't draw this
      break;
    default:
      m_debugDraw.drawSegment(x1, p1, color);
      m_debugDraw.drawSegment(p1, p2, color);
      m_debugDraw.drawSegment(x2, p2, color);
  }
  pool.pushVec2(2);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:41,代碼來源:World.java

示例12: Physics

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public Physics(){
	world = new World(new Vec2(gravity.x, gravity.y));
	
	//setup the callback trackers
	setTracker(new ContactTracker(this));
	
	instance = this;
}
 
開發者ID:tek256,項目名稱:LD38,代碼行數:9,代碼來源:Physics.java

示例13: setGravity

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public void setGravity(float x, float y){
	if(x == gravity.x && y == gravity.y)
		return;
	
	this.gravity.set(x, y);
	world.setGravity(new Vec2(gravity.x, gravity.y));
}
 
開發者ID:tek256,項目名稱:LD38,代碼行數:8,代碼來源:Physics.java

示例14: initReel

import org.jbox2d.common.Vec2; //導入依賴的package包/類
private void initReel() {
    BodyDef reelDef = new BodyDef();
    reelDef.type = BodyType.DYNAMIC;
    reelDef.position = new Vec2(3, 3);
    reel = world.createBody(reelDef);

    FixtureDef fixture = new FixtureDef();
    fixture.friction = 0.5f;
    fixture.restitution = 0.4f;
    fixture.density = 1;

    int parts = 30;
    for (int i = 0; i < parts; ++i) {
        System.out.println("New reel part");
        PolygonShape shape = new PolygonShape();
        double angle1 = i / (double) parts * 2 * Math.PI;
        double x1 = 2.7 * Math.cos(angle1);
        double y1 = 2.7 * Math.sin(angle1);
        double angle2 = (i + 1) / (double) parts * 2 * Math.PI;
        double x2 = 2.7 * Math.cos(angle2);
        double y2 = 2.7 * Math.sin(angle2);
        double angle = (angle1 + angle2) / 2;
        double x = 0.01 * Math.cos(angle);
        double y = 0.01 * Math.sin(angle);

        shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2),
                new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4);
        fixture.shape = shape;
        reel.createFixture(fixture);
    }
}
 
開發者ID:mirkosertic,項目名稱:Bytecoder,代碼行數:32,代碼來源:JBox2DTest.java

示例15: getVec2Array

import org.jbox2d.common.Vec2; //導入依賴的package包/類
public final Vec2[] getVec2Array(int argLength) {
  if (!avecs.containsKey(argLength)) {
    Vec2[] ray = new Vec2[argLength];
    for (int i = 0; i < argLength; i++) {
      ray[i] = new Vec2();
    }
    avecs.put(argLength, ray);
  }

  assert (avecs.get(argLength).length == argLength) : "Array not built with correct length";
  return avecs.get(argLength);
}
 
開發者ID:jfcameron,項目名稱:G2Dj,代碼行數:13,代碼來源:DefaultWorldPool.java


注:本文中的org.jbox2d.common.Vec2類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。