Correct draw Gizmo Rotate/Scale, OK!!
This commit is contained in:
parent
e18a6e7a4a
commit
c3a1266da6
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 7f39d7731845b3592cab7b5267eac88f7b13573b
|
Subproject commit 7165984d2270c61f19653a3a256c05786ec478fa
|
@ -14,6 +14,12 @@ CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
|||||||
CreateProject(02_RayPicking RayPicking.cpp)
|
CreateProject(02_RayPicking RayPicking.cpp)
|
||||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||||
|
|
||||||
CreateProject(04_Gizmo3DTest GizmoTest.cpp Gizmo3DMove.cpp Gizmo.h GizmoResource.h GizmoResource.cpp)
|
CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||||
|
Gizmo.h
|
||||||
|
GizmoResource.h
|
||||||
|
GizmoResource.cpp
|
||||||
|
Gizmo3DMove.cpp
|
||||||
|
Gizmo3DScale.cpp
|
||||||
|
Gizmo3DRotate.cpp)
|
||||||
|
|
||||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
||||||
|
@ -25,14 +25,16 @@ enum class GizmoShape:uint
|
|||||||
Sphere, //球
|
Sphere, //球
|
||||||
Cone, //圆锥
|
Cone, //圆锥
|
||||||
Cylinder, //圆柱
|
Cylinder, //圆柱
|
||||||
|
Torus, //圆环
|
||||||
|
|
||||||
ENUM_CLASS_RANGE(Plane,Cylinder)
|
ENUM_CLASS_RANGE(Plane,Torus)
|
||||||
};
|
};
|
||||||
|
|
||||||
bool InitGizmoResource(RenderResource *);
|
bool InitGizmoResource(RenderResource *);
|
||||||
void FreeGizmoResource();
|
void FreeGizmoResource();
|
||||||
|
|
||||||
|
|
||||||
StaticMesh *GetGizmoMoveStaticMesh();
|
StaticMesh *GetGizmoMoveStaticMesh();
|
||||||
|
StaticMesh *GetGizmoScaleStaticMesh();
|
||||||
|
StaticMesh *GetGizmoRotateStaticMesh();
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -76,17 +76,20 @@ bool InitGizmoMoveStaticMesh()
|
|||||||
|
|
||||||
if(!cone[i])
|
if(!cone[i])
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
if(!plane[i])
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SceneNode *root_node=new SceneNode(sphere);
|
SceneNode *root_node=new SceneNode(scale(0.5f),sphere);
|
||||||
|
|
||||||
{
|
{
|
||||||
Transform tm;
|
Transform tm;
|
||||||
|
|
||||||
constexpr const Vector3f one_scale(1);
|
constexpr const Vector3f one_scale(1);
|
||||||
constexpr const Vector3f plane_scale(2);
|
constexpr const Vector3f plane_scale(2);
|
||||||
constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.5f);
|
constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.0f);
|
||||||
|
|
||||||
{
|
{
|
||||||
tm.SetScale(cylinder_scale);
|
tm.SetScale(cylinder_scale);
|
||||||
|
66
example/Gizmo/Gizmo3DRotate.cpp
Normal file
66
example/Gizmo/Gizmo3DRotate.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include"GizmoResource.h"
|
||||||
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static StaticMesh *sm_gizmo_rotate=nullptr;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
StaticMesh *GetGizmoRotateStaticMesh()
|
||||||
|
{
|
||||||
|
return sm_gizmo_rotate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearGizmoRotateStaticMesh()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(sm_gizmo_rotate);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InitGizmoRotateStaticMesh()
|
||||||
|
{
|
||||||
|
Renderable *torus[4]
|
||||||
|
{
|
||||||
|
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Red),
|
||||||
|
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Green),
|
||||||
|
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::Blue),
|
||||||
|
|
||||||
|
GetGizmoRenderable(GizmoShape::Torus,GizmoColor::White),
|
||||||
|
};
|
||||||
|
|
||||||
|
for(int i=0;i<4;i++)
|
||||||
|
{
|
||||||
|
if(!torus[i])
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SceneNode *root_node=new SceneNode();
|
||||||
|
|
||||||
|
{
|
||||||
|
Transform tm;
|
||||||
|
|
||||||
|
tm.SetScale(10.0f);
|
||||||
|
|
||||||
|
tm.SetRotation(AXIS::Z,90);
|
||||||
|
root_node->CreateSubNode(tm,torus[0]);
|
||||||
|
|
||||||
|
tm.ClearRotation();
|
||||||
|
root_node->CreateSubNode(tm,torus[1]);
|
||||||
|
|
||||||
|
tm.SetRotation(AXIS::X,90);
|
||||||
|
root_node->CreateSubNode(tm,torus[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
sm_gizmo_rotate=CreateGizmoStaticMesh(root_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sm_gizmo_rotate)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
149
example/Gizmo/Gizmo3DScale.cpp
Normal file
149
example/Gizmo/Gizmo3DScale.cpp
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
Gizmo move
|
||||||
|
|
||||||
|
ref: Blender 4
|
||||||
|
|
||||||
|
|
||||||
|
0 9-10
|
||||||
|
*----------------->>>>
|
||||||
|
|
|
||||||
|
|
|
||||||
|
| 5+
|
||||||
|
| +6
|
||||||
|
|
|
||||||
|
|
|
||||||
|
v
|
||||||
|
|
||||||
|
假设轴尺寸为10
|
||||||
|
箭头长度为2,直径为2
|
||||||
|
双轴调节正方形,长宽为1,位置为5,5
|
||||||
|
|
||||||
|
中心球半径为1
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include"GizmoResource.h"
|
||||||
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static StaticMesh *sm_gizmo_scale=nullptr;
|
||||||
|
}//namespace
|
||||||
|
|
||||||
|
StaticMesh *GetGizmoScaleStaticMesh()
|
||||||
|
{
|
||||||
|
return sm_gizmo_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearGizmoScaleStaticMesh()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(sm_gizmo_scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InitGizmoScaleStaticMesh()
|
||||||
|
{
|
||||||
|
Renderable *sphere=GetGizmoRenderable(GizmoShape::Sphere,GizmoColor::White);
|
||||||
|
Renderable *cylinder[3]
|
||||||
|
{
|
||||||
|
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Red),
|
||||||
|
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Green),
|
||||||
|
GetGizmoRenderable(GizmoShape::Cylinder,GizmoColor::Blue),
|
||||||
|
};
|
||||||
|
|
||||||
|
Renderable *cube[3]
|
||||||
|
{
|
||||||
|
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Red),
|
||||||
|
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Green),
|
||||||
|
GetGizmoRenderable(GizmoShape::Cube,GizmoColor::Blue),
|
||||||
|
};
|
||||||
|
|
||||||
|
Renderable *plane[3]=
|
||||||
|
{
|
||||||
|
GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Red),
|
||||||
|
GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Green),
|
||||||
|
GetGizmoRenderable(GizmoShape::Plane,GizmoColor::Blue)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!sphere)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
for(int i=0;i<3;i++)
|
||||||
|
{
|
||||||
|
if(!cylinder[i])
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!cube[i])
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!plane[i])
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SceneNode *root_node=new SceneNode(scale(0.5f),sphere);
|
||||||
|
|
||||||
|
{
|
||||||
|
Transform tm;
|
||||||
|
|
||||||
|
constexpr const Vector3f one_scale(2);
|
||||||
|
constexpr const Vector3f plane_scale(2);
|
||||||
|
constexpr const Vector3f cylinder_scale(0.35f,0.35f,4.0f);
|
||||||
|
|
||||||
|
{
|
||||||
|
tm.SetScale(cylinder_scale);
|
||||||
|
tm.SetTranslation(0,0,4.5f);
|
||||||
|
root_node->CreateSubNode(tm,cylinder[2]); //Z 向上圆柱
|
||||||
|
|
||||||
|
tm.SetScale(one_scale);
|
||||||
|
tm.SetTranslation(0,0,9.5f);
|
||||||
|
root_node->CreateSubNode(tm,cube[2]); //Z 向上圆锥
|
||||||
|
|
||||||
|
tm.SetScale(plane_scale);
|
||||||
|
tm.SetTranslation(5,5,0);
|
||||||
|
root_node->CreateSubNode(tm,plane[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
tm.SetScale(cylinder_scale);
|
||||||
|
tm.SetRotation(AxisVector::Y,90);
|
||||||
|
tm.SetTranslation(4.5f,0,0);
|
||||||
|
root_node->CreateSubNode(tm,cylinder[0]); //X 向右圆柱
|
||||||
|
|
||||||
|
tm.SetScale(one_scale);
|
||||||
|
tm.SetTranslation(9.5f,0,0);
|
||||||
|
root_node->CreateSubNode(tm,cube[0]); //X 向右圆锥
|
||||||
|
|
||||||
|
tm.SetScale(plane_scale);
|
||||||
|
tm.SetTranslation(0,5,5);
|
||||||
|
root_node->CreateSubNode(tm,plane[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
tm.SetScale(cylinder_scale);
|
||||||
|
tm.SetRotation(AxisVector::X,-90);
|
||||||
|
tm.SetTranslation(0,4.5f,0);
|
||||||
|
|
||||||
|
root_node->CreateSubNode(tm,cylinder[1]); //Y 向前圆柱
|
||||||
|
|
||||||
|
tm.SetScale(one_scale);
|
||||||
|
tm.SetTranslation(0,9.5f,0);
|
||||||
|
root_node->CreateSubNode(tm,cube[1]); //Y 向前圆锥
|
||||||
|
|
||||||
|
tm.SetScale(plane_scale);
|
||||||
|
tm.SetTranslation(5,0,5);
|
||||||
|
root_node->CreateSubNode(tm,plane[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sm_gizmo_scale=CreateGizmoStaticMesh(root_node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sm_gizmo_scale)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
@ -15,6 +15,12 @@ VK_NAMESPACE_BEGIN
|
|||||||
bool InitGizmoMoveStaticMesh();
|
bool InitGizmoMoveStaticMesh();
|
||||||
void ClearGizmoMoveStaticMesh();
|
void ClearGizmoMoveStaticMesh();
|
||||||
|
|
||||||
|
bool InitGizmoScaleStaticMesh();
|
||||||
|
void ClearGizmoScaleStaticMesh();
|
||||||
|
|
||||||
|
bool InitGizmoRotateStaticMesh();
|
||||||
|
void ClearGizmoRotateStaticMesh();
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static RenderResource * gizmo_rr=nullptr;
|
static RenderResource * gizmo_rr=nullptr;
|
||||||
@ -198,7 +204,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,32),gizmo_triangle.pipeline);
|
InitGizmoRenderable(GizmoShape::Sphere,CreateSphere(gizmo_triangle.prim_creater,8),gizmo_triangle.pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -206,8 +212,8 @@ namespace
|
|||||||
|
|
||||||
cci.radius =1; //圆锥半径
|
cci.radius =1; //圆锥半径
|
||||||
cci.halfExtend =1; //圆锤一半高度
|
cci.halfExtend =1; //圆锤一半高度
|
||||||
cci.numberSlices=32; //圆锥底部分割数
|
cci.numberSlices=16; //圆锥底部分割数
|
||||||
cci.numberStacks=8; //圆锥高度分割数
|
cci.numberStacks=3; //圆锥高度分割数
|
||||||
|
|
||||||
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoRenderable(GizmoShape::Cone,CreateCone(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||||
}
|
}
|
||||||
@ -216,12 +222,23 @@ namespace
|
|||||||
struct CylinderCreateInfo cci;
|
struct CylinderCreateInfo cci;
|
||||||
|
|
||||||
cci.halfExtend =1; //圆柱一半高度
|
cci.halfExtend =1; //圆柱一半高度
|
||||||
cci.numberSlices=32; //圆柱底部分割数
|
cci.numberSlices=16; //圆柱底部分割数
|
||||||
cci.radius =1; //圆柱半径
|
cci.radius =1; //圆柱半径
|
||||||
|
|
||||||
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
InitGizmoRenderable(GizmoShape::Cylinder,CreateCylinder(gizmo_triangle.prim_creater,&cci),gizmo_triangle.pipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct TorusCreateInfo tci;
|
||||||
|
|
||||||
|
tci.innerRadius=0.975;
|
||||||
|
tci.outerRadius=1.0;
|
||||||
|
tci.numberSlices=64;
|
||||||
|
tci.numberStacks=32;
|
||||||
|
|
||||||
|
InitGizmoRenderable(GizmoShape::Torus,CreateTorus(gizmo_triangle.prim_creater,&tci),gizmo_triangle.pipeline);
|
||||||
|
}
|
||||||
|
|
||||||
ENUM_CLASS_FOR(GizmoShape,int,i)
|
ENUM_CLASS_FOR(GizmoShape,int,i)
|
||||||
{
|
{
|
||||||
if(!gizmo_rederable[i].prim)
|
if(!gizmo_rederable[i].prim)
|
||||||
@ -252,12 +269,16 @@ bool InitGizmoResource(RenderResource *rr)
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
InitGizmoMoveStaticMesh();
|
InitGizmoMoveStaticMesh();
|
||||||
|
InitGizmoScaleStaticMesh();
|
||||||
|
InitGizmoRotateStaticMesh();
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeGizmoResource()
|
void FreeGizmoResource()
|
||||||
{
|
{
|
||||||
|
ClearGizmoRotateStaticMesh();
|
||||||
|
ClearGizmoScaleStaticMesh();
|
||||||
ClearGizmoMoveStaticMesh();
|
ClearGizmoMoveStaticMesh();
|
||||||
|
|
||||||
for(GizmoRenderable &gr:gizmo_rederable)
|
for(GizmoRenderable &gr:gizmo_rederable)
|
||||||
@ -295,4 +316,4 @@ StaticMesh *CreateGizmoStaticMesh(SceneNode *root_node)
|
|||||||
return(new StaticMesh(root_node));
|
return(new StaticMesh(root_node));
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -6,7 +6,8 @@ using namespace hgl::graph;
|
|||||||
|
|
||||||
class TestApp:public SceneAppFramework
|
class TestApp:public SceneAppFramework
|
||||||
{
|
{
|
||||||
StaticMesh *sm=nullptr;
|
StaticMesh *sm_move=nullptr;
|
||||||
|
StaticMesh *sm_rotate=nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -15,7 +16,8 @@ private:
|
|||||||
if(!InitGizmoResource(db))
|
if(!InitGizmoResource(db))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
sm=GetGizmoMoveStaticMesh();
|
sm_move =GetGizmoMoveStaticMesh();
|
||||||
|
sm_rotate =GetGizmoRotateStaticMesh();
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -34,7 +36,7 @@ public:
|
|||||||
camera_control->SetTarget(Vector3f(0,0,0));
|
camera_control->SetTarget(Vector3f(0,0,0));
|
||||||
camera_control->Refresh();
|
camera_control->Refresh();
|
||||||
|
|
||||||
SceneNode *sn=sm->GetScene();
|
SceneNode *sn=sm_rotate->GetScene();
|
||||||
|
|
||||||
sn->RefreshMatrix();
|
sn->RefreshMatrix();
|
||||||
|
|
||||||
|
2
res
2
res
@ -1 +1 @@
|
|||||||
Subproject commit 475d8ad43ceee084cd24f5d0bed59de9f6aa36fd
|
Subproject commit e1a36d78f0eead5f6bb65493432c4690637b991d
|
@ -802,9 +802,9 @@ namespace hgl
|
|||||||
// generate normal and stores it in the right position
|
// generate normal and stores it in the right position
|
||||||
// NOTE: cos (2PIx) = cos (x) and sin (2PIx) = sin (x) so, we can use this formula
|
// NOTE: cos (2PIx) = cos (x) and sin (2PIx) = sin (x) so, we can use this formula
|
||||||
// normal = {cos(2PIs)cos(2PIt) , sin(2PIs)cos(2PIt) ,sin(2PIt)}
|
// normal = {cos(2PIs)cos(2PIt) , sin(2PIs)cos(2PIt) ,sin(2PIt)}
|
||||||
*np = +cos2PIs * cos2PIt; ++np;
|
*np = cos2PIs * cos2PIt; ++np;
|
||||||
*np = +sin2PIt; ++np;
|
*np = sin2PIt; ++np;
|
||||||
*np = +sin2PIs * cos2PIt; ++np;
|
*np = sin2PIs * cos2PIt; ++np;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tcp)
|
if(tcp)
|
||||||
|
@ -47,7 +47,7 @@ void main()
|
|||||||
|
|
||||||
float specular=max(dot(half_vector,Input.Normal),0.0);
|
float specular=max(dot(half_vector,Input.Normal),0.0);
|
||||||
|
|
||||||
spec_color=specular*pow(specular,64)*SUN_COLOR;
|
spec_color=specular*pow(specular,16)*SUN_COLOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragColor=vec4(direct_color+spec_color,1.0);
|
FragColor=vec4(direct_color+spec_color,1.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user