Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Added a helper void Frustum::SetWorldMatrix to easily specify the pos…

…, front and up vectors of a camera.
  • Loading branch information...
commit 1f48aceb681ebe480a788f85054824e5befa0190 1 parent e2a4501
@juj authored
Showing with 18 additions and 0 deletions.
  1. +12 −0 src/Geometry/Frustum.cpp
  2. +6 −0 src/Geometry/Frustum.h
12 src/Geometry/Frustum.cpp
@@ -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
6 src/Geometry/Frustum.h
@@ -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

0 comments on commit 1f48ace

Please sign in to comment.
Something went wrong with that request. Please try again.