This is an example on how to use the vec3.h file.
#include "../Test.h"
template<class T>
class Vec3TestCase : public Test
{
bool testInitialization() {
T vals[3] = { 2, 4, 6 };
vec3<T> vec = build_vec3<T>((
void*)vals);
assert(anotherVec3.
x == (T)1);
assert(anotherVec3.
y == (T)1);
assert(anotherVec3.
z == (T)1);
assert(anotherVec3 == a4_3);
return true;
}
bool testAssignment() {
foo[0] = (T)4;
foo[1] = (T)5;
foo[2] = (T)6;
return true;
}
bool testMemberAccess() {
assert(foo[0] == 1);
assert(foo[1] == 2);
assert(foo[2] == 3);
return true;
}
bool testMisc() {
assert(foo.
length() == 3.46410155f);
assert(bar.
length() == 3.46410155f);
assert(baz.
length() == 10.1980391f);
if(extended) {
assert(normFoo.
x - (T)0.577350259f < 1e-7);
assert(normFoo.
y - (T)0.577350259f < 1e-7);
assert(normFoo.
z - (T)0.577350259f < 1e-7);
assert(normBar.
x - (T)0.577350259f < 1e-7);
assert(normBar.
y - (T)-0.577350259f < 1e-7);
assert(normBar.
z - (T)0.577350259f < 1e-7);
assert(normBaz.
x - (T)0.980580688f < 1e-7);
assert(normBaz.
y - (T)0.0f < 1e-7);
assert(normBaz.
z - (T)0.196116135 < 1e-7);
}
return true;
}
bool testOperators() {
fooCopy += bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
assert(fooCopy.
z == 2.0f);
fooCopy = foo + bar;
assert(fooCopy.
x == 2.0f);
assert(fooCopy.
y == 0.0f);
assert(fooCopy.
z == 2.0f);
fooCopy = foo;
fooCopy -= bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
assert(fooCopy.
z == 0.0f);
fooCopy = foo - bar;
assert(fooCopy.
x == 0.0f);
assert(fooCopy.
y == 2.0f);
assert(fooCopy.
z == 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);
fooCopy = foo * 2.0f;
assert(fooCopy.
x == (T)2.0f);
assert(fooCopy.
y == (T)2.0f);
assert(fooCopy.
z == (T)2.0f);
float fooVal = foo * bar;
assert(fooVal == (T)1.0f);
fooVal = foo * baz;
assert(fooVal == (T)10.0f);
fooCopy = foo;
fooCopy /= 2.0f;
assert(fooCopy.
x == (T)0.5f);
assert(fooCopy.
y == (T)0.5f);
assert(fooCopy.
z == (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);
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() {
Vec3TestCase<int>().run();
auto testCase = Vec3TestCase<float>();
testCase.extended = true;
testCase.run();
auto testCase2 = Vec3TestCase<double>();
testCase2.extended = true;
testCase2.run();
return 0;
}
vec3< T > normalize() const
Definition: vec3.h:141
float length() const
Definition: vec3.h:136
vec3< T > cross(const vec3< T > &rhs) const
Definition: vec3.h:124