fixed RayPicking.cpp, it can RUN ok!
This commit is contained in:
parent
a1e7b105f7
commit
10d4f2f04a
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 5107b34d1617413c40537502181694f80f82782f
|
||||
Subproject commit ab0292d27e9825f1259688f78cf3bd02fbc9e785
|
@ -1 +1 @@
|
||||
Subproject commit bc0b1d5a2ce66c3b9875df4dcbd1a7575c35782b
|
||||
Subproject commit 3b53b04262e3641cbaa68deabc6fc46839ecf1f5
|
@ -10,4 +10,6 @@
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "ULRE/Example/Gizmo")
|
||||
endmacro()
|
||||
|
||||
CreateProject(PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
||||
CreateProject(02_RayPicking RayPicking.cpp)
|
||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
||||
|
@ -1,4 +1,4 @@
|
||||
// 4.Geometry3D
|
||||
// PlaneGrid3D
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
@ -15,19 +15,8 @@ using namespace hgl::graph;
|
||||
constexpr uint32_t SCREEN_WIDTH=1280;
|
||||
constexpr uint32_t SCREEN_HEIGHT=720;
|
||||
|
||||
constexpr const Vector4f GridColor[3]=
|
||||
{
|
||||
{1,0,0,1},
|
||||
{0,1,0,1},
|
||||
{0,0,1,1}
|
||||
};
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
DeviceBuffer *ubo_color=nullptr;
|
||||
|
||||
private:
|
||||
|
||||
SceneNode render_root;
|
||||
@ -54,11 +43,18 @@ private:
|
||||
|
||||
db->global_descriptor.Bind(material);
|
||||
|
||||
Color4f GridColor;
|
||||
COLOR ce=COLOR::BlenderAxisRed;
|
||||
|
||||
for(uint i=0;i<3;i++)
|
||||
{
|
||||
material_instance[i]=db->CreateMaterialInstance(material);
|
||||
|
||||
material_instance[i]->WriteMIData(GridColor[i]);
|
||||
GridColor=GetColor4f(ce,1.0);
|
||||
|
||||
material_instance[i]->WriteMIData(GridColor);
|
||||
|
||||
ce=COLOR((int)ce+1);
|
||||
}
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/Ray.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/3d/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -21,11 +22,10 @@ static float position_data[2][3]=
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static float color_data[2][4]=
|
||||
{
|
||||
{1,1,0,1},
|
||||
{1,1,0,1}
|
||||
};
|
||||
static float lumiance_data[2]={1,1};
|
||||
|
||||
static Color4f white_color(1,1,1,1);
|
||||
static Color4f yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public CameraAppFramework
|
||||
{
|
||||
@ -39,12 +39,14 @@ private:
|
||||
RenderList * render_list =nullptr;
|
||||
|
||||
Material * material =nullptr;
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
Primitive * ro_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
|
||||
@ -52,26 +54,46 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
bool InitMDP()
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
material=db->CreateMaterial(OS_TEXT("res/material/VertexColor3D"));
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexLuminance3D(&cfg);
|
||||
|
||||
material=db->CreateMaterial(mci);
|
||||
if(!material)return(false);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(material);
|
||||
if(!material_instance)return(false);
|
||||
db->global_descriptor.Bind(material);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(material);
|
||||
if(!mi_plane_grid)return(false);
|
||||
mi_plane_grid->WriteMIData(white_color);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(material);
|
||||
if(!mi_line)return(false);
|
||||
mi_line->WriteMIData(yellow_color);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,const Matrix4f &mat)
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,material_instance,pipeline);
|
||||
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
|
||||
|
||||
render_root.CreateSubNode(mat,ri);
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.CreateSubNode(ri);
|
||||
|
||||
return ri;
|
||||
}
|
||||
@ -83,31 +105,24 @@ private:
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
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);
|
||||
pgci.grid_size.width =32;
|
||||
pgci.grid_size.height=32;
|
||||
|
||||
pgci.step.x=32;
|
||||
pgci.step.y=32;
|
||||
pgci.sub_count.width =8;
|
||||
pgci.sub_count.height=8;
|
||||
|
||||
pgci.side_step.x=8;
|
||||
pgci.side_step.y=8;
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
pgci.color.Set(0.25,0,0,1);
|
||||
pgci.side_color.Set(1,0,0,1);
|
||||
|
||||
const VIL *vil=material_instance->GetVIL();
|
||||
|
||||
ro_plane_grid=CreatePlaneGrid(db,vil,&pgci);
|
||||
ro_plane_grid=CreatePlaneGrid(db,material->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
ro_line=db->CreatePrimitive(2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos=db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,2,color_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos= db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Luminance, db->CreateVBO(VF_V1F,2,lumiance_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
@ -115,15 +130,15 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(ro_plane_grid,Matrix4f(1.0f));
|
||||
Add(ro_line,Matrix4f(1.0f));
|
||||
Add(ro_plane_grid,mi_plane_grid);
|
||||
Add(ro_line,mi_line);
|
||||
|
||||
camera->pos=Vector3f(100,100,50);
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(camera->info,&render_root);
|
||||
render_list->Expend(&render_root);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -142,7 +157,7 @@ public:
|
||||
|
||||
render_list=new RenderList(device);
|
||||
|
||||
if(!InitMDP())
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
@ -157,16 +172,14 @@ public:
|
||||
void BuildCommandBuffer(uint32 index)
|
||||
{
|
||||
const CameraInfo &ci=GetCameraInfo();
|
||||
const ViewportInfo &vi=GetViewportInfo();
|
||||
|
||||
ray.Set(GetMouseCoord(),&ci); //设置射线查询的屏幕坐标点
|
||||
ray.Set(GetMouseCoord(),&ci,&vi); //设置射线查询的屏幕坐标点
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(ci,&render_root);
|
||||
|
||||
VulkanApplicationFramework::BuildCommandBuffer(index,render_list);
|
||||
}
|
||||
|
@ -60,6 +60,9 @@ namespace hgl
|
||||
|
||||
SceneNode *CreateSubNode(Renderable *ri)
|
||||
{
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
SceneNode *sn=new SceneNode(ri);
|
||||
|
||||
SubNode.Add(sn);
|
||||
@ -76,6 +79,9 @@ namespace hgl
|
||||
|
||||
SceneNode *CreateSubNode(const Matrix4f &mat,Renderable *ri)
|
||||
{
|
||||
if(!ri)
|
||||
return(nullptr);
|
||||
|
||||
SceneNode *sn=new SceneNode(mat,ri);
|
||||
|
||||
SubNode.Add(sn);
|
||||
|
Loading…
x
Reference in New Issue
Block a user