From 75091f718cd8bea4fee35db89ccd35d5fe5f9792 Mon Sep 17 00:00:00 2001 From: parax0 Date: Mon, 25 Jan 2016 22:26:38 -0700 Subject: [PATCH] Added rotation arrow for when billboards are selected --- resources/RotationArrow.cmdl | Bin 0 -> 832 bytes src/Core/Scene/CSceneNode.cpp | 7 +++++++ src/Core/Scene/CSceneNode.h | 1 + src/Core/Scene/CScriptNode.cpp | 19 +++++++++++++++--- src/Editor/CGizmo.cpp | 12 +++++------ src/Editor/CGizmo.h | 9 ++++++--- src/Editor/ModelEditor/CModelEditorWindow.cpp | 2 +- 7 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 resources/RotationArrow.cmdl diff --git a/resources/RotationArrow.cmdl b/resources/RotationArrow.cmdl new file mode 100644 index 0000000000000000000000000000000000000000..d3edccbaa3a6f6ecb90aa5261d2fc2db48a26f4d GIT binary patch literal 832 zcmd^-u?@m75Jk_J1R+r{07XV%f@A@PaKj$%DQFpih5?|6G6Mt9(z1d1-##NyA`rCv z=;dGToU?TH<#1|6WCV)V;|*HmQ(!;`oZ{hG6#}QgdSd?-*on+HTD9tCeZDbd zf3QsP}_xdt)VO+ literal 0 HcmV?d00001 diff --git a/src/Core/Scene/CSceneNode.cpp b/src/Core/Scene/CSceneNode.cpp index 5d1e5326..c1f57afa 100644 --- a/src/Core/Scene/CSceneNode.cpp +++ b/src/Core/Scene/CSceneNode.cpp @@ -3,6 +3,7 @@ #include "Core/Render/CGraphics.h" #include "Core/Render/CDrawUtil.h" #include "Core/Resource/CGameArea.h" +#include "Core/Resource/CResCache.h" #include #include @@ -215,6 +216,12 @@ void CSceneNode::DrawBoundingBox() const CDrawUtil::DrawWireCube(AABox(), CColor::skWhite); } +void CSceneNode::DrawRotationArrow() const +{ + static TResPtr spArrowModel = gResCache.GetResource("../resources/RotationArrow.cmdl"); + spArrowModel->Draw(eNoRenderOptions, 0); +} + void CSceneNode::AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& rkViewInfo) { u32 SurfaceCount = pModel->GetSurfaceCount(); diff --git a/src/Core/Scene/CSceneNode.h b/src/Core/Scene/CSceneNode.h index 917c279d..e422bbee 100644 --- a/src/Core/Scene/CSceneNode.h +++ b/src/Core/Scene/CSceneNode.h @@ -74,6 +74,7 @@ public: void BuildLightList(CGameArea *pArea); void LoadLights(const SViewInfo& ViewInfo); void DrawBoundingBox() const; + void DrawRotationArrow() const; void AddSurfacesToRenderer(CRenderer *pRenderer, CModel *pModel, u32 MatSet, const SViewInfo& ViewInfo); // Transform diff --git a/src/Core/Scene/CScriptNode.cpp b/src/Core/Scene/CScriptNode.cpp index aa74ccb1..8a6707e5 100644 --- a/src/Core/Scene/CScriptNode.cpp +++ b/src/Core/Scene/CScriptNode.cpp @@ -197,15 +197,28 @@ void CScriptNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn void CScriptNode::DrawSelection() { glBlendFunc(GL_ONE, GL_ZERO); + LoadModelMatrix(); - // Draw wireframe for models; billboards only get tinted + // Draw wireframe for models if (UsesModel()) { - LoadModelMatrix(); CModel *pModel = (mpActiveModel ? mpActiveModel : CDrawUtil::GetCubeModel()); pModel->DrawWireframe(eNoRenderOptions, WireframeColor()); } + // Draw rotation arrow for billboards + else + { + // Create model matrix that doesn't take scaling into account, and draw + CTransform4f Transform; + Transform.Rotate(AbsoluteRotation()); + Transform.Translate(AbsolutePosition()); + CGraphics::sMVPBlock.ModelMatrix = Transform.ToMatrix4f(); + CGraphics::UpdateMVPBlock(); + + DrawRotationArrow(); + } + if (mpInstance) { CGraphics::sMVPBlock.ModelMatrix = CMatrix4f::skIdentity; @@ -503,7 +516,7 @@ void CScriptNode::CalculateTransform(CTransform4f& rOut) const rOut.Scale(Scale * pTemp->PreviewScale()); } - if (UsesModel() && pTemp->RotationType() == CScriptTemplate::eRotationEnabled) + if (pTemp->RotationType() == CScriptTemplate::eRotationEnabled) rOut.Rotate(AbsoluteRotation()); rOut.Translate(AbsolutePosition()); diff --git a/src/Editor/CGizmo.cpp b/src/Editor/CGizmo.cpp index d4c4922d..045d6e81 100644 --- a/src/Editor/CGizmo.cpp +++ b/src/Editor/CGizmo.cpp @@ -569,21 +569,21 @@ void CGizmo::SetMode(EGizmoMode mode) { case eTranslate: mpCurrentParts = smTranslateModels; - mNumCurrentParts = 9; + mNumCurrentParts = CGIZMO_TRANSLATE_NUM; mDeltaRotation = CQuaternion::skIdentity; mDeltaScale = CVector3f::skOne; break; case eRotate: mpCurrentParts = smRotateModels; - mNumCurrentParts = 5; + mNumCurrentParts = CGIZMO_ROTATE_NUM; mDeltaTranslation = CVector3f::skZero; mDeltaScale = CVector3f::skOne; break; case eScale: mpCurrentParts = smScaleModels; - mNumCurrentParts = 10; + mNumCurrentParts = CGIZMO_SCALE_NUM; mDeltaTranslation = CVector3f::skZero; mDeltaRotation = CQuaternion::skIdentity; break; @@ -730,6 +730,6 @@ void CGizmo::WrapCursor() // ************ STATIC MEMBER INITIALIZATION ************ bool CGizmo::smModelsLoaded = false; -CGizmo::SModelPart CGizmo::smTranslateModels[9]; -CGizmo::SModelPart CGizmo::smRotateModels[5]; -CGizmo::SModelPart CGizmo::smScaleModels[10]; +CGizmo::SModelPart CGizmo::smTranslateModels[CGIZMO_TRANSLATE_NUM]; +CGizmo::SModelPart CGizmo::smRotateModels[CGIZMO_ROTATE_NUM]; +CGizmo::SModelPart CGizmo::smScaleModels[CGIZMO_SCALE_NUM]; diff --git a/src/Editor/CGizmo.h b/src/Editor/CGizmo.h index eecd6dae..df4c8614 100644 --- a/src/Editor/CGizmo.h +++ b/src/Editor/CGizmo.h @@ -20,11 +20,13 @@ #define CGIZMO_TRANSLATE_POLY_XY 6 #define CGIZMO_TRANSLATE_POLY_XZ 7 #define CGIZMO_TRANSLATE_POLY_YZ 8 +#define CGIZMO_TRANSLATE_NUM 9 #define CGIZMO_ROTATE_OUTLINE 0 #define CGIZMO_ROTATE_X 1 #define CGIZMO_ROTATE_Y 2 #define CGIZMO_ROTATE_Z 3 #define CGIZMO_ROTATE_XYZ 4 +#define CGIZMO_ROTATE_NUM 5 #define CGIZMO_SCALE_X 0 #define CGIZMO_SCALE_Y 1 #define CGIZMO_SCALE_Z 2 @@ -35,6 +37,7 @@ #define CGIZMO_SCALE_POLY_XZ 7 #define CGIZMO_SCALE_POLY_YZ 8 #define CGIZMO_SCALE_XYZ 9 +#define CGIZMO_SCALE_NUM 10 class CGizmo : public IRenderable { @@ -116,9 +119,9 @@ private: // Static static bool smModelsLoaded; - static SModelPart smTranslateModels[9]; - static SModelPart smRotateModels[5]; - static SModelPart smScaleModels[10]; + static SModelPart smTranslateModels[CGIZMO_TRANSLATE_NUM]; + static SModelPart smRotateModels[CGIZMO_ROTATE_NUM]; + static SModelPart smScaleModels[CGIZMO_SCALE_NUM]; public: CGizmo(); diff --git a/src/Editor/ModelEditor/CModelEditorWindow.cpp b/src/Editor/ModelEditor/CModelEditorWindow.cpp index 5304dc8d..9e5433d7 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.cpp +++ b/src/Editor/ModelEditor/CModelEditorWindow.cpp @@ -542,7 +542,7 @@ void CModelEditorWindow::UpdateMaterial(QColor Color) if (mIgnoreSignals) return; EModelEditorWidget Widget = (EModelEditorWidget) sender()->property("ModelEditorWidgetType").toInt(); - CColor KColor((u8) Color.red(), (u8) Color.green(), (u8) Color.blue(), (u8) Color.alpha()); + CColor KColor(Color.red() / 255.f, Color.green() / 255.f, Color.blue() / 255.f, Color.alpha() / 255.f); switch (Widget) {