3.0以后最Box2d和chipmunk这两个物理引擎进行了封装,使用起来非常的便利。
官方链接地址:英文版
泰然网:中文教程
offset:重心点
veLocity:速度
dadamPing:阻尼
rerestitution:d力
mamaterial:材质
mass:质量
moment:力矩,当他碰到另一个刚体时候 ,会产生一股扭转力,做旋转运动
body:刚体,表示物理世界中的抽象实体,附带有物理属性
shape:刚体的形状,同一个body可以附加多个shape 该shape们不会发生碰撞
joint:关节,可以连接>=2个刚体
/** 创建一个body mass和moment为默认值 */ static PhysicsBody* create(); /** 创建一个质量为mass的body moment为默认值. */ static PhysicsBody* create(float mass); /** 创建一个body 并为mass 和moment赋值 */ static PhysicsBody* create(float mass,float moment); /**创建一个shape为圆形的body */ static PhysicsBody* createCircle(float radius,const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAulT,const Point& offset = Point::ZERO); /** 创建一个shape为四边形的body. */ static PhysicsBody* createBox(const Size& size,const Point& offset = Point::ZERO); /**创建一个动态多边形刚体,多边形的顶点存放在Point array[ ]中 示例:Point array[ ]={ point(1,1),point(2,2)} 注意:顶点必须按顺时针存放,并且图形为凸状,不能是凹的*/ static PhysicsBody* createpolygon(const Point* points,int count,const Point& offset = Point::ZERO); /** 创建一个静态的线状刚体. */ static PhysicsBody* createEdgeSegment(const Point& a,const Point& b,float border = 1); /** 创建一个静态四边形刚体. */ static PhysicsBody* createEdgeBox(const Size& size,float border = 1,const Point& offset = Point::ZERO); /** 创建一个静态多边形刚体. */ static PhysicsBody* createEdgepolygon(const Point* points,float border = 1); /** 创建一个链条状刚体 */ static PhysicsBody* createEdgeChain(const Point* points,float border = 1); /* 添加一个shape mass和moment赋值true */ virtual PhysiCSShape* addShape(PhysiCSShape* shape,bool addMassAndMoment = true); /*通过shape移除shape*/ voID removeShape(PhysiCSShape* shape,bool reduceMassAndMoment = true); /*通过tag移除shape*/ voID removeShape(int tag,bool reduceMassAndMoment = true); /* 移除body的所有shape */ voID removeAllShapes(bool reduceMassAndMoment = true); /* 获取body的shapes */ inline const Vector<PhysiCSShape*>& getShapes() const { return _shapes; } /* 获取第一个shape. */ inline PhysiCSShape* getFirstShape() const { return _shapes.size() >= 1 ? _shapes.at(0) : nullptr; } /* 通过tag从body中获取shape */ PhysiCSShape* getShape(int tag) const; /**给body施加一个循序渐进的力,物体会受加速度影响,越来越快,像火车一样*/ virtual voID applyForce(const Vect& force); /** offset为偏移度 指碰到物体时 body旋转 偏移 一般设为默认值 值越大 旋转越快 偏移角度越大*/ virtual voID applyForce(const Vect& force,const Point& offset); /** 重置施加在body上的力 清0了. */ virtual voID resetForces(); /** 不会产生力,直接与body的速度叠加 产生新的速度. */ virtual voID applyImpulse(const Vect& impulse); /** ApplIEs a continuous force to body. */ virtual voID applyImpulse(const Vect& impulse,const Point& offset); /**施加一个扭转力到刚体上 就像向前翻转一块大石头一样. */ virtual voID applyTorque(float torque); /** 设置刚体的速度*/ virtual voID setVeLocity(const Vect& veLocity); /** 获取刚体的速度 */ virtual Point getVeLocity(); /** 设置刚体角速度 就是单位时间内转动的弧度*/ virtual voID setAngularVeLocity(float veLocity); /** 通过一个局部点获取刚体的角速度*/ virtual Point getVeLocityAtLocalPoint(const Point& point); /** 通过世界点获取刚体的角速度*/ virtual Point getVeLocityAtWorldPoint(const Point& point); /** 获取刚体的角速度 */ virtual float getAngularVeLocity(); /** 设置速度的极限值*/ virtual voID setVeLocitylimit(float limit); /**获取速度的极限值 */ virtual float getVeLocitylimit(); /** 设置角速度极限值 */ virtual float getAngularVeLocitylimit(); /** 从world中移除body */ voID removeFromWorld(); /** 获取world */ inline PhysicsWorld* getWorld() const { return _world; } /**获取body的所有关节 */ inline const std::vector<PhysicsJoint*>& getJoints() const { return _joints; } /** 取得body设置的sprite. */ inline Node* getNode() const { return _node; } /** * A mask that defines which categorIEs this physics body belongs to. * Every physics body in a scene can be assigned to up to 32 different categorIEs,each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask propertIEs,you define which physics bodIEs interact with each other and when your game is notifIEd of these interactions. * The default value is 0xFFFFFFFF (all bits set). */没搞懂 voID setcategoryBitmask(int bitmask); /** * A mask that defines which categorIEs of bodIEs cause intersection notifications with this physics body. * When two bodIEs share the same space,each body’s category mask is tested against the other body’s contact mask by performing a logical AND operation. If either comparison results in a non-zero value,an PhysicsContact object is created and passed to the physics world’s delegate. For best performance,only set bits in the contacts mask for interactions you are interested in. * The default value is 0x00000000 (all bits cleared). */ voID setContactTestBitmask(int bitmask); /** * A mask that defines which categorIEs of physics bodIEs can collIDe with this physics body. * When two physics bodIEs contact each other,a collision may occur. This body’s collision mask is compared to the other body’s category mask by performing a logical AND operation. If the result is a non-zero value,then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example,you might use this to avoID collision calculations that would make negligible changes to a body’s veLocity. * The default value is 0xFFFFFFFF (all bits set). */ voID setCollisionBitmask(int bitmask); /** get the category bit mask */ inline int getcategoryBitmask() const { return _categoryBitmask; } /** get the contact test bit mask */ inline int getContactTestBitmask() const { return _contactTestBitmask; } /** get the collision bit mask */ inline int getCollisionBitmask() const { return _collisionBitmask; } /** * set the group of body * Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collIDe (positive index) or never collIDe (negative index) * it have high priority than bit masks */ voID setGroup(int group); /** get the group of body */ inline int getGroup() const { return _group; } /** 获取body坐标 */ Point getposition() const; /** 获取body角度. */ float getRotation() const; /**判断body是否静止*/ inline bool isDynamic() const { return _dynamic; } /**设置body状态 false为静态 true为动态*/ voID setDynamic(bool dynamic); /**设置mass值 如果需要增加mass 有addmass方法 不要在这里做加减 */ voID setMass(float mass); /** 取得mass. */ inline float getMass() const { return _mass; } /** * @brIEf add mass to body. * if _mass(mass of the body) == PHYSICS_INFINITY,it remains. * if mass == PHYSICS_INFINITY,_mass will be PHYSICS_INFINITY. * if mass == -PHYSICS_INFINITY,_mass will not change. * if mass + _mass <= 0,_mass will equal to MASS_DEFAulT(1.0) * other wise,mass = mass + _mass; */增加质量 voID addMass(float mass); /** * @brIEf set the body moment of inertia. * @note if you need add/subtract moment to body,don't use setMoment(getMoment() +/- moment),because the moment of body may be equal to PHYSICS_INFINITY,it will cause some unexpected result,please use addMoment() instead. */设置力矩 voID setMoment(float moment); /** 获取惯性的力矩. */ inline float getMoment(float moment) const { return _moment; } /** * @brIEf add moment of inertia to body. * if _moment(moment of the body) == PHYSICS_INFINITY,it remains. * if moment == PHYSICS_INFINITY,_moment will be PHYSICS_INFINITY. * if moment == -PHYSICS_INFINITY,_moment will not change. * if moment + _moment <= 0,_moment will equal to MASS_DEFAulT(1.0) * other wise,moment = moment + _moment; */增加力矩 voID addMoment(float moment); /** 取得线性阻尼 */ inline float getlineardamPing() const { return _lineardamPing; } /** * 设置阻尼值 *它用来模拟body在气体或者液体中的摩擦力 *取值范围是 0.0f to 1.0f. */ inline voID setlineardamPing(float damPing) { _lineardamPing = damPing; } /** 获取角阻尼 */ inline float getAngulardamPing() const { return _angulardamPing; } /** * 设置角阻尼 * 它用来模拟body在气体或者液体中的角阻尼 * the value is 0.0f to 1.0f. */ inline voID setAngulardamPing(float damPing) { _angulardamPing = damPing; } /** 判断body是否是 休息状态 */ bool isResting() const; /** *判断body能否在物理世界中模拟 */ inline bool isEnabled() const { return _enable; } /** 设置body能否在物理世界中模拟 */ voID setEnable(bool enable); /** whether the body can rotation */ inline bool isRotationEnabled() const { return _rotationEnable; } /**设置能否旋转*/ voID setRotationEnable(bool enable); /** 判断body是否受引力影响 */ inline bool isGravityEnabled() const { return _gravityEnable; } /** 设置body是否受引力影响 */ voID setGravityEnable(bool enable); /** 取得body 的tag值 */ inline int getTag() const { return _tag; } /** 设置body tag值*/ inline voID setTag(int tag) { _tag = tag; } /** 转换 世界点 到 局部点 类似 世界坐标和 局部坐标的转换*/ Point world2local(const Point& point); /** 转换局部坐标到 世界坐标 */ Point local2World(const Point& point);
2.PhysiCSShape
/** 通过shape 取得body */ inline PhysicsBody* getbody() const { return _body; } /** 返回shape的类型 */ inline Type getType() const { return _type; } /** 返回shape的面积 */ inline float getArea() const { return _area; } /** 取得moment 力矩 */ inline float getMoment() const { return _moment; } /** Set moment,it will change the body's moment this shape attaches */ voID setMoment(float moment);//设置力矩 inline voID setTag(int tag) { _tag = tag; }//设置标签tag inline int getTag() const { return _tag; }//取得tag标签 /**获取质量 */ inline float getMass() const { return _mass; } /** Set mass,it will change the body's mass this shape attaches */<span > </span> voID setMass(float mass);//设置质量 inline float getDensity() const { return _material.density; }//density为密度 voID setDensity(float density);//获取密度 inline float getRestitution() const { return _material.restitution; }//获取d性 voID setRestitution(float restitution);//设置d性 inline float getFriction() const { return _material.friction; }//friction为摩擦力 voID setFriction(float friction);//设置摩擦力 const PhysicsMaterial& getMaterial() const { return _material; }//Material为材质 voID setMaterial(const PhysicsMaterial& material);设置材质 /** 返回默认力矩 其值为0 */ virtual float calculateDefaultMoment() { return 0.0f; } /** 取得重心 初始值为zero */ virtual Point getoffset() { return Point::ZERO; } /** 获取shape的重心点 */ virtual Point getCenter() { return getoffset(); } /**shape是否包含该点 */ bool containsPoint(const Point& point) const; /** 改变重心点 */ static voID recenterPoints(Point* points,const Point& center = Point::ZERO); /** 取得多边形的重心点 */ static Point getpolyonCenter(const Point* points,int count); /** * A mask that defines which categorIEs this physics body belongs to. * Every physics body in a scene can be assigned to up to 32 different categorIEs,you define which physics bodIEs interact with each other and when your game is notifIEd of these interactions. * The default value is 0xFFFFFFFF (all bits set). */ inline voID setcategoryBitmask(int bitmask) { _categoryBitmask = bitmask; } inline int getcategoryBitmask() const { return _categoryBitmask; } /** * A mask that defines which categorIEs of bodIEs cause intersection notifications with this physics body. * When two bodIEs share the same space,only set bits in the contacts mask for interactions you are interested in. * The default value is 0x00000000 (all bits cleared). */ inline voID setContactTestBitmask(int bitmask) { _contactTestBitmask = bitmask; } inline int getContactTestBitmask() const { return _contactTestBitmask; } /** * A mask that defines which categorIEs of physics bodIEs can collIDe with this physics body. * When two physics bodIEs contact each other,you might use this to avoID collision calculations that would make negligible changes to a body’s veLocity. * The default value is 0xFFFFFFFF (all bits set). */ inline voID setCollisionBitmask(int bitmask) { _collisionBitmask = bitmask; } inline int getCollisionBitmask() const { return _collisionBitmask; } voID setGroup(int group); inline int getGroup() { return _group; }
转自 http://blog.csdn.net/v_leg/article/details/22584743总结
以上是内存溢出为你收集整理的cocos2d-x 3.0开发笔记---物理引擎封装 Physics深入学习全部内容,希望文章能够帮你解决cocos2d-x 3.0开发笔记---物理引擎封装 Physics深入学习所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)