fix cam pan tilt and max and cam speed

This commit is contained in:
MagicTINTIN 2023-03-15 09:37:44 +01:00
parent f602eb7428
commit 08d0e691fb
2 changed files with 15 additions and 10 deletions

21
main.c
View file

@ -30,6 +30,10 @@ unsigned int VAO;
float currentTime, deltaTime, lastFrame,startTime;
float mousePosX,mousePosY,camPosX,camPosY,camPosZ,camDirX,camDirY,camDirZ;
//283=3.14/2 * 180
const int maxYmouse = 283;
// more precision means less speed
const int camPrecision = 2;
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
@ -58,24 +62,25 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
{
mousePosX = xpos;
mousePosY = ypos;
/*
//if (xpos>283){ //////283=3.14/2 * 180
// //xpos=283
//}
//if (xpos<-283){
// //xpos=-283
//}
if (ypos>283){
//ypos=283
//}*/
int maxYcorrected = maxYmouse*camPrecision;
if (ypos>maxYcorrected){
glfwSetCursorPos(window, xpos, maxYcorrected);
}
if (ypos<283){
//ypos=-283
if (ypos<-maxYcorrected){
glfwSetCursorPos(window, xpos, -maxYcorrected);
}
*/
if (DEBUG_MODE % 3 == 0)
printf("x:%f | y:%f\n",xpos, ypos);
mousePosX = xpos/camPrecision;
mousePosY = ypos/camPrecision;
}
int main (){

View file

@ -89,8 +89,8 @@ 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);
int parity = int(tilt/3.14-.5);
if(parity%2==1){