From 7f074c6c7944c3f051a0fcb66be79f23c4c8f8fd Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 1 Aug 2024 01:42:21 +0800 Subject: [PATCH] Added a white ring outside gizmo_rotate --- CMCore | 2 +- CMSceneGraph | 2 +- example/Gizmo/Gizmo.h | 2 ++ example/Gizmo/GizmoTest.cpp | 59 ++++++++++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/CMCore b/CMCore index 7165984d..7589d627 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 7165984d2270c61f19653a3a256c05786ec478fa +Subproject commit 7589d62732b68b99de1bec561b1703dd2b043c03 diff --git a/CMSceneGraph b/CMSceneGraph index f11e4936..53f0c618 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit f11e49363bed867c5fb5584277718983e6b6b697 +Subproject commit 53f0c618567a0e85aca2de4e9e06e08f587c1f7e diff --git a/example/Gizmo/Gizmo.h b/example/Gizmo/Gizmo.h index 115fa88d..8a595dd8 100644 --- a/example/Gizmo/Gizmo.h +++ b/example/Gizmo/Gizmo.h @@ -33,6 +33,8 @@ enum class GizmoShape:uint bool InitGizmoResource(RenderResource *); void FreeGizmoResource(); +Renderable *GetGizmoRenderable(const GizmoShape &shape,const GizmoColor &color); + StaticMesh *GetGizmoMoveStaticMesh(); StaticMesh *GetGizmoScaleStaticMesh(); StaticMesh *GetGizmoRotateStaticMesh(); diff --git a/example/Gizmo/GizmoTest.cpp b/example/Gizmo/GizmoTest.cpp index 749e0039..6635bd3c 100644 --- a/example/Gizmo/GizmoTest.cpp +++ b/example/Gizmo/GizmoTest.cpp @@ -1,9 +1,22 @@ #include"VulkanAppFramework.h" #include"Gizmo.h" +#include using namespace hgl; using namespace hgl::graph; +/** +* 求一个世界坐标在屏幕上的位置 +*/ +Vector2f WorldToScreen(const Vector3f &world_pos,const CameraInfo &ci,const ViewportInfo &vi) +{ + Vector4f pos=ci.vp*Vector4f(world_pos,1); + + pos/=pos.w; + + return Vector2f((pos.x+1)*vi.GetViewportWidth()/2,(1-pos.y)*vi.GetViewportHeight()/2); +} + class TestApp:public SceneAppFramework { SceneNode root; @@ -11,6 +24,8 @@ class TestApp:public SceneAppFramework StaticMesh *sm_move=nullptr; StaticMesh *sm_rotate=nullptr; + Renderable *face_torus=nullptr; + private: bool InitGizmo() @@ -21,6 +36,8 @@ private: sm_move =GetGizmoMoveStaticMesh(); sm_rotate =GetGizmoRotateStaticMesh(); + face_torus =GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White); + return(true); } @@ -36,13 +53,6 @@ public: camera->pos=Vector3f(32,32,32); camera_control->SetTarget(Vector3f(0,0,0)); - camera_control->Refresh(); - - root.CreateSubNode(sm_move->GetScene()); - root.CreateSubNode(sm_rotate->GetScene()); - - root.RefreshMatrix(); - render_list->Expend(&root); return(true); } @@ -51,6 +61,41 @@ public: { FreeGizmoResource(); } + + void BuildCommandBuffer(uint32 index) override + { + camera_control->Refresh(); + + const CameraInfo &ci=camera_control->GetCameraInfo(); + const ViewportInfo &vi=GetViewportInfo(); + + const float screen_height=vi.GetViewportHeight(); + + root.Clear(); + + const Vector3f GizmoPosition(0,0,0); + + const Vector4f pos=ci.Project(GizmoPosition); + + root.SetLocalMatrix(scale(pos.w*16.0f/screen_height)); + + root.CreateSubNode(sm_move->GetScene()); + root.CreateSubNode(sm_rotate->GetScene()); + + { + Transform tm; + + tm.SetRotation(CalculateFacingRotationQuat(GizmoPosition,ci.view,AxisVector::X)); + tm.SetScale(15); + + root.CreateSubNode(tm,face_torus); + } + + root.RefreshMatrix(); + render_list->Expend(&root); + + SceneAppFramework::BuildCommandBuffer(index); + } };//class TestApp:public SceneAppFramework int main(int,char **)