Skip to content

Commit 5f8784e

Browse files
committed
Minor optimization, use sqrt instead of sqrtf
1 parent 02182e8 commit 5f8784e

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

source/Camera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace dae
5555

5656
float Camera::CalculateFOV(float angle) const
5757
{
58-
const float halfAlpha{(angle / 2.0f) * TO_RADIANS};
58+
const float halfAlpha{(angle * 0.5f) * TO_RADIANS};
5959
return std::tanf(halfAlpha);
6060
}
6161

source/Utils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace dae
2121
const float d2{Vector3::Dot(L, L) - tca * tca}; // distance from sphere center to ray
2222
const float radius2{sphere.radius * sphere.radius};
2323
if (d2 > radius2) return false;
24-
const float thc{std::sqrtf(radius2 - d2)}; // distance from ray to sphere surface
24+
const float thc{std::sqrt(radius2 - d2)}; // distance from ray to sphere surface
2525
float t0{tca - thc}; // distance from ray's origin to sphere surface
2626
//float t1{tca + thc}; // distance from ray's origin to sphere surface
2727
if (t0 < ray.min or t0 > ray.max) return false;
@@ -44,8 +44,7 @@ namespace dae
4444
#pragma endregion
4545
#pragma region Plane HitTest
4646
//PLANE HIT-TESTS
47-
inline bool HitTest_Plane(const Plane& plane, const Ray& ray, HitRecord& hitRecord,
48-
bool ignoreHitRecord = false)
47+
inline bool HitTest_Plane(const Plane& plane, const Ray& ray, HitRecord& hitRecord, bool ignoreHitRecord = false)
4948
{
5049
const float denom{Vector3::Dot(plane.normal, ray.direction)};
5150
if (denom >= 0.0f) return false;

0 commit comments

Comments
 (0)