Add x, y, z keys to change rotation axis
This commit is contained in:
1 parent
f265d3777d
commit
d7d2462835
1 file changed
+36
-3
@@ -21,6 +21,14 @@ static const vertex_t vertices[] = {
|
|||||||
|
|
||||||
static const uint16_t indices[] = { 0, 1, 2, 2, 3, 0 };
|
static const uint16_t indices[] = { 0, 1, 2, 2, 3, 0 };
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
AXIS_X,
|
||||||
|
AXIS_Y,
|
||||||
|
AXIS_Z,
|
||||||
|
} axis_t;
|
||||||
|
|
||||||
|
static axis_t rot_axis = AXIS_Y;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define ID \
|
#define ID \
|
||||||
{ \
|
{ \
|
||||||
@@ -78,11 +86,23 @@ key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
|||||||
(void)scancode;
|
(void)scancode;
|
||||||
(void)mods;
|
(void)mods;
|
||||||
|
|
||||||
|
if (action != GLFW_PRESS)
|
||||||
|
return;
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case GLFW_KEY_Q:
|
case GLFW_KEY_Q:
|
||||||
if (action == GLFW_PRESS)
|
|
||||||
glfwSetWindowShouldClose(window, GL_TRUE);
|
glfwSetWindowShouldClose(window, GL_TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GLFW_KEY_X:
|
||||||
|
rot_axis = AXIS_X;
|
||||||
|
break;
|
||||||
|
case GLFW_KEY_Y:
|
||||||
|
rot_axis = AXIS_Y;
|
||||||
|
break;
|
||||||
|
case GLFW_KEY_Z:
|
||||||
|
rot_axis = AXIS_Z;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,13 +164,26 @@ int main()
|
|||||||
};
|
};
|
||||||
persp(mvp.proj, (float)W / H, M_PI / 6, 0.1, 10.0);
|
persp(mvp.proj, (float)W / H, M_PI / 6, 0.1, 10.0);
|
||||||
|
|
||||||
const mat4_t rot = ROT_Y(M_PI / 128);
|
const mat4_t rotx = ROT_X(M_PI / 128);
|
||||||
|
const mat4_t roty = ROT_Y(M_PI / 128);
|
||||||
|
const mat4_t rotz = ROT_Z(M_PI / 128);
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
mat4_t tmp;
|
mat4_t tmp;
|
||||||
memcpy(tmp, mvp.model, sizeof(mat4_t));
|
memcpy(tmp, mvp.model, sizeof(mat4_t));
|
||||||
mul(mvp.model, rot, tmp);
|
switch (rot_axis) {
|
||||||
|
case AXIS_X:
|
||||||
|
mul(mvp.model, rotx, tmp);
|
||||||
|
break;
|
||||||
|
case AXIS_Y:
|
||||||
|
mul(mvp.model, roty, tmp);
|
||||||
|
break;
|
||||||
|
case AXIS_Z:
|
||||||
|
mul(mvp.model, rotz, tmp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
gpu_render(&gpu, &mvp);
|
gpu_render(&gpu, &mvp);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user