Finish ClampToCube().

This commit is contained in:
scorpioblood 2024-05-22 22:12:50 +02:00
parent 93cdd83005
commit b6195a2b63

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
// TODO: BoundToCube
// TODO: ClampToCube
// TODO: Slerp (using Quaternions) // TODO: Slerp (using Quaternions)
@ -867,17 +864,6 @@ namespace Phanes::Core::Math {
return v1; return v1;
} }
/**
* Binds vector into cube.
*
* @param(v1) Vector to clamp
* @param(cubeRadius) Radius of the cube
*
* @note result is stored in v1.
*/
template<RealType T>
TVector3<T> BoundToCubeV(TVector3<T> v1, T cubeRadius) {};
/** /**
* Clamps vector into cube. * Clamps vector into cube.
@ -889,7 +875,14 @@ namespace Phanes::Core::Math {
*/ */
template<RealType T> template<RealType T>
TVector3<T> ClampToCubeV(TVector3<T> v1, T cubeRadius) {}; TVector3<T> ClampToCubeV(TVector3<T> v1, T cubeRadius)
{
v1.x = Clamp(v1.x, -cubeRadius, cubeRadius);
v1.y = Clamp(v1.y, -cubeRadius, cubeRadius);
v1.z = Clamp(v1.z, -cubeRadius, cubeRadius);
return v1;
};
/** /**
* Reflect by plane * Reflect by plane
@ -1301,18 +1294,6 @@ namespace Phanes::Core::Math {
return unitVec * magnitude; return unitVec * magnitude;
} }
/**
* Binds vector into cube.
*
* @param(v1) Vector to clamp
* @param(cubeRadius) Radius of the cube
*
* @result Vector clamped in cube.
*/
template<RealType T>
TVector3<T> BoundToCube(const TVector3<T>& v1, T cubeRadius) {};
/** /**
* Clamps vector into cube. * Clamps vector into cube.
* *
@ -1323,7 +1304,14 @@ namespace Phanes::Core::Math {
*/ */
template<RealType T> template<RealType T>
TVector3<T> ClampToCube(const TVector3<T>& v1, T cubeRadius) {}; TVector3<T> ClampToCube(const TVector3<T>& v1, T cubeRadius)
{
return TVector3<T>(
Clamp(v1.x, -cubeRadius, cubeRadius),
Clamp(v1.y, -cubeRadius, cubeRadius),
Clamp(v1.z, -cubeRadius, cubeRadius),
);
};
/** /**
* Scales vector two specific magnitude. * Scales vector two specific magnitude.