상속: IDisposable
예제 #1
0
 internal static HandleRef getCPtr(btHingeConstraint obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
예제 #2
0
    public bool OnBulletCreate()
    {
        if( ConstraintType == ConstraintTypes.Point2Point )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                point2pointConstraint = new btPoint2PointConstraint(rA,vecA.GetSwigPtr());
                constraintPtr = point2pointConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                point2pointConstraint = new btPoint2PointConstraint(rA,rB,vecA.GetSwigPtr(),vecB.GetSwigPtr());
                constraintPtr = point2pointConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Hinge )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                hingeConstraint = new btHingeConstraint(rA,vecA.GetSwigPtr(),axisA.GetSwigPtr(),useReferenceFrameAHinge);
                constraintPtr = hingeConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btVector3 axisB = new btVector3(AxisInB.x,AxisInB.y,AxisInB.z);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                hingeConstraint = new btHingeConstraint(rA,rB,vecA.GetSwigPtr(),vecB.GetSwigPtr(),axisA.GetSwigPtr(),axisB.GetSwigPtr(),useReferenceFrameAHinge);
                constraintPtr = hingeConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Slider )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rot = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rot);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                sliderConstraint = new btSliderConstraint(rA,transA.GetSwigPtr(),useLinearReferenceFrameASlider);
                constraintPtr = sliderConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                sliderConstraint = new btSliderConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr(), useLinearReferenceFrameASlider);
                constraintPtr = sliderConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.ConeTwist )
        {
            if( RigidBodyA != null && RigidBodyB == null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rot = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rot);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                coneTwistConstraint = new btConeTwistConstraint(rA,transA.GetSwigPtr());
                constraintPtr = coneTwistConstraint.GetSwigPtr();
                return true;
            }
            else if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                coneTwistConstraint = new btConeTwistConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr());
                constraintPtr = coneTwistConstraint.GetSwigPtr();
                return true;
            }

            return false;
        }
        else if( ConstraintType == ConstraintTypes.Gear )
        {
            if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 axisA = new btVector3(AxisInA.x,AxisInA.y,AxisInA.z);
                btVector3 axisB = new btVector3(AxisInB.x,AxisInB.y,AxisInB.z);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                gearConstraint = new btGearConstraint(rA,rB,axisA.GetSwigPtr(),axisB.GetSwigPtr(),GearConstraintRatio);
                constraintPtr = gearConstraint.GetSwigPtr();
                return true;
            }
            return false;
        }
        else if( ConstraintType == ConstraintTypes.Generic6Dof )
        {
            if( RigidBodyA != null && RigidBodyB != null )
            {
                btVector3 vecA = new btVector3(PivotInA.x,PivotInA.y,PivotInA.z);
                btQuaternion rotA = new btQuaternion(RotationA.x,RotationA.y,RotationA.z);
                btTransform transA = new btTransform();
                transA.setIdentity();
                transA.setOrigin(vecA);
                transA.setRotation(rotA);
                btRigidBody rA = RigidBodyA.GetRigidBody();
                if( rA == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                btVector3 vecB = new btVector3(PivotInB.x,PivotInB.y,PivotInB.z);
                btQuaternion rotB = new btQuaternion(RotationB.x,RotationB.y,RotationB.z);
                btTransform transB = new btTransform();
                transB.setIdentity();
                transB.setOrigin(vecB);
                transB.setRotation(rotB);
                btRigidBody rB = RigidBodyB.GetRigidBody();
                if( rB == null )
                {
                    Debug.LogError("Can't Create Constraint for null RigidBody!");
                    return false;
                }
                generic6Dof = new btGeneric6DofConstraint(rA,rB,transA.GetSwigPtr(),transB.GetSwigPtr(),useLinearReferenceFrameASlider);
                if( UseLinearLimit )
                {
                    btVector3 lowerVec = new btVector3(LinearLowerLimit.x,LinearLowerLimit.y,LinearLowerLimit.z);
                    btVector3 uppderVec = new btVector3(LinearUpperLimit.x,LinearUpperLimit.y,LinearUpperLimit.z);
                    generic6Dof.setLinearLowerLimit(lowerVec.GetSwigPtr());
                    generic6Dof.setLinearUpperLimit(uppderVec.GetSwigPtr());
                }
                if( UseAngularLimit )
                {
                    btVector3 lowerVec = new btVector3(AngularLowerLimit.x,AngularLowerLimit.y,AngularLowerLimit.z);
                    btVector3 uppderVec = new btVector3(AngularUpperLimit.x,AngularUpperLimit.y,AngularUpperLimit.z);
                    generic6Dof.setAngularLowerLimit(lowerVec.GetSwigPtr());
                    generic6Dof.setAngularUpperLimit(uppderVec.GetSwigPtr());
                }

                constraintPtr = generic6Dof.GetSwigPtr();
                return true;
            }

            return false;
        }

        return false;
    }
 internal static HandleRef getCPtr(btHingeConstraint obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }