This is a little weird, but I think the vector object is setup to let you bypass handles, by overloading opAssign and opCmp.
You can probably remove the @ from the function, but if you keep it, this line:
vector ret=normalize(test);
Probably needs the @:
vector@ ret=normalize(test);
But I think, for vectors, you can ignore handles entirely.
I was confused, originally, but all of these functions appear to work:
vector rotate(vector p, vector o, double theta) {
vector r;
r.x = (cosine(theta) * (p.x-o.x)) - (sine(theta) * (p.y-o.y)) + o.x;
r.y = (sine(theta) * (p.x-o.x)) + (cosine(theta) * (p.y-o.y)) + o.y;
return r;
}// Rotate.
vector get_vector(double x, double y, double z=0) {vector ret(x, y, z); return ret;}
vector cross(vector a, vector b) {
vector c;
c.x = (a.y*b.z) - (a.z*b.y);
c.y = (a.z*b.x) - (a.x*b.z);
c.z = (a.x*b.y) - (a.y*b.x);
return c;
}
double dot(vector a, vector b) {
return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
}
It does present problems, if, for example, you need a vector to be null. I got around the uncertainty by assigning a vector I would never use to represent null, but this only works if you are sure you'll never need that specific vector.
看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
George... Don't do that.