diff --git a/source/maths/MathUtil.h b/source/maths/MathUtil.h index 015f04dc72..d8d981c6c7 100644 --- a/source/maths/MathUtil.h +++ b/source/maths/MathUtil.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -45,13 +45,14 @@ inline T SmoothStep(T edge0, T edge1, T value) return value * value * (3 - 2 * value); } -inline float sgn(float a) +template +inline T Sign(const T value) { - if (a > 0.0f) - return 1.0f; - if (a < 0.0f) - return -1.0f; - return 0.0f; + if (value > T(0)) + return T(1); + if (value < T(0)) + return T(-1); + return T(0); } #endif // INCLUDED_MATHUTIL diff --git a/source/renderer/SceneRenderer.cpp b/source/renderer/SceneRenderer.cpp index e35e3805b1..82a2634e46 100644 --- a/source/renderer/SceneRenderer.cpp +++ b/source/renderer/SceneRenderer.cpp @@ -501,10 +501,10 @@ void CSceneRenderer::SetObliqueFrustumClipping(CCamera& camera, const CVector4D& // by the inverse of the projection matrix CVector4D q; - q.X = (sgn(camPlane.X) - matrix[8]/matrix[11]) / matrix[0]; - q.Y = (sgn(camPlane.Y) - matrix[9]/matrix[11]) / matrix[5]; - q.Z = 1.0f/matrix[11]; - q.W = (1.0f - matrix[10]/matrix[11]) / matrix[14]; + q.X = (Sign(camPlane.X) - matrix[8] / matrix[11]) / matrix[0]; + q.Y = (Sign(camPlane.Y) - matrix[9] / matrix[11]) / matrix[5]; + q.Z = 1.0f / matrix[11]; + q.W = (1.0f - matrix[10] / matrix[11]) / matrix[14]; // Calculate the scaled plane vector CVector4D c = camPlane * (2.0f * matrix[11] / camPlane.Dot(q));