Add .clang-format and .gitignore
This commit is contained in:
95
src/input.c
95
src/input.c
@@ -1,9 +1,9 @@
|
||||
#include "main.h"
|
||||
#include <cglm/quat.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cglm/quat.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ANGLE ((float)0x01/0xff*2*GLM_PI)
|
||||
#define ANGLE ((float)0x01 / 0xff * 2 * GLM_PI)
|
||||
|
||||
unsigned char selected_axis = 0;
|
||||
int window_width;
|
||||
@@ -11,8 +11,7 @@ int window_height;
|
||||
|
||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
vec3 axis[3] =
|
||||
{
|
||||
vec3 axis[3] = {
|
||||
{1, 0, 0},
|
||||
{0, 1, 0},
|
||||
{0, 0, 1},
|
||||
@@ -20,61 +19,59 @@ vec3 axis[3] =
|
||||
|
||||
extern struct projection projection;
|
||||
|
||||
void __key_callback_input(GLFWwindow * window, int key, int scancode, int action, int mods )
|
||||
void __key_callback_input(
|
||||
GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if( action != GLFW_PRESS)
|
||||
if (action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
|
||||
if( GLFW_KEY_0<key && key<=GLFW_KEY_9 )
|
||||
if (GLFW_KEY_0 < key && key <= GLFW_KEY_9)
|
||||
{
|
||||
unsigned char selected_coord;
|
||||
|
||||
selected_coord = key-GLFW_KEY_0-1;
|
||||
selected_coord = key - GLFW_KEY_0 - 1;
|
||||
|
||||
if( selected_coord >= projection.m )
|
||||
if (selected_coord >= projection.m)
|
||||
return;
|
||||
if( selected_coord == projection.x )
|
||||
if (selected_coord == projection.x)
|
||||
return;
|
||||
if( selected_coord == projection.y )
|
||||
if (selected_coord == projection.y)
|
||||
return;
|
||||
if( selected_coord == projection.z )
|
||||
if (selected_coord == projection.z)
|
||||
return;
|
||||
|
||||
selected_coord = projection.w;
|
||||
}
|
||||
|
||||
if( projection.w >= projection.m )
|
||||
if (projection.w >= projection.m)
|
||||
return;
|
||||
|
||||
switch( key )
|
||||
switch (key)
|
||||
{
|
||||
unsigned char tmp;
|
||||
unsigned char tmp;
|
||||
|
||||
case GLFW_KEY_P:
|
||||
tmp=projection.w;
|
||||
projection.w=projection.x;
|
||||
projection.x=tmp;
|
||||
tmp = projection.w;
|
||||
projection.w = projection.x;
|
||||
projection.x = tmp;
|
||||
break;
|
||||
case GLFW_KEY_O:
|
||||
tmp=projection.w;
|
||||
projection.w=projection.y;
|
||||
projection.y=tmp;
|
||||
tmp = projection.w;
|
||||
projection.w = projection.y;
|
||||
projection.y = tmp;
|
||||
break;
|
||||
case GLFW_KEY_I:
|
||||
tmp=projection.w;
|
||||
projection.w=projection.z;
|
||||
projection.z=tmp;
|
||||
tmp = projection.w;
|
||||
projection.w = projection.z;
|
||||
projection.z = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
set_projection_mesh( projection );
|
||||
set_projection_mesh(projection);
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void __window_callback_input(GLFWwindow * window, int w, int h)
|
||||
void __window_callback_input(GLFWwindow *window, int w, int h)
|
||||
{
|
||||
int m;
|
||||
|
||||
@@ -85,32 +82,33 @@ void __window_callback_input(GLFWwindow * window, int w, int h)
|
||||
glViewport((w - m) / 2, (h - m) / 2, m, m);
|
||||
}
|
||||
|
||||
void __mouse_callback_input(GLFWwindow* window, int button, int action, int mods)
|
||||
void __mouse_callback_input(
|
||||
GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
unsigned char green_value;
|
||||
double xpos, ypos;
|
||||
|
||||
if( button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS )
|
||||
return;
|
||||
if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
glfwGetCursorPos(window, &xpos, &ypos);
|
||||
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN,
|
||||
glReadPixels((int)xpos, (int)(window_height - ypos), 1, 1, GL_GREEN,
|
||||
GL_UNSIGNED_BYTE, &green_value);
|
||||
|
||||
switch(green_value)
|
||||
switch (green_value)
|
||||
{
|
||||
case 0xD3:
|
||||
case 0xD4:
|
||||
case 0xD5:
|
||||
selected_axis = green_value-0xD3;
|
||||
selected_axis = green_value - 0xD3;
|
||||
}
|
||||
}
|
||||
|
||||
void __scroll_callback_input(GLFWwindow* window, double xoffset, double yoffset)
|
||||
void __scroll_callback_input(GLFWwindow *window, double xoffset, double yoffset)
|
||||
{
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
glm_quatv(p, yoffset*ANGLE, axis[selected_axis]);
|
||||
glm_quatv(p, yoffset * ANGLE, axis[selected_axis]);
|
||||
|
||||
glm_quat_mul(p, q, q);
|
||||
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||
@@ -122,43 +120,42 @@ quat_t poll_input(window_t window)
|
||||
{
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
if( glfwGetKey((GLFWwindow*)window, 'Q') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'Q') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, ANGLE, axis[0]);
|
||||
goto end;
|
||||
}
|
||||
if( glfwGetKey((GLFWwindow*)window, 'W') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'W') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, -ANGLE, axis[0]);
|
||||
goto end;
|
||||
}
|
||||
if( glfwGetKey((GLFWwindow*)window, 'A') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'A') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, ANGLE, axis[1]);
|
||||
goto end;
|
||||
}
|
||||
if( glfwGetKey((GLFWwindow*)window, 'S') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'S') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, -ANGLE, axis[1]);
|
||||
goto end;
|
||||
}
|
||||
if( glfwGetKey((GLFWwindow*)window, 'Z') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'Z') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, ANGLE, axis[2]);
|
||||
goto end;
|
||||
}
|
||||
if( glfwGetKey((GLFWwindow*)window, 'X') == GLFW_PRESS )
|
||||
if (glfwGetKey((GLFWwindow *)window, 'X') == GLFW_PRESS)
|
||||
{
|
||||
glm_quatv(p, -ANGLE, axis[2]);
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
glm_quat_mul( p, q, q );
|
||||
glm_quat_rotatev( p, axis[0], axis[0] );
|
||||
glm_quat_rotatev( p, axis[1], axis[1] );
|
||||
glm_quat_rotatev( p, axis[2], axis[2] );
|
||||
glm_quat_normalize( q );
|
||||
glm_quat_mul(p, q, q);
|
||||
glm_quat_rotatev(p, axis[0], axis[0]);
|
||||
glm_quat_rotatev(p, axis[1], axis[1]);
|
||||
glm_quat_rotatev(p, axis[2], axis[2]);
|
||||
glm_quat_normalize(q);
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user