#ifndef _STRUCTS_H_ #define _STRUCTS_H_ #include #include #include #include typedef struct Vector { float i; float j; float k; inline float magnitude() { return sqrt(pow(i,2)+pow(j,2)+pow(k,2)); } inline static void normalize(Vector* dest, Vector src) { float m = src.magnitude(); dest->i = src.i / m; dest->j = src.j / m; dest->k = src.k / m; } } Vector; typedef struct Point { float x; float y; float z; std::vector incidentTriangles; Point() { x = y = z = 0; } inline void printMe() { std::cout << "x: " << x << " y: " << y << " z: " << z; } inline Point operator- (Point a) { Point temp; temp.x = x - a.x; temp.y = y - a.y; temp.z = z - a.z; return temp; } inline float magnitude() { return sqrt(pow(x,2)+pow(y,2)+pow(z,2)); } inline static void normalize(Point* dest, Point src) { float m = src.magnitude(); dest->x = src.x / m; dest->y = src.y / m; dest->z = src.z / m; } inline Point operator+ (Point p) { Point t; t.x = x + p.x; t.y = y + p.y; t.z = z + p.z; return t; } inline void operator+= (Point p) { x += p.x; y += p.y; z += p.z; } inline void operator+= (int i) { x += i; y += i; z += i; } inline Point operator* (Point p) { Point t; t.x = x * p.x; t.y = y * p.y; t.z = z * p.z; return t; } inline Point operator* (float f) { Point t; t.x = x * f; t.y = y * f; t.z = z * f; return t; } inline Point operator/ (float f) { Point t; t.x = x / f; t.y = y / f; t.z = z / f; return t; } } Point; typedef struct Triangle { Vector normal; int a1; int a2; int a3; inline bool contains(int a) { return (a == a1 || a == a2 || a == a3); } inline int indexOf(int n1, int n2) { if ((a1 == n1 || a1 == n2) && (a2 == n1 || a2 == n2)) { return 3; } else if ((a2 == n1 || a2 == n2) && (a3 == n1 || a3 == n2)) { return 1; } else if ((a3 == n1 || a3 == n2) && (a1 == n1 || a1 == n2)) { return 2; } else { return -1; } } inline bool operator== (Triangle t) { return (a1 == t.a1) && (a2 == t.a2) && (a3 == t.a3); } } Triangle; typedef struct Adjacency { int a1; int a2; int a3; inline bool contains(int i) { if (a1 == i || a2 == i || a3 == i) { return true; } } inline void push(int i, int in1, int in2) { if (a1 != in1 && a1 != in2) { a1 = i; } else if (a2 != in1 && a2 != in2) { a2 = i; } else if (a3 != in1 && a3 != in2) { a3 = i; } #ifdef _DEBUG else { assert(NULL != NULL); } #endif } } Adjacency; #endif