コード例 #1
0
        public virtual void FixedUpdateBones(RealHand targetHand, VCHand vcHand, int f)
        {
            RealFinger finger = targetHand.fingers[f];

            Vector3 displacement = bones [bones.Length - 1].position - finger.bones [bones.Length - 1].position;
            Vector3 force        = posSD.GetForce(displacement, boneBodys [bones.Length - 1].velocity);

            CapsuleCollider boneCol = boneCols [bones.Length - 1];
            Vector3         I       = CapsuleI(boneCol.radius, boneCol.height, posSD.m);

            Quaternion targetRot = finger.bones[bones.Length - 1].rotation;
            Quaternion boneRot   = bones[bones.Length - 1].rotation;
            Vector3    torque    = rotSD.GetTorque(boneRot, targetRot, boneBodys[bones.Length - 1].angularVelocity, I);

            MoveBones(vcHand, finger, force, torque);
        }
コード例 #2
0
        //位置がずれる、なぜ....
        public override void FixedUpdateBones(RealHand targetHand, VCHand vcHand, int f)
        {
            RealFinger finger = targetHand.fingers[f];

            Vector3 targetLocalPos = finger.bones [bones.Length - 1].position - targetHand.palm.position;
            Vector3 localPos       = bones [bones.Length - 1].position - targetHand.palm.position;
            Vector3 localVelocity  = boneBodys [bones.Length - 1].velocity - vcHand.palmBody.velocity;
            Vector3 force          = posSD.GetForce(localPos - targetLocalPos, localVelocity);

            CapsuleCollider boneCol              = boneCols [bones.Length - 1];
            Vector3         I                    = CapsuleI(boneCol.radius, boneCol.height, posSD.m);
            Quaternion      targetLocalRot       = finger.bones [bones.Length - 1].rotation * Quaternion.Inverse(targetHand.palm.rotation);
            Quaternion      boneLocalRot         = bones[bones.Length - 1].rotation * Quaternion.Inverse(targetHand.palm.rotation);
            Vector3         localAngularVelocity = boneBodys [bones.Length - 1].angularVelocity - vcHand.palmBody.angularVelocity;
            Vector3         torque               = rotSD.GetTorque(boneLocalRot, targetLocalRot, localAngularVelocity, I);

            MoveBones(vcHand, finger, force, torque);
        }
コード例 #3
0
        protected void MoveBones(VCHand vcHand, RealFinger finger, Vector3 force, Vector3 torque)
        {
            boneBodys [bones.Length - 1].AddForce(force);
            boneBodys[bones.Length - 1].AddTorque(torque);

            for (int b = 0; b < bones.Length; ++b)
            {
                if (bones [b] != null && boneBodys [b])
                {
                    boneCols [b].radius = finger.boneWidths[b] / 2f;
                    boneCols [b].height = finger.boneLengths[b] + finger.boneWidths [b];


                    if (vcHand.useSkin && fingerSkins[b])
                    {
                        fingerSkins[b].FixedUpdateSkin(bones[b], boneBodys[b], boneCols[b]);
                    }

                    /*
                     * Vector3 displacement = bones [b].position - finger.bones [b].Center.ToVector3 ();
                     * //Debug.DrawRay (finger.bones [b].Center.ToVector3 (), finger.bones[b].Direction.ToVector3(), Color.green, Time.fixedDeltaTime);
                     * Vector3 force = posSD.GetForce (displacement, boneBodys [b].velocity);
                     * boneBodys [b].AddForce (force);
                     *
                     * Quaternion targetRot = finger.bones[b].Rotation.ToQuaternion();
                     * Quaternion boneRot = bones[b].rotation;
                     * Vector3 torque = rotSD.GetTorque (boneRot, targetRot, boneBodys[b].angularVelocity);
                     * boneBodys[b].AddTorque (torque);
                     */

                    //回転軸の描画

                    /*
                     * if (b >= 2) {//Element0は空なので
                     *      float axisStartZ = -boneCols [b].height / 2f + boneCols [b].radius;
                     *      Vector3 start = bones [b].position + bones [b].forward * axisStartZ;
                     *      Vector3 rotAxis = Vector3.Cross (bones [b].forward, bones [b - 1].forward);
                     *      Debug.DrawRay (start, rotAxis, Color.red);
                     * }
                     */
                }
            }
        }