完成mvp 矩阵,和shader
This commit is contained in:
@@ -594,6 +594,7 @@ void TextureLoading::draw()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
std::unique_lock<std::mutex> lock_point(mtx_point);
|
||||
std::unique_lock<std::mutex> lock_mvp(mtx_mvp);
|
||||
ApiVulkanSample::prepare_frame();
|
||||
|
||||
// --- 新增:在命令缓冲区中绘制点云 ---
|
||||
@@ -901,18 +902,40 @@ void TextureLoading::prepare_uniform_buffers_point()
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||
VMA_MEMORY_USAGE_CPU_TO_GPU);
|
||||
|
||||
update_uniform_buffers_point();
|
||||
update_uniform_buffers_point(60, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 2);
|
||||
}
|
||||
|
||||
void TextureLoading::update_uniform_buffers_point()
|
||||
{
|
||||
ubo_vs_point.projection = glm::perspective(glm::radians(60.0f), static_cast<float>(width) / static_cast<float>(height), 0.001f, 256.0f);
|
||||
glm::mat4 view_matrix = glm::translate(glm::mat4(1.0f), camear_pos_point);
|
||||
|
||||
ubo_vs_point.model = view_matrix * glm::translate(glm::mat4(1.0f), face_pos_point);
|
||||
ubo_vs_point.model = glm::rotate(ubo_vs_point.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
ubo_vs_point.model = glm::rotate(ubo_vs_point.model, glm::radians(rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
ubo_vs_point.model = glm::rotate(ubo_vs_point.model, glm::radians(rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
void global_update_mvp(float fov, float x, float y, float z, float sx, float sy, float sz, float rotx, float roty, float rotz, float camx, float camy, float camz)
|
||||
{
|
||||
TextureLoading::Get()->update_uniform_buffers_point(fov, x, y, z, sx, sy, sz, rotx, roty, rotz, camx, camy, camz);
|
||||
}
|
||||
|
||||
void TextureLoading::update_uniform_buffers_point(float fov, float x, float y, float z, float sx, float sy, float sz, float rotx, float roty, float rotz, float camx, float camy, float camz)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx_mvp);
|
||||
ubo_vs_point.projection = glm::perspective(glm::radians(fov), static_cast<float>(width) / static_cast<float>(height), 0.001f, 256.0f);
|
||||
|
||||
//glm::vec3 cameraPos = glm::vec3(camx, camy, camz);
|
||||
//glm::vec3 cameraTarget = glm::vec3(0, 0, 0);
|
||||
//glm::vec3 cameraUp = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
//ubo_vs_point.view = glm::lookAt(cameraPos, cameraTarget, cameraUp);
|
||||
|
||||
ubo_vs_point.view = glm::translate(glm::mat4(1.0f), glm::vec3(camx, camy, camz));
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f); // 单位矩阵
|
||||
|
||||
// 1. 先平移
|
||||
model = glm::translate(model, glm::vec3(x, y, z));
|
||||
|
||||
// 2. 然后旋转(注意顺序:通常Z->Y->X或按需求)
|
||||
model = glm::rotate(model, glm::radians(rotz), glm::vec3(0.0f, 0.0f, 1.0f)); // Z轴旋转
|
||||
model = glm::rotate(model, glm::radians(roty), glm::vec3(0.0f, 1.0f, 0.0f)); // Y轴旋转
|
||||
model = glm::rotate(model, glm::radians(rotx), glm::vec3(1.0f, 0.0f, 0.0f)); // X轴旋转
|
||||
|
||||
// 3. 最后缩放
|
||||
model = glm::scale(model, glm::vec3(sx, sy, sz));
|
||||
ubo_vs_point.model = model;
|
||||
|
||||
uniform_buffer_vs_point->convert_and_update(ubo_vs_point);
|
||||
}
|
||||
@@ -1220,11 +1243,15 @@ bool TextureLoading::prepare(const vkb::ApplicationOptions& options)
|
||||
prepare_pipeline_bg();
|
||||
prepare_pipeline_point();
|
||||
|
||||
float z = 0.1f;
|
||||
float z = -2.0f;
|
||||
float testPoint[] = {
|
||||
1,1,z,
|
||||
0,0,z,
|
||||
0.05,0.05,z,
|
||||
0.1,0.1,z,
|
||||
0.2,0.2,z,
|
||||
0.3,0.3,z,
|
||||
0.5,0.5,z,
|
||||
1,1,z,
|
||||
};
|
||||
int pointCount = sizeof(testPoint) / (3*4);
|
||||
update_point_vertex_buffer(testPoint, pointCount);
|
||||
@@ -1281,7 +1308,6 @@ void TextureLoading::render(float delta_time)
|
||||
void TextureLoading::view_changed()
|
||||
{
|
||||
update_uniform_buffers();
|
||||
update_uniform_buffers_point();
|
||||
}
|
||||
|
||||
void TextureLoading::on_update_ui_overlay(vkb::Drawer& drawer)
|
||||
|
||||
Reference in New Issue
Block a user