Advertisement
lucasgautheron

tempest readdepth fix

Aug 28th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. void readdepth(int w, int h, vec &pos)
  2. {    
  3.     // tempest readdepth fix
  4.     float yaw = camera1->yaw-90, pitch = -camera1->pitch;
  5.     vec from = camera1->o, dir, surface;
  6.  
  7.     float sin_yaw = sinf(yaw*RAD);
  8.     float cos_yaw = cosf(yaw*RAD);
  9.  
  10.     float sin_pitch = sinf(pitch*RAD);
  11.     float cos_pitch = cosf(pitch*RAD);
  12.  
  13.     dir.x = cos_pitch * cos_yaw;
  14.     dir.y = cos_pitch * sin_yaw;
  15.     dir.z = -sin_pitch;
  16.    
  17.     vec ray = dir;
  18.     float dist = raycube(from, ray, surface);
  19.     if(dist < 0) dist = 1000.0f;                // if skymap was hit, dist is always -1 ...
  20.     pos = vec(dir).mul(dist).add(from);
  21.  
  22.     loopv(ents)
  23.     {
  24.         entity &e = ents[i];
  25.         if(e.type != MAPMODEL) continue;
  26.         if(from.dist(vec(e.x, e.y, e.z)) < dist && intersect(&e, from, pos))
  27.             dist = from.dist(vec(e.x, e.y, e.z));
  28.     }
  29.  
  30.     pos = dir.mul(dist).add(from);  // once again, now with correct dist
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement