This is an example on how to use the vec4.h file.
#include "../Test.h"
#include <sstream>
template<class T>
class Vec4TestCase : public Test
{
bool testInitialization() {
vec4<T> foo2((T)1, (T)2, (T)3, (T)4);
T vals[4] = { 2, 4, 6, 8 };
vec4<T> vec = build_vec4<T>((
void*)vals);
return true;
}
bool testAssignment() {
foo[0] = (T)5;
foo[1] = (T)6;
foo[2] = (T)7;
foo[3] = (T)8;
return true;
}
bool testMemberAccess() {
assert(foo[0] == 1);
assert(foo[1] == 2);
assert(foo[2] == 3);
assert(foo[3] == 4);
return true;
}
bool testMisc() {
assert(baz.
length() == 10.3923044f);
if(extended) {
assert(normFoo.
x - (T)0.5f < 1e-7);
assert(normFoo.
y - (T)0.5f < 1e-7);
assert(normFoo.
z - (T)0.5f < 1e-7);
assert(normFoo.
w - (T)0.5f < 1e-7);
assert(normBar.
x - (T)0.5f < 1e-7);
assert(normBar.
y - (T)-0.5f < 1e-7);
assert(normBar.
z - (T)0.5f < 1e-7);
assert(normBar.
w - (T)0.5f < 1e-7);
assert(normBaz.
x - (T)0.962250471f < 1e-7);
assert(normBaz.
y - (T)0.0f < 1e-7);
assert(normBaz.
z - (T)0.192450091f < 1e-7);
assert(normBaz.
w - (T)0.192450091f < 1e-7);
}
return true;
}
bool testOperators() {
fooCopy += bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
assert(fooCopy.
z == 2.0f);
assert(fooCopy.
w == 2.0f);
fooCopy = foo + bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
assert(fooCopy.
z == 2.0f);
assert(fooCopy.
w == 2.0f);
fooCopy = foo;
fooCopy -= bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
assert(fooCopy.
z == 0.0f);
assert(fooCopy.
w == 0.0f);
fooCopy = foo - bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
assert(fooCopy.
z == 0.0f);
assert(fooCopy.
w == 0.0f);
fooCopy = foo;
fooCopy *= 2.0f;
assert(fooCopy.
x == (T)2.0f);
assert(fooCopy.
y == (T)2.0f);
assert(fooCopy.
z == (T)2.0f);
assert(fooCopy.
w == (T)2.0f);
fooCopy = foo * 2.0f;
assert(fooCopy.
x == (T)2.0f);
assert(fooCopy.
y == (T)2.0f);
assert(fooCopy.
z == (T)2.0f);
assert(fooCopy.
w == (T)2.0f);
float fooVal = (foo * bar).sum();
assert(fooVal == (T)2.0f);
fooVal = (foo * baz).sum();
assert(fooVal == (T)11.0f);
fooCopy = foo;
fooCopy /= 2.0f;
assert(fooCopy.
x == (T)0.5f);
assert(fooCopy.
y == (T)0.5f);
assert(fooCopy.
z == (T)0.5f);
assert(fooCopy.
w == (T)0.5f);
fooCopy = foo / 2.0f;
assert(fooCopy.
x == (T)0.5f);
assert(fooCopy.
y == (T)0.5f);
assert(fooCopy.
z == (T)0.5f);
assert(fooCopy.
w == (T)0.5f);
return true;
}
bool testComparison() {
assert(a == b);
return true;
}
bool testCast() {
assert(a2 == b);
return true;
}
public:
virtual void run() {
testInitialization();
testAssignment();
testMemberAccess();
testMisc();
testOperators();
testCast();
testComparison();
}
};
int main() {
Vec4TestCase<int>().run();
auto testCase = Vec4TestCase<float>();
testCase.extended = true;
testCase.run();
auto testCase2 = Vec4TestCase<double>();
testCase2.extended = true;
testCase2.run();
return 0;
}
vec4< T > normalize() const
Definition: vec4.h:118
float length() const
Definition: vec4.h:112