From 057a6e2bd06a4419d0d9ce03b861fff4e160141e Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 11 Mar 2022 19:13:20 +0800 Subject: [PATCH] updated CameraControl's codes. --- CMSceneGraph | 2 +- example/Vulkan/OffscreenRender.cpp | 25 +++++----------------- example/common/VulkanAppFramework.h | 32 ++++++++++++++++++++++------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CMSceneGraph b/CMSceneGraph index 846113e0..40d54352 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 846113e0fbb9f354300c21052c2c4ff0440c6dc6 +Subproject commit 40d5435239ad76d46223bd73e73c58f0332d0ed7 diff --git a/example/Vulkan/OffscreenRender.cpp b/example/Vulkan/OffscreenRender.cpp index fa62f461..c6fd1c0f 100644 --- a/example/Vulkan/OffscreenRender.cpp +++ b/example/Vulkan/OffscreenRender.cpp @@ -70,17 +70,8 @@ public: if(!ro->ubo_camera_info) return(false); - - { - MaterialParameters *mp_global=ro->material_instance->GetMP(DescriptorSetsType::Global); - - if(!mp_global) - return(false); - if(!mp_global->BindUBO("g_camera",ro->ubo_camera_info))return(false); - - mp_global->Update(); - } + BindCameraUBO(ro->material_instance); return(true); } @@ -142,20 +133,14 @@ public: cube.sampler=db->CreateSampler(); if(!cube.sampler)return(false); - { - MaterialParameters *mp_texture=cube.material_instance->GetMP(DescriptorSetsType::Value); - - if(!mp_texture) - return(false); - - if(!mp_texture->BindSampler("tex",os.render_taget->GetColorTexture(),cube.sampler))return(false); - - mp_texture->Update(); - } + if(!cube.material_instance->BindSampler(DescriptorSetsType::Value,"tex",os.render_taget->GetColorTexture(),cube.sampler)) + return(false); { CubeCreateInfo cci; + cci.tex_coord=true; + Renderable *render_obj=CreateRenderableCube(db,cube.material_instance->GetVAB(),&cci); if(!render_obj)return(false); diff --git a/example/common/VulkanAppFramework.h b/example/common/VulkanAppFramework.h index 7d138508..4ac8135c 100644 --- a/example/common/VulkanAppFramework.h +++ b/example/common/VulkanAppFramework.h @@ -394,6 +394,15 @@ protected: return(true); } + + bool OnWheel(int,int y) override + { + if(y==0)return(false); + + camera->Forward(float(y)/10.0f); + + return(true); + } bool OnMove(int x,int y) override { @@ -402,17 +411,26 @@ protected: bool left=HasPressed(MouseButton::Left); bool right=HasPressed(MouseButton::Right); - - if(left||right) + + Vector2f pos(x,y); + Vector2f gap=pos-mouse_last_pos; + + if(left) { - Vector2f pos(x,y); - Vector2f gap=pos-mouse_last_pos; + gap/=-5.0f; camera->Rotate(gap); - - last_time=cur_time; - mouse_last_pos=Vector2f(x,y); } + else + if(right) + { + gap/=10.0f; + + camera->Move(Vector3f(gap.x,0,gap.y)); + } + + last_time=cur_time; + mouse_last_pos=Vector2f(x,y); return(true); }