Код: Выделить всё
void updateUniformBuffer(uint32_t currentImage) {
static auto startTime = std::chrono::high_resolution_clock::now();
auto currentTime = std::chrono::high_resolution_clock::now();
float time = std::chrono::duration(currentTime - startTime).count();
glm::quat mockOriginData(1,0,0,0);
// Quaternion data
motionPacket packetData = *getRecentQuaternionData();
glm::quat q(packetData.orientData.qw, packetData.orientData.qy, packetData.orientData.qx, packetData.orientData.qz); //yxz ~kind of working. -> nvm.
glm::normalize(q);
UniformBufferObject ubo{};
// -> Take the existing quaternion and transform it to match sword standards
ubo.model = glm::mat4_cast(glm::inverse(mockOriginData) * q);
// View transofrmation to look at the geometry from 45 deg. above
// -> params: eye position, center position, and up axis (2,2,2 makes equilateral triangle so deg. is 45)
ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
// Projection transformation with 45 deg. FOV
// -> params: FOV angle, aspect ratio, near and far view planes
ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float)swapChainExtent.height, 0.1f, 10.0f);
// Invert Y coordinate as GLm was designed for OpenGL.
ubo.proj[1][1] *= -1;
// Now copy data from uniform buffer object to the uniform buffer; better to use push constants tho :(
memcpy(uniformBuffersMapped[currentImage], &ubo, sizeof(ubo));
}
Но я не знаю, как это сделать: (
Подробнее здесь: https://stackoverflow.com/questions/796 ... ent-rotati