Start implementation for swizzle operaators. operator+ and operator- have been added.

This commit is contained in:
athile
2011-09-21 12:19:27 -04:00
parent d942261f23
commit 5d3c6fb4ca
2 changed files with 98 additions and 58 deletions

View File

@@ -103,30 +103,20 @@ int test_vec3_swizzle3_3()
glm::vec3 v(1, 2, 3);
glm::vec3 u;
u = v;
Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.xyz;
Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.zyx;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.zyx = v;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.xyz; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.zyx; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.zyx = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.rgb;
Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.bgr;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.bgr = v;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.rgb; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.bgr; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.bgr = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.stp;
Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v;
Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u = v.stp; Error += (u.x == 1.0f && u.y == 2.0f && u.z == 3.0f) ? 0 : 1;
u = v.pts; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
u.pts = v; Error += (u.x == 3.0f && u.y == 2.0f && u.z == 1.0f) ? 0 : 1;
return Error;
}
@@ -140,12 +130,8 @@ int test_vec3_swizzle_half()
glm::hvec3 v(a1, b1, c1);
glm::hvec3 u;
float c = v.x;
float d = v.y;
u = v;
float a = u.x;
float b = u.y;
Error += (u.x.toFloat() == 1.0f && u.y.toFloat() == 2.0f && u.z.toFloat() == 3.0f) ? 0 : 1;
u = v.xyz;
@@ -172,6 +158,22 @@ int test_vec3_swizzle_half()
return Error;
}
int test_vec3_swizzle_operators()
{
int Error = 0;
glm::vec3 q, u, v;
u = glm::vec3(1, 2, 3);
v = glm::vec3(10, 20, 30);
q = u.xyz + v.xyz; Error += (q == (u + v)) ? 0 : 1;
q = (u.zyx + v.zyx).zyx; Error += (q == (u + v)) ? 0 : 1;
q = (u.xyz - v.xyz); Error += (q == (u - v)) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
@@ -181,6 +183,7 @@ int main()
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_vec3_swizzle_half();
Error += test_vec3_swizzle_operators();
return Error;
}