Basically what I'm trying to do is rotate a camera around an object in the center when I hold down "c" and use the arrow keys.
My first question doesn't have much to do with the camera, but with having a key callback recognize 2 keys at the same time.
My function DOES work if I have separate if statements for L/R keys and no "c", but I can't get it to work when I only want the camera to rotate when I'm holding down "c". I have tried using switch(key) and if statements within if statements. Both implementations I've tried are in the code below:
float R = 0.0;
float U = 0.0;
static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if(key == GLFW_KEY_C && action == GLFW_PRESS) {
switch(key) {
case GLFW_KEY_RIGHT:
R+=0.05;
camera(R, U);
break;
case GLFW_KEY_LEFT:
R-=0.05;
camera(R, U);
break;
case GLFW_KEY_UP:
break;
case GLFW_KEY_DOWN:
break;
default:
break;
}
}
//OR --
if(key == GLFW_KEY_C && action == GLFW_PRESS) {
if(key == GLFW_KEY_RIGHT && action == GLFW_PRESS) {
R+=0.05;
camera(R, U);
}
}
}
What am I doing wrong? Is there something else I can try?
My second question has more to do with the camera. It rotates fine for a half circle around the object with my current code, but then once it reaches a certain point, the camera just pans farther and farther away from the object, rather than rotating. This is the code for my camera function:
GLfloat ox = 10.0;
GLfloat oy = 10.0;
static void camera(float RL, float UD) {
ox+=cos(glm::radians(RL));
oy+=sin(glm::radians(RL));
gViewMatrix = glm::lookAt(glm::vec3(ox, oy, 10.0f), // eye
glm::vec3(0.0, 0.0, 0.0), // center
glm::vec3(0.0, 1.0, 0.0));
}