Fixed timing

This commit is contained in:
connellpaxton 2024-02-01 11:54:18 -05:00
parent 843899f8b9
commit 48a3749bd5
8 changed files with 17 additions and 13 deletions

View File

@ -36,8 +36,8 @@ Input::Input(INPUT_PTR in) : in(in) {
glfwSetKeyCallback(in, [](GLFWwindow* in, int key, int scancode, int action, int mods) {
int state = (action == GLFW_PRESS || action == GLFW_REPEAT);
static const char* action_strings[] = { "RELEASE", "PRESS", "REPEAT" };
Log::info("Event Received:Key:\"%s\" %s\n", glfwGetKeyName(key, scancode), action_strings[action]);
// static const char* action_strings[] = { "RELEASE", "PRESS", "REPEAT" };
// Log::info("Event Received:Key:\"%s\" %s\n", glfwGetKeyName(key, scancode), action_strings[action]);
Input* input = reinterpret_cast<Input*>(glfwGetWindowUserPointer(in));
InputModifierBit i_mods = eNONE;

View File

@ -320,17 +320,16 @@ void Renderer::draw() {
const auto p = glm::perspective(glm::radians(90.0f), static_cast<float>(sz.width) / static_cast<float>(sz.height), 0.01f, 2000.0f);
const auto t = static_cast<float>(frame) * 0.0167f;
uniform_buffer->upload(UniformData{
.mvp = p * cam.view(),
.time = t,
.time = time,
.aspect_ratio = static_cast<float>(sz.width)/static_cast<float>(sz.height),
});
//command_buffer->draw(std::size(triangle), 1, 0, 0);
command_buffer->command_buffer.drawIndexed(models[0]->indices.size(), 1, 0, 0, 0);
command_buffer->command_buffer.drawIndexed(models[0]->indices.size(), 10, 0, 0, 0);
/*command_buffer->bind(*models[1]->vertex_buffer);
command_buffer->command_buffer.bindIndexBuffer(*models[1]->index_buffer, 0, vk::IndexType::eUint16);
@ -385,6 +384,7 @@ void Renderer::present() {
}
frame++;
time += 0.0167f * speed * static_cast<float>(running);
}
Renderer::~Renderer() {

View File

@ -64,4 +64,8 @@ struct Renderer {
bool capture_mouse = false;
bool flycam = false;
/* time speed */
float time = 0.0;
float speed = 1.0;
bool running = true;
};

View File

@ -12,5 +12,5 @@ layout (set = 0, binding = 0) uniform Matrices {
layout (set = 0, binding = 1) uniform sampler2D tex;
void main() {
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
FragColor = vec4(norm, 1.0);
}

Binary file not shown.

View File

@ -12,8 +12,7 @@ layout (set = 0, binding = 0) uniform Matrices {
};
void main() {
//gl_Position = mvp * vec4(aPos, 1.0);
gl_Position = vec4(aPos, 1.0);
gl_Position = vec4(aPos + (vec3(10.0) * gl_InstanceIndex), 1.0);
texCoord = aTexCoord;
norm = aNorm;
}

Binary file not shown.

View File

@ -21,7 +21,6 @@ int main(int argc, char* argv[]) {
auto in = win.getInput();
Renderer ren(win);
bool paused = false;
while (!in->shouldClose()) {
Timer frame_timer;
in->poll();
@ -63,11 +62,15 @@ int main(int argc, char* argv[]) {
ren.capture_mouse = !ren.capture_mouse;
in->setCursor(!ren.capture_mouse);
} else if (event.key.key == GLFW_KEY_R && event.key.state == GLFW_PRESS) {
ren.frame = 0;
ren.time = 0;
} else if (event.key.key == GLFW_KEY_C && event.key.state == GLFW_PRESS) {
ren.flycam = !ren.flycam;
} else if (event.key.key == GLFW_KEY_P && event.key.state == GLFW_PRESS) {
paused = !paused;
ren.running = !ren.running;
} else if (event.key.key == GLFW_KEY_T && event.key.state == GLFW_PRESS) {
ren.speed *= 10.0;
} else if (event.key.key == GLFW_KEY_Y && event.key.state == GLFW_PRESS) {
ren.speed /= 10.0;
}
break;
}
@ -80,8 +83,6 @@ int main(int argc, char* argv[]) {
while (frame_timer.read() < 16.60)
;
if(paused)
ren.frame -= 1;
}
} catch (const std::string& e) {