69 lines
2.8 KiB
C++
69 lines
2.8 KiB
C++
/*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
|
*/
|
|
|
|
#include "frustum.hpp"
|
|
|
|
using util::geom::frustum;
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
template <typename T>
|
|
frustum<T>::frustum (const matrix4<T> &transform)
|
|
{
|
|
// left
|
|
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];
|
|
|
|
// Right clipping plane
|
|
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];
|
|
|
|
// Top clipping plane
|
|
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];
|
|
|
|
// Bottom clipping plane
|
|
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];
|
|
|
|
// Near clipping plane
|
|
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];
|
|
|
|
// Far clipping plane
|
|
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];
|
|
|
|
for (auto &p: planes)
|
|
p = normalised (p);
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
template struct util::geom::frustum<float>;
|