TerraForge3D  2.3.1
3D Terrain And Landscape Generator
ExplorerControls.cpp
1#include "Misc/ExplorerControls.h"
2
3#include "Base/Application.h"
4
5#include <Utils.h>
6#include <GLFW/glfw3.h>
7
8static float cpos[3], crot[3];
9
10static glm::vec2 mosePos(0.0f);
11
12void SetupExplorerControls()
13{
14 double x, y;
15 glfwGetCursorPos(Application::Get()->GetWindow()->GetNativeWindow(), &x, &y);
16 mosePos.x = (float)x;
17 mosePos.y = (float)y;
18}
19
20void UpdateExplorerControls(float *pos, float *rot, bool isIEx, float *xO, float *yO)
21{
22 double x, y;
23 glfwGetCursorPos(Application::Get()->GetWindow()->GetNativeWindow(), &x, &y);
24 float dX = (float)x - mosePos.x;
25 float dY = (float)y - mosePos.y;
26 mosePos.x = (float)x;
27 mosePos.y = (float)y;
28 rot[0] += dX * 10.0f;
29 rot[1] += dY * 10.0f;
30 static float movementSpeed = 0.001f;
31
32 if (glfwGetKey(Application::Get()->GetWindow()->GetNativeWindow(), GLFW_KEY_W))
33 {
34 glm::vec3 pPos = glm::vec3(pos[0], pos[1], pos[2]);
35 float dist = pPos.y * pPos.y+ 10;
36 pPos += glm::vec3(0.0f, 0.0f, -1.0f) * dist * movementSpeed;
37 pos[0] = pPos.x;
38 pos[1] = pPos.y;
39 pos[2] = pPos.z;
40 }
41
42 if (glfwGetKey(Application::Get()->GetWindow()->GetNativeWindow(), GLFW_KEY_S))
43 {
44 glm::vec3 pPos = glm::vec3(pos[0], pos[1], pos[2]);
45 float dist = pPos.y * pPos.y+ 10;
46 pPos -= glm::vec3(0.0f, 0.0f, -1.0f) * dist * movementSpeed;
47 pos[0] = pPos.x;
48 pos[1] = pPos.y;
49 pos[2] = pPos.z;
50 }
51
52 if (glfwGetKey(Application::Get()->GetWindow()->GetNativeWindow(), GLFW_KEY_A))
53 {
54 glm::vec3 pPos = glm::vec3(pos[0], pos[1], pos[2]);
55 float dist = pPos.y * pPos.y+ 10;
56 pPos -= glm::vec3(1.0f, 0.0f, 0.0f) * dist * movementSpeed;
57 pos[0] = pPos.x;
58 pos[1] = pPos.y;
59 pos[2] = pPos.z;
60 }
61
62 if (glfwGetKey(Application::Get()->GetWindow()->GetNativeWindow(), GLFW_KEY_D))
63 {
64 glm::vec3 pPos = glm::vec3(pos[0], pos[1], pos[2]);
65 float dist = pPos.y * pPos.y+ 10;
66 pPos += glm::vec3(1.0f, 0.0f, 0.0f) * dist * movementSpeed;
67 pos[0] = pPos.x;
68 pos[1] = pPos.y;
69 pos[2] = pPos.z;
70 }
71}
72
73void ExPRestoreCamera(float *pos, float *rot)
74{
75 pos[0] = cpos[0];
76 pos[1] = cpos[1];
77 pos[2] = cpos[2];
78 rot[0] = crot[0];
79 rot[1] = crot[1];
80 rot[2] = crot[2];
81}
82
83void ExPSaveCamera(float *pos, float *rot)
84{
85 cpos[0] = pos[0];
86 cpos[1] = pos[1];
87 cpos[2] = pos[2];
88 crot[0] = rot[0];
89 crot[1] = rot[1];
90 crot[2] = rot[2];
91}