GigaSphere
360 Tiled panorama engine
Loading...
Searching...
No Matches
Revoid.GigaSphere.MathUtility Class Reference

Utility class for mathematical operations related to panoramic spheres. Provides conversions between different coordinate systems: longitude/latitude, 3D vectors, UV coordinates, and angles. More...

Static Public Member Functions

static Vector3 FromLonLat (float longitude, float latitude)
 Converts longitude and latitude (in degrees) to a normalized direction vector on the unit sphere.
 
static Vector3 FromLonLatRadians (float longitude, float latitude)
 Converts longitude and latitude (in radians) to a normalized direction vector on the unit sphere.
 
static void ToLonLat (Vector3 direction, out float longitude, out float latitude)
 Converts a direction vector to longitude and latitude (in degrees).
 
static void ToLonLatRadians (Vector3 direction, out float longitude, out float latitude)
 Converts a direction vector to longitude and latitude (in radians).
 
static Vector2 ToLonLatVector (Vector3 direction)
 Converts a direction vector to a Vector2 containing longitude and latitude in degrees.
 
static Vector3 FromUV (Vector2 uv)
 Converts UV coordinates on a 2:1 equirectangular panorama texture to a direction vector on the unit sphere.
 
static Vector3 FromUV (float u, float v)
 Converts UV coordinates on a 2:1 equirectangular panorama texture to a direction vector on the unit sphere.
 
static Vector2 ToUV (Vector3 direction)
 Converts a direction vector to UV coordinates on a 2:1 equirectangular panorama texture.
 
static Vector3 FromAngles (float horizontalAngle, float verticalAngle)
 Converts horizontal and vertical angles to a direction vector.
 
static void ToAngles (Vector3 direction, out float horizontalAngle, out float verticalAngle)
 Converts a direction vector to horizontal and vertical angles.
 
static Vector2 ToAnglesVector (Vector3 direction)
 Converts a direction vector to a Vector2 containing horizontal and vertical angles in degrees.
 
static float AngularDistance (Vector3 direction1, Vector3 direction2)
 Calculates the angular distance (in degrees) between two direction vectors on the unit sphere.
 
static float AngularDistanceRadians (Vector3 direction1, Vector3 direction2)
 Calculates the angular distance (in radians) between two direction vectors on the unit sphere.
 
static Vector3 SlerpDirection (Vector3 from, Vector3 to, float t)
 Performs spherical linear interpolation (Slerp) between two direction vectors on the unit sphere.
 
static float NormalizeLongitude (float longitude)
 Ensures longitude is in the range [-180, 180].
 
static float ClampLatitude (float latitude)
 Clamps latitude to the valid range [-90, 90].
 
static bool IsValidUV (Vector2 uv)
 Validates if UV coordinates are within the valid range [0, 1].
 
static Vector2 ClampUV (Vector2 uv)
 Clamps UV coordinates to the valid range [0, 1].
 
static Vector3 OffsetDirection (Vector3 direction, float horizontalOffset, float verticalOffset)
 Offsets a direction vector by the specified horizontal and vertical angles.
 
static Vector3 OffsetDirectionUV (Vector3 baseDirection, Vector2 uvOffset)
 Creates a direction vector at a specified offset from a base direction in UV space.
 
static Vector3[] GenerateGrid (int horizontalCount, int verticalCount)
 Generates a grid of direction vectors on the panorama sphere.
 
static Vector3[] GenerateRing (float latitude, int count)
 Generates direction vectors in a ring pattern at a specific latitude.
 

Static Public Attributes

const float Deg2Rad = Mathf.PI / 180f
 Degrees to radians conversion constant.
 
const float Rad2Deg = 180f / Mathf.PI
 Radians to degrees conversion constant.
 

Properties

static Vector3 DirectionFront [get]
 Gets the direction vector for front/center of the panorama.
 
static Vector3 DirectionBack [get]
 Gets the direction vector for back of the panorama.
 
static Vector3 DirectionRight [get]
 Gets the direction vector for right of the panorama.
 
static Vector3 DirectionLeft [get]
 Gets the direction vector for left of the panorama.
 
static Vector3 DirectionTop [get]
 Gets the direction vector for top (zenith) of the panorama.
 
static Vector3 DirectionBottom [get]
 Gets the direction vector for bottom (nadir) of the panorama.
 

Detailed Description

Utility class for mathematical operations related to panoramic spheres. Provides conversions between different coordinate systems: longitude/latitude, 3D vectors, UV coordinates, and angles.

Member Function Documentation

◆ AngularDistance()

static float Revoid.GigaSphere.MathUtility.AngularDistance ( Vector3 direction1,
Vector3 direction2 )
inlinestatic

Calculates the angular distance (in degrees) between two direction vectors on the unit sphere.

Parameters
direction1First direction vector.
direction2Second direction vector.
Returns
Angular distance in degrees. Range: [0, 180].

◆ AngularDistanceRadians()

static float Revoid.GigaSphere.MathUtility.AngularDistanceRadians ( Vector3 direction1,
Vector3 direction2 )
inlinestatic

Calculates the angular distance (in radians) between two direction vectors on the unit sphere.

Parameters
direction1First direction vector.
direction2Second direction vector.
Returns
Angular distance in radians. Range: [0, PI].

◆ ClampLatitude()

static float Revoid.GigaSphere.MathUtility.ClampLatitude ( float latitude)
inlinestatic

Clamps latitude to the valid range [-90, 90].

Parameters
latitudeLatitude in degrees.
Returns
Clamped latitude in the range [-90, 90].

◆ ClampUV()

static Vector2 Revoid.GigaSphere.MathUtility.ClampUV ( Vector2 uv)
inlinestatic

Clamps UV coordinates to the valid range [0, 1].

Parameters
uvUV coordinates to clamp.
Returns
Clamped UV coordinates.

◆ FromAngles()

static Vector3 Revoid.GigaSphere.MathUtility.FromAngles ( float horizontalAngle,
float verticalAngle )
inlinestatic

Converts horizontal and vertical angles to a direction vector.

Parameters
horizontalAngleHorizontal angle in degrees (yaw). 0 is forward (Z+), positive rotates right.
verticalAngleVertical angle in degrees (pitch). 0 is horizontal, positive looks up, negative looks down.
Returns
A normalized Vector3 representing the direction.

This matches the camera configuration in LocationInfo (openHorizontalAngle, openVerticalAngle).

◆ FromLonLat()

static Vector3 Revoid.GigaSphere.MathUtility.FromLonLat ( float longitude,
float latitude )
inlinestatic

Converts longitude and latitude (in degrees) to a normalized direction vector on the unit sphere.

Parameters
longitudeLongitude in degrees. Range: [-180, 180] where 0 is front, -180/180 is back, -90 is left, 90 is right.
latitudeLatitude in degrees. Range: [-90, 90] where 0 is equator, 90 is top (zenith), -90 is bottom (nadir).
Returns
A normalized Vector3 representing the direction on the unit sphere in Unity world coordinates (X: right/left, Y: up/down, Z: forward/backward).

Unity coordinate system:

  • X: right (+) / left (-)
  • Y: up (+) / down (-)
  • Z: forward (+) / backward (-)

◆ FromLonLatRadians()

static Vector3 Revoid.GigaSphere.MathUtility.FromLonLatRadians ( float longitude,
float latitude )
inlinestatic

Converts longitude and latitude (in radians) to a normalized direction vector on the unit sphere.

Parameters
longitudeLongitude in radians. Range: [-PI, PI].
latitudeLatitude in radians. Range: [-PI/2, PI/2].
Returns
A normalized Vector3 representing the direction on the unit sphere.

◆ FromUV() [1/2]

static Vector3 Revoid.GigaSphere.MathUtility.FromUV ( float u,
float v )
inlinestatic

Converts UV coordinates on a 2:1 equirectangular panorama texture to a direction vector on the unit sphere.

Parameters
uHorizontal coordinate [0, 1]. 0 is left edge (-180°), 1 is right edge (+180°).
vVertical coordinate [0, 1]. 0 is top edge (+90°), 1 is bottom edge (-90°).
Returns
A normalized Vector3 representing the direction on the unit sphere.

◆ FromUV() [2/2]

static Vector3 Revoid.GigaSphere.MathUtility.FromUV ( Vector2 uv)
inlinestatic

Converts UV coordinates on a 2:1 equirectangular panorama texture to a direction vector on the unit sphere.

Parameters
uvUV coordinates where X and Y are in range [0, 1]. U=0 is left edge (-180°), U=1 is right edge (+180°). V=0 is top edge (+90°), V=1 is bottom edge (-90°).
Returns
A normalized Vector3 representing the direction on the unit sphere.

This matches the coordinate system used in HotspotEditorWindow for panorama rendering.

◆ GenerateGrid()

static Vector3[] Revoid.GigaSphere.MathUtility.GenerateGrid ( int horizontalCount,
int verticalCount )
inlinestatic

Generates a grid of direction vectors on the panorama sphere.

Parameters
horizontalCountNumber of points horizontally.
verticalCountNumber of points vertically.
Returns
Array of direction vectors arranged in a grid pattern.

Useful for creating evenly distributed hotspots or test patterns.

◆ GenerateRing()

static Vector3[] Revoid.GigaSphere.MathUtility.GenerateRing ( float latitude,
int count )
inlinestatic

Generates direction vectors in a ring pattern at a specific latitude.

Parameters
latitudeLatitude in degrees for the ring.
countNumber of points in the ring.
Returns
Array of direction vectors forming a ring.

Useful for creating circular patterns of hotspots around the panorama.

◆ IsValidUV()

static bool Revoid.GigaSphere.MathUtility.IsValidUV ( Vector2 uv)
inlinestatic

Validates if UV coordinates are within the valid range [0, 1].

Parameters
uvUV coordinates to validate.
Returns
True if both U and V are in range [0, 1], false otherwise.

◆ NormalizeLongitude()

static float Revoid.GigaSphere.MathUtility.NormalizeLongitude ( float longitude)
inlinestatic

Ensures longitude is in the range [-180, 180].

Parameters
longitudeLongitude in degrees.
Returns
Normalized longitude in the range [-180, 180].

◆ OffsetDirection()

static Vector3 Revoid.GigaSphere.MathUtility.OffsetDirection ( Vector3 direction,
float horizontalOffset,
float verticalOffset )
inlinestatic

Offsets a direction vector by the specified horizontal and vertical angles.

Parameters
directionBase direction vector.
horizontalOffsetHorizontal offset in degrees.
verticalOffsetVertical offset in degrees.
Returns
New direction vector offset by the specified angles.

◆ OffsetDirectionUV()

static Vector3 Revoid.GigaSphere.MathUtility.OffsetDirectionUV ( Vector3 baseDirection,
Vector2 uvOffset )
inlinestatic

Creates a direction vector at a specified offset from a base direction in UV space.

Parameters
baseDirectionBase direction vector.
uvOffsetOffset in UV coordinates (normalized [0-1] space).
Returns
New direction vector offset in UV space.

Useful for positioning hotspots relative to each other in panorama space.

◆ SlerpDirection()

static Vector3 Revoid.GigaSphere.MathUtility.SlerpDirection ( Vector3 from,
Vector3 to,
float t )
inlinestatic

Performs spherical linear interpolation (Slerp) between two direction vectors on the unit sphere.

Parameters
fromStarting direction vector.
toEnding direction vector.
tInterpolation parameter. Range: [0, 1].
Returns
Interpolated direction vector on the unit sphere.

◆ ToAngles()

static void Revoid.GigaSphere.MathUtility.ToAngles ( Vector3 direction,
out float horizontalAngle,
out float verticalAngle )
inlinestatic

Converts a direction vector to horizontal and vertical angles.

Parameters
directionThe direction vector (will be normalized internally).
horizontalAngleOutput horizontal angle in degrees. Range: [-180, 180].
verticalAngleOutput vertical angle in degrees. Range: [-90, 90].

◆ ToAnglesVector()

static Vector2 Revoid.GigaSphere.MathUtility.ToAnglesVector ( Vector3 direction)
inlinestatic

Converts a direction vector to a Vector2 containing horizontal and vertical angles in degrees.

Parameters
directionThe direction vector.
Returns
Vector2 where X is horizontal angle [-180, 180] and Y is vertical angle [-90, 90].

◆ ToLonLat()

static void Revoid.GigaSphere.MathUtility.ToLonLat ( Vector3 direction,
out float longitude,
out float latitude )
inlinestatic

Converts a direction vector to longitude and latitude (in degrees).

Parameters
directionThe direction vector on the sphere (will be normalized internally).
longitudeOutput longitude in degrees. Range: [-180, 180].
latitudeOutput latitude in degrees. Range: [-90, 90].

◆ ToLonLatRadians()

static void Revoid.GigaSphere.MathUtility.ToLonLatRadians ( Vector3 direction,
out float longitude,
out float latitude )
inlinestatic

Converts a direction vector to longitude and latitude (in radians).

Parameters
directionThe direction vector on the sphere (will be normalized internally).
longitudeOutput longitude in radians. Range: [-PI, PI].
latitudeOutput latitude in radians. Range: [-PI/2, PI/2].

◆ ToLonLatVector()

static Vector2 Revoid.GigaSphere.MathUtility.ToLonLatVector ( Vector3 direction)
inlinestatic

Converts a direction vector to a Vector2 containing longitude and latitude in degrees.

Parameters
directionThe direction vector on the sphere.
Returns
Vector2 where X is longitude [-180, 180] and Y is latitude [-90, 90].

◆ ToUV()

static Vector2 Revoid.GigaSphere.MathUtility.ToUV ( Vector3 direction)
inlinestatic

Converts a direction vector to UV coordinates on a 2:1 equirectangular panorama texture.

Parameters
directionThe direction vector on the sphere (will be normalized internally).
Returns
UV coordinates where X and Y are in range [0, 1].

Member Data Documentation

◆ Deg2Rad

const float Revoid.GigaSphere.MathUtility.Deg2Rad = Mathf.PI / 180f
static

Degrees to radians conversion constant.

◆ Rad2Deg

const float Revoid.GigaSphere.MathUtility.Rad2Deg = 180f / Mathf.PI
static

Radians to degrees conversion constant.

Property Documentation

◆ DirectionBack

Vector3 Revoid.GigaSphere.MathUtility.DirectionBack
staticget

Gets the direction vector for back of the panorama.

◆ DirectionBottom

Vector3 Revoid.GigaSphere.MathUtility.DirectionBottom
staticget

Gets the direction vector for bottom (nadir) of the panorama.

◆ DirectionFront

Vector3 Revoid.GigaSphere.MathUtility.DirectionFront
staticget

Gets the direction vector for front/center of the panorama.

◆ DirectionLeft

Vector3 Revoid.GigaSphere.MathUtility.DirectionLeft
staticget

Gets the direction vector for left of the panorama.

◆ DirectionRight

Vector3 Revoid.GigaSphere.MathUtility.DirectionRight
staticget

Gets the direction vector for right of the panorama.

◆ DirectionTop

Vector3 Revoid.GigaSphere.MathUtility.DirectionTop
staticget

Gets the direction vector for top (zenith) of the panorama.


The documentation for this class was generated from the following file: