fr1kin

Get3DCoords

Jun 22nd, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local function AngleMatrix( ang, matrix )
  2.     local rp = math.rad( ang.p );
  3.     local sp, cp = math.sin( rp ), math.cos( rp );
  4.     local ry = math.rad( ang.y );
  5.     local sy, cy = math.sin( ry ), math.cos( ry );
  6.     local rr = math.rad( ang.r );
  7.     local sr, cr = math.sin( rr ), math.cos( rr );
  8.     matrix[0].x = cp * cy;
  9.     matrix[1].x = cp * sy;
  10.     matrix[2].x = -sp;
  11.     local crcy = cr * cy;
  12.     local crsy = cr * sy;
  13.     local srcy = sr * cy;
  14.     local srsy = sr * sy;
  15.     matrix[0].y = sp * srcy - crsy;
  16.     matrix[1].y = sp * srsy + crcy;
  17.     matrix[2].y = sr * cp;
  18.     matrix[0].z = ( sp * crcy + srsy );
  19.     matrix[1].z = ( sp * crsy - srcy );
  20.     matrix[2].z = cr * cp;
  21.     return matrix;
  22. end
  23.  
  24. local function RotateVector( vec, matrix, set )
  25.     set.x = vec:DotProduct( matrix[0] );
  26.     set.y = vec:DotProduct( matrix[1] );
  27.     set.z = vec:DotProduct( matrix[2] );
  28.     return set;
  29. end
  30.  
  31. local function Get3DCoords( org, mins, maxs, ang, keeplocal )
  32.     local vecs = {
  33.         [0] = Vector( mins.x, mins.y, mins.z ), // front-bottom-right
  34.         [1] = Vector( maxs.x, mins.y, mins.z ), // front-top-right
  35.         [2] = Vector( maxs.x, maxs.y, mins.z ), // back-top-right
  36.         [3] = Vector( mins.x, maxs.y, mins.z ), // back-bottom-right
  37.         [4] = Vector( mins.x, mins.y, maxs.z ), // front-bottom-left
  38.         [5] = Vector( maxs.x, mins.y, maxs.z ), // front-top-left
  39.         [6] = Vector( maxs.x, maxs.y, maxs.z ), // back-top-left
  40.         [7] = Vector( mins.x, maxs.y, maxs.z ), // back-bottom-left
  41.     };
  42.     local angmatrix = {
  43.         [0] = Vector( 0, 0, 0 ),
  44.         [1] = Vector( 0, 0, 0 ),
  45.         [2] = Vector( 0, 0, 0 ),
  46.     };
  47.    
  48.     AngleMatrix( ang, angmatrix );
  49.    
  50.     local retv = {};
  51.     for i = 0, 7 do
  52.         if( !vecs[i] ) then continue; end
  53.         retv[i] = Vector( 0, 0, 0 );
  54.         RotateVector( vecs[i], angmatrix, retv[i] );
  55.         if( !keeplocal ) then
  56.             retv[i] = retv[i] + org;
  57.         end
  58.     end
  59.    
  60.     return retv;
  61. end
Advertisement
Add Comment
Please, Sign In to add comment