调整好坐标轴方向以及裁剪面,并增加最简易坐标轴绘制范例
This commit is contained in:
@@ -70,7 +70,7 @@ private:
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
const auto ext=GetExtent();
|
||||
|
@@ -1,30 +0,0 @@
|
||||
// Blender axis
|
||||
/**
|
||||
* 0 1 2 3 4 5 6 7
|
||||
* 0+---------->>>> X
|
||||
* 1|
|
||||
* 2|
|
||||
* 3| +--+
|
||||
* 4| +--+
|
||||
* 5|
|
||||
* 6V
|
||||
* 7V
|
||||
*
|
||||
* 坐标轴参考Blender设计
|
||||
*
|
||||
* 单方向坐标轴长度为8
|
||||
* 最终箭头长度为2
|
||||
*
|
||||
* 负责2D平移的方块尺寸为1,位置在3-4
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 缩放工具
|
||||
*/
|
||||
class GizmoScale
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
};//class GizmoScale
|
@@ -10,9 +10,9 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||
CreateProject(01_SimplestAxis SimplestAxis.cpp)
|
||||
CreateProject(02_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(03_RayPicking RayPicking.cpp)
|
||||
|
||||
CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||
Gizmo.h
|
||||
@@ -22,5 +22,3 @@ CreateProject(04_Gizmo3DTest GizmoTest.cpp
|
||||
#Gizmo3DScale.cpp
|
||||
#Gizmo3DRotate.cpp
|
||||
)
|
||||
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
||||
|
@@ -63,11 +63,11 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
GetGizmoMesh(GizmoShape::Cone,GizmoColor::Blue),
|
||||
};
|
||||
|
||||
Mesh *circle[3]=
|
||||
Mesh *square[3]=
|
||||
{
|
||||
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Circle,GizmoColor::Blue)
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Red),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Green),
|
||||
GetGizmoMesh(GizmoShape::Square,GizmoColor::Blue)
|
||||
};
|
||||
|
||||
if(!sphere)
|
||||
@@ -81,7 +81,7 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
if(!cone[i])
|
||||
return(false);
|
||||
|
||||
if(!circle[i])
|
||||
if(!square[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -94,21 +94,21 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
Transform tm;
|
||||
|
||||
const Vector3f one_scale(1);
|
||||
const Vector3f circle_scale(2);
|
||||
const Vector3f square_scale(2);
|
||||
const Vector3f cylinder_scale(GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_RADIUS,GIZMO_CYLINDER_HALF_LENGTH);
|
||||
|
||||
{
|
||||
tm.SetScale(cylinder_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CYLINDER_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cylinder[2]); //Z 向上圆柱
|
||||
|
||||
tm.SetScale(one_scale);
|
||||
tm.SetTranslation(0,0,GIZMO_CONE_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[2]); //Z 向上圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[2]);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[2]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -121,9 +121,9 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
tm.SetTranslation(GIZMO_CONE_OFFSET,0,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[0]); //X 向右圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(0,GIZMO_TWO_AXIS_OFFSET,GIZMO_TWO_AXIS_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[0]);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[0]);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -136,9 +136,9 @@ bool InitGizmoMoveNode(RenderFramework *render_framework)
|
||||
tm.SetTranslation(0,GIZMO_CONE_OFFSET,0);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,cone[1]); //Y 向前圆锥
|
||||
|
||||
tm.SetScale(circle_scale);
|
||||
tm.SetScale(square_scale);
|
||||
tm.SetTranslation(GIZMO_TWO_AXIS_OFFSET,0,GIZMO_TWO_AXIS_OFFSET);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,circle[1]);
|
||||
render_framework->CreateComponent<MeshComponent>(tm.GetMatrix(),sn_gizmo_move,square[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,147 +0,0 @@
|
||||
// Metric Cells Grid
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
struct MetricCellsGridData
|
||||
{
|
||||
Color4f x_color;
|
||||
Color4f y_color;
|
||||
Color4f x_axis_color;
|
||||
Color4f y_axis_color;
|
||||
Color4f center_color;
|
||||
|
||||
Vector2f lum;
|
||||
Vector2f cell_step;
|
||||
Vector2f big_cell_step;
|
||||
Vector2f scale;
|
||||
|
||||
float axis_line_width;
|
||||
float center_radius;
|
||||
};
|
||||
|
||||
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
||||
|
||||
constexpr const float PLANE_SIZE=1024;
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private:
|
||||
|
||||
MetricCellsGridData mcg_data;
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDevAttr(),"MetricCellsGrid",PrimitiveType::Fan);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/MetricCellsGrid",&cfg);
|
||||
if(!material)return(false);
|
||||
|
||||
{
|
||||
mcg_data.x_color=Color4f(1,1,1,1);
|
||||
mcg_data.y_color=Color4f(1,1,1,1);
|
||||
|
||||
mcg_data.x_axis_color=GetColor4f(COLOR::BlenderAxisRed, 1.0);
|
||||
mcg_data.y_axis_color=GetColor4f(COLOR::BlenderAxisGreen, 1.0);
|
||||
|
||||
mcg_data.center_color=Color4f(1,1,0,1);
|
||||
|
||||
mcg_data.lum =Vector2f(0.1,0.2);
|
||||
mcg_data.cell_step =Vector2f(8,8);
|
||||
mcg_data.big_cell_step =Vector2f(32,32);
|
||||
mcg_data.scale =Vector2f(PLANE_SIZE,PLANE_SIZE);
|
||||
|
||||
mcg_data.axis_line_width=1.0;
|
||||
mcg_data.center_radius =4.0;
|
||||
}
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material,nullptr,&mcg_data);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,PrimitiveType::Fan);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
PrimitiveCreater pc(device,material->GetDefaultVIL());
|
||||
|
||||
ro_plane=inline_geometry::CreatePlaneSqaure(&pc);
|
||||
|
||||
if(ro_plane)
|
||||
db->Add(ro_plane);
|
||||
|
||||
return ro_plane;
|
||||
}
|
||||
|
||||
Mesh *Add(MaterialInstance *mi,const Matrix4f &mat)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(ro_plane,mi,pipeline);
|
||||
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(material_instance,scale(PLANE_SIZE,PLANE_SIZE,1));
|
||||
|
||||
camera->pos=Vector3f(PLANE_SIZE/4,PLANE_SIZE/2,PLANE_SIZE/4);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint width,uint height) override
|
||||
{
|
||||
if(!SceneAppFramework::Init(width,height))
|
||||
return(false);
|
||||
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
return RunApp<TestApp>(1280,720);
|
||||
}
|
100
example/Gizmo/SimplestAxis.cpp
Normal file
100
example/Gizmo/SimplestAxis.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// SimplestAxis
|
||||
// 直接从0,0,0向三个方向画一条直线,用于确认坐标轴方向
|
||||
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/component/MeshComponent.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_axis =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(PrimitiveType::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material_instance=CreateMaterialInstance(mtl::inline_material::VertexColor3D,&cfg);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D);
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
auto pc=GetPrimitiveCreater(material_instance);
|
||||
|
||||
inline_geometry::AxisCreateInfo aci;
|
||||
|
||||
prim_axis=CreateAxis(pc,&aci);
|
||||
|
||||
return prim_axis;
|
||||
}
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(prim_axis,material_instance,pipeline);
|
||||
|
||||
CreateComponent<MeshComponent>(GetSceneRoot(),ri);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
camera_control->SetPosition(Vector3f(32,32,32));
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
|
||||
// camera_control->SetReserveDirection(true,true); //反转x,y
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_axis);
|
||||
}
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMDP())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
if(!InitScene())
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
return RunFramework<TestApp>(OS_TEXT("SimplestAxis"),1280,720);
|
||||
}
|
Reference in New Issue
Block a user