From dcd9359ac46f9c2b31baf1b21885fb5c54b0322b Mon Sep 17 00:00:00 2001 From: Szymon Szczubkowski Date: Wed, 31 Jan 2024 00:53:17 +0100 Subject: [PATCH] make ship movement independent from frames --- cw_8/grk-cw8.vcxproj | 2 ++ cw_8/grk-cw8.vcxproj.filters | 6 ++++++ cw_8/shaders/part.frag | 0 cw_8/shaders/part.vert | 0 cw_8/src/projekt.hpp | 21 ++++++++++++++++++++- cw_8/textures/ship/albedo.png | Bin 24855054 -> 24855054 bytes grk-cw.sln | 6 ------ 7 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 cw_8/shaders/part.frag create mode 100644 cw_8/shaders/part.vert diff --git a/cw_8/grk-cw8.vcxproj b/cw_8/grk-cw8.vcxproj index 5a10a58..d712d67 100644 --- a/cw_8/grk-cw8.vcxproj +++ b/cw_8/grk-cw8.vcxproj @@ -37,6 +37,8 @@ + + diff --git a/cw_8/grk-cw8.vcxproj.filters b/cw_8/grk-cw8.vcxproj.filters index 23c9dba..a93d698 100644 --- a/cw_8/grk-cw8.vcxproj.filters +++ b/cw_8/grk-cw8.vcxproj.filters @@ -103,5 +103,11 @@ Shader Files + + Shader Files + + + Shader Files + \ No newline at end of file diff --git a/cw_8/shaders/part.frag b/cw_8/shaders/part.frag new file mode 100644 index 0000000..e69de29 diff --git a/cw_8/shaders/part.vert b/cw_8/shaders/part.vert new file mode 100644 index 0000000..e69de29 diff --git a/cw_8/src/projekt.hpp b/cw_8/src/projekt.hpp index c3869dd..e714c37 100644 --- a/cw_8/src/projekt.hpp +++ b/cw_8/src/projekt.hpp @@ -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) @@ -331,4 +339,15 @@ glm::mat4 createCameraMatrix() glm::mat4 cameraMatrix = cameraRotrationMatrix * glm::translate(-cameraPos); return cameraMatrix; +} + +void updateDeltaTime(float time) { + if (lastTime < 0) { + lastTime = time; + return; + } + + deltaTime = time - lastTime; + if (deltaTime > 0.1) deltaTime = 0.1; + lastTime = time; } \ No newline at end of file diff --git a/cw_8/textures/ship/albedo.png b/cw_8/textures/ship/albedo.png index 65b8e2de827c6cbdf98776c5f7c3ac443cea349f..68fc99754399a4d058a9a85a3cbc2cd72c7e9deb 100644 GIT binary patch delta 1286 zcmWmA)q)TN00mJNDOp?^=|(!GyFoySp}V_L(n1*(6~ylD?nF%N?(Pok?(4((fSK)E z_7rZ99YYI?b{8vFw7cN+mPNHTBLz}i_L34(Qc6i_DIp$rI|FB7Sd8$No#2%ZKa*GmkzSO zbd*lgS-MD9=_cK!hxC+Q(p&mSU+E|PWq=HnK{8l|$WS>zhRJXlAqUDqGEzp#Xc;33 zA1mWzyiAaZGD#-O6qzd1WV+0dnKDae%N&_2^JKm(kcF~H7RwS@D$8WKtdNzmN>*RX5L2i_r zr^0+)9Ps&sBv^*ov z%5(C(ydW>iOY*Y3BCpD8^18esZ^~Qpw!9|jnNAj_JBA?1<^0|B=U&>eV zwd|2^w=QF7}C{C?6G~VpNLCQ6;KIwb(bRM~$c%wW4;^iMmlQ>PLfU7>%NFG>QG9X*7%G z(IQ$#t7siV z#IP71BjUg~C`QJp7#(Bc|CeK9T#SziF)=2^i+-$ delta 1286 zcmWmA)q)TN00mK&mZcYw?gnX4y1N-tNrG%7}Qc_yVNLkrS%1NP=mkLr*DoJIjB2}eG zs>$9`UG|Y0Qd4S4ZK)%5rJmH62GUR(Nn>duO{JMMmlo1eT1jhZBl}8QX(#QagLITm z(pkDlSJ_YYmu}KsdPq;{CB3DO^p$?nUk1oP86<;chzylsGF(Q;NEs!gWsHoKaWY;K zK0zkRB$+HzWU3q>(`35LkeM<|4wQprw#<=(E4SuQJN zrL2P1aa*13jm&xUFgTyU zC^yN?a*Nz5x5@2thukT5$=$L`?vdScuiPj1%LDSDJR}dxBl4&`CXdS#@}xW^Ps=m% ztUM>r%M0?Nyd*EnEApzmCa=pI@}|5cZ_7LKuDmDj%LnqId?X*sC-SL$CZEd}@}+zw zU&|i(M!uEreQ2BWgyis2z2pZq$qV(I6T|qi7sWqG>dX=FuWr zMyqHYZDQYO8||Wfbcl}8DLO}&=oHGiy diff --git a/grk-cw.sln b/grk-cw.sln index 5351dca..124132f 100644 --- a/grk-cw.sln +++ b/grk-cw.sln @@ -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