Description
The SnapToGrid
method adjusts the angles of an Angles
object to align with a specified grid size. This is useful for ensuring that angles are rounded to the nearest grid increment, which can be particularly helpful in scenarios like snapping objects to a grid in a 3D environment.
Usage
To use the SnapToGrid
method, call it on an instance of the Angles
struct. Provide the grid size as a float
and specify which axes (pitch, yaw, roll) should be snapped by passing true
or false
for the sx
, sy
, and sz
parameters respectively.
Example
// Example of using SnapToGrid
Angles angles = new Angles(45.0f, 30.0f, 90.0f);
float gridSize = 15.0f;
// Snap angles to the grid size of 15 on all axes
Angles snappedAngles = angles.SnapToGrid(gridSize, true, true, true);
// Output the snapped angles
// snappedAngles will have its pitch, yaw, and roll adjusted to the nearest multiple of 15