-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simple class that represents 3D rotations in space and allows to apply rotations on an 3d matrix.
- Loading branch information
Showing
7 changed files
with
99 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "Rotation3D.h" | ||
#include "pch.h" | ||
|
||
glm::mat4 Rotation3D::rotate(glm::mat4 model, std::initializer_list<EulerAngle> ordering) const | ||
{ | ||
for (const auto axisRotation: ordering) | ||
{ | ||
switch (axisRotation) | ||
{ | ||
case EulerAngle::YAW: | ||
model = glm::rotate(model, glm::radians(yaw), glm::vec3(0.0f, 1.0f, 0.0f)); | ||
break; | ||
case EulerAngle::PITCH: | ||
model = glm::rotate(model, glm::radians(pitch), glm::vec3(1.0f, 0.0f, 0.0f)); | ||
break; | ||
case EulerAngle::ROLL: | ||
model = glm::rotate(model, glm::radians(roll), glm::vec3(0.0f, 0.0f, 1.0f)); | ||
break; | ||
} | ||
} | ||
return model; | ||
} | ||
|
||
void Rotation3D::imGuiRotationSlider() | ||
{ | ||
ImGui::SliderFloat("Roll", &roll, -360, 360.0f); | ||
ImGui::SliderFloat("Pitch", &pitch, -360, 360.0f); | ||
ImGui::SliderFloat("Yaw", &yaw, -360, 360.0f); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
/** | ||
* \brief Represents a 3D rotation using Euler angles. | ||
*/ | ||
struct Rotation3D | ||
{ | ||
/** | ||
* \brief Angles of Euler rotation. | ||
*/ | ||
enum class EulerAngle | ||
{ | ||
ROLL, | ||
PITCH, | ||
YAW | ||
}; | ||
|
||
float yaw{0}; | ||
float pitch{0}; | ||
float roll{0}; | ||
|
||
/** | ||
* \brief Applies rotation to a 3D model matrix in a specified order. | ||
* \param model The model matrix to be rotated. | ||
* \param ordering The order in which yaw, pitch, and roll are applied. | ||
* \return The rotated model matrix. | ||
*/ | ||
[[nodiscard]] glm::mat4 rotate(glm::mat4 model, | ||
std::initializer_list<EulerAngle> ordering = { | ||
EulerAngle::YAW, EulerAngle::PITCH, EulerAngle::ROLL}) const; | ||
|
||
/** | ||
* \brief Renders an ImGui slider interface for adjusting the rotation. | ||
*/ | ||
void imGuiRotationSlider(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters