구현사항
- 헬리콥터의 이동
- 마우스 드래그에 따라 헬리콥터의 방향이 회전됨
- wasd 입력에 따라 헬리콥터가 원하는 방향으로 움직임
- enter키를 누르면 헬리콥터의 날개가 회전/정지함
- q/e 키를 누르면 헬리콥터가 상승/하강함
- 쉐이더 레벨
구현방식
void computeMouseRotates() {
static double lastTime = glfwGetTime();
double currentTime = glfwGetTime();
float deltaTime = float(currentTime - lastTime);
glfwGetCursorPos(window, &xpos, &ypos);
horizontalAngle = 0.0;
verticalAngle = 0.0;
if (xpos < xpos_prev)
horizontalAngle = -deltaTime * mouseSpeed;
else if (xpos > xpos_prev)
horizontalAngle = deltaTime * mouseSpeed;
else
horizontalAngle = 0.0;
if (ypos < ypos_prev)
verticalAngle = -deltaTime * mouseSpeed;
else if (ypos > ypos_prev)
verticalAngle = deltaTime * mouseSpeed;
else
verticalAngle = 0.0;
G_ModelMatrix *= glm::eulerAngleYXZ(horizontalAngle, verticalAngle, 0.0f);
xpos_prev = xpos;
ypos_prev = ypos;
lastTime = currentTime;
}
void computeKeyboardTranslates(bool &isPropellerRotating)
{
static double lastTime = glfwGetTime();
double currentTime = glfwGetTime();
float deltaTime = float(currentTime - lastTime);
glm::vec3 right = glm::vec3(0.0f, 0.0f, -1.0f);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 forward = glm::vec3(-1.0f, 0.0f, 0.0f);
glm::vec3 translateFactor = glm::vec3(0.0f);
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) {
if (!isPropellerRotating) return;
translateFactor += up * deltaTime * speed;
currHeight++;
}
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS && currHeight >= 0) {
if (currHeight < boundary && !isPropellerRotating) return;
translateFactor -= up * deltaTime * speed;
currHeight--;
}
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS && currHeight >= boundary) {
translateFactor += right * deltaTime * speed;
}
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS && currHeight >= boundary) {
translateFactor -= right * deltaTime * speed;
}
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS && currHeight >= boundary) {
translateFactor += forward * deltaTime * speed;
}
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS && currHeight >= boundary) {
translateFactor -= forward * deltaTime * speed;
}
G_ModelMatrix *= glm::translate(glm::mat4(1.0f), translateFactor);
if (glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) {
if (currHeight > boundary)
isPropellerRotating;
else
isPropellerRotating = !isPropellerRotating;
}
if (isPropellerRotating == false)
{
}
else {
gOrientation += 3.14159f * deltaTime * rotSpeed;
G_RotateWingMatrix = eulerAngleYXZ(gOrientation, 0.0f, 0.0f);
}
lastTime = currentTime;
}
float ambientStrength = 0.5;
vec3 ambient = ambientStrength * objectColor;
float diffuseStrength = 0.5;
vec3 norm = normalize(normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diffuseStrength * diff * objectColor;
float specularStrength = 0.5;
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 7);
vec3 specular = specularStrength * spec * objectColor;
vec3 result = (ambient + diffuse + specular);