-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#179]: Move Gizmo logic to separate struct
- Loading branch information
1 parent
38da5f8
commit dfa1079
Showing
13 changed files
with
211 additions
and
86 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,97 @@ | ||
#include "gizmo.hpp" | ||
|
||
namespace looper { | ||
|
||
void | ||
Gizmo::Initialize() | ||
{ | ||
gizmoCenter_.SetSpriteTextured(glm::vec3{}, {16, 16}, "rounded_square.png"); | ||
gizmoCenter_.SetColor({0.3f, 0.3f, 0.3f, 1.0f}); | ||
|
||
gizmoUp_.SetSpriteTextured(glm::vec3{}, {96, 32}, "arrow.png"); | ||
gizmoUp_.Rotate(90.0f, renderer::Sprite::RotationType::DEGREES); | ||
gizmoUp_.SetColor({0.0f, 1.0f, 0.0f, 1.0f}); | ||
|
||
gizmoSide_.SetSpriteTextured(glm::vec3{}, {96, 32}, "arrow.png"); | ||
gizmoSide_.SetColor({1.0f, 0.0f, 0.0f, 1.0f}); | ||
} | ||
|
||
void | ||
Gizmo::Show() | ||
{ | ||
gizmoCenter_.Show(); | ||
gizmoSide_.Show(); | ||
gizmoUp_.Show(); | ||
} | ||
void | ||
Gizmo::Hide() | ||
{ | ||
gizmoCenter_.Hide(); | ||
gizmoSide_.Hide(); | ||
gizmoUp_.Hide(); | ||
} | ||
void | ||
Gizmo::Render() | ||
{ | ||
gizmoCenter_.Render(); | ||
gizmoSide_.Render(); | ||
gizmoUp_.Render(); | ||
} | ||
void | ||
Gizmo::NewObjectSelected(const glm::vec2& centeredPos) | ||
{ | ||
gizmoCenter_.SetInitialPosition(glm::vec3{centeredPos, 0.0f}); | ||
|
||
gizmoUp_.SetInitialPosition( | ||
gizmoCenter_.GetPosition() | ||
+ glm::vec3{0.0f, gizmoCenter_.GetSize().y / 2.0f + gizmoUp_.GetSize().x / 1.85f, 0.0f}); | ||
|
||
|
||
gizmoSide_.SetInitialPosition( | ||
gizmoCenter_.GetPosition() | ||
+ glm::vec3{glm::vec2(gizmoCenter_.GetSize().x / 2.0f + gizmoSide_.GetSize().x / 1.85f, 0.0f), | ||
0.0f}); | ||
} | ||
|
||
void | ||
Gizmo::CheckHovered(const glm::vec3& cameraPos, const glm::vec2& globalPosition) | ||
{ | ||
bool gizmoTouched = false; | ||
auto checkGizmo = [&gizmoTouched, cameraPos, globalPosition](auto& gizmo) { | ||
if (not gizmoTouched and gizmo.CheckIfCollidedScreenPosion(cameraPos, globalPosition)) | ||
{ | ||
gizmo.SetSize(gizmo.initialSize_ * 1.1f); | ||
gizmoTouched = true; | ||
} | ||
else | ||
{ | ||
gizmo.SetSize(gizmo.initialSize_); | ||
} | ||
}; | ||
|
||
checkGizmo(gizmoCenter_); | ||
checkGizmo(gizmoSide_); | ||
checkGizmo(gizmoUp_); | ||
} | ||
void | ||
Gizmo::SwitchToScale() | ||
{ | ||
gizmoSide_.SetTextureID(renderer::TextureType::DIFFUSE_MAP, | ||
renderer::TextureLibrary::GetTexture("scale_slider.png")->GetID()); | ||
gizmoUp_.SetTextureID(renderer::TextureType::DIFFUSE_MAP, | ||
renderer::TextureLibrary::GetTexture("scale_slider.png")->GetID()); | ||
} | ||
void | ||
Gizmo::SwitchToRotate() | ||
{ | ||
} | ||
void | ||
Gizmo::SwitchToTranslate() | ||
{ | ||
gizmoSide_.SetTextureID(renderer::TextureType::DIFFUSE_MAP, | ||
renderer::TextureLibrary::GetTexture("arrow.png")->GetID()); | ||
gizmoUp_.SetTextureID(renderer::TextureType::DIFFUSE_MAP, | ||
renderer::TextureLibrary::GetTexture("arrow.png")->GetID()); | ||
} | ||
|
||
} // namespace looper |
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,31 @@ | ||
#include "renderer/sprite.hpp" | ||
|
||
namespace looper { | ||
|
||
struct Gizmo | ||
{ | ||
void | ||
Initialize(); | ||
void | ||
Show(); | ||
void | ||
Hide(); | ||
void | ||
Render(); | ||
void | ||
NewObjectSelected(const glm::vec2& centeredPos); | ||
|
||
void | ||
CheckHovered(const glm::vec3& cameraPos, const glm::vec2& globalPosition); | ||
void | ||
SwitchToScale(); | ||
void | ||
SwitchToRotate(); | ||
void | ||
SwitchToTranslate(); | ||
|
||
renderer::Sprite gizmoCenter_ = {}; | ||
renderer::Sprite gizmoUp_ = {}; | ||
renderer::Sprite gizmoSide_ = {}; | ||
}; | ||
} // namespace looper |
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
Oops, something went wrong.