Skip to content

Commit 286b106

Browse files
author
Adrien GIVRY
authored
Merge pull request #130 from kmqwerty/feature/adding_Rotation_and_Rotate
adding OvMaths::FMatrix4::Rotation and OvMaths::FMatrix4::Rotate
2 parents f3b8c75 + 8ecd3e2 commit 286b106

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

Sources/Overload/OvMaths/include/OvMaths/FMatrix4.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
#include "OvMaths/FVector3.h"
1717
#include "OvMaths/FVector4.h"
1818

19+
1920
namespace OvMaths
2021
{
22+
23+
/**
24+
* Forward declaration due to circular reference
25+
*/
26+
struct FQuaternion;
27+
2128
/**
2229
* Mathematic representation of a 4x4 Matrix of floats
2330
*/
@@ -341,6 +348,19 @@ namespace OvMaths
341348
*/
342349
static FMatrix4 Scale(const FMatrix4& p_matrix, const FVector3& p_scale);
343350

351+
/**
352+
* Return rotation matrix from quaternion
353+
* @param p_quaternion
354+
*/
355+
static FMatrix4 Rotation(const FQuaternion& p_quaternion);
356+
357+
/**
358+
* Return rotate matrix in 3D on quaternion
359+
* @param p_matrix
360+
* @param p_quaternion
361+
*/
362+
static FMatrix4 Rotate(const FMatrix4& p_matrix, const FQuaternion& p_quaternion);
363+
344364
/**
345365
* Return perspective matrix
346366
* @param p_fov

Sources/Overload/OvMaths/include/OvMaths/FQuaternion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace OvMaths
1717
{
18+
1819
/**
1920
* Mathematic representation of a Quaternion with float precision
2021
*/

Sources/Overload/OvMaths/src/OvMaths/FMatrix4.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "OvMaths/FMatrix4.h"
1313
#include "OvMaths/FVector3.h"
14+
#include "OvMaths/FQuaternion.h"
1415

1516
const OvMaths::FMatrix4 OvMaths::FMatrix4::Identity = FMatrix4(1.f, 0.f, 0.f, 0.f,
1617
0.f, 1.f, 0.f, 0.f,
@@ -442,6 +443,16 @@ OvMaths::FMatrix4 OvMaths::FMatrix4::Scale(const FMatrix4& p_matrix, const FVect
442443
return p_matrix * Scaling(p_scale);
443444
}
444445

446+
OvMaths::FMatrix4 OvMaths::FMatrix4::Rotation(const FQuaternion& p_quaternion)
447+
{
448+
return OvMaths::FQuaternion::ToMatrix4(p_quaternion);
449+
}
450+
451+
OvMaths::FMatrix4 OvMaths::FMatrix4::Rotate(const FMatrix4& p_matrix, const FQuaternion& p_quaternion)
452+
{
453+
return p_matrix * Rotation(p_quaternion);
454+
}
455+
445456
OvMaths::FMatrix4 OvMaths::FMatrix4::CreatePerspective(const float p_fov, const float p_aspectRatio, const float p_zNear, const float p_zFar)
446457
{
447458
const float tangent = tanf(p_fov / 2.0f * PI / 180.0f);

0 commit comments

Comments
 (0)