Hi people. I'm creating this camera class which i want to combine usability of world system coordinates and local rotations. I've encountered very strange results and can't quite pinpoint the source of the problem.
class CCam
{
public:
// constructors, destructors
CCam() {}
CCam(float px, float py, float pz, float ax, float ay, float az, float ux, float uy, float uz)
{
pos.x = px;
pos.y = py;
pos.z = pz;
at.x = ax;
at.y = ay;
at.z = az;
up.x = ux;
up.y = uy;
up.z = uz;
at = at-pos;
at.Normalize();
at = pos+at;
up.Normalize();
up=pos+up;
side = (up - pos)^(at-pos);
side.Normalize();
side = side + pos;
up = (at - pos)^(side - pos);
up.Normalize();
up = up + pos;
}
~CCam() {}
void Pitch(float angle) // dunno if this is correct english name - it is supposed to be rotation of 'at' vector about 'up' vector ;)
{
at = at - pos;
up = up - pos;
at = at.Rotate(angle, up);
at.Normalize();
at = pos + at;
up = up + pos;
side = (up - pos)^(at-pos);
side.Normalize();
side = side + pos;
}
Oh yeah, my vector cross product, magnitude and normalize methods look like this (maybe the error's here?):
CVector operator^(const CVector &v) const { return CVector(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);}
float Magnitude() const { return sqrt(x*x + y*y + z*z);}
void Normalize() { if(Magnitude() != 0)*this /= Magnitude();}
Any help would be welcome :)
If only noobs were boobs... the world would be a better place.