Program that converts geometric and animation 3D scene data, from a COLLADA "*.dae" file to a binary file, with a custom format.
#ifndef MATH_VEC2_H_
#define MATH_VEC2_H_
#include "../def.hpp"
#include "./functions.h"
namespace math
{
struct VEC2
{
float x, y;
VEC2() {}
VEC2(float s) : x(s), y(s) {}
VEC2(float x, float y) : x(x), y(y) {}
inline float& operator [] (int index) const { ASSERT(index >= 0 && index <= 1); return ((float*)this)[index]; }
inline bool operator == (const VEC2 &v) const { return x == v.x && y == v.y; }
inline bool operator != (const VEC2 &v) const { return !(*this == v); }
inline bool operator == (float s) const { return x == s && y == s; }
inline bool operator != (float s) const { return !(*this == s); }
inline bool operator < (const VEC2 &v) const { return x < v.x && y < v.y; }
inline bool operator > (const VEC2 &v) const { return x > v.x && y > v.y; }
inline VEC2 operator - () const { return VEC2(-x, -y); }
VEC2& operator += (const VEC2 &v) { x += v.x; y += v.y; return *this; }
VEC2& operator -= (const VEC2 &v) { x -= v.x; y -= v.y; return *this; }
VEC2& operator *= (const VEC2 &v) { x *= v.x; y *= v.y; return *this; }
VEC2& operator /= (const VEC2 &v) { x /= v.x; y /= v.y; return *this; }
VEC2& operator += (float s) { x += s; y += s; return *this; }
VEC2& operator -= (float s) { x -= s; y -= s; return *this; }
VEC2& operator *= (float s) { x *= s; y *= s; return *this; }
VEC2& operator /= (float s) { x /= s; y /= s; return *this; }
VEC2 operator + (const VEC2 &v) const { return VEC2(x + v.x, y + v.y); }
VEC2 operator - (const VEC2 &v) const { return VEC2(x - v.x, y - v.y); }
VEC2 operator * (const VEC2 &v) const { return VEC2(x * v.x, y * v.y); }
VEC2 operator / (const VEC2 &v) const { return VEC2(x / v.x, y / v.y); }
VEC2 operator + (float s) const { return VEC2(x + s, y + s ); }
VEC2 operator - (float s) const { return VEC2(x - s, y - s ); }
VEC2 operator * (float s) const { return VEC2(x * s, y * s ); }
VEC2 operator / (float s) const { return VEC2(x / s, y / s ); }
float dot(const VEC2 &v) const { return x * v.x + y * v.y; }
float cross(const VEC2 &v) const { return x * v.y - y * v.x; }
float length2() const { return dot(*this); }
float length() const { return fSQRTF(length2()); }
VEC2 abs() const { return VEC2(fFABS(x), fFABS(y)); }
VEC2 normal() const { float s = length(); return s == 0.0 ? (*this) : (*this)*(1.0f/s); }
VEC2& rotate(const VEC2 &cs) { *this = VEC2(x*cs.x - y*cs.y, x*cs.y + y*cs.x); return *this; }
VEC2& rotate(float angle) { VEC2 cs; fFAST_SINCOS(angle, &cs.y, &cs.x); return rotate(cs); }
//float angle() const { return atan2f(y, x); }
};
}
#endif