add: gamepad integration
This commit is contained in:
parent
2e26ed7042
commit
64ed0d6551
@ -43,6 +43,8 @@
|
||||
<None Include="shaders\part.vert" />
|
||||
<None Include="shaders\pbr.frag" />
|
||||
<None Include="shaders\pbr.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
<None Include="shaders\shader_skybox.vert" />
|
||||
<None Include="shaders\sun.frag" />
|
||||
<None Include="shaders\sun.vert" />
|
||||
</ItemGroup>
|
||||
@ -58,14 +60,14 @@
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -94,6 +94,8 @@ glm::vec3 spaceshipDir = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
GLFWgamepadstate currentState;
|
||||
|
||||
//declarations of functions
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context);
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
@ -111,7 +113,8 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint a
|
||||
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
if (!glfwJoystickPresent(GLFW_JOYSTICK_1)) {
|
||||
|
||||
if (!glfwJoystickIsGamepad(GLFW_JOYSTICK_1)) {
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
|
||||
@ -124,9 +127,18 @@ void processInput(GLFWwindow* window)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(cameraSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-cameraSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
|
||||
}else if (glfwGetGamepadState(GLFW_JOYSTICK_1, ¤tState)) {
|
||||
if(currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.01)
|
||||
spaceshipPos += deltaTime * 5 * spaceshipDir * currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER];
|
||||
if (currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER] > 0.01)
|
||||
spaceshipPos -= deltaTime * 5 * spaceshipDir * currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER];
|
||||
if (abs(currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_X]) > 0.01)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(deltaTime * -5 * currentState.axes[GLFW_GAMEPAD_AXIS_LEFT_X]) * glm::vec4(spaceshipDir, 0));
|
||||
if (abs(currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]) > 0.01)
|
||||
spaceshipDir.y = currentState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]/3;
|
||||
}
|
||||
|
||||
|
||||
std::cout << glm::to_string(spaceshipDir) << std::endl;
|
||||
cameraDir = spaceshipDir;
|
||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.05f;
|
||||
}
|
||||
@ -201,8 +213,6 @@ void drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint text
|
||||
Core::DrawContext(context);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user