Exemplo n.º 1
0
        /// <summary>
        /// Adds an AngularLimit between the specified bones.
        /// </summary>
        /// <param name="skeletonPose">The skeleton pose.</param>
        /// <param name="ragdoll">The ragdoll.</param>
        /// <param name="parent">The parent bone.</param>
        /// <param name="child">The child bone.</param>
        /// <param name="minimum">The minimum limits for each constraint axis (x/y/z).</param>
        /// <param name="maximum">The maximum limits for each constraint axis (x/y/z).</param>
        /// <remarks>
        /// The constraint anchor orientation is the orientation of the child bone.
        /// </remarks>
        private static void AddAngularLimit(SkeletonPose skeletonPose, Ragdoll ragdoll, int parent, int child, Vector3F minimum, Vector3F maximum)
        {
            var skeleton     = skeletonPose.Skeleton;
            var childBody    = ragdoll.Bodies[child];
            var childOffset  = ragdoll.BodyOffsets[child];
            var parentBody   = ragdoll.Bodies[parent];
            var parentOffset = ragdoll.BodyOffsets[parent];

            var parentBindPoseAbsolute = (Pose)skeleton.GetBindPoseAbsoluteInverse(parent).Inverse;
            var childBindPoseAbsolute  = (Pose)skeleton.GetBindPoseAbsoluteInverse(child).Inverse;
            var bindPoseRelative       = parentBindPoseAbsolute.Inverse * childBindPoseAbsolute;

            var limit = new AngularLimit
            {
                BodyA = parentBody,
                BodyB = childBody,
                AnchorOrientationALocal = parentOffset.Orientation.Transposed * bindPoseRelative.Orientation,
                AnchorOrientationBLocal = childOffset.Orientation.Transposed,
                Minimum        = minimum,
                Maximum        = maximum,
                ErrorReduction = new Vector3F(0.2f),
                Softness       = new Vector3F(0.001f)
            };

            ragdoll.Limits.Add(limit);
        }
Exemplo n.º 2
0
 public static void Start()
 {
     RuntimeObject.Init();
     RigidBody.Init();
     CollisionBody.Init();
     CollisionSensor.Init();
     TransportSurface.Init();
     CollisionMaterial.Init();
     HingeJoint.Init();
     SlidingJoint.Init();
     CylindricalJoint.Init();
     FixedJoint.Init();
     BallJoint.Init();
     AngularLimit.Init();
     LinearLimit.Init();
     AngularSpring.Init();
     LinearSpring.Init();
     SpeedControl.Init();
     PositionControl.Init();
     BreakingConstraint.Init();
     GearCoupling.Init();
     CamCoupling.Init();
     ElecCamCoupling.Init();
     PreventCollision.Init();
     ChangeMaterial.Init();
     ComponentPart.Init();
     SourceBehavior.Init();
     SinkBehavior.Init();
     GraphControl.Init();
     ExternalConnection.Init();
     SignalAdapter.Init();
     Signal.Init();
     ProxyObject.Init();
     RuntimeParameters.Init();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Visualizes the constraints of the ragdoll (for debugging).
        /// </summary>
        /// <param name="debugRenderer">The debug renderer.</param>
        /// <param name="ragdoll">The ragdoll.</param>
        /// <param name="scale">
        /// A scale factor that determines the size of the drawn elements.
        /// </param>
        /// <param name="drawOverScene">
        /// If set to <see langword="true"/> the object is drawn over the graphics scene (depth-test
        /// disabled).
        /// </param>
        /// <remarks>
        /// Currently, only <see cref="TwistSwingLimit" />s and <see cref="AngularLimit" />s are
        /// supported.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="debugRenderer" /> or <paramref name="ragdoll" /> is <see langword="null" />.
        /// </exception>
        public static void DrawConstraints(this DebugRenderer debugRenderer, Ragdoll ragdoll, float scale, bool drawOverScene)
        {
            if (debugRenderer == null)
            {
                throw new ArgumentNullException("debugRenderer");
            }
            if (ragdoll == null)
            {
                throw new ArgumentNullException("ragdoll");
            }

            // Render information for each limit.
            foreach (Constraint limit in ragdoll.Limits)
            {
                // Get the ball joint constraint that connects the two bodies of the limit.
                BallJoint joint = null;
                foreach (Constraint constraint in ragdoll.Joints)
                {
                    if (constraint.BodyA == limit.BodyA && constraint.BodyB == limit.BodyB ||
                        constraint.BodyA == limit.BodyB && constraint.BodyB == limit.BodyA)
                    {
                        joint = constraint as BallJoint;
                        break;
                    }
                }

                // Skip this limit if no joint was found.
                if (joint == null)
                {
                    continue;
                }

                TwistSwingLimit twistSwingLimit = limit as TwistSwingLimit;
                if (twistSwingLimit != null)
                {
                    DrawTwistSwingLimit(debugRenderer, joint, twistSwingLimit, scale, drawOverScene);
                    continue;
                }

                AngularLimit angularLimit = limit as AngularLimit;
                if (angularLimit != null)
                {
                    DrawAngularLimit(debugRenderer, joint, angularLimit, scale, drawOverScene);
                    continue;
                }
            }
        }
Exemplo n.º 4
0
        private static void AddAngularLimit(Ragdoll ragdoll, Skeleton skeleton, AvatarBone parentBone, AvatarBone childBone, Matrix33F orientationA, Matrix33F orientationB, Vector3F minimum, Vector3F maximum)
        {
            // Similar to AddTwistSwingLimit

            int parentIndex = (int)parentBone;
            int childIndex  = (int)childBone;

            var limit = new AngularLimit
            {
                BodyA = ragdoll.Bodies[parentIndex],
                BodyB = ragdoll.Bodies[childIndex],
                AnchorOrientationALocal = ragdoll.BodyOffsets[parentIndex].Orientation.Transposed * skeleton.GetBindPoseAbsoluteInverse(parentIndex).Rotation.ToRotationMatrix33() * orientationA,
                AnchorOrientationBLocal = ragdoll.BodyOffsets[childIndex].Orientation.Transposed * skeleton.GetBindPoseAbsoluteInverse(childIndex).Rotation.ToRotationMatrix33() * orientationB,
                Minimum        = minimum,
                Maximum        = maximum,
                ErrorReduction = new Vector3F(0.2f),
                Softness       = new Vector3F(0.001f)
            };

            ragdoll.Limits[childIndex] = limit;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Visualizes the <see cref="AngularLimit"/> of a <see cref="BallJoint"/>.
        /// </summary>
        /// <param name="debugRenderer">The debug renderer.</param>
        /// <param name="joint">The joint.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="scale">
        /// A scale factor that determines the size of the drawn elements.
        /// </param>
        /// <param name="drawOverScene">
        /// If set to <see langword="true"/> the object is drawn over the graphics scene (depth-test
        /// disabled).
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="debugRenderer" />, <paramref name="joint" />,  or <paramref name="limit" />
        /// is <see langword="null" />.
        /// </exception>
        public static void DrawAngularLimit(this DebugRenderer debugRenderer, BallJoint joint, AngularLimit limit, float scale, bool drawOverScene)
        {
            if (debugRenderer == null)
            {
                throw new ArgumentNullException("debugRenderer");
            }
            if (joint == null)
            {
                throw new ArgumentNullException("joint");
            }
            if (limit == null)
            {
                throw new ArgumentNullException("limit");
            }

            Vector3 jointPosition = joint.BodyA.Pose.ToWorldPosition(joint.AnchorPositionALocal);

            // A transformation that converts from constraint anchor space to world space.
            Pose constraintToWorld = limit.BodyA.Pose * new Pose(limit.AnchorOrientationALocal);

            // Draw an arc for each rotation axis.
            DrawArc(debugRenderer, constraintToWorld, jointPosition, Vector3.UnitX, Vector3.UnitY, limit.Minimum.X, limit.Maximum.X, scale, Color.Red, drawOverScene);
            DrawArc(debugRenderer, constraintToWorld, jointPosition, Vector3.UnitY, Vector3.UnitX, limit.Minimum.Y, limit.Maximum.Y, scale, Color.Green, drawOverScene);
            DrawArc(debugRenderer, constraintToWorld, jointPosition, Vector3.UnitZ, Vector3.UnitX, limit.Minimum.Z, limit.Maximum.Z, scale, Color.Blue, drawOverScene);
        }
Exemplo n.º 6
0
 public void Connect(string strName, out AngularLimit item)
 {
     ExAddProperty(this.m_pSelf, strName, 4, 0x69dc);
     item = null;
 }
Exemplo n.º 7
0
 public void Connect(string strName, out AngularLimit item)
 {
     item = RuntimeObject.FromPtr(ExGetProperty(this.m_pSelf, strName, 4, 0x69dc)) as AngularLimit;
 }