• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DistanceJointDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createDistanceJoint

import org.jbox2d.dynamics.joints.DistanceJointDef; //导入依赖的package包/类
public Joint createDistanceJoint(Body body1, Body body2, float distance) {
	DistanceJointDef jointDef = new DistanceJointDef();
	jointDef.initialize(body1, body2, body1.getPosition(), body2.getPosition());
	jointDef.length = distance;
	jointDef.frequencyHz = 4;
	jointDef.dampingRatio = 0.1f;
	jointDef.collideConnected = true;
	
	return (DistanceJoint) physicsWorld.createJoint(jointDef);
}
 
开发者ID:lowkey42,项目名称:java-jumpandrun-dev,代码行数:11,代码来源:Box2dPhysicalWorld.java


示例2: createChain

import org.jbox2d.dynamics.joints.DistanceJointDef; //导入依赖的package包/类
public void createChain(Vec2 ankerA, Vec2 ankerB, float radius, float spacing){
  Vec2 AB = ankerB.sub(ankerA);
  float distance = AB.length();
  
  int count = 1 + (int) (distance / (radius * 2 + spacing));
  float dist = distance / (count-1);
  Vec2 step = AB.mul(dist / distance);

  CircleShape cshape = new CircleShape();
  cshape.m_p.set(0,0);
  cshape.m_radius = radius;
  
  int col = color(255);
  
  Body body_prev = null;
  for(int i = 0; i < count; i++){
    BodyDef bdef = new BodyDef();
    bdef.position = ankerA.add(step.mul(i));
    
    if(i == 0 || i == count-1 || i % 20 == 0){
      bdef.type = BodyType.STATIC;
    } else {
      bdef.type = BodyType.DYNAMIC;
    }
    
    Body body_curr = world.createBody(bdef);
    body_curr.createFixture(cshape, 0);
    world.bodies.add(body_curr, true, col, true, 0xFF000000, 1f);
    
    if(body_prev != null){
      DistanceJointDef djointdef = new DistanceJointDef();      
      djointdef.initialize(body_prev, body_curr, body_prev.m_xf.p, body_curr.m_xf.p);
      djointdef.dampingRatio = 0.3f;
      djointdef.frequencyHz = 15f;
      DistanceJoint djoint = (DistanceJoint) world.createJoint(djointdef);
      world.bodies.add(djoint, false, col, true, col, 5);
    }

    body_prev = body_curr;
  }
  
}
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:43,代码来源:liquidfun_Chain_DistanceJoints_LiquidFx.java


示例3: doSomethingWithCollisionContactsAndDistanceJoints

import org.jbox2d.dynamics.joints.DistanceJointDef; //导入依赖的package包/类
public void doSomethingWithCollisionContactsAndDistanceJoints(){
    
    DistanceJointDef djd = new DistanceJointDef();
    djd.dampingRatio = 0.5f;
    djd.frequencyHz = 20.0f;
    djd.collideConnected = false; // default anyways
    
//    RopeJointDef rjd = new RopeJointDef();

 
    // iterate through all contacts since the previous world-update-step
    for(Contact contact = world.getContactList(); contact != null; contact = contact.m_next){
      
      // both bodies of the contact
      Body bodyA = contact.m_fixtureA.getBody();
      Body bodyB = contact.m_fixtureB.getBody();
      
      // ignore contaxt with static bodies
      if(bodyA.m_type == BodyType.STATIC || bodyB.m_type == BodyType.STATIC ){
        continue;
      }
      
      // body world positions
      Vec2 posA = bodyA.getTransform().p;
      Vec2 posB = bodyB.getTransform().p;
      
      // create joint bodyA <-> bodyB
      djd.initialize(bodyA, bodyB, posA, posB);
      Joint joint = world.createJoint(djd);
      
//      Vec2 distAB = posA.sub(posB);
// 
//      rjd.bodyA = bodyA;
//      rjd.bodyB = bodyB;
//      rjd.localAnchorA.set(bodyA.getLocalPoint(posA));
//      rjd.localAnchorB.set(bodyB.getLocalPoint(posB));
//      rjd.maxLength = distAB.length();
//      Joint joint = world.createJoint(rjd);
      
      // add joint shape and a style
      DwJoint dwjoint = world.bodies.add(joint, false, color(0), true, color(255, 160), 1.0f);
      

//      // replace the line shape with a rectangle shape
//      // to apply a color transition for the joint.
//      // unfortunately this doesnt work for a line, only for a Polygon, like a rectangle.
//      DwFixture fA = DwWorld.getShape(contact.m_fixtureA);
//      DwFixture fB = DwWorld.getShape(contact.m_fixtureB);
//      
//      float h = 1f / world.transform.screen_scale;
//      
//      PShape shape_rect = createShape();
//      shape_rect.beginShape(QUADS);
//      shape_rect.noStroke();
//      shape_rect.fill(fA.shape.getFill(0));
//      shape_rect.vertex(0,-h);
//      shape_rect.vertex(0,+h);
//      shape_rect.fill(fB.shape.getFill(0));
//      shape_rect.vertex(1,+h);
//      shape_rect.vertex(1,-h);
//      shape_rect.endShape();
//
//      dwjoint.replaceShape(shape_rect);

    }
  }
 
开发者ID:diwi,项目名称:LiquidFunProcessing,代码行数:67,代码来源:box2d_Collisions.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CrossSiteIframeLinker类代码示例发布时间:2022-05-22
下一篇:
Java Attribute类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap