#include <math.h>
#include <assert.h>
#include <maya/MIOStream.h>
#define COMPILE_OUTSIDE_MAYA
#include <AwPoint.h>
#include <AwMatrix.h>
const AwPoint AwPoint::origin;
AwVector AwPoint::cartesianSub(const AwPoint &otherPt) const
{
AwPoint ptA = cartesian();
AwPoint ptB = otherPt.cartesian();
return AwVector(ptA.x - ptB.x, ptA.y - ptB.y, ptA.z - ptB.z);
}
AwPoint AwPoint::cartesianAdd(const AwVector &v) const
{
AwPoint pt = cartesian();
return AwPoint(pt.x + v.x, pt.y + v.y, pt.z + v.z);
}
AwPoint AwPoint::cartesianSub(const AwVector &v) const
{
AwPoint pt = cartesian();
return AwPoint(pt.x - v.x, pt.y - v.y, pt.z - v.z);
}
AwPoint& AwPoint::cartesianize()
{
if (w != 1.0) {
assert(w != 0.0);
double wInv = 1.0/w;
x *= wInv; y *= wInv; z *= wInv; w = 1.0;
}
return *this;
}
inline AwPoint AwPoint::operator*(const AwMatrix &right) const
{
AwPoint tmp;
const double *a = (const double *) (right.matrix);
tmp.x = x * a[0] + y * a[4] + z * a[8] + w * a[12];
tmp.y = x * a[1] + y * a[5] + z * a[9] + w * a[13];
tmp.z = x * a[2] + y * a[6] + z * a[10] + w * a[14];
tmp.w = x * a[3] + y * a[7] + z * a[11] + w * a[15];
return tmp;
}
ostream &operator<<(ostream &os, const AwPoint &p)
{
os << "[" << p.x << ", " << p.y << ", " << p.z << ", " << p.w << "]";
return os;
}