2019-05-28 14:25:58 +08:00
|
|
|
|
// 4.Geometry3D
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
#include"VulkanAppFramework.h"
|
|
|
|
|
#include<hgl/filesystem/FileSystem.h>
|
|
|
|
|
#include<hgl/graph/InlineGeometry.h>
|
2020-10-21 12:39:22 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2020-11-19 22:12:31 +08:00
|
|
|
|
#include<hgl/graph/Camera.h>
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
using namespace hgl;
|
|
|
|
|
using namespace hgl::graph;
|
|
|
|
|
|
2020-06-12 15:53:37 +08:00
|
|
|
|
constexpr uint32_t SCREEN_WIDTH=1280;
|
|
|
|
|
constexpr uint32_t SCREEN_HEIGHT=720;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2019-06-15 18:07:20 +08:00
|
|
|
|
class TestApp:public CameraAppFramework
|
2019-05-27 22:48:01 +08:00
|
|
|
|
{
|
2020-01-20 20:28:01 +08:00
|
|
|
|
Color4f color;
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
GPUBuffer *ubo_color=nullptr;
|
2020-01-20 20:28:01 +08:00
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
SceneNode render_root;
|
2021-06-22 21:33:47 +08:00
|
|
|
|
RenderList *render_list=nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
Material * material =nullptr;
|
|
|
|
|
MaterialInstance * material_instance =nullptr;
|
|
|
|
|
Pipeline * pipeline =nullptr;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
Renderable * ro_plane_grid[3];
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
bool InitMDP()
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
|
|
|
|
if(!material)return(false);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
material_instance=db->CreateMaterialInstance(material);
|
|
|
|
|
if(!material_instance)return(false);
|
2021-09-22 17:22:17 +08:00
|
|
|
|
|
|
|
|
|
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
|
|
|
|
if(!pipeline)
|
2021-09-15 19:17:56 +08:00
|
|
|
|
return(false);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2020-09-21 20:34:47 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
RenderableInstance *Add(Renderable *r,const Matrix4f &mat)
|
2019-07-11 11:18:34 +08:00
|
|
|
|
{
|
2021-09-15 19:17:56 +08:00
|
|
|
|
RenderableInstance *ri=db->CreateRenderableInstance(r,material_instance,pipeline);
|
2019-07-11 11:18:34 +08:00
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
render_root.CreateSubNode(mat,ri);
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
|
|
|
|
return ri;
|
2019-07-11 11:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
void CreateRenderObject()
|
|
|
|
|
{
|
2019-06-11 23:14:13 +08:00
|
|
|
|
struct PlaneGridCreateInfo pgci;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-24 20:49:20 +08:00
|
|
|
|
pgci.coord[0]=Vector3f(-100,-100,0);
|
|
|
|
|
pgci.coord[1]=Vector3f( 100,-100,0);
|
|
|
|
|
pgci.coord[2]=Vector3f( 100, 100,0);
|
|
|
|
|
pgci.coord[3]=Vector3f(-100, 100,0);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-24 20:49:20 +08:00
|
|
|
|
pgci.step.x=20;
|
|
|
|
|
pgci.step.y=20;
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-24 20:49:20 +08:00
|
|
|
|
pgci.side_step.x=10;
|
|
|
|
|
pgci.side_step.y=10;
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0.5,0,0,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(1,0,0,1);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2021-11-30 15:01:55 +08:00
|
|
|
|
const VAB *vab=material_instance->GetVAB();
|
|
|
|
|
|
|
|
|
|
ro_plane_grid[0]=CreateRenderablePlaneGrid(db,vab,&pgci);
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0,0.5,0,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(0,1,0,1);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2021-11-30 15:01:55 +08:00
|
|
|
|
ro_plane_grid[1]=CreateRenderablePlaneGrid(db,vab,&pgci);
|
2019-05-28 14:25:58 +08:00
|
|
|
|
|
2020-10-17 22:13:08 +08:00
|
|
|
|
pgci.color.Set(0,0,0.5,1);
|
2019-06-11 23:14:13 +08:00
|
|
|
|
pgci.side_color.Set(0,0,1,1);
|
2021-11-30 15:01:55 +08:00
|
|
|
|
ro_plane_grid[2]=CreateRenderablePlaneGrid(db,vab,&pgci);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
bool InitScene()
|
|
|
|
|
{
|
2021-09-26 20:55:18 +08:00
|
|
|
|
Add(ro_plane_grid[0],Matrix4f(1.0f));
|
2021-09-22 17:22:17 +08:00
|
|
|
|
Add(ro_plane_grid[1],rotate(HGL_RAD_90,0,1,0));
|
|
|
|
|
Add(ro_plane_grid[2],rotate(HGL_RAD_90,1,0,0));
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
2022-01-18 12:10:02 +08:00
|
|
|
|
camera->pos=Vector3f(200,200,200);
|
2022-01-27 10:20:49 +08:00
|
|
|
|
camera_control->SetTarget(Vector3f(0,0,0));
|
|
|
|
|
camera_control->Refresh();
|
2022-01-18 12:10:02 +08:00
|
|
|
|
|
2020-10-28 12:30:44 +08:00
|
|
|
|
render_root.RefreshMatrix();
|
2021-06-22 21:33:47 +08:00
|
|
|
|
render_list->Expend(camera->info,&render_root);
|
2020-10-28 12:30:44 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
~TestApp()
|
|
|
|
|
{
|
|
|
|
|
SAFE_CLEAR(render_list);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 22:48:01 +08:00
|
|
|
|
bool Init()
|
|
|
|
|
{
|
2019-06-15 18:07:20 +08:00
|
|
|
|
if(!CameraAppFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
2021-06-22 21:33:47 +08:00
|
|
|
|
|
|
|
|
|
render_list=new RenderList(device);
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
2021-09-15 19:17:56 +08:00
|
|
|
|
if(!InitMDP())
|
2019-05-27 22:48:01 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-07-11 11:18:34 +08:00
|
|
|
|
CreateRenderObject();
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
if(!InitScene())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-06-13 23:12:11 +08:00
|
|
|
|
|
2019-06-18 00:48:05 +08:00
|
|
|
|
void BuildCommandBuffer(uint32 index)
|
2019-06-13 23:12:11 +08:00
|
|
|
|
{
|
2022-01-18 12:10:02 +08:00
|
|
|
|
render_root.RefreshMatrix();
|
|
|
|
|
render_list->Expend(GetCameraInfo(),&render_root);
|
|
|
|
|
|
2021-06-22 21:33:47 +08:00
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
2019-06-13 23:12:11 +08:00
|
|
|
|
}
|
2021-09-15 19:17:56 +08:00
|
|
|
|
|
|
|
|
|
void Resize(int w,int h)override
|
|
|
|
|
{
|
|
|
|
|
CameraAppFramework::Resize(w,h);
|
|
|
|
|
|
|
|
|
|
VulkanApplicationFramework::BuildCommandBuffer(render_list);
|
|
|
|
|
}
|
2019-06-15 18:07:20 +08:00
|
|
|
|
};//class TestApp:public CameraAppFramework
|
2019-05-27 22:48:01 +08:00
|
|
|
|
|
|
|
|
|
int main(int,char **)
|
|
|
|
|
{
|
|
|
|
|
TestApp app;
|
|
|
|
|
|
|
|
|
|
if(!app.Init())
|
|
|
|
|
return(-1);
|
|
|
|
|
|
|
|
|
|
while(app.Run());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|