Exemplo n.º 1
0
        //====================================================
        //    非メンバ関数のテスト
        //====================================================
        public void crossProductTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            LDVector3 actual = new LDVector3();
            LDVector3 expected = new LDVector3();
            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected.zero();
            actual = LDVector3.crossProduct(vector1, vector2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 1.0, y = 2.0, z = 3.0} (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 1.0f;
            vector2.y = 2.0f;
            vector2.z = 3.0f;
            expected.x = vector1.y * vector2.z - vector1.z * vector2.y;
            expected.y = vector1.z * vector2.x - vector1.x * vector2.z;
            expected.z = vector1.x * vector2.y - vector1.y * vector2.x;
            actual = LDVector3.crossProduct(vector1, vector2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 2
0
        /**
         * @brief 最小弧クォータニオン 二点を結ぶ最小の弧を描く。(v1,v2が単位ベクトルであることがわかっている場合は useNormalizeを false にすると計算量が多少減る)
         * @param &v1 EVector3をセットする
         * @param &v2 EVector3をセットする
         * @param useNormalize 正規化する場合はtrue, そうでない場合はfalseをセットする。(入力無き場合はtrue)
         */
        void setToRotationArc(LDVector3 v1, LDVector3 v2, bool useNormalize = true)
        {
            LDVector3 vv1;
            LDVector3 vv2;
            LDVector3 tmp1;
            LDVector3 tmp2;

            if (useNormalize)
            {
                tmp1 = v1;
                tmp1.normalize();

                tmp2 = v2;
                tmp2.normalize();
                vv1 = tmp1;
                vv2 = tmp2;
            }
            else
            {
                vv1 = v1;
                vv2 = v2;
            }

            LDVector3 c = LDVector3.crossProduct(vv1, vv2);
            ld_float  d = vv1.dotProduct(vv2);

            ld_float s = (ld_float)Math.Sqrt((1 + d) * 2);

            this.x = c.x / s;
            this.y = c.y / s;
            this.z = c.z / s;
            this.w = s / 2.0f;
        } // not public
Exemplo n.º 3
0
        } // not public

        /**
         * @brief 独自の球面線形補間(回転角度を保つ)。y軸90度、z軸90度の回転をSLERPで計算する場合、t が変化した時、軸は最小距離を移動するが、角度は、90度ではなく小さな値となる。この計算を 90度の回転を保って、中心を通る計算についてテスト実装
         * @param &q1 クォータニオン(EQuat)をセットする
         * @param t 補間位置を表す数値をセットする
         * @return 補間結果を返す
         */
        LDQuat mySlerp(LDQuat q1, ld_float t)
        {
            LDQuat q0 = this;

            // 範囲外の時は端点を返す
            if (t <= 0.0f)
            {
                return(q0);
            }
            if (t >= 1.0f)
            {
                return(q1);
            }

            LDVector3 n0 = q0.getAxis();
            LDVector3 n1 = q1.getAxis();
            ld_float  a0 = q0.getAngle();
            ld_float  a1 = q1.getAngle();

            //
            ld_float  adiff = LDMathUtil.getAngleDiff(a1, a0);
            ld_float  at    = a0 + adiff * t;
            LDVector3 nt    = LDVector3.blend(n0, n1, 1 - t, t);

            nt.normalize();

            LDQuat ret = new LDQuat();

            ret.setToRotateAxis(nt, at);
            return(ret);
        }
Exemplo n.º 4
0
 /**
  * @brief vector3 ,w を指定して初期化
  * @param _v EVector3をセットする
  * @param w 初期値をセットする
  */
 public LDQuat(LDVector3 _v, ld_float _w)
 {
     x = _v.x;
     y = _v.y;
     z = _v.z;
     w = _w;
 }
Exemplo n.º 5
0
        public LDPoint transform(LDPoint p)
        {
            LDVector3 srcVec = new LDVector3(p.x(), p.y(), 0);
            LDVector3 dstVec = m_matrix.transform(srcVec);

            return(new LDPoint(dstVec.x, dstVec.y));
        }
Exemplo n.º 6
0
 /**
 * @brief vector3 ,w を指定して初期化
 * @param _v EVector3をセットする
 * @param w 初期値をセットする
 */
 public LDQuat(LDVector3 _v, ld_float _w)
 {
     x = _v.x;
     y = _v.y;
     z = _v.z;
     w = _w;
 }
Exemplo n.º 7
0
        public void normalizeTest()
        {
            LDVector3 vector = new LDVector3();
            ld_float  expected_x;
            ld_float  expected_y;
            ld_float  expected_z;

            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected_x = 0.0f;
            expected_y = 0.0f;
            expected_z = 0.0f;
            vector.normalize();
            TestUtil.COMPARE(expected_x, vector.x);
            TestUtil.COMPARE(expected_y, vector.y);
            TestUtil.COMPARE(expected_z, vector.z);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x   = 1.0f;
            vector.y   = 2.0f;
            vector.z   = 3.0f;
            expected_x = vector.x / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            expected_y = vector.y / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            expected_z = vector.z / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            vector.normalize();
            TestUtil.COMPARE(expected_x, vector.x);
            TestUtil.COMPARE(expected_y, vector.y);
            TestUtil.COMPARE(expected_z, vector.z);
        }
Exemplo n.º 8
0
        public void dotTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            ld_float  actual;
            ld_float  expected;

            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected = 0.0f;
            actual   = LDVector3.dot(vector1, vector2);
            TestUtil.COMPARE(expected, actual);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 1.0, y = 2.0, z = 3.0} (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 1.0f;
            vector2.y = 2.0f;
            vector2.z = 3.0f;
            expected  = vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z;
            actual    = LDVector3.dot(vector1, vector2);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 9
0
        public void distanceTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            ld_float  actual;
            ld_float  expected;

            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected = 0.0f;
            actual   = LDVector3.distance(vector1, vector2);
            TestUtil.COMPARE(expected, actual);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 4.0, y = 5.0, z = 6.0} (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;

            ld_float dx = vector1.x - vector2.x;
            ld_float dy = vector1.y - vector2.y;
            ld_float dz = vector1.z - vector2.z;

            expected = (ld_float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
            actual   = LDVector3.distance(vector1, vector2);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 10
0
        //====================================================
        //	非メンバ関数のテスト
        //====================================================
        public void crossProductTest()
        {
            LDVector3 vector1  = new LDVector3();
            LDVector3 vector2  = new LDVector3();
            LDVector3 actual   = new LDVector3();
            LDVector3 expected = new LDVector3();

            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected.zero();
            actual = LDVector3.crossProduct(vector1, vector2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 1.0, y = 2.0, z = 3.0} (任意の値)
            vector1.x  = 1.0f;
            vector1.y  = 2.0f;
            vector1.z  = 3.0f;
            vector2.x  = 1.0f;
            vector2.y  = 2.0f;
            vector2.z  = 3.0f;
            expected.x = vector1.y * vector2.z - vector1.z * vector2.y;
            expected.y = vector1.z * vector2.x - vector1.x * vector2.z;
            expected.z = vector1.x * vector2.y - vector1.y * vector2.x;
            actual     = LDVector3.crossProduct(vector1, vector2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 11
0
        public float transform(float p)
        {
            LDVector3 srcVec = new LDVector3(p, 0, 0);
            LDVector3 dstVec = m_matrix.transform(srcVec);

            return(dstVec.x);
        }
Exemplo n.º 12
0
        //------ ベクトルの変換 -------

        /**
         * @brief 変換を行う
         * @param p EVector3をセットする
         * @return 変換行列を返す
         */
        public LDVector3 transform(LDVector3 p)
        {
            return(new LDVector3(
                       m11 * p.x + m12 * p.y + m13 * p.z + m14,
                       m21 * p.x + m22 * p.y + m13 * p.z + m24,
                       m31 * p.y + m32 * p.y + m13 * p.z + m34
                       ));
        }
Exemplo n.º 13
0
        /**
         * @brief 2つの点の距離を取得する
         * @param v1 EVector3をセットする
         * @param v2 EVector3をセットする
         * @return 2つの点の距離を返す
         */
        public static ld_float distance(LDVector3 v1, LDVector3 v2)
        {
            ld_float dx = v1.x - v2.x;
            ld_float dy = v1.y - v2.y;
            ld_float dz = v1.z - v2.z;

            return((ld_float)Math.Sqrt(dx * dx + dy * dy + dz * dz));
        }
Exemplo n.º 14
0
        /**
         * @brief 変換を行う
         * @param p EVector3をセットする
         * @param *dst 変換行列を受け取るポインタをセットする
         */
        public void transform(LDVector3 p, LDVector3 dst)
        {
            //p == dst の場合も考慮し、退避して計算する
            ld_float x = m11 * p.x + m12 * p.y + m13 * p.z + m14;
            ld_float y = m21 * p.x + m22 * p.y + m13 * p.z + m24;

            dst.z = m31 * p.y + m32 * p.y + m13 * p.z + m34;
            dst.x = x;
            dst.y = y;
        }
Exemplo n.º 15
0
        public void setToRotateAxis(LDVector3 axis, ld_float theta)
        {
            Debug.Assert(Math.Abs(axis.length() - 1.0f) < 0.01f);

            ld_float theta_over2 = theta * 0.5f;
            ld_float sinQ_over2  = (ld_float)Math.Sin(theta_over2);

            w = (ld_float)Math.Cos(theta_over2);
            x = axis.x * sinQ_over2;
            y = axis.y * sinQ_over2;
            z = axis.z * sinQ_over2;
        }
Exemplo n.º 16
0
        public void getAxisTest()
        {
            LDQuat    quat     = new LDQuat(0.0f, 0.0f, 0.0f, 0.0f);
            LDVector3 actual   = new LDVector3();
            LDVector3 expected = new LDVector3();

            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0, w = 0.0 (ゼロクォータニオン)
            expected.zero();
            actual = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : x = 0.0, y = 0.0, z = 0.0, w = 1.0 (単位クォータニオン)
            quat.x     = 0.0f;
            quat.y     = 0.0f;
            quat.z     = 0.0f;
            quat.w     = 1.0f;
            expected.x = 1.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual     = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : x = 1.0, y = 2.0, z = 3.0, w = 0.5 (任意の値)
            quat.x     = 1.0f;
            quat.y     = 2.0f;
            quat.z     = 3.0f;
            quat.w     = 0.5f;
            expected.x = quat.x * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            expected.y = quat.y * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            expected.z = quat.z * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            actual     = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 17
0
        public void getAxisTest()
        {
            LDQuat quat = new LDQuat(0.0f, 0.0f, 0.0f, 0.0f);
            LDVector3 actual = new LDVector3();
            LDVector3 expected = new LDVector3();
            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0, w = 0.0 (ゼロクォータニオン)
            expected.zero();
            actual = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : x = 0.0, y = 0.0, z = 0.0, w = 1.0 (単位クォータニオン)
            quat.x = 0.0f;
            quat.y = 0.0f;
            quat.z = 0.0f;
            quat.w = 1.0f;
            expected.x = 1.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : x = 1.0, y = 2.0, z = 3.0, w = 0.5 (任意の値)
            quat.x = 1.0f;
            quat.y = 2.0f;
            quat.z = 3.0f;
            quat.w = 0.5f;
            expected.x = quat.x * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            expected.y = quat.y * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            expected.z = quat.z * 1.0f / (float)Math.Sqrt(1.0f - quat.w * quat.w);
            actual = quat.getAxis();
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 18
0
        public void blendTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            LDVector3 actual = new LDVector3();
            LDVector3 expected = new LDVector3();
            //ld_float delta = 0.00001f;
            ld_float t1;
            ld_float t2;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}
            //		   vector2{x = 0.0, y = 0.0, z = 0.0}, t1 = 0.0, t2 = 0.0 (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            t1 = 0.0f;
            t2 = 0.0f;
            expected.zero();
            actual = LDVector3.blend(vector1, vector2, t1, t2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}
            //		   vector2{x = 4.0, y = 5.0, z = 6.0}, t1 = 1.0, t2 = 2.0 (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;
            t1 = 1.0f;
            t2 = 2.0f;
            expected.x = vector1.x * t1 + vector2.x * t2;
            expected.y = vector1.y * t1 + vector2.y * t2;
            expected.z = vector1.z * t1 + vector2.z * t2;
            actual = LDVector3.blend(vector1, vector2, t1, t2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 19
0
        public void blendTest()
        {
            LDVector3 vector1  = new LDVector3();
            LDVector3 vector2  = new LDVector3();
            LDVector3 actual   = new LDVector3();
            LDVector3 expected = new LDVector3();
            //ld_float delta = 0.00001f;
            ld_float t1;
            ld_float t2;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}
            //		   vector2{x = 0.0, y = 0.0, z = 0.0}, t1 = 0.0, t2 = 0.0 (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            t1 = 0.0f;
            t2 = 0.0f;
            expected.zero();
            actual = LDVector3.blend(vector1, vector2, t1, t2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}
            //		   vector2{x = 4.0, y = 5.0, z = 6.0}, t1 = 1.0, t2 = 2.0 (任意の値)
            vector1.x  = 1.0f;
            vector1.y  = 2.0f;
            vector1.z  = 3.0f;
            vector2.x  = 4.0f;
            vector2.y  = 5.0f;
            vector2.z  = 6.0f;
            t1         = 1.0f;
            t2         = 2.0f;
            expected.x = vector1.x * t1 + vector2.x * t2;
            expected.y = vector1.y * t1 + vector2.y * t2;
            expected.z = vector1.z * t1 + vector2.z * t2;
            actual     = LDVector3.blend(vector1, vector2, t1, t2);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 20
0
        public void lengthTest()
        {
            LDVector3 vector = new LDVector3();
            ld_float  actual;
            ld_float  expected;

            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected = 0.0f;
            actual   = vector.length();
            TestUtil.COMPARE(expected, actual);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            expected = (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            actual   = vector.length();
            TestUtil.COMPARE(expected, actual);

            // 非メンバ関数lengthのテスト

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected = 0.0f;
            actual   = LDVector3.length(vector);
            TestUtil.COMPARE(expected, actual);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            expected = (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            actual   = LDVector3.length(vector);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 21
0
        //------ EQuat.h ------

        public void setToRotateAxisTest()
        {
            LDVector3 vector   = new LDVector3();
            LDQuat    actual   = new LDQuat();
            LDQuat    expected = new LDQuat();
            //ld_float delta = 0.00001f;
            ld_float theta;

            // Input : vector{x = 1.0, y = 0.0, z = 0.0}, theta = 0.0 (単位ベクトル)
            vector.x = 1.0f;
            vector.y = 0.0f;
            vector.z = 0.0f;
            vector.normalize();
            theta      = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual.setToRotateAxis(vector, theta);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector{x = 1.0, y = 2.0, z = 3.0}, theta = EUC_PI_OVER_2 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            vector.normalize();
            theta      = LDMathUtil.PI_OVER_2;
            expected.x = vector.x * (float)Math.Sin(theta * 0.5f);
            expected.y = vector.y * (float)Math.Sin(theta * 0.5f);
            expected.z = vector.z * (float)Math.Sin(theta * 0.5f);
            expected.w = (float)Math.Cos(theta * 0.5f);
            actual.setToRotateAxis(vector, theta);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);
        }
Exemplo n.º 22
0
        public void transformTest()
        {
            LDVector3  vector   = new LDVector3();
            LDVector3  expected = new LDVector3();
            LDVector3  actual   = new LDVector3();
            LDMatrix43 matrix   = new LDMatrix43();

            //ld_float delta = 0.00001f;

            // Input : matrix = 単位行列, vector = 0.0 (ゼロ)
            vector.zero();
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual     = matrix.transform(vector);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : matrix = 任意の値, x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x   = 1.0f;
            vector.y   = 2.0f;
            vector.z   = 3.0f;
            matrix.m11 = 1.0f;
            matrix.m12 = 2.0f;
            matrix.m13 = 3.0f;
            matrix.m14 = 4.0f;
            matrix.m21 = 1.0f;
            matrix.m22 = 2.0f;
            matrix.m23 = 3.0f;
            matrix.m24 = 4.0f;
            matrix.m31 = 1.0f;
            matrix.m32 = 2.0f;
            matrix.m33 = 3.0f;
            matrix.m34 = 4.0f;
            expected.x = matrix.m11 * vector.x + matrix.m12 * vector.y + matrix.m13 * vector.z + matrix.m14;
            expected.y = matrix.m21 * vector.x + matrix.m22 * vector.y + matrix.m13 * vector.z + matrix.m24;
            expected.z = matrix.m31 * vector.y + matrix.m32 * vector.y + matrix.m13 * vector.z + matrix.m34;
            actual     = matrix.transform(vector);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : matrix = 任意の値, x = 1.0, y = 2.0, z = 3.0 (任意の値) (p == dstの場合)
            vector.x   = 1.0f;
            vector.y   = 2.0f;
            vector.z   = 3.0f;
            matrix.m11 = 1.0f;
            matrix.m12 = 2.0f;
            matrix.m13 = 3.0f;
            matrix.m14 = 4.0f;
            matrix.m21 = 1.0f;
            matrix.m22 = 2.0f;
            matrix.m23 = 3.0f;
            matrix.m24 = 4.0f;
            matrix.m31 = 1.0f;
            matrix.m32 = 2.0f;
            matrix.m33 = 3.0f;
            matrix.m34 = 4.0f;
            expected.x = matrix.m11 * vector.x + matrix.m12 * vector.y + matrix.m13 * vector.z + matrix.m14;
            expected.y = matrix.m21 * vector.x + matrix.m22 * vector.y + matrix.m13 * vector.z + matrix.m24;
            expected.z = matrix.m31 * vector.y + matrix.m32 * vector.y + matrix.m13 * vector.z + matrix.m34;
            matrix.transform(vector, out vector);
            TestUtil.COMPARE(expected.x, vector.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 23
0
 /**
  * @brief 2つのベクトルをブレンドする
  * @param v1 EVector3をセットする
  * @param v2 EVector3をセットする
  * @param t1 v1にかけるスカラー値t1をセットする
  * @param t2 v2にかけるスカラー値t2をセットする
  * @return ブレンドしたベクトルを返す
  */
 public static LDVector3 blend(LDVector3 v1, LDVector3 v2, ld_float t1, ld_float t2)
 {
     return(new LDVector3(v1.x * t1 + v2.x * t2, v1.y * t1 + v2.y * t2, v1.z * t1 + v2.z * t2));
 }
Exemplo n.º 24
0
        /**
        * @brief 最小弧クォータニオン 二点を結ぶ最小の弧を描く。(v1,v2が単位ベクトルであることがわかっている場合は useNormalizeを false にすると計算量が多少減る)
        * @param &v1 EVector3をセットする
        * @param &v2 EVector3をセットする
        * @param useNormalize 正規化する場合はtrue, そうでない場合はfalseをセットする。(入力無き場合はtrue)
        */
        public void setToRotationArc(LDVector3 v1, LDVector3 v2, bool useNormalize = true)
        {
            LDVector3 vv1;
            LDVector3 vv2;
            LDVector3 tmp1;
            LDVector3 tmp2;

            if (useNormalize)
            {
                tmp1 = v1;
                tmp1.normalize();

                tmp2 = v2;
                tmp2.normalize();
                vv1 = tmp1;
                vv2 = tmp2;
            }
            else
            {
                vv1 = v1;
                vv2 = v2;
            }

            LDVector3 c = LDVector3.crossProduct(vv1, vv2);
            ld_float d = vv1.dotProduct(vv2);

            ld_float s = (ld_float)Math.Sqrt((1 + d) * 2);
            this.x = c.x / s;
            this.y = c.y / s;
            this.z = c.z / s;
            this.w = s / 2.0f;
        }
Exemplo n.º 25
0
        public float transform(float p)
        {
            LDVector3 srcVec = new LDVector3(p,0, 0);
            LDVector3 dstVec = m_matrix.transform(srcVec);

            return dstVec.x;
        }
Exemplo n.º 26
0
 /**
  * @brief ベクトルの内積
  * @param v1 EVector3をセットする
  * @param v2 EVector3をセットする
  * @return ベクトルの内積を返す
  */
 public static ld_float dot(LDVector3 v1, LDVector3 v2)
 {
     return(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
 }
Exemplo n.º 27
0
        /// <summary>
        /// TODO:要実装 LDFUZZY_COMPARE
        /// </summary>
        public void setToRotationArcTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            LDVector3 vector3 = new LDVector3();
            LDQuat actual = new LDQuat();
            LDQuat expected = new LDQuat();
            //ld_float delta = 0.00001f;
            ld_float d;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2 {x = 0.0, y = 0.0, z = 0.0}, useNormalize = false
            //         actual {x = 0.0, y = 0.0, z = 0.0, w = 0.0}
            // useNormalize = false, (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            actual.x = 0.0f;
            actual.y = 0.0f;
            actual.z = 0.0f;
            actual.w = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            expected.w = (float)Math.Sqrt(2.0f) / 2.0f;
            actual.setToRotationArc(vector1, vector2, false);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            //LDFUZZY_COMPARE(expected.w, actual.w, TEST_TOLERANCE);

            //	QVERIFY(qFuzzyCompare(expected.w, actual.w));
            //	TestUtil.COMPARE(expected.w, actual.w);//極小誤差によりFalse

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2 {x = 0.0, y = 0.0, z = 0.0}, useNormalize = true
            //         actual {x = 0.0, y = 0.0, z = 0.0, w = 0.0}
            // useNormalize = true, (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            actual.x = 0.0f;
            actual.y = 0.0f;
            actual.z = 0.0f;
            actual.w = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            expected.w = (float)Math.Sqrt(2.0f) / 2.0f;
            actual.setToRotationArc(vector1, vector2, true);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            //LDFUZZY_COMPARE(expected.w, actual.w, TEST_TOLERANCE);

            //	TestUtil.COMPARE(expected.w, actual.w);//極小誤差によりFalse

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2 {x = 4.0, y = 5.0, z = 6.0}, useNormalize = false
            //         actual {x = 1.0, y = 2.0, z = 3.0, w = 0.5}
            // useNormalize = false, (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;
            actual.x = 1.0f;
            actual.y = 2.0f;
            actual.z = 3.0f;
            actual.w = 0.5f;

            vector3 = LDVector3.crossProduct(vector1, vector2);
            d = vector1.dotProduct(vector2);

            expected.x = vector3.x / (float)Math.Sqrt((1 + d) * 2);
            expected.y = vector3.y / (float)Math.Sqrt((1 + d) * 2);
            expected.z = vector3.z / (float)Math.Sqrt((1 + d) * 2);
            expected.w = (float)Math.Sqrt((1 + d) * 2) / 2.0f;
            actual.setToRotationArc(vector1, vector2, false);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2 {x = 4.0, y = 5.0, z = 6.0}, useNormalize = true
            //         actual {x = 1.0, y = 2.0, z = 3.0, w = 0.5}
            // useNormalize = true, (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;
            actual.x = 1.0f;
            actual.y = 2.0f;
            actual.z = 3.0f;
            actual.w = 0.5f;

            vector1.normalize();
            vector2.normalize();
            vector3 = LDVector3.crossProduct(vector1, vector2);
            d = vector1.dotProduct(vector2);

            expected.x = vector3.x / (float)Math.Sqrt((1 + d) * 2);
            expected.y = vector3.y / (float)Math.Sqrt((1 + d) * 2);
            expected.z = vector3.z / (float)Math.Sqrt((1 + d) * 2);
            expected.w = (float)Math.Sqrt((1 + d) * 2) / 2.0f;
            actual.setToRotationArc(vector1, vector2, true);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);
        }
Exemplo n.º 28
0
 /**
 * @brief ベクトルの内積
 * @param v2 EVector3をセットする
 * @return ベクトルの内積を返す
 */
 public ld_float dotProduct(LDVector3 v2)
 {
     return this.x * v2.x + this.y * v2.y + this.z * v2.z;
 }
Exemplo n.º 29
0
        //====================================================
        //	非メンバ関数
        //====================================================

        /**
         * @brief ベクトルの長さ
         * @param v EVector3をセットする
         * @return ベクトルの長さを返す
         */
        public static ld_float length(LDVector3 v)
        {
            return((ld_float)Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z));
        }
Exemplo n.º 30
0
        /// <summary>
        /// TODO:要実装 LDFUZZY_COMPARE
        /// </summary>
        public void setToRotationArcTest()
        {
            LDVector3 vector1  = new LDVector3();
            LDVector3 vector2  = new LDVector3();
            LDVector3 vector3  = new LDVector3();
            LDQuat    actual   = new LDQuat();
            LDQuat    expected = new LDQuat();
            //ld_float delta = 0.00001f;
            ld_float d;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2 {x = 0.0, y = 0.0, z = 0.0}, useNormalize = false
            //         actual {x = 0.0, y = 0.0, z = 0.0, w = 0.0}
            // useNormalize = false, (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            actual.x   = 0.0f;
            actual.y   = 0.0f;
            actual.z   = 0.0f;
            actual.w   = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            expected.w = (float)Math.Sqrt(2.0f) / 2.0f;
            actual.setToRotationArc(vector1, vector2, false);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);


            //LDFUZZY_COMPARE(expected.w, actual.w, TEST_TOLERANCE);


            //	QVERIFY(qFuzzyCompare(expected.w, actual.w));
            //	TestUtil.COMPARE(expected.w, actual.w);//極小誤差によりFalse

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2 {x = 0.0, y = 0.0, z = 0.0}, useNormalize = true
            //         actual {x = 0.0, y = 0.0, z = 0.0, w = 0.0}
            // useNormalize = true, (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            actual.x   = 0.0f;
            actual.y   = 0.0f;
            actual.z   = 0.0f;
            actual.w   = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            expected.w = (float)Math.Sqrt(2.0f) / 2.0f;
            actual.setToRotationArc(vector1, vector2, true);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);



            //LDFUZZY_COMPARE(expected.w, actual.w, TEST_TOLERANCE);



            //	TestUtil.COMPARE(expected.w, actual.w);//極小誤差によりFalse

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2 {x = 4.0, y = 5.0, z = 6.0}, useNormalize = false
            //         actual {x = 1.0, y = 2.0, z = 3.0, w = 0.5}
            // useNormalize = false, (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;
            actual.x  = 1.0f;
            actual.y  = 2.0f;
            actual.z  = 3.0f;
            actual.w  = 0.5f;

            vector3 = LDVector3.crossProduct(vector1, vector2);
            d       = vector1.dotProduct(vector2);

            expected.x = vector3.x / (float)Math.Sqrt((1 + d) * 2);
            expected.y = vector3.y / (float)Math.Sqrt((1 + d) * 2);
            expected.z = vector3.z / (float)Math.Sqrt((1 + d) * 2);
            expected.w = (float)Math.Sqrt((1 + d) * 2) / 2.0f;
            actual.setToRotationArc(vector1, vector2, false);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2 {x = 4.0, y = 5.0, z = 6.0}, useNormalize = true
            //         actual {x = 1.0, y = 2.0, z = 3.0, w = 0.5}
            // useNormalize = true, (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;
            actual.x  = 1.0f;
            actual.y  = 2.0f;
            actual.z  = 3.0f;
            actual.w  = 0.5f;

            vector1.normalize();
            vector2.normalize();
            vector3 = LDVector3.crossProduct(vector1, vector2);
            d       = vector1.dotProduct(vector2);

            expected.x = vector3.x / (float)Math.Sqrt((1 + d) * 2);
            expected.y = vector3.y / (float)Math.Sqrt((1 + d) * 2);
            expected.z = vector3.z / (float)Math.Sqrt((1 + d) * 2);
            expected.w = (float)Math.Sqrt((1 + d) * 2) / 2.0f;
            actual.setToRotationArc(vector1, vector2, true);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);
        }
Exemplo n.º 31
0
        public void mySlerpTest()
        {
            LDQuat quat1    = new LDQuat();
            LDQuat quat2    = new LDQuat();
            LDQuat actual   = new LDQuat();
            LDQuat expected = new LDQuat();
            //ld_float delta = 0.00001f;
            ld_float t;

            // Input : quat1{x = 1.0, y = 2.0, z = 3.0, w = 0.1}, quat2{x = 4.0, y = 5.0, z = 6.0, w = 0.2}, t = 0.0
            // 範囲外t <= 0.0fのケース
            quat1.x    = 1.0f;
            quat1.y    = 2.0f;
            quat1.z    = 3.0f;
            quat1.w    = 0.1f;
            quat2.x    = 4.0f;
            quat2.y    = 5.0f;
            quat2.z    = 6.0f;
            quat2.w    = 0.2f;
            t          = 0.0f;
            expected.x = 4.0f;
            expected.y = 5.0f;
            expected.z = 6.0f;
            expected.w = 0.2f;
            actual     = quat2.mySlerp(quat1, t);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);

            // Input : quat1{x = 1.0, y = 2.0, z = 3.0, w = 0.1}, quat2{x = 4.0, y = 5.0, z = 6.0, w = 0.2}, t = 1.0
            // 範囲外t >= 1.0fのケース
            quat1.x    = 1.0f;
            quat1.y    = 2.0f;
            quat1.z    = 3.0f;
            quat1.w    = 0.1f;
            quat2.x    = 4.0f;
            quat2.y    = 5.0f;
            quat2.z    = 6.0f;
            quat2.w    = 0.2f;
            t          = 1.0f;
            expected.x = 1.0f;
            expected.y = 2.0f;
            expected.z = 3.0f;
            expected.w = 0.1f;
            actual     = quat2.mySlerp(quat1, t);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);

            // Input : quat1{x = 0.49, y = 0.5, z = 0.5, w = 0.5}, quat2{x = 0.5, y = 0.49, z = 0.5, w = 0.5}, t = 0.5
            // cosOmega <= 0.9999fのケース
            quat1.x = 0.49f;
            quat1.y = 0.5f;
            quat1.z = 0.5f;
            quat1.w = 0.5f;
            quat2.x = 0.5f;
            quat2.y = 0.49f;
            quat2.z = 0.5f;
            quat2.w = 0.5f;
            t       = 0.5f;
            LDVector3 n0    = quat2.getAxis();
            LDVector3 n1    = quat1.getAxis();
            ld_float  a0    = quat2.getAngle();
            ld_float  a1    = quat1.getAngle();
            ld_float  adiff = LDMathUtil.getAngleDiff(a1, a0);
            ld_float  at    = a0 + adiff * t;
            LDVector3 nt    = LDVector3.blend(n0, n1, 1 - t, t);

            nt.normalize();
            expected.setToRotateAxis(nt, at);
            actual = quat2.mySlerp(quat1, t);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);
        }
Exemplo n.º 32
0
        public void lengthTest()
        {
            LDVector3 vector = new LDVector3();
            ld_float actual;
            ld_float expected;
            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected = 0.0f;
            actual = vector.length();
            TestUtil.COMPARE(expected, actual);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            expected = (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            actual = vector.length();
            TestUtil.COMPARE(expected, actual);

            // 非メンバ関数lengthのテスト

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected = 0.0f;
            actual = LDVector3.length(vector);
            TestUtil.COMPARE(expected, actual);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            expected = (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            actual = LDVector3.length(vector);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 33
0
        public void dotTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            ld_float actual;
            ld_float expected;
            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected = 0.0f;
            actual = LDVector3.dot(vector1, vector2);
            TestUtil.COMPARE(expected, actual);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 1.0, y = 2.0, z = 3.0} (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 1.0f;
            vector2.y = 2.0f;
            vector2.z = 3.0f;
            expected = vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z;
            actual = LDVector3.dot(vector1, vector2);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 34
0
        public LDPoint transform(LDPoint p)
        {
            LDVector3 srcVec=new LDVector3(p.x(), p.y(), 0);
            LDVector3 dstVec = m_matrix.transform(srcVec);

            return new LDPoint(dstVec.x, dstVec.y);
        }
Exemplo n.º 35
0
 /**
  * @brief 代入する
  * @param v EVector3をセットする
  * @return 自身を返す
  */
 public void CopyFrom(LDVector3 v)
 {
     this.x = v.x;
     this.y = v.y;
     this.z = v.z;
 }
Exemplo n.º 36
0
 /**
 * @brief 代入する
 * @param v EVector3をセットする
 * @return 自身を返す
 */
 public void CopyFrom(LDVector3 v)
 {
     this.x = v.x;
     this.y = v.y;
     this.z = v.z;
 }
Exemplo n.º 37
0
 /**
 * @brief コンストラクタ
 * @param v EVector3をセットする
 */
 public LDVector3(LDVector3 v)
 {
     this.x = v.x;
     this.y = v.y;
     this.z = v.z;
 }
Exemplo n.º 38
0
 /**
 * @brief 変換を行う
 * @param p EVector3をセットする
 * @param *dst 変換行列を受け取るポインタをセットする
 */
 public void transform(LDVector3 p, out LDVector3 dst)
 {
     //p == dst の場合も考慮し、退避して計算する
     ld_float x = m11 * p.x + m12 * p.y + m13 * p.z + m14;
     ld_float y = m21 * p.x + m22 * p.y + m13 * p.z + m24;
     dst = new LDVector3();
     dst.z = m31 * p.y + m32 * p.y + m13 * p.z + m34;
     dst.x = x;
     dst.y = y;
 }
Exemplo n.º 39
0
 /**
  * @brief ベクトルの内積
  * @param v2 EVector3をセットする
  * @return ベクトルの内積を返す
  */
 public ld_float dotProduct(LDVector3 v2)
 {
     return(this.x * v2.x + this.y * v2.y + this.z * v2.z);
 }
Exemplo n.º 40
0
 /**
 * @brief ベクトルの外積
 * @param v1 EVector3をセットする
 * @param v2 EVector3をセットする
 * @return ベクトルの外積を返す
 */
 public static LDVector3 crossProduct(LDVector3 v1, LDVector3 v2)
 {
     return new LDVector3(v1.y * v2.z - v1.z * v2.y,
                       v1.z * v2.x - v1.x * v2.z,
                       v1.x * v2.y - v1.y * v2.x);
 }
Exemplo n.º 41
0
 /**
  * @brief ベクトルの外積
  * @param v1 EVector3をセットする
  * @param v2 EVector3をセットする
  * @return ベクトルの外積を返す
  */
 public static LDVector3 crossProduct(LDVector3 v1, LDVector3 v2)
 {
     return(new LDVector3(v1.y * v2.z - v1.z * v2.y,
                          v1.z * v2.x - v1.x * v2.z,
                          v1.x * v2.y - v1.y * v2.x));
 }
Exemplo n.º 42
0
        public void setToRotateAxis(LDVector3 axis, ld_float theta)
        {
            Debug.Assert(Math.Abs(axis.length() - 1.0f) < 0.01f);

            ld_float theta_over2 = theta * 0.5f;
            ld_float sinQ_over2 = (ld_float)Math.Sin(theta_over2);

            w = (ld_float)Math.Cos(theta_over2);
            x = axis.x * sinQ_over2;
            y = axis.y * sinQ_over2;
            z = axis.z * sinQ_over2;
        }
Exemplo n.º 43
0
        public void normalizeTest()
        {
            LDVector3 vector = new LDVector3();
            ld_float expected_x;
            ld_float expected_y;
            ld_float expected_z;
            //ld_float delta = 0.00001f;

            // Input : x = 0.0, y = 0.0, z = 0.0 (ゼロベクトル)
            vector.zero();
            expected_x = 0.0f;
            expected_y = 0.0f;
            expected_z = 0.0f;
            vector.normalize();
            TestUtil.COMPARE(expected_x, vector.x);
            TestUtil.COMPARE(expected_y, vector.y);
            TestUtil.COMPARE(expected_z, vector.z);

            // Input : x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            expected_x = vector.x / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            expected_y = vector.y / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            expected_z = vector.z / (ld_float)Math.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z);
            vector.normalize();
            TestUtil.COMPARE(expected_x, vector.x);
            TestUtil.COMPARE(expected_y, vector.y);
            TestUtil.COMPARE(expected_z, vector.z);
        }
Exemplo n.º 44
0
        //------ EQuat.h ------
        public void setToRotateAxisTest()
        {
            LDVector3 vector=new LDVector3();
            LDQuat actual = new LDQuat();
            LDQuat expected = new LDQuat();
            //ld_float delta = 0.00001f;
            ld_float theta;

            // Input : vector{x = 1.0, y = 0.0, z = 0.0}, theta = 0.0 (単位ベクトル)
            vector.x = 1.0f;
            vector.y = 0.0f;
            vector.z = 0.0f;
            vector.normalize();
            theta = 0.0f;
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual.setToRotateAxis(vector, theta);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : vector{x = 1.0, y = 2.0, z = 3.0}, theta = EUC_PI_OVER_2 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            vector.normalize();
            theta = LDMathUtil.PI_OVER_2;
            expected.x = vector.x * (float)Math.Sin(theta * 0.5f);
            expected.y = vector.y * (float)Math.Sin(theta * 0.5f);
            expected.z = vector.z * (float)Math.Sin(theta * 0.5f);
            expected.w = (float)Math.Cos(theta * 0.5f);
            actual.setToRotateAxis(vector, theta);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
            TestUtil.COMPARE(expected.w, actual.w);
        }
Exemplo n.º 45
0
 /**
  * @brief コンストラクタ
  * @param v EVector3をセットする
  */
 public LDVector3(LDVector3 v)
 {
     this.x = v.x;
     this.y = v.y;
     this.z = v.z;
 }
Exemplo n.º 46
0
 /**
 * @brief ベクトルの内積
 * @param v1 EVector3をセットする
 * @param v2 EVector3をセットする
 * @return ベクトルの内積を返す
 */
 public static ld_float dot(LDVector3 v1, LDVector3 v2)
 {
     return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
 }
Exemplo n.º 47
0
 /**
  * @brief 単位ベクトル1 から 単位ベクトル2への回転を表すクォータニオンを返す
  * @param unitVec1 EVector3をセットする
  * @param unitVec2 EVector3をセットする
  * @return クォータニオンを返す
  */
 static public LDQuat getRotation(LDVector3 unitVec1, LDVector3 unitVec2)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 48
0
 //====================================================
 //    非メンバ関数
 //====================================================
 /**
 * @brief ベクトルの長さ
 * @param v EVector3をセットする
 * @return ベクトルの長さを返す
 */
 public static ld_float length(LDVector3 v)
 {
     return (ld_float)Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
 }
Exemplo n.º 49
0
 /**
  * @brief 軸と回転角を指定して、クォータニオンを返す
  * @param unitVec EVector3をセットする
  * @param radian 回転角[rad]をセットする
  * @return クォータニオンを返す
  */
 static public LDQuat getRotation(LDVector3 unitVec, float radian)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 50
0
 /**
 * @brief 2つの点の距離を取得する
 * @param v1 EVector3をセットする
 * @param v2 EVector3をセットする
 * @return 2つの点の距離を返す
 */
 public static ld_float distance(LDVector3 v1, LDVector3 v2)
 {
     ld_float dx = v1.x - v2.x;
     ld_float dy = v1.y - v2.y;
     ld_float dz = v1.z - v2.z;
     return (ld_float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
 }
Exemplo n.º 51
0
        public void distanceTest()
        {
            LDVector3 vector1 = new LDVector3();
            LDVector3 vector2 = new LDVector3();
            ld_float actual;
            ld_float expected;
            //ld_float delta = 0.00001f;

            // Input : vector1{x = 0.0, y = 0.0, z = 0.0}, vector2{x = 0.0, y = 0.0, z = 0.0} (ゼロベクトル)
            vector1.zero();
            vector2.zero();
            expected = 0.0f;
            actual = LDVector3.distance(vector1, vector2);
            TestUtil.COMPARE(expected, actual);

            // Input : vector1{x = 1.0, y = 2.0, z = 3.0}, vector2{x = 4.0, y = 5.0, z = 6.0} (任意の値)
            vector1.x = 1.0f;
            vector1.y = 2.0f;
            vector1.z = 3.0f;
            vector2.x = 4.0f;
            vector2.y = 5.0f;
            vector2.z = 6.0f;

            ld_float dx = vector1.x - vector2.x;
            ld_float dy = vector1.y - vector2.y;
            ld_float dz = vector1.z - vector2.z;
            expected = (ld_float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
            actual = LDVector3.distance(vector1, vector2);
            TestUtil.COMPARE(expected, actual);
        }
Exemplo n.º 52
0
 /**
 * @brief 軸と回転角を指定して、クォータニオンを返す
 * @param unitVec EVector3をセットする
 * @param radian 回転角[rad]をセットする
 * @return クォータニオンを返す
 */
 public static LDQuat getRotation(LDVector3 unitVec, float radian)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 53
0
 //------ ベクトルの変換 -------
 /**
 * @brief 変換を行う
 * @param p EVector3をセットする
 * @return 変換行列を返す
 */
 public LDVector3 transform(LDVector3 p)
 {
     return new LDVector3(
        m11 * p.x + m12 * p.y + m13 * p.z + m14,
        m21 * p.x + m22 * p.y + m13 * p.z + m24,
        m31 * p.y + m32 * p.y + m13 * p.z + m34
    );
 }
Exemplo n.º 54
0
 /**
 * @brief 単位ベクトル1 から 単位ベクトル2への回転を表すクォータニオンを返す
 * @param unitVec1 EVector3をセットする
 * @param unitVec2 EVector3をセットする
 * @return クォータニオンを返す
 */
 public static LDQuat getRotation(LDVector3 unitVec1, LDVector3 unitVec2)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 55
0
        public void transformTest()
        {
            LDVector3 vector=new LDVector3();
            LDVector3 expected = new LDVector3();
            LDVector3 actual = new LDVector3();
            LDMatrix44 matrix=new LDMatrix44();
            //ld_float delta = 0.00001f;

            // Input : matrix = 単位行列, vector = 0.0 (ゼロ)
            vector.zero();
            expected.x = 0.0f;
            expected.y = 0.0f;
            expected.z = 0.0f;
            actual = matrix.transform(vector);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : matrix = 任意の値, x = 1.0, y = 2.0, z = 3.0 (任意の値)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            matrix.m11 = 1.0f;
            matrix.m12 = 2.0f;
            matrix.m13 = 3.0f;
            matrix.m14 = 4.0f;
            matrix.m21 = 1.0f;
            matrix.m22 = 2.0f;
            matrix.m23 = 3.0f;
            matrix.m24 = 4.0f;
            matrix.m31 = 1.0f;
            matrix.m32 = 2.0f;
            matrix.m33 = 3.0f;
            matrix.m34 = 4.0f;
            expected.x = matrix.m11 * vector.x + matrix.m12 * vector.y + matrix.m13 * vector.z + matrix.m14;
            expected.y = matrix.m21 * vector.x + matrix.m22 * vector.y + matrix.m13 * vector.z + matrix.m24;
            expected.z = matrix.m31 * vector.y + matrix.m32 * vector.y + matrix.m13 * vector.z + matrix.m34;
            actual = matrix.transform(vector);
            TestUtil.COMPARE(expected.x, actual.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);

            // Input : matrix = 任意の値, x = 1.0, y = 2.0, z = 3.0 (任意の値) (p == dstの場合)
            vector.x = 1.0f;
            vector.y = 2.0f;
            vector.z = 3.0f;
            matrix.m11 = 1.0f;
            matrix.m12 = 2.0f;
            matrix.m13 = 3.0f;
            matrix.m14 = 4.0f;
            matrix.m21 = 1.0f;
            matrix.m22 = 2.0f;
            matrix.m23 = 3.0f;
            matrix.m24 = 4.0f;
            matrix.m31 = 1.0f;
            matrix.m32 = 2.0f;
            matrix.m33 = 3.0f;
            matrix.m34 = 4.0f;
            expected.x = matrix.m11 * vector.x + matrix.m12 * vector.y + matrix.m13 * vector.z + matrix.m14;
            expected.y = matrix.m21 * vector.x + matrix.m22 * vector.y + matrix.m13 * vector.z + matrix.m24;
            expected.z = matrix.m31 * vector.y + matrix.m32 * vector.y + matrix.m13 * vector.z + matrix.m34;
            matrix.transform(vector, vector);
            TestUtil.COMPARE(expected.x, vector.x);
            TestUtil.COMPARE(expected.y, actual.y);
            TestUtil.COMPARE(expected.z, actual.z);
        }
Exemplo n.º 56
0
 /**
 * @brief 2つのベクトルをブレンドする
 * @param v1 EVector3をセットする
 * @param v2 EVector3をセットする
 * @param t1 v1にかけるスカラー値t1をセットする
 * @param t2 v2にかけるスカラー値t2をセットする
 * @return ブレンドしたベクトルを返す
 */
 public static LDVector3 blend(LDVector3 v1, LDVector3 v2, ld_float t1, ld_float t2)
 {
     return new LDVector3(v1.x * t1 + v2.x * t2, v1.y * t1 + v2.y * t2, v1.z * t1 + v2.z * t2);
 }