• Prismatic Joint(移动关节)


    Prismatic Joint的作用是在一个方向上移动某一个刚体,移动的最大距离和最小距离可以定义,移动过程中刚体不能转动。一般可以用着活塞运动。

    下面的是创建移动关节的主要代码:

    var pristmaticRect:Rect = new Rect(40, 40, new Point(275, 200), new Point(), new MyRect(), _container);
    var prismaticJointDef:b2PrismaticJointDef = new b2PrismaticJointDef();
    prismaticJointDef.Initialize(_world.GetGroundBody(), pristmaticRect.body, pristmaticRect.body.GetPosition(), new b2Vec2(1, 0));
    prismaticJointDef.enableMotor = true;
    prismaticJointDef.enableLimit = true;
    prismaticJointDef.motorSpeed = Math.PI / 5;
    prismaticJointDef.maxMotorForce = 300;
    prismaticJointDef.upperTranslation = 150 / PhyOption.PHYSCALE;
    prismaticJointDef.lowerTranslation = -150 / PhyOption.PHYSCALE;
    _prismaticJoint = _world.CreateJoint(prismaticJointDef) as b2PrismaticJoint;
    

    4-7行的属性跟Revolute Joint中一样,具体说明上一篇有详细介绍。

    8-9行分别是刚体沿某个方向移动的最大最小距离,以米为单位。

    3行Initialize方法的第四个参数设定的是刚体移动的方向,如x轴方向或者y轴方向。此参数是一个b2Vec2对象,且其x,y属性都不能超过1,否则会有意想不到结果。当要沿x轴移动时,设置为x=1,y=0;要沿y轴移动时,设置为y=1,x=0;

  • 相关阅读:
    代理模式
    工厂模式
    Mysql索引数据结构为什么是B+树?
    mxgraph中mxStencil使用经验
    !dbobji.cpp@8615
    ForkJoinPool线程池
    保障线程安全的设计技术
    Java利用线程工厂监控线程池
    使用Arthas分析线上问题
    使用规则执行器代替 if else 判断
  • 原文地址:https://www.cnblogs.com/ywxgod/p/1737813.html
Copyright © 2020-2023  润新知