2018-03-13 22:37:40 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-03-13 22:37:40 +11:00
|
|
|
*
|
|
|
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "frustum.hpp"
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using cruft::geom::frustum;
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T>
|
|
|
|
frustum<T>::frustum (const matrix4<T> &transform)
|
|
|
|
{
|
|
|
|
// left
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[X_NEG].coefficients[0] = transform[3][0] + transform[0][0];
|
|
|
|
planes[X_NEG].coefficients[1] = transform[3][1] + transform[0][1];
|
|
|
|
planes[X_NEG].coefficients[2] = transform[3][2] + transform[0][2];
|
|
|
|
planes[X_NEG].coefficients[3] = transform[3][3] + transform[0][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
// Right clipping plane
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[X_POS].coefficients[0] = transform[3][0] - transform[0][0];
|
|
|
|
planes[X_POS].coefficients[1] = transform[3][1] - transform[0][1];
|
|
|
|
planes[X_POS].coefficients[2] = transform[3][2] - transform[0][2];
|
|
|
|
planes[X_POS].coefficients[3] = transform[3][3] - transform[0][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
// Top clipping plane
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[Y_POS].coefficients[0] = transform[3][0] - transform[1][0];
|
|
|
|
planes[Y_POS].coefficients[1] = transform[3][1] - transform[1][1];
|
|
|
|
planes[Y_POS].coefficients[2] = transform[3][2] - transform[1][2];
|
|
|
|
planes[Y_POS].coefficients[3] = transform[3][3] - transform[1][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
// Bottom clipping plane
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[Y_NEG].coefficients[0] = transform[3][0] + transform[1][0];
|
|
|
|
planes[Y_NEG].coefficients[1] = transform[3][1] + transform[1][1];
|
|
|
|
planes[Y_NEG].coefficients[2] = transform[3][2] + transform[1][2];
|
|
|
|
planes[Y_NEG].coefficients[3] = transform[3][3] + transform[1][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
// Near clipping plane
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[Z_POS].coefficients[0] = transform[3][0] + transform[2][0];
|
|
|
|
planes[Z_POS].coefficients[1] = transform[3][1] + transform[2][1];
|
|
|
|
planes[Z_POS].coefficients[2] = transform[3][2] + transform[2][2];
|
|
|
|
planes[Z_POS].coefficients[3] = transform[3][3] + transform[2][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
// Far clipping plane
|
2018-05-07 11:09:53 +10:00
|
|
|
planes[Z_NEG].coefficients[0] = transform[3][0] - transform[2][0];
|
|
|
|
planes[Z_NEG].coefficients[1] = transform[3][1] - transform[2][1];
|
|
|
|
planes[Z_NEG].coefficients[2] = transform[3][2] - transform[2][2];
|
|
|
|
planes[Z_NEG].coefficients[3] = transform[3][3] - transform[2][3];
|
2018-03-13 22:37:40 +11:00
|
|
|
|
|
|
|
for (auto &p: planes)
|
|
|
|
p = normalised (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-08-05 14:42:02 +10:00
|
|
|
template struct cruft::geom::frustum<float>;
|