Add Camera::IsLeftHanded()
A method that returns true if the camera's coordinate system is left-handed.
This commit is contained in:
parent
a7020545c1
commit
c2a4372467
2 changed files with 28 additions and 3 deletions
|
@ -91,6 +91,25 @@ Camera::SetUp(const Vector3& up)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Camera::IsLeftHanded()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The cross product of the up and direction vectors is a vector
|
||||||
|
* perpendicular to the plane containing those vectors. By definition the
|
||||||
|
* right vector is (in almost all cases) perpendicular to that plane.
|
||||||
|
*
|
||||||
|
* The dot product indicates the angle between this vector and the right
|
||||||
|
* vector. If it's greater than 0, then the vector is pointing right of the
|
||||||
|
* up-direction plane and the coordinate system is right handed. If less
|
||||||
|
* than 0, the vector is pointing left of the up-direction plane and the
|
||||||
|
* coordinate system is left-handed.
|
||||||
|
*/
|
||||||
|
return mUp.cross(mDirection).dot(mRight) < 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Camera::LookAt(const Vector3& pt)
|
Camera::LookAt(const Vector3& pt)
|
||||||
{
|
{
|
||||||
|
@ -101,8 +120,7 @@ Camera::LookAt(const Vector3& pt)
|
||||||
const Double directionLength = mDirection.length();
|
const Double directionLength = mDirection.length();
|
||||||
const Double rightLength = mRight.length();
|
const Double rightLength = mRight.length();
|
||||||
const Double upLength = mUp.length();
|
const Double upLength = mUp.length();
|
||||||
/* TODO: What does this actually do? */
|
const bool isLeftHanded = IsLeftHanded();
|
||||||
const Double handedness = mUp.cross(mDirection).dot(mRight);
|
|
||||||
|
|
||||||
mDirection = (pt - mOrigin).normalize();
|
mDirection = (pt - mOrigin).normalize();
|
||||||
/* TODO: Check for zero length direction vector. */
|
/* TODO: Check for zero length direction vector. */
|
||||||
|
@ -116,7 +134,7 @@ Camera::LookAt(const Vector3& pt)
|
||||||
mUp = mDirection.cross(mRight);
|
mUp = mDirection.cross(mRight);
|
||||||
|
|
||||||
mDirection *= directionLength;
|
mDirection *= directionLength;
|
||||||
mRight *= (handedness > 0.0) ? rightLength : -rightLength;
|
mRight *= isLeftHanded ? rightLength : -rightLength;
|
||||||
mUp *= upLength;
|
mUp *= upLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,13 @@ struct Camera
|
||||||
const Vector3& GetUp() const;
|
const Vector3& GetUp() const;
|
||||||
void SetUp(const Vector3& up);
|
void SetUp(const Vector3& up);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the camera's handedness. Left handed is the default.
|
||||||
|
*
|
||||||
|
* @returns `true` if the camera is set up for left-handed coordinates.
|
||||||
|
*/
|
||||||
|
bool IsLeftHanded() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pan and tilt the camera towards the given point.
|
* Pan and tilt the camera towards the given point.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue