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


Java PbShapeType类代码示例

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


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

示例1: serializeShape

import org.box2d.proto.Box2D.PbShapeType; //导入依赖的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.box2d.proto.Box2D.PbShapeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。