Skip to content

Commit aa8ba29

Browse files
committed
Check camera field of view range.
1 parent 208cdbe commit aa8ba29

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

Sources/EngineTest/CameraTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TEST (IsValidCameraTest)
1515
ASSERT (!IsValidCamera (glm::dvec3 (0.0, 0.0, -1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 45.0, 0.1, 100.0));
1616
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), -45.0, 0.1, 100.0));
1717
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 0.0, 0.1, 100.0));
18+
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 180.0, 0.1, 100.0));
1819
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 45.0, -0.1, 100.0));
1920
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 45.0, 0.1, -100.0));
2021
ASSERT (!IsValidCamera (glm::dvec3 (3.0, 2.0, 1.0), glm::dvec3 (0.0, 0.0, 0.0), glm::dvec3 (0.0, 0.0, 1.0), 45.0, 100.0, 10.0));

Sources/Geometry/Geometry.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ bool IsGreater (float a, float b)
2626
return a - b > FEPS;
2727
}
2828

29+
bool IsLowerOrEqual (float a, float b)
30+
{
31+
return IsLower (a, b) || IsEqual (a, b);
32+
}
33+
34+
bool IsGreaterOrEqual (float a, float b)
35+
{
36+
return IsGreater (a, b) || IsEqual (a, b);
37+
}
38+
2939
bool IsEqual (double a, double b)
3040
{
3141
return fabs (a - b) < EPS;
@@ -41,6 +51,16 @@ bool IsGreater (double a, double b)
4151
return a - b > EPS;
4252
}
4353

54+
bool IsLowerOrEqual (double a, double b)
55+
{
56+
return IsLower (a, b) || IsEqual (a, b);
57+
}
58+
59+
bool IsGreaterOrEqual (double a, double b)
60+
{
61+
return IsGreater (a, b) || IsEqual (a, b);
62+
}
63+
4464
bool IsPositive (double a)
4565
{
4666
return a > EPS;

Sources/Geometry/Geometry.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ extern const double EPS;
1313
bool IsEqual (float a, float b);
1414
bool IsLower (float a, float b);
1515
bool IsGreater (float a, float b);
16+
bool IsLowerOrEqual (float a, float b);
17+
bool IsGreaterOrEqual (float a, float b);
1618

1719
bool IsEqual (double a, double b);
1820
bool IsLower (double a, double b);
1921
bool IsGreater (double a, double b);
22+
bool IsLowerOrEqual (double a, double b);
23+
bool IsGreaterOrEqual (double a, double b);
2024

2125
bool IsPositive (double a);
2226
bool IsNegative (double a);

Sources/Modeler/Camera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool IsValidCamera (const glm::dvec3& eye,
163163
return false;
164164
}
165165

166-
if (!Geometry::IsPositive (fieldOfViewY)) {
166+
if (Geometry::IsLowerOrEqual (fieldOfViewY, 0.0) || Geometry::IsGreaterOrEqual (fieldOfViewY, 180.0)) {
167167
return false;
168168
}
169169

0 commit comments

Comments
 (0)