|
@@ -1,13 +1,13 @@
|
|
|
#include "math/Frustum.h"
|
|
|
|
|
|
-Frustum::Frustum(float fieldOfView, float nearClip, float farClip, const Size& size) : size(size),
|
|
|
-fieldOfView(fieldOfView), nearClip(nearClip), farClip(farClip) {
|
|
|
+Frustum::Frustum(float fieldOfView, float nearClip, float farClip, const Size& size)
|
|
|
+ : size(size), fieldOfView(fieldOfView), nearClip(nearClip), farClip(farClip) {
|
|
|
}
|
|
|
|
|
|
Matrix& Frustum::updateProjection() {
|
|
|
float tan = tanf(fieldOfView * (0.5f * M_PI / 180.0f));
|
|
|
float q = 1.0f / tan;
|
|
|
- float aspect = static_cast<float> (size.width) / size.height;
|
|
|
+ float aspect = static_cast<float>(size.width) / size.height;
|
|
|
float diff = 1.0f / (nearClip - farClip);
|
|
|
|
|
|
projection.set(0, Vector4(q / aspect, 0.0f, 0.0f, 0.0f));
|
|
@@ -19,7 +19,7 @@ Matrix& Frustum::updateProjection() {
|
|
|
|
|
|
void Frustum::updatePlanes(const Vector3& pos, const Vector3& right, const Vector3& up, const Vector3& front) {
|
|
|
float tan = tanf(fieldOfView * (0.5f * M_PI / 180.0f));
|
|
|
- float aspect = static_cast<float> (size.width) / size.height;
|
|
|
+ float aspect = static_cast<float>(size.width) / size.height;
|
|
|
|
|
|
float halfNearHeight = tan * nearClip;
|
|
|
float halfNearWidth = halfNearHeight * aspect;
|
|
@@ -37,12 +37,12 @@ void Frustum::updatePlanes(const Vector3& pos, const Vector3& right, const Vecto
|
|
|
Vector3 nearBottomLeft = nearCenter - (up * halfNearHeight) - (right * halfNearWidth);
|
|
|
Vector3 nearBottomRight = nearCenter - (up * halfNearHeight) + (right * halfNearWidth);
|
|
|
|
|
|
- planes[0] = Plane(nearBottomRight, nearTopLeft, nearBottomLeft);
|
|
|
- planes[1] = Plane(farTopRight, farBottomRight, farTopLeft);
|
|
|
+ planes[0] = Plane(nearBottomRight, nearTopLeft, nearBottomLeft);
|
|
|
+ planes[1] = Plane(farTopRight, farBottomRight, farTopLeft);
|
|
|
planes[2] = Plane(nearBottomRight, nearBottomLeft, farBottomRight);
|
|
|
- planes[3] = Plane(farTopLeft, nearTopLeft, farTopRight);
|
|
|
- planes[4] = Plane(nearBottomLeft, nearTopLeft, farTopLeft);
|
|
|
- planes[5] = Plane(farBottomRight, farTopRight, nearBottomRight);
|
|
|
+ planes[3] = Plane(farTopLeft, nearTopLeft, farTopRight);
|
|
|
+ planes[4] = Plane(nearBottomLeft, nearTopLeft, farTopLeft);
|
|
|
+ planes[5] = Plane(farBottomRight, farTopRight, nearBottomRight);
|
|
|
}
|
|
|
|
|
|
bool Frustum::isInside(const Vector3& pos) const {
|