Fixed timing
This commit is contained in:
parent
843899f8b9
commit
48a3749bd5
@ -36,8 +36,8 @@ Input::Input(INPUT_PTR in) : in(in) {
|
|||||||
|
|
||||||
glfwSetKeyCallback(in, [](GLFWwindow* in, int key, int scancode, int action, int mods) {
|
glfwSetKeyCallback(in, [](GLFWwindow* in, int key, int scancode, int action, int mods) {
|
||||||
int state = (action == GLFW_PRESS || action == GLFW_REPEAT);
|
int state = (action == GLFW_PRESS || action == GLFW_REPEAT);
|
||||||
static const char* action_strings[] = { "RELEASE", "PRESS", "REPEAT" };
|
// static const char* action_strings[] = { "RELEASE", "PRESS", "REPEAT" };
|
||||||
Log::info("Event Received:Key:\"%s\" %s\n", glfwGetKeyName(key, scancode), action_strings[action]);
|
// Log::info("Event Received:Key:\"%s\" %s\n", glfwGetKeyName(key, scancode), action_strings[action]);
|
||||||
Input* input = reinterpret_cast<Input*>(glfwGetWindowUserPointer(in));
|
Input* input = reinterpret_cast<Input*>(glfwGetWindowUserPointer(in));
|
||||||
InputModifierBit i_mods = eNONE;
|
InputModifierBit i_mods = eNONE;
|
||||||
|
|
||||||
|
|||||||
@ -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 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{
|
uniform_buffer->upload(UniformData{
|
||||||
.mvp = p * cam.view(),
|
.mvp = p * cam.view(),
|
||||||
.time = t,
|
.time = time,
|
||||||
.aspect_ratio = static_cast<float>(sz.width)/static_cast<float>(sz.height),
|
.aspect_ratio = static_cast<float>(sz.width)/static_cast<float>(sz.height),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//command_buffer->draw(std::size(triangle), 1, 0, 0);
|
//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->bind(*models[1]->vertex_buffer);
|
||||||
command_buffer->command_buffer.bindIndexBuffer(*models[1]->index_buffer, 0, vk::IndexType::eUint16);
|
command_buffer->command_buffer.bindIndexBuffer(*models[1]->index_buffer, 0, vk::IndexType::eUint16);
|
||||||
@ -385,6 +384,7 @@ void Renderer::present() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
frame++;
|
frame++;
|
||||||
|
time += 0.0167f * speed * static_cast<float>(running);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer() {
|
Renderer::~Renderer() {
|
||||||
|
|||||||
@ -64,4 +64,8 @@ struct Renderer {
|
|||||||
|
|
||||||
bool capture_mouse = false;
|
bool capture_mouse = false;
|
||||||
bool flycam = false;
|
bool flycam = false;
|
||||||
|
/* time speed */
|
||||||
|
float time = 0.0;
|
||||||
|
float speed = 1.0;
|
||||||
|
bool running = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -12,5 +12,5 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||||||
layout (set = 0, binding = 1) uniform sampler2D tex;
|
layout (set = 0, binding = 1) uniform sampler2D tex;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
FragColor = vec4(norm, 1.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -12,8 +12,7 @@ layout (set = 0, binding = 0) uniform Matrices {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
//gl_Position = mvp * vec4(aPos, 1.0);
|
gl_Position = vec4(aPos + (vec3(10.0) * gl_InstanceIndex), 1.0);
|
||||||
gl_Position = vec4(aPos, 1.0);
|
|
||||||
texCoord = aTexCoord;
|
texCoord = aTexCoord;
|
||||||
norm = aNorm;
|
norm = aNorm;
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -21,7 +21,6 @@ int main(int argc, char* argv[]) {
|
|||||||
auto in = win.getInput();
|
auto in = win.getInput();
|
||||||
Renderer ren(win);
|
Renderer ren(win);
|
||||||
|
|
||||||
bool paused = false;
|
|
||||||
while (!in->shouldClose()) {
|
while (!in->shouldClose()) {
|
||||||
Timer frame_timer;
|
Timer frame_timer;
|
||||||
in->poll();
|
in->poll();
|
||||||
@ -63,11 +62,15 @@ int main(int argc, char* argv[]) {
|
|||||||
ren.capture_mouse = !ren.capture_mouse;
|
ren.capture_mouse = !ren.capture_mouse;
|
||||||
in->setCursor(!ren.capture_mouse);
|
in->setCursor(!ren.capture_mouse);
|
||||||
} else if (event.key.key == GLFW_KEY_R && event.key.state == GLFW_PRESS) {
|
} 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) {
|
} else if (event.key.key == GLFW_KEY_C && event.key.state == GLFW_PRESS) {
|
||||||
ren.flycam = !ren.flycam;
|
ren.flycam = !ren.flycam;
|
||||||
} else if (event.key.key == GLFW_KEY_P && event.key.state == GLFW_PRESS) {
|
} 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;
|
break;
|
||||||
}
|
}
|
||||||
@ -80,8 +83,6 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
while (frame_timer.read() < 16.60)
|
while (frame_timer.read() < 16.60)
|
||||||
;
|
;
|
||||||
if(paused)
|
|
||||||
ren.frame -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (const std::string& e) {
|
} catch (const std::string& e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user