Removed binary, made program more hardware-independent, and created gitignore

This commit is contained in:
Mossfet 2024-03-26 00:29:22 +00:00
parent 0e5053b5a8
commit 754776687c
3 changed files with 12 additions and 13 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
VulkanTest

Binary file not shown.

View file

@ -246,10 +246,10 @@ class HelloTriangleApplication {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<float> pos_dist(-0.5, 0.5);
std::uniform_real_distribution<float> speed_dist(0.0f, 0.0001f);
std::uniform_real_distribution<float> speed_dist(0.0f, 0.00001f);
std::uniform_real_distribution<float> size_dist;
if (scenario == 0) {
size_dist = std::uniform_real_distribution(4.0f, 12.0f);
size_dist = std::uniform_real_distribution(4.0f, 40.0f);
} else if (scenario == 1) {
size_dist = std::uniform_real_distribution(-10.0f, 10.0f);
}
@ -265,8 +265,9 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
int64_t startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
glfwPollEvents();
drawFrame();
drawFrame(startTime);
}
vkDeviceWaitIdle(device);
@ -1034,12 +1035,9 @@ class HelloTriangleApplication {
}
}
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<float, std::chrono::seconds::period>(currentTime - startTime).count();
void updateUniformBuffer(uint32_t currentImage, uint64_t startTime) {
uint64_t timeNow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
float dTime = static_cast<float>(startTime - timeNow);
UniformBufferObject ubo{};
int arrayLen = sizeof(ballsArr) / sizeof(ballsArr[0]);
@ -1050,7 +1048,7 @@ class HelloTriangleApplication {
//ballsArr[3] = ballsArr[3] + glm::vec4(0.003f, -0.003f, 0.0f, 0.0f);
for (int i = 0; i < arrayLen; i++) {
ballsArr[i] = ballsArr[i] + glm::vec4(speedArr[i].first, speedArr[i].second, 0.0f, 0.0f) * time;
ballsArr[i] = ballsArr[i] + glm::vec4(speedArr[i].first, speedArr[i].second, 0.0f, 0.0f) * (dTime/1000000000000000000);
}
//ubo.balls = ballsVec;
@ -1069,7 +1067,7 @@ class HelloTriangleApplication {
vkUnmapMemory(device, uniformBuffersMemory[currentImage]);
}
void drawFrame() {
void drawFrame(int64_t startTime) {
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
uint32_t imageIndex;
@ -1082,8 +1080,6 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to acquire swap chain image!");
}
updateUniformBuffer(currentFrame);
vkResetFences(device, 1, &inFlightFences[currentFrame]);
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
@ -1128,6 +1124,8 @@ class HelloTriangleApplication {
throw std::runtime_error("failed to present swap chain image!");
}
updateUniformBuffer(currentFrame, startTime);
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
}