adding fov and speed control wheel
This commit is contained in:
parent
08d0e691fb
commit
9da5a33893
3 changed files with 34 additions and 10 deletions
34
main.c
34
main.c
|
@ -8,15 +8,17 @@
|
||||||
#include "./Libraries/stb/stb_image.h"
|
#include "./Libraries/stb/stb_image.h"
|
||||||
#include "headers/shader.h"
|
#include "headers/shader.h"
|
||||||
#define FULLSCREEN 0
|
#define FULLSCREEN 0
|
||||||
|
#define EXPERIMENTAL_FEATURES 1
|
||||||
/* ## DEBUG MODE ##
|
/* ## DEBUG MODE ##
|
||||||
* 0 for all
|
* 0 for all
|
||||||
* 1 for nothing
|
* 1 for nothing
|
||||||
* 2 for FPS
|
* 2 for FPS
|
||||||
* 3 for cursor position
|
* 3 for cursor position
|
||||||
|
* 5 for scroll level and precision
|
||||||
*
|
*
|
||||||
* For instance if you want fps and position set the value to 2*3=6
|
* For instance if you want fps and position set the value to 2*3=6
|
||||||
*/
|
*/
|
||||||
#define DEBUG_MODE 3
|
#define DEBUG_MODE 5
|
||||||
|
|
||||||
GLuint screenWidth = 720, screenHeight = 480;
|
GLuint screenWidth = 720, screenHeight = 480;
|
||||||
const GLFWvidmode* mode;
|
const GLFWvidmode* mode;
|
||||||
|
@ -29,11 +31,12 @@ void setupVAO();
|
||||||
unsigned int VAO;
|
unsigned int VAO;
|
||||||
|
|
||||||
float currentTime, deltaTime, lastFrame,startTime;
|
float currentTime, deltaTime, lastFrame,startTime;
|
||||||
float mousePosX,mousePosY,camPosX,camPosY,camPosZ,camDirX,camDirY,camDirZ;
|
float mousePosX,mousePosY,camPosX,camPosY,camPosZ;
|
||||||
|
float fovValue=1.0;
|
||||||
//283=3.14/2 * 180
|
//283=3.14/2 * 180
|
||||||
const int maxYmouse = 283;
|
const int maxYmouse = 283;
|
||||||
// more precision means less speed
|
// more precision means less speed
|
||||||
const int camPrecision = 2;
|
float camPrecision = 2.;
|
||||||
|
|
||||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +62,27 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
||||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
|
{
|
||||||
|
int stateControl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL);
|
||||||
|
|
||||||
|
// we only use yoffset as it is present on normal mice
|
||||||
|
if (DEBUG_MODE % 5 == 0)
|
||||||
|
printf("scroll value : %f | precision : %f | ",yoffset, camPrecision);
|
||||||
|
printf((stateControl == GLFW_PRESS) ? "ctrl -> speed" : "Zooming");
|
||||||
|
printf("\n");
|
||||||
|
if (stateControl == GLFW_PRESS) {
|
||||||
|
camPrecision += yoffset/2;
|
||||||
|
if (camPrecision <= 1)
|
||||||
|
camPrecision=1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fovValue += yoffset/5;
|
||||||
|
if (fovValue <= 0.2 && EXPERIMENTAL_FEATURES == 0)
|
||||||
|
fovValue=0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
|
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
{
|
{
|
||||||
|
@ -136,6 +160,7 @@ int main (){
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(window, key_callback);
|
||||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
glfwSetScrollCallback(window, scroll_callback);
|
||||||
|
|
||||||
GLFWimage images[1];
|
GLFWimage images[1];
|
||||||
images[0].pixels = stbi_load("./assets/icon.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
images[0].pixels = stbi_load("./assets/icon.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
||||||
|
@ -177,8 +202,7 @@ int main (){
|
||||||
glUniform1f(glGetUniformLocation(quad_shader, "iTime"), currentTime-startTime);
|
glUniform1f(glGetUniformLocation(quad_shader, "iTime"), currentTime-startTime);
|
||||||
glUniform2f(glGetUniformLocation(quad_shader, "iMousePos"), mousePosX,mousePosY);
|
glUniform2f(glGetUniformLocation(quad_shader, "iMousePos"), mousePosX,mousePosY);
|
||||||
glUniform3f(glGetUniformLocation(quad_shader, "iCamPos"), camPosX,camPosY,camPosZ);
|
glUniform3f(glGetUniformLocation(quad_shader, "iCamPos"), camPosX,camPosY,camPosZ);
|
||||||
glUniform3f(glGetUniformLocation(quad_shader, "iCamDir"), camDirX,camDirY,camDirZ);
|
glUniform1f(glGetUniformLocation(quad_shader, "iFovValue"), fovValue);
|
||||||
|
|
||||||
// glBindVertexArray(0); // no need to unbind it every time
|
// glBindVertexArray(0); // no need to unbind it every time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ out vec2 FragCoord;
|
||||||
out float Time;
|
out float Time;
|
||||||
out vec2 MousePos;
|
out vec2 MousePos;
|
||||||
out vec3 CamPos;
|
out vec3 CamPos;
|
||||||
out vec3 CamDir;
|
out float fovValue;
|
||||||
|
|
||||||
uniform float iTime;
|
uniform float iTime;
|
||||||
uniform vec2 iMousePos;
|
uniform vec2 iMousePos;
|
||||||
uniform vec3 iCamPos;
|
uniform vec3 iCamPos;
|
||||||
uniform vec3 iCamDir;
|
uniform float iFovValue;
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
@ -22,5 +22,5 @@ void main()
|
||||||
Time=iTime;
|
Time=iTime;
|
||||||
MousePos = iMousePos;
|
MousePos = iMousePos;
|
||||||
CamPos = iCamPos;
|
CamPos = iCamPos;
|
||||||
CamDir = iCamDir;
|
fovValue = iFovValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ in vec2 FragCoord;
|
||||||
in float Time;
|
in float Time;
|
||||||
in vec2 MousePos;
|
in vec2 MousePos;
|
||||||
in vec3 CamPos;
|
in vec3 CamPos;
|
||||||
in vec3 CamDir;
|
in float fovValue;
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
//uniform sampler2D generalTexture;
|
//uniform sampler2D generalTexture;
|
||||||
|
@ -101,7 +101,7 @@ void main(){
|
||||||
vec3 ex = normalize(cross(ez,vec3(0.,1.,0.)));
|
vec3 ex = normalize(cross(ez,vec3(0.,1.,0.)));
|
||||||
vec3 ey = cross(ex,ez);
|
vec3 ey = cross(ex,ez);
|
||||||
|
|
||||||
vec3 dir = normalize(FragCoord.x * ex + FragCoord.y*ey + 1.*ez);
|
vec3 dir = normalize(FragCoord.x * ex + FragCoord.y*ey + fovValue*ez);
|
||||||
|
|
||||||
|
|
||||||
//float c=Mandel(FragCoord*1.5);
|
//float c=Mandel(FragCoord*1.5);
|
||||||
|
|
Loading…
Reference in a new issue