Esempio n. 1
0
        private PmdBone m_pNeckBone;            // 首のボーン


        private void getMotionPosRot(MotionData pMotionData, float fFrame, MmdVector3 pvec3Pos, MmdVector4 pvec4Rot)
        {
            int i;
            int ulNumKeyFrame = pMotionData.ulNumKeyFrames;

            // 最終フレームを過ぎていた場合
            if (fFrame > pMotionData.pKeyFrames[ulNumKeyFrame - 1].fFrameNo)
            {
                fFrame = pMotionData.pKeyFrames[ulNumKeyFrame - 1].fFrameNo;
            }

            // 現在の時間がどのキー近辺にあるか
            for (i = 0; i < ulNumKeyFrame; i++)
            {
                if (fFrame <= pMotionData.pKeyFrames[i].fFrameNo)
                {
                    break;
                }
            }

            // 前後のキーを設定
            int lKey0,
                lKey1;

            lKey0 = i - 1;
            lKey1 = i;

            if (lKey0 <= 0)
            {
                lKey0 = 0;
            }
            if (i == ulNumKeyFrame)
            {
                lKey1 = ulNumKeyFrame - 1;
            }

            // 前後のキーの時間
            float fTime0 = pMotionData.pKeyFrames[lKey0].fFrameNo;
            float fTime1 = pMotionData.pKeyFrames[lKey1].fFrameNo;

            // 前後のキーの間でどの位置にいるか
            float fLerpValue;

            if (lKey0 != lKey1)
            {
                fLerpValue = (fFrame - fTime0) / (fTime1 - fTime0);
                pvec3Pos.Vector3Lerp(pMotionData.pKeyFrames[lKey0].vec3Position, pMotionData.pKeyFrames[lKey1].vec3Position, fLerpValue);
                pvec4Rot.QuaternionSlerp(pMotionData.pKeyFrames[lKey0].vec4Rotate, pMotionData.pKeyFrames[lKey1].vec4Rotate, fLerpValue);
                pvec4Rot.QuaternionNormalize(pvec4Rot);//これほんとにいるの?
            }
            else
            {
                pvec3Pos.setValue(pMotionData.pKeyFrames[lKey0].vec3Position);
                pvec4Rot.setValue(pMotionData.pKeyFrames[lKey0].vec4Rotate);
            }
        }
Esempio n. 2
0
        public void lookAt(MmdVector3 pvecTargetPos)
        {
            // どうもおかしいので要調整
            MmdMatrix  matTemp           = this._lookAt_matTemp;
            MmdMatrix  matInvTemp        = this._lookAt_matInvTemp;
            MmdVector3 vec3LocalTgtPosZY = this._lookAt_vec3LocalTgtPosZY;
            MmdVector3 vec3LocalTgtPosXZ = this._lookAt_vec3LocalTgtPosXZ;

            matTemp.MatrixIdentity();
            matTemp.m[3, 0] = m_vec3Position.x + m_vec3Offset.x;
            matTemp.m[3, 1] = m_vec3Position.y + m_vec3Offset.y;
            matTemp.m[3, 2] = m_vec3Position.z + m_vec3Offset.z;

            if (this._parent_bone != null)
            {
                matInvTemp.MatrixInverse(_parent_bone.m_matLocal);
                matTemp.MatrixMultiply(matTemp, matInvTemp);
            }
            matTemp.MatrixInverse(matTemp);


            vec3LocalTgtPosZY.Vector3Transform(pvecTargetPos, matTemp);

            vec3LocalTgtPosXZ.setValue(vec3LocalTgtPosZY);
            vec3LocalTgtPosXZ.y = 0.0f;
            vec3LocalTgtPosXZ.Vector3Normalize(vec3LocalTgtPosXZ);

            vec3LocalTgtPosZY.x = 0.0f;
            vec3LocalTgtPosZY.Vector3Normalize(vec3LocalTgtPosZY);

            MmdVector3 vec3Angle = this._lookAt_vec3Angle;

            vec3Angle.x = vec3Angle.y = vec3Angle.z = 0;

            if (vec3LocalTgtPosZY.z > 0.0f)
            {
                vec3Angle.x = (float)(Math.Asin(vec3LocalTgtPosZY.y) - (20.0 * Math.PI / 180.0));
            }
            if (vec3LocalTgtPosXZ.x < 0.0f)
            {
                vec3Angle.y = (float)Math.Acos(vec3LocalTgtPosXZ.z);
            }
            else
            {
                vec3Angle.y = (float)-Math.Acos(vec3LocalTgtPosXZ.z);
            }

            if (vec3Angle.x < (-25.0 * Math.PI / 180.0))
            {
                vec3Angle.x = (float)(-25.0 * Math.PI / 180.0);
            }
            if ((45.0f * Math.PI / 180.0) < vec3Angle.x)
            {
                vec3Angle.x = (float)(45.0 * Math.PI / 180.0);
            }
            if (vec3Angle.y < (-80.0 * Math.PI / 180.0))
            {
                vec3Angle.y = (float)(-80.0 * Math.PI / 180.0);
            }
            if ((80.0 * Math.PI / 180.0) < vec3Angle.y)
            {
                vec3Angle.y = (float)(80.0 * Math.PI / 180.0);
            }

            m_vec4Rotate.QuaternionCreateEuler(vec3Angle);
        }