Esempio n. 1
0
        private void limitAngle(MmdVector4 pvec4Out, MmdVector4 pvec4Src)
        {
            MmdVector3 vec3Angle = this._work_vector3[0];

            // XYZ軸回転の取得
            vec3Angle.QuaternionToEuler(pvec4Src);

            // 角度制限
            if (vec3Angle.x < -Math.PI)
            {
                vec3Angle.x = (float)-Math.PI;
            }
            if (-0.002f < vec3Angle.x)
            {
                vec3Angle.x = -0.002f;
            }
            vec3Angle.y = 0.0f;
            vec3Angle.z = 0.0f;

            // XYZ軸回転からクォータニオンへ
            pvec4Out.QuaternionCreateEuler(vec3Angle);
            return;
        }
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);
        }