SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLFrustum Class Reference

Matrix to 6 frustum plane conversion functions. More...

#include <SLFrustum.h>

Static Public Member Functions

static void viewToFrustumPlanes (SLPlane *planes, const SLMat4f &projectionMat, const SLMat4f &viewMat)
 
static void viewToFrustumPlanes (SLPlane *planes, const SLMat4f &A)
 
static void getPointsInViewSpace (SLVec3f *points, float fovV, float ratio, float clipNear, float clipFar)
 Returns frustum points in view space. More...
 

Detailed Description

Matrix to 6 frustum plane conversion functions.

Definition at line 15 of file SLFrustum.h.

Member Function Documentation

◆ getPointsInViewSpace()

void SLFrustum::getPointsInViewSpace ( SLVec3f points,
float  fovV,
float  ratio,
float  clipNear,
float  clipFar 
)
static

Returns frustum points in view space.

Definition at line 73 of file SLFrustum.cpp.

78 {
79  SLfloat tanFovV = tan(Utils::DEG2RAD * fovV * 0.5f);
80 
81  // Calculate the 4 points on the near plane
82  SLfloat t = tanFovV * clipNear; // top
83  SLfloat b = -t; // bottom
84  SLfloat r = ratio * t; // right
85  SLfloat l = -r; // left
86  points[0] = (SLVec3f(r, t, -clipNear));
87  points[1] = (SLVec3f(r, b, -clipNear));
88  points[2] = (SLVec3f(l, t, -clipNear));
89  points[3] = (SLVec3f(l, b, -clipNear));
90 
91  // Calculate the 4 points on the far plane
92  t = tanFovV * clipFar; // top
93  b = -t; // bottom
94  r = ratio * t; // right
95  l = -r; // left
96 
97  points[4] = (SLVec3f(r, t, -clipFar));
98  points[5] = (SLVec3f(r, b, -clipFar));
99  points[6] = (SLVec3f(l, t, -clipFar));
100  points[7] = (SLVec3f(l, b, -clipFar));
101 }
float SLfloat
Definition: SL.h:173
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
static const float DEG2RAD
Definition: Utils.h:239

◆ viewToFrustumPlanes() [1/2]

void SLFrustum::viewToFrustumPlanes ( SLPlane planes,
const SLMat4f A 
)
static

Calculates the coefficients of the 6 frustum planes from the passed matrix A. See the paper from Gribb and Hartmann: https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf

Parameters
planesPointer to an array of 6 SLPlanes (L R T B N F)
AThe projection matrix

Definition at line 42 of file SLFrustum.cpp.

43 {
44  // set the A,B,C & D coefficient for each plane
45  // Order is L R T B N F
46  planes[0].setCoefficients(A.m(0) + A.m(3),
47  A.m(4) + A.m(7),
48  A.m(8) + A.m(11),
49  A.m(12) + A.m(15));
50  planes[1].setCoefficients(-A.m(0) + A.m(3),
51  -A.m(4) + A.m(7),
52  -A.m(8) + A.m(11),
53  -A.m(12) + A.m(15));
54  planes[2].setCoefficients(-A.m(1) + A.m(3),
55  -A.m(5) + A.m(7),
56  -A.m(9) + A.m(11),
57  -A.m(13) + A.m(15));
58  planes[3].setCoefficients(A.m(1) + A.m(3),
59  A.m(5) + A.m(7),
60  A.m(9) + A.m(11),
61  A.m(13) + A.m(15));
62  planes[4].setCoefficients(A.m(2) + A.m(3),
63  A.m(6) + A.m(7),
64  A.m(10) + A.m(11),
65  A.m(14) + A.m(15));
66  planes[5].setCoefficients(-A.m(2) + A.m(3),
67  -A.m(6) + A.m(7),
68  -A.m(10) + A.m(11),
69  -A.m(14) + A.m(15));
70 }
void m(int i, T val)
Definition: SLMat4.h:93
void setCoefficients(const SLfloat A, const SLfloat B, const SLfloat C, const SLfloat D)
Definition: SLPlane.cpp:50

◆ viewToFrustumPlanes() [2/2]

void SLFrustum::viewToFrustumPlanes ( SLPlane planes,
const SLMat4f projectionMat,
const SLMat4f viewMat 
)
static

Calculates the coefficients of the 6 frustum planes from the passed projection and view matrices. See the paper from Gribb and Hartmann: https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf

Parameters
planesPointer to an array of 6 SLPlanes (L R T B N F)
projectionMat4x4 projection matrix
viewMat4x4 view matrix

Definition at line 24 of file SLFrustum.cpp.

27 {
28  // Combine view and projection matrix
29  SLMat4f A = projectionMat * viewMat;
30 
31  // Order is L R T B N F
32  viewToFrustumPlanes(planes, A);
33 }
static void viewToFrustumPlanes(SLPlane *planes, const SLMat4f &projectionMat, const SLMat4f &viewMat)
Definition: SLFrustum.cpp:24

The documentation for this class was generated from the following files: