moving ex ey ez to main c
This commit is contained in:
parent
a04cf1236d
commit
3fa0ae660c
3 changed files with 42 additions and 11 deletions
25
main.c
25
main.c
|
@ -38,6 +38,16 @@ const int maxYmouse = 283;
|
|||
// more precision means less speed
|
||||
float camPrecision = 2.;
|
||||
|
||||
/*float[3] crossProduct(float vect_A[3], float vect_B[3])
|
||||
|
||||
{
|
||||
float cross_P[3];
|
||||
cross_P[0] = vect_A[1] * vect_B[2] - vect_A[2] * vect_B[1];
|
||||
cross_P[1] = vect_A[2] * vect_B[0] - vect_A[0] * vect_B[2];
|
||||
cross_P[2] = vect_A[0] * vect_B[1] - vect_A[1] * vect_B[0];
|
||||
return cross_P;
|
||||
}*/
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (!action == GLFW_PRESS)
|
||||
|
@ -183,6 +193,17 @@ int main (){
|
|||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
continue;
|
||||
}
|
||||
|
||||
float pan=-mousePosX/180.;
|
||||
float tilt=-mousePosY/180.;
|
||||
float ez[3] = {cos(tilt)*sin(pan),sin(tilt),cos(tilt)*cos(pan)};//normalize(lookingAt-posCam);////base orthonormée
|
||||
float ex[3] = {-ez[2],0,ez[0]};//crossProduct(ez,{0.,1.,0.});
|
||||
float ey[3] = {
|
||||
ex[1] * ez[2] - ex[2] * ez[1],
|
||||
ex[2] * ez[0] - ex[0] * ez[2],
|
||||
ex[0] * ez[1] - ex[1] * ez[0]
|
||||
};//crossProduct(ex,ez);
|
||||
|
||||
currentTime = glfwGetTime();
|
||||
deltaTime = currentTime - lastFrame;
|
||||
lastFrame = currentTime;
|
||||
|
@ -200,7 +221,9 @@ int main (){
|
|||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
glUniform1f(glGetUniformLocation(quad_shader, "iTime"), currentTime-startTime);
|
||||
glUniform2f(glGetUniformLocation(quad_shader, "iMousePos"), mousePosX,mousePosY);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iEx"), ex[0],ex[1],ex[2]);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iEy"), ey[0],ey[1],ey[2]);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iEz"), ez[0],ez[1],ez[2]);
|
||||
glUniform3f(glGetUniformLocation(quad_shader, "iCamPos"), camPosX,camPosY,camPosZ);
|
||||
glUniform1f(glGetUniformLocation(quad_shader, "iFovValue"), fovValue);
|
||||
// glBindVertexArray(0); // no need to unbind it every time
|
||||
|
|
|
@ -5,12 +5,16 @@ layout (location = 2) in vec2 texCoord;
|
|||
|
||||
out vec2 FragCoord;
|
||||
out float Time;
|
||||
out vec2 MousePos;
|
||||
out vec3 Ex;
|
||||
out vec3 Ey;
|
||||
out vec3 Ez;
|
||||
out vec3 CamPos;
|
||||
out float fovValue;
|
||||
|
||||
uniform float iTime;
|
||||
uniform vec2 iMousePos;
|
||||
uniform vec3 iEx;
|
||||
uniform vec3 iEy;
|
||||
uniform vec3 iEz;
|
||||
uniform vec3 iCamPos;
|
||||
uniform float iFovValue;
|
||||
|
||||
|
@ -20,7 +24,9 @@ void main()
|
|||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||
FragCoord = texCoord;
|
||||
Time=iTime;
|
||||
MousePos = iMousePos;
|
||||
Ex = iEx;
|
||||
Ey = iEy;
|
||||
Ez = iEz;
|
||||
CamPos = iCamPos;
|
||||
fovValue = iFovValue;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
in vec2 FragCoord;
|
||||
in float Time;
|
||||
in vec2 MousePos;
|
||||
in vec3 Ex;
|
||||
in vec3 Ey;
|
||||
in vec3 Ez;
|
||||
in vec3 CamPos;
|
||||
in float fovValue;
|
||||
|
||||
|
@ -89,15 +91,15 @@ void main(){
|
|||
vec3 lookingAt = vec3(0.);
|
||||
vec3 posCam = vec3(2.5,0.5,2.5);//vec3(-3.*sin(Time*.15),.6*cos(Time*.15),3.*cos(Time*.15));
|
||||
//vec3 posCam = vec3(-3.*sin(MousePos.x/400)*(1-abs(atan(MousePos.y/500))),2*atan(MousePos.y/300),3.*cos(MousePos.x/400)*(1-abs(atan(MousePos.y/500))));
|
||||
float pan=-MousePos.x/180.;
|
||||
float tilt=-MousePos.y/180.;
|
||||
//float pan=-MousePos.x/180.;
|
||||
//float tilt=-MousePos.y/180.;
|
||||
//tilt=max(min(tilt,3.14*.45),-3.14*.45);
|
||||
|
||||
vec3 ez = vec3(cos(tilt)*sin(pan),sin(tilt),cos(tilt)*cos(pan));//normalize(lookingAt-posCam);////base orthonormée
|
||||
vec3 ex = normalize(cross(ez,vec3(0.,1.,0.)));
|
||||
vec3 ey = cross(ex,ez);
|
||||
//vec3 ez = vec3(cos(tilt)*sin(pan),sin(tilt),cos(tilt)*cos(pan));//normalize(lookingAt-posCam);////base orthonormée
|
||||
//vec3 ex = normalize(cross(ez,vec3(0.,1.,0.)));
|
||||
//vec3 ey = cross(ex,ez);
|
||||
|
||||
vec3 dir = normalize(FragCoord.x * ex + FragCoord.y*ey + fovValue*ez);
|
||||
vec3 dir = normalize(FragCoord.x * normalize(Ex) + FragCoord.y * normalize(Ey) + fovValue * Ez);
|
||||
|
||||
|
||||
//float c=Mandel(FragCoord*1.5);
|
||||
|
|
Loading…
Reference in a new issue