Skip to content

Commit

Permalink
Added a helper void Frustum::SetWorldMatrix to easily specify the pos…
Browse files Browse the repository at this point in the history
…, front and up vectors of a camera.
  • Loading branch information
juj committed May 28, 2012
1 parent e2a4501 commit 1f48ace
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Geometry/Frustum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ Plane Frustum::BottomPlane() const
return Plane(pos, bottomSideNormal);
}

void Frustum::SetWorldMatrix(const float3x4 &worldTransform)
{
pos = worldTransform.TranslatePart();
front = -worldTransform.Col(2); // The camera looks towards -Z axis of the given transform.
up = worldTransform.Col(1); // The camera up points towards +Y of the given transform.
assume(pos.IsFinite());
assume(front.IsNormalized());
assume(up.IsNormalized());
assume(worldTransform.IsColOrthogonal3()); // Front and up must be orthogonal to each other.
assume(EqualAbs(worldTransform.Determinant(), 1.f)); // The matrix cannot contain mirroring.
}

float3x4 Frustum::WorldMatrix() const
{
assume(up.IsNormalized());
Expand Down
6 changes: 6 additions & 0 deletions src/Geometry/Frustum.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class Frustum
@see CornerPoint(). */
float3 ExtremePoint(const float3 &direction) const;

/// Sets the pos, front and up members of this frustum from the given world transform.
/** This function sets the 'front' parameter of this Frustum to look towards the -Z axis of the given matrix,
and the 'up' parameter of this Frustum to point towards the +Y axis of the given matrix.
@param worldTransform An orthonormalized matrix with determinant of +1 (no mirroring). */
void SetWorldMatrix(const float3x4 &worldTransform);

/// Computes the matrix that transforms from the view space to the world (global) space of this Frustum.
/** @note The returned matrix is the inverse of the matrix returned by ViewMatrix().
@return An orthonormal affine matrix that performs the view->world transformation. The returned
Expand Down

0 comments on commit 1f48ace

Please sign in to comment.