当前位置: 首页>>代码示例>>Java>>正文


Java ChainShape类代码示例

本文整理汇总了Java中org.jbox2d.collision.shapes.ChainShape的典型用法代码示例。如果您正苦于以下问题:Java ChainShape类的具体用法?Java ChainShape怎么用?Java ChainShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChainShape类属于org.jbox2d.collision.shapes包,在下文中一共展示了ChainShape类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createChainLink

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
/**
 * 
 */
private void createChainLink() {		
	ChainShape chainShape = new ChainShape();	
	Vec2[] vecArray = new Vec2[m_paddleVecList.size()];
	vecArray = m_paddleVecList.toArray(vecArray);
	
	if (!checkPositionsOutOfBounds(vecArray) && m_chainDistance < 15) {
	
		try {
			chainShape.createChain(vecArray, m_paddleVecList.size());	
			BodyDef chainBodyDef = new BodyDef();	
			Body chainBody = this.getWorld().createBody(chainBodyDef);	
			chainBody.createFixture(chainShape, 1);
			m_chainBodyList.add(chainBody);				
			m_chainDistance+= calculateChainLinkDistance(vecArray);
		} catch(RuntimeException e) {
			// probably a 'verticies of chain shape are too close together
			// this because we only save chain link pairs at the moment, so
			// if the mouse doubles back onto an existing segment, problems...
		}
	
	}

}
 
开发者ID:davidholiday,项目名称:ALTk,代码行数:27,代码来源:AdSplodeTestRun.java

示例2: evaluate

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
@Override
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
  ChainShape chain = (ChainShape) m_fixtureA.getShape();
  chain.getChildEdge(edge, m_indexA);
  pool.getCollision().collideEdgeAndPolygon(manifold, edge, xfA,
      (PolygonShape) m_fixtureB.getShape(), xfB);
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:8,代码来源:ChainAndPolygonContact.java

示例3: evaluate

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
@Override
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
  ChainShape chain = (ChainShape) m_fixtureA.getShape();
  chain.getChildEdge(edge, m_indexA);
  pool.getCollision().collideEdgeAndCircle(manifold, edge, xfA,
      (CircleShape) m_fixtureB.getShape(), xfB);
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:8,代码来源:ChainAndCircleContact.java

示例4: setGround

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
private void setGround() {
    BodyDef bd = new BodyDef();
    bd.position.set(Math.max(-groundLength / 2, -10), 0f);
    bd.type = BodyType.STATIC;

    // add chain segments to the ground
    ChainShape shape = new ChainShape();

    ArrayList<Vec2> groundVertices = new ArrayList<Vec2>();

    for (int i = 0; i < groundLength / 5; ++i) {
        Vec2 segment = new Vec2((float) 5 * i, 0f);
        groundVertices.add(segment);
    }

    Vec2[] spec = {};

    shape.createChain(groundVertices.toArray(spec), groundVertices.size());

    FixtureDef fd = new FixtureDef();
    fd.shape = shape;
    Filter filter = new Filter();
    filter.groupIndex = 1;
    fd.filter = filter;
    fd.friction = 0.3f;
    fd.restitution = 0.5f;

    // create the body and add fixture to it
    Body body = world.createBody(bd);
    body.createFixture(fd);
    body.setUserData(new GroundUserData());
}
 
开发者ID:corazza,项目名称:Robot-Evolution,代码行数:33,代码来源:Simulation.java

示例5: set

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
/**
 * Initialize the proxy using the given shape. The shape must remain in scope while the proxy is
 * in use.
 */
public final void set(final Shape shape, int index) {
  switch (shape.getType()) {
    case CIRCLE:
      final CircleShape circle = (CircleShape) shape;
      m_vertices[0].set(circle.m_p);
      m_count = 1;
      m_radius = circle.m_radius;

      break;
    case POLYGON:
      final PolygonShape poly = (PolygonShape) shape;
      m_count = poly.m_count;
      m_radius = poly.m_radius;
      for (int i = 0; i < m_count; i++) {
        m_vertices[i].set(poly.m_vertices[i]);
      }
      break;
    case CHAIN:
      final ChainShape chain = (ChainShape) shape;
      assert (0 <= index && index < chain.m_count);

      m_buffer[0] = chain.m_vertices[index];
      if (index + 1 < chain.m_count) {
        m_buffer[1] = chain.m_vertices[index + 1];
      } else {
        m_buffer[1] = chain.m_vertices[0];
      }

      m_vertices[0].set(m_buffer[0]);
      m_vertices[1].set(m_buffer[1]);
      m_count = 2;
      m_radius = chain.m_radius;
      break;
    case EDGE:
      EdgeShape edge = (EdgeShape) shape;
      m_vertices[0].set(edge.m_vertex1);
      m_vertices[1].set(edge.m_vertex2);
      m_count = 2;
      m_radius = edge.m_radius;
      break;
    default:
      assert (false);
  }
}
 
开发者ID:jfcameron,项目名称:G2Dj,代码行数:49,代码来源:Distance.java

示例6: initScene

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
public void initScene() {
  
  float dimx = world.transform.box2d_dimx;
  float dimy = world.transform.box2d_dimy;
  float thick = 30f / world.transform.screen_scale;

  float dimxh = dimx/2;
  float dimyh = dimy/2;
  
  float bucket_w = dimx / num_buckets;

  {
    BodyDef bd = new BodyDef();
    Body ground = world.createBody(bd);

    ChainShape shape = new ChainShape();
    Vec2[] vertices = {new Vec2(-dimxh, 0), new Vec2(dimxh, 0), new Vec2(dimxh, dimy), new Vec2(-dimxh, dimy)};
    shape.createLoop(vertices, 4);
    Fixture boundary = ground.createFixture(shape, 0.0f);
    
    PolygonShape pshape = new PolygonShape();
    pshape.setAsBox(dimxh, thick);
    Fixture bottom = ground.createFixture(pshape, 0.0f);

    float shift_x = -dimxh + bucket_w;
    for(int i = 0; i < num_buckets - 1; i++){        
      float w = thick / 6;
      float h = 5f * dimy / 6f;
      pshape.setAsBox(w, h/2, new Vec2(shift_x + i * bucket_w, h/2), 0);
      Fixture separes = ground.createFixture(pshape, 0.0f);
    }

    world.bodies.add(ground, true, color(0), false, color(0), 1f);
    world.setStyle(boundary, false, color(0), false, color(0), 1f);
  }
  

  // save current spawn type
  int spawn_type_cpy = spawn_type;
  
  
  float bucket_w_screen = width / (float) num_buckets;
  for(int i = 0; i < num_buckets; i++){
    float cx = i * bucket_w_screen + bucket_w_screen * 0.5f;
    float cy = 1 * height / 3f;
    
    setParticleSpawnProperties(i);

    float screen_x = cx;
    float screen_y = cy;
    float size_x = bucket_w_screen * 0.66f;
    float size_y = size_x * 2;
    world.mouse_spawn_particles.setBoxShape(size_x, size_y);
    world.mouse_spawn_particles.spawn(screen_x, screen_y);
  }
  
  // reset type/color to last used type
  setParticleSpawnProperties(spawn_type_cpy);
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:60,代码来源:liquidfun_ParticleTypes.java

示例7: deserializeShape

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
public Shape deserializeShape(PbShape argShape) {
  PbShape s = argShape;

  Shape shape = null;
  switch (s.getType()) {
    case CIRCLE:
      CircleShape c = new CircleShape();
      c.m_p.set(pbToVec(s.getCenter()));
      shape = c;
      break;
    case POLYGON:
      PolygonShape p = new PolygonShape();
      p.m_centroid.set(pbToVec(s.getCentroid()));
      p.m_count = s.getPointsCount();
      for (int i = 0; i < p.m_count; i++) {
        p.m_vertices[i].set(pbToVec(s.getPoints(i)));
        p.m_normals[i].set(pbToVec(s.getNormals(i)));
      }
      shape = p;
      break;
    case EDGE:
      EdgeShape edge = new EdgeShape();
      edge.m_vertex0.set(pbToVec(s.getV0()));
      edge.m_vertex1.set(pbToVec(s.getV1()));
      edge.m_vertex2.set(pbToVec(s.getV2()));
      edge.m_vertex3.set(pbToVec(s.getV3()));
      edge.m_hasVertex0 = s.getHas0();
      edge.m_hasVertex3 = s.getHas3();
      shape = edge;
      break;
    case CHAIN: {
      ChainShape chain = new ChainShape();
      chain.m_count = s.getPointsCount();
      chain.m_vertices = new Vec2[chain.m_count];
      for (int i = 0; i < chain.m_count; i++) {
        chain.m_vertices[i] = new Vec2(pbToVec(s.getPoints(i)));
      }
      chain.m_hasPrevVertex = s.getHas0();
      chain.m_hasNextVertex = s.getHas3();
      chain.m_prevVertex.set(pbToVec(s.getPrev()));
      chain.m_nextVertex.set(pbToVec(s.getNext()));
      shape = chain;
      break;
    }
    default: {
      UnsupportedObjectException e =
          new UnsupportedObjectException("Unknown shape type: " + s.getType(), Type.SHAPE);
      if (ulistener == null || ulistener.isUnsupported(e)) {
        throw e;
      }
      return null;
    }
  }
  shape.m_radius = s.getRadius();

  if (listener != null && s.hasTag()) {
    listener.processShape(shape, s.getTag());
  }
  return shape;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:61,代码来源:PbDeserializer.java

示例8: serializeShape

import org.jbox2d.collision.shapes.ChainShape; //导入依赖的package包/类
public PbShape.Builder serializeShape(Shape argShape) {
  final PbShape.Builder builder = PbShape.newBuilder();
  if (signer != null) {
    Long tag = signer.getTag(argShape);
    if (tag != null) {
      builder.setTag(tag);
    }
  }
  builder.setRadius(argShape.m_radius);

  switch (argShape.m_type) {
    case CIRCLE:
      CircleShape c = (CircleShape) argShape;
      builder.setType(PbShapeType.CIRCLE);
      builder.setCenter(vecToPb(c.m_p));
      break;
    case POLYGON:
      PolygonShape p = (PolygonShape) argShape;
      builder.setType(PbShapeType.POLYGON);
      builder.setCentroid(vecToPb(p.m_centroid));
      for (int i = 0; i < p.m_count; i++) {
        builder.addPoints(vecToPb(p.m_vertices[i]));
        builder.addNormals(vecToPb(p.m_normals[i]));
      }
      break;
    case EDGE:
      EdgeShape e = (EdgeShape) argShape;
      builder.setType(PbShapeType.EDGE);
      builder.setV0(vecToPb(e.m_vertex0));
      builder.setV1(vecToPb(e.m_vertex1));
      builder.setV2(vecToPb(e.m_vertex2));
      builder.setV3(vecToPb(e.m_vertex3));
      builder.setHas0(e.m_hasVertex0);
      builder.setHas3(e.m_hasVertex3);
      break;
    case CHAIN:
      ChainShape h = (ChainShape) argShape;
      builder.setType(PbShapeType.CHAIN);
      for (int i = 0; i < h.m_count; i++) {
        builder.addPoints(vecToPb(h.m_vertices[i]));
      }
      builder.setPrev(vecToPb(h.m_prevVertex));
      builder.setNext(vecToPb(h.m_nextVertex));
      builder.setHas0(h.m_hasPrevVertex);
      builder.setHas3(h.m_hasNextVertex);
      break;
    default:
      UnsupportedObjectException ex = new UnsupportedObjectException(
          "Currently only encodes circle and polygon shapes", Type.SHAPE);
      if (listener == null || listener.isUnsupported(ex)) {
        throw ex;
      }
      return null;
  }

  return builder;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:58,代码来源:PbSerializer.java


注:本文中的org.jbox2d.collision.shapes.ChainShape类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。