Original Post
I've been using the GameTutorials.com code as a base for my Camera class, but I can't seem to get the code working correctly.
I think I have narrowed it down to two sources, either the camera rotation code, or the cross product of the vector (formula gained from a website). Could you be so kind to check over the two?
Here's the cross product:
And here is the rotation code:
If these two function's aren't the problem, then can anyone recommend a good place to start looking for the problem? Sometimes the scene flashes on the screen, but the dissapears again when the buffers are swapped and camera position updated.
Thank you in advance.
[edited by - MDI on March 20, 2003 4:40:44 AM]
Vector3 Vector3 :: crossProduct (const Vector3& rhs) {
double tX = (vecY * rhs.vecZ) - (vecZ * rhs.vecY);
double tY = (vecZ * rhs.vecX) - (vecX * rhs.vecZ);
double tZ = (vecX * rhs.vecY) - (vecY * rhs.vecX);
return Vector3 (tX, tY, tZ);
}
void W32Camera :: rotateCamera (float angle, const Vector3& rotator) {
Vector3 nView;
Vector3 View = target - position;
double x = rotator.getX ();
double y = rotator.getY ();
double z = rotator.getZ ();
float cAng = static_cast <float> (cos (angle));
float sAng = static_cast <float> (sin (angle));
nView.setX ((cAng + (1 - cAng) * x * x) * View.getX ());
nView.setX (nView.getX () + ((1 - cAng) * x * y - z * sAng) * View.getY ());
nView.setX (nView.getX () + ((1 - cAng) * x * z + y * sAng) * View.getZ ());
nView.setY (((1 - cAng) * x * y + z * sAng) * View.getX ());
nView.setY (nView.getY () + (cAng + (1 - cAng) * y * y) * View.getY ());
nView.setY (nView.getY () + ((1 - cAng) * y * z - x * sAng) * View.getZ ());
nView.setZ (((1 - cAng) * x * z - y * sAng) * View.getX ());
nView.setZ ((nView.getZ () + (1 - cAng) * y * z + x * sAng) * View.getY ());
nView.setZ ((nView.getZ () + cAng + (1 - cAng) * z * z) * View.getZ ());
target = position + nView;
}