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); }
//==================================================== // 非メンバ関数のテスト //==================================================== 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); }
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); }
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); }
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); }
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); }
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); }
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); }
/// <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); }
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); }