Dimenticare

mouse vector

Dec 8th, 2017
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// void UpdateMouseVector(xfrom, yfrom, zfrom, xto, yto, zto, xup, yup, zup);
  2. with (World){
  3.     var mm,dX,dY,dZ,uX,uY,uZ,vX,vY,vZ,mX,mY,mZ, width, height, tFOV, asp;
  4.     width = WW;
  5.     height = HH;
  6.     asp=width/height;
  7.    
  8.     // normalize TO vector
  9.     dX = argument3-argument0;
  10.     dY = argument4-argument1;
  11.     dZ = argument5-argument2;
  12.     mm = sqrt(dX*dX+dY*dY+dZ*dZ);
  13.     dX /= mm;
  14.     dY /= mm;
  15.     dZ /= mm;
  16.    
  17.     // fix UP vector and normalize it
  18.     uX = argument6;
  19.     uY = argument7;
  20.     uZ = argument8;
  21.     mm = uX*dX+uY*dY+uZ*dZ;
  22.     uX -= mm*dX;
  23.     uY -= mm*dY;
  24.     uZ -= mm*dZ
  25.     mm = sqrt(uX*uX+uY*uY+uZ*uZ);
  26.     uX /= mm;
  27.     uY /= mm;
  28.     uZ /= mm;
  29.    
  30.    
  31.     // make x vector using TO and UP
  32.     vX = uY*dZ-dY*uZ;
  33.     vY = uZ*dX-dZ*uX;
  34.     vZ = uX*dY-dX*uY;
  35.    
  36.     // convert angle to screen width and height
  37.     tFOV = tan(fov*pi/360);
  38.     uX *= tFOV;
  39.     uY *= tFOV;
  40.     uZ *= tFOV;
  41.     vX *= tFOV*asp;
  42.     vY *= tFOV*asp;
  43.     vZ *= tFOV*asp;
  44.    
  45.     // add UP*MOUSE_Y and X*MOUSE_X vector to TO vector
  46.     mX = dX+uX*(1-2*MOUSE_Y/height)+vX*(2*MOUSE_X/width-1);
  47.     mY = dY+uY*(1-2*MOUSE_Y/height)+vY*(2*MOUSE_X/width-1);
  48.     mZ = dZ+uZ*(1-2*MOUSE_Y/height)+vZ*(2*MOUSE_X/width-1);
  49.     mm = sqrt(mX*mX+mY*mY+mZ*mZ);
  50.    
  51.     // normalize mouse direction vector
  52.     mouse_dx=mX/mm;
  53.     mouse_dy=mY/mm;
  54.     mouse_dz=mZ/mm;
  55.    
  56.     xx=Camera.x+mouse_dx*edit_distance;
  57.     yy=Camera.y+mouse_dy*edit_distance;
  58.     zz=Camera.z+mouse_dz*edit_distance;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment