Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Angle:SnapTo( component, degrees ) where component is p/y/r / p…
…itch/yaw/roll, and degrees is the interval; will return an Angle for all cases so multiple snaps can be strung on one line. Examples, Angle( 0, 92, 0 ):SnapTo( "y", 90 ); will return Angle( 0, 90, 0 ); Angle( 0, 115, 0 ):SnapTo( "y", 45 ); will return Angle( 0, 137, 0 ); Angle( 12, 98, 167 ):SnapTo( "p", 30 ):SnapTo( "y", 45 ):SnapTo( "r", 45 ); will return Angle( 0, 90, -180 ); Added Vector:ToColor( ) to compliment other addition Color:ToVector( ) Added Color:ToVector( ) to compliment other addition Vector:ToColor( ) 3 simple yet useful functions; and we may as well add to the 3 meta files...
- Loading branch information
Showing
3 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
local meta = FindMetaTable( "Angle" ) | ||
|
||
-- Nothing in here, still leaving this file here just in case | ||
|
||
--[[--------------------------------------------------------- | ||
Angle Snap to nearest interval of degrees | ||
-----------------------------------------------------------]] | ||
function meta:SnapTo( component, degrees ) | ||
if ( degrees == 0 ) then ErrorNoHalt( "The snap degrees must be non-zero.\n" ); return self; end | ||
if ( !self[ component ] ) then ErrorNoHalt( "You must choose a valid component of Angle( p || pitch, y || yaw, r || roll ) to snap such as Angle( 80, 40, 30 ):SnapTo( \"p\", 90 ):SnapTo( \"y\", 45 ):SnapTo( \"r\", 40 ); and yes, you can keep adding snaps.\n" ); return self; end | ||
self[ component ] = math.Round( self[ component ] / degrees ) * degrees | ||
self[ component ] = math.NormalizeAngle( self[ component ] | ||
return self | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
local meta = FindMetaTable( "Vector" ) | ||
|
||
-- Nothing in here, still leaving this file here just in case | ||
|
||
--[[--------------------------------------------------------- | ||
Converts Vector To Color - alpha precision lost, must reset | ||
-----------------------------------------------------------]] | ||
function meta:ToColor( ) | ||
return Vector( self.x * 255, self.y * 255, self.z * 255, 255 ) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6cc5352
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Angle:SnapTo() should be done for Vectors and Colors too.