make ship movement independent from frames
This commit is contained in:
parent
a82556f390
commit
dcd9359ac4
@ -37,6 +37,8 @@
|
||||
<ClInclude Include="src\Texture.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\part.frag" />
|
||||
<None Include="shaders\part.vert" />
|
||||
<None Include="shaders\pbr.frag" />
|
||||
<None Include="shaders\pbr.vert" />
|
||||
<None Include="shaders\sun.frag" />
|
||||
|
@ -103,5 +103,11 @@
|
||||
<None Include="shaders\sun.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\part.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\part.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
0
cw_8/shaders/part.frag
Normal file
0
cw_8/shaders/part.frag
Normal file
0
cw_8/shaders/part.vert
Normal file
0
cw_8/shaders/part.vert
Normal file
@ -12,6 +12,7 @@
|
||||
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programParticle;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
@ -82,12 +83,17 @@ glm::vec3 cameraDir;
|
||||
glm::vec3 spaceshipPos = glm::vec3(-4.0f, 0.0f, 0.0f);
|
||||
glm::vec3 spaceshipDir = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
//declarations of functions
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context);
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
void processInput(GLFWwindow* window);
|
||||
void shutdown(GLFWwindow* window);
|
||||
|
||||
void updateDeltaTime(float time);
|
||||
|
||||
glm::mat4 createPerspectiveMatrix();
|
||||
glm::mat4 createCameraMatrix();
|
||||
|
||||
@ -102,6 +108,7 @@ void init(GLFWwindow* window)
|
||||
|
||||
program = shaderLoader.CreateProgram("shaders/pbr.vert", "shaders/pbr.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/sun.vert", "shaders/sun.frag");
|
||||
//programParticle = shaderLoader.CreateProgram("shaders/part.vert", "shaders/part.frag");
|
||||
|
||||
//load models here
|
||||
|
||||
@ -168,6 +175,7 @@ void renderScene(GLFWwindow* window){
|
||||
glUseProgram(program);
|
||||
|
||||
float time = glfwGetTime();
|
||||
updateDeltaTime(time);
|
||||
|
||||
//desired objects go here
|
||||
drawObjectSun(sunContext, glm::scale(glm::vec3(0.1f)) * glm::eulerAngleY(time/10));
|
||||
@ -208,7 +216,7 @@ void processInput(GLFWwindow* window)
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
|
||||
float cameraSpeed = 0.1f;
|
||||
float cameraSpeed = 0.1f * deltaTime * 30;
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
spaceshipPos += cameraSpeed * spaceshipDir;
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
@ -332,3 +340,14 @@ glm::mat4 createCameraMatrix()
|
||||
|
||||
return cameraMatrix;
|
||||
}
|
||||
|
||||
void updateDeltaTime(float time) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = time;
|
||||
return;
|
||||
}
|
||||
|
||||
deltaTime = time - lastTime;
|
||||
if (deltaTime > 0.1) deltaTime = 0.1;
|
||||
lastTime = time;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 24 MiB After Width: | Height: | Size: 24 MiB |
@ -5,8 +5,6 @@ VisualStudioVersion = 17.1.32319.34
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw8", "cw_8\grk-cw8.vcxproj", "{6D813233-7D21-4888-944E-8E3CCAC3EFD3}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grk-cw4", "..\cw 4\grk-cw4.vcxproj", "{D7858112-9412-4E7E-AB73-A911604592EC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
@ -17,10 +15,6 @@ Global
|
||||
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Debug|x86.Build.0 = Debug|Win32
|
||||
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.ActiveCfg = Release|Win32
|
||||
{6D813233-7D21-4888-944E-8E3CCAC3EFD3}.Release|x86.Build.0 = Release|Win32
|
||||
{D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{D7858112-9412-4E7E-AB73-A911604592EC}.Debug|x86.Build.0 = Debug|Win32
|
||||
{D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.ActiveCfg = Release|Win32
|
||||
{D7858112-9412-4E7E-AB73-A911604592EC}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user