Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function AngleMatrix( ang, matrix )
- local rp = math.rad( ang.p );
- local sp, cp = math.sin( rp ), math.cos( rp );
- local ry = math.rad( ang.y );
- local sy, cy = math.sin( ry ), math.cos( ry );
- local rr = math.rad( ang.r );
- local sr, cr = math.sin( rr ), math.cos( rr );
- matrix[0].x = cp * cy;
- matrix[1].x = cp * sy;
- matrix[2].x = -sp;
- local crcy = cr * cy;
- local crsy = cr * sy;
- local srcy = sr * cy;
- local srsy = sr * sy;
- matrix[0].y = sp * srcy - crsy;
- matrix[1].y = sp * srsy + crcy;
- matrix[2].y = sr * cp;
- matrix[0].z = ( sp * crcy + srsy );
- matrix[1].z = ( sp * crsy - srcy );
- matrix[2].z = cr * cp;
- return matrix;
- end
- local function RotateVector( vec, matrix, set )
- set.x = vec:DotProduct( matrix[0] );
- set.y = vec:DotProduct( matrix[1] );
- set.z = vec:DotProduct( matrix[2] );
- return set;
- end
- local function Get3DCoords( org, mins, maxs, ang, keeplocal )
- local vecs = {
- [0] = Vector( mins.x, mins.y, mins.z ), // front-bottom-right
- [1] = Vector( maxs.x, mins.y, mins.z ), // front-top-right
- [2] = Vector( maxs.x, maxs.y, mins.z ), // back-top-right
- [3] = Vector( mins.x, maxs.y, mins.z ), // back-bottom-right
- [4] = Vector( mins.x, mins.y, maxs.z ), // front-bottom-left
- [5] = Vector( maxs.x, mins.y, maxs.z ), // front-top-left
- [6] = Vector( maxs.x, maxs.y, maxs.z ), // back-top-left
- [7] = Vector( mins.x, maxs.y, maxs.z ), // back-bottom-left
- };
- local angmatrix = {
- [0] = Vector( 0, 0, 0 ),
- [1] = Vector( 0, 0, 0 ),
- [2] = Vector( 0, 0, 0 ),
- };
- AngleMatrix( ang, angmatrix );
- local retv = {};
- for i = 0, 7 do
- if( !vecs[i] ) then continue; end
- retv[i] = Vector( 0, 0, 0 );
- RotateVector( vecs[i], angmatrix, retv[i] );
- if( !keeplocal ) then
- retv[i] = retv[i] + org;
- end
- end
- return retv;
- end
Advertisement
Add Comment
Please, Sign In to add comment