Constraints

来源:互联网 发布:苹果手机网络卡怎么办 编辑:程序博客网 时间:2024/05/20 07:19

Constraints

Bullet engine (as of version 2.82) supports 6 types of constraints, as described below.

Contents

[hide]
  • 1Examples
  • 2Constraints
    • 2.1Point-to-Point (Ball socket)
    • 2.2Hinge
      • 2.2.1Hinge rotation limits
    • 2.3Slider
    • 2.4Cone Twist
    • 2.5Generic 6 Degrees of Freedom (DoF) Constraint
      • 2.5.1Configuring limits
    • 2.6Fixed

Examples

Examples using constraints can be found at Demos/ConstraintDemo
A sliding constraint example can be found at Demos/ForkLiftDemo
A ragdoll example using cone twist constraints can be found at Demos/RagdollDemo

Small Tips:
If we enable the DebugDrawing

HingeConstraint->setDbgDrawSize(btScalar(5.f));

We can see two local coordinates at the constraint pivot, expressed in RGB colors to represent three axis.File:HingeConstraintDebug.png

Constraints

Point-to-Point (Ball socket)

The point to point constraint, also known as ball socket joint, limits the translation so that the local pivot points of two rigidbodies match in worldspace. A chain of rigidbodies can be connected using this constraint.
The point-to-point constraint uses the following constructors:

btPoint2PointConstraint(btRigidBody& rbA,                        const btVector3& pivotInA);btPoint2PointConstraint(btRigidBody& rbA,                        btRigidBody& rbB,                        const btVector3& pivotInA,                        const btVector3& pivotInB);

Hinge

Hinge constraint, or revolute joint, restricts two additional angular degrees of freedom, so the body can only rotate around one axis, the hinge axis. This can be useful to represent doors or wheels rotating around one axis. Limits and motor can be specified for the hinge.
The hinge constraint uses the following constructors:

btHingeConstraint(btRigidBody& rbA,                  const btTransform& rbAFrame,                  bool useReferenceFrameA = false)

btHingeConstraint(btRigidBody& rbA,                  const btVector3& pivotInA,                  btVector3& axisInA,                  bool useReferenceFrameA = false);

The pivot and axis in A/B are all expressed in local coordinate of Object A/B. For a door, even if we lay down the door, axisInA/B is still (0,1,0).
As long as the constraint structure doesn't change, the local coordinates won't change.

btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB,                  const btVector3& pivotInA,                  const btVector3& pivotInB,                  btVector3& axisInA,                  btVector3& axisInB,                  bool useReferenceFrameA = false);

Normally two axis in hinge-connected objects should align and point to the same direction, such as a door. But you can set two axis as different vectors.

btHingeConstraint(btRigidBody& rbA,                  btRigidBody& rbB,                  const btTransform& rbAFrame,                  const btTransform& rbBFrame,                  bool useReferenceFrameA = false)
Hinge rotation limits

The hinge constraint has the following method for setting its limits:

'/tmp/highlight.css' was not created by highlight --fragment --syntax='cpp' --style-outfile='/tmp/highlight.css' (dir=/tmp)

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl, a4c, abp, ada, agda, ampl, amtrix, applescript,arc, arm, as, asm, asp,aspect, au3, avenue, awk, bat, bb, bib, bms, boo,c, cb, cfc, clipper, clp,cob, cs, css, d, diff,dot, dylan, e, erl, euphoria,exp, f77, f90, flx, frink,haskell, hcl, httpd, icn, idl, ini, inp, io, j, java, js, jsp, lbn, ldif,lgt, lisp, lotos, ls, lsl,lua, ly, m, make, mel,mib, miranda, ml, mo, mod3,mpl, ms, mssql, n, nas,nice, nsi, nut, oberon, objc, octave, oorexx, os, pas,php, pike, pl, pl1, pov,pro, progress, ps, ps1, psl, py, pyx, q, qu, r, rb, rexx, rnc, s, sas, sc, scala, scilab, sh,sma, smalltalk, sml, snobol, spec, spn, sql, sybase, tcl,tcsh, test_re, tex, ttcn3, txt, vb, verilog, vhd, xml,xpp, y

Slider

The slider constraint allows the body to rotate around one axis and translate along this axis.
The slider twist uses the following constructor:

btSliderConstraint(btRigidBody& rbA,                   btRigidBody& rbB,                   const btTransform& frameInA,                   const btTransform& frameInB,                   bool useLinearReferenceFrameA);

Cone Twist

The cone twist is a special point-to-point constraint that adds cone and twist axis limits. The x-axis serves as twist axis. It is useful when creating ragdolls, specially for limbs like the upper arm.

The cone twist constraint uses the following constructors:

btConeTwistConstraint(btRigidBody& rbA,                      const btTransform& rbAFrame)btConeTwistConstraint(btRigidBody& rbA,                      btRigidBody& rbB,                      const btTransform& rbAFrame,                      const btTransform& rbBFrame)

File:Ill_ragdollconeequalperspnumbers.png

It may be a little tricky to set up the constraint limit for cone twist constraint:

void btConeTwistConstraint::setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan,btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f)

Let's see the examples in Ragdoll Demo to better understand:

//Spline-Head JointconeC->setLimit(M_PI_4, M_PI_4, M_PI_2);//Hip-Thigh JointconeC->setLimit(M_PI_4, M_PI_4, 0);// Torso-Shoulder JointconeC->setLimit(M_PI_2, M_PI_2, 0);

From the definition, we know the first two limits are cone limits, while the last one is twist limit. First, let's discuss about the twist limit, for the head, you are supposed to turn your head Left/Right, which equals pi/2 (What you doing is twisting along the axis). While your head can lean foward, or backward, Left/Right to your shoulder, about pi/4, it accounts for first two parameters.

For your upper arm and thigh, they are not supposed to twist along the bone, leading to third parameter as 0. But the space your upper arm/thigh can occupy is a cone, and the angles for this cone is pi/4 (thigh) and pi/2 (upper arm).

Generic 6 Degrees of Freedom (DoF) Constraint

This generic constraint can emulate a variety of standard constraints, by configuring each of the 6 degrees of freedom (DoF). The first 3 DoF axis are linear axis, which represent translation of rigid bodies, and the latter 3 axis represent the angular motion. Each axis can be either locked, free or limited. Note that several combinations that include free and/or limited angular degrees of freedom are undefined.
The generic 6DoF constraint has the following constructor:

'/tmp/highlight.css' was not created by highlight --fragment --syntax='cpp' --style-outfile='/tmp/highlight.css' (dir=/tmp)

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl, a4c, abp, ada, agda, ampl, amtrix, applescript,arc, arm, as, asm, asp,aspect, au3, avenue, awk, bat, bb, bib, bms, boo,c, cb, cfc, clipper, clp,cob, cs, css, d, diff,dot, dylan, e, erl, euphoria,exp, f77, f90, flx, frink,haskell, hcl, httpd, icn, idl, ini, inp, io, j, java, js, jsp, lbn, ldif,lgt, lisp, lotos, ls, lsl,lua, ly, m, make, mel,mib, miranda, ml, mo, mod3,mpl, ms, mssql, n, nas,nice, nsi, nut, oberon, objc, octave, oorexx, os, pas,php, pike, pl, pl1, pov,pro, progress, ps, ps1, psl, py, pyx, q, qu, r, rb, rexx, rnc, s, sas, sc, scala, scilab, sh,sma, smalltalk, sml, snobol, spec, spn, sql, sybase, tcl,tcsh, test_re, tex, ttcn3, txt, vb, verilog, vhd, xml,xpp, y

Configuring limits

On construction of a new btGeneric6DofConstraint, all axis are locked. The limits of the 6DoF constraint are set through 4 vectors. Two represent the upper and lower limits of the angular motion and the other two do the same for the linear motion.

btGeneric6DofConstraint has the following methods for setting limits:

void setLinearLowerLimit(const btVector3& linearLower)void setLinearUpperLimit(const btVector3& linearUpper)void setAngularLowerLimit(const btVector3& angularLower)void setAngularUpperLimit(const btVector3& angularUpper)

For each axis, if

  • lower limit = upper limit

The axis is locked

  • lower limit < upper limit

The axis is limited between the specified values

  • lower limit > upper limit

The axis is free and has no limits


Fixed

The fixed constraint has all the degrees of freedom locked.

It uses the following constructor:

btFixedConstraint(btRigidBody& rbA,                  btRigidBody& rbB,                  const btTransform& frameInA,                  const btTransform& frameInB);
0 0
原创粉丝点击