Angles SnapToGrid( float gridSize, bool sx, bool sy, bool sz )

book_4_sparkGenerated
code_blocksInput

Description

The SnapToGrid method adjusts the angles of an Angles object to the nearest grid point based on the specified grid size. This method allows you to snap the pitch, yaw, and roll components of the angles to a grid, which can be useful for aligning objects in a scene or ensuring consistent rotations.

Usage

To use the SnapToGrid method, call it on an instance of the Angles struct. You need to provide the grid size and specify which components (pitch, yaw, roll) should be snapped by setting the corresponding boolean parameters to true or false.

Parameters:

  • gridSize (System.Single): The size of the grid to snap to. This determines the increments to which the angles will be adjusted.
  • sx (System.Boolean): If true, the pitch component will be snapped to the grid.
  • sy (System.Boolean): If true, the yaw component will be snapped to the grid.
  • sz (System.Boolean): If true, the roll component will be snapped to the grid.

Example

// Example of using SnapToGrid
Angles angles = new Angles(45.0f, 30.0f, 60.0f);
float gridSize = 15.0f;

// Snap pitch and yaw to the grid, but not roll
Angles snappedAngles = angles.SnapToGrid(gridSize, true, true, false);

// snappedAngles now contains the angles snapped to the nearest 15-degree increment for pitch and yaw.