Class Utils
Contains utility functions for various tasks within the Genesis.Core namespace.
Inherited Members
Namespace: Genesis.Core
Assembly: Genesis.dll
Syntax
public class Utils
Constructors
Utils()
Declaration
public Utils()
Methods
BuildPhysicsMatrix(Vector3, Quaternion, Vector3)
Builds a transformation matrix for physics calculations based on location, quaternion rotation, and scale.
Declaration
public static Matrix BuildPhysicsMatrix(Vector3 location, Quaternion rotation, Vector3 scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | location | The position vector. |
| Quaternion | rotation | The rotation quaternion. |
| Vector3 | scale | The scale vector. |
Returns
| Type | Description |
|---|---|
| Matrix | A transformation matrix combining translation, quaternion rotation, and scaling. |
BuildPhysicsMatrix(Vector3, Vector3, Vector3)
Builds a transformation matrix for physics calculations based on location, rotation, and scale.
Declaration
public static Matrix BuildPhysicsMatrix(Vector3 location, Vector3 rotation, Vector3 scale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | location | The position vector. |
| Vector3 | rotation | The rotation vector in Euler angles. |
| Vector3 | scale | The scale vector. |
Returns
| Type | Description |
|---|---|
| Matrix | A transformation matrix combining translation, rotation, and scaling. |
CalculateCameraFront(Camera)
Calculates the front vector of a camera using its location and rotation.
Declaration
public static Vec3 CalculateCameraFront(Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera. |
Returns
| Type | Description |
|---|---|
| Vec3 | The front vector of the camera. |
CalculateCameraFront2(Camera)
Calculates the front vector of a camera using its rotation angles.
Declaration
public static Vec3 CalculateCameraFront2(Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera. |
Returns
| Type | Description |
|---|---|
| Vec3 | The front vector of the camera. |
CalculateDirectionVector(Vec3, Vec3)
Calculates the direction vector from point A to point B.
Declaration
public static Vec3 CalculateDirectionVector(Vec3 pointA, Vec3 pointB)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | pointA | The starting point. |
| Vec3 | pointB | The target point. |
Returns
| Type | Description |
|---|---|
| Vec3 | The direction vector from point A to point B. |
CalculateFrontVec3(Vec3, Vec3, float)
Calculates a vector infront of the given point
Declaration
public static Vec3 CalculateFrontVec3(Vec3 location, Vec3 rotation, float dist)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | location | The source location |
| Vec3 | rotation | The rotation |
| float | dist | The distance |
Returns
| Type | Description |
|---|---|
| Vec3 | Front vector |
CalculateLightspaceMatrix(mat4, mat4)
Calculates the light space transformation matrix using light projection and view matrices.
Declaration
public static mat4 CalculateLightspaceMatrix(mat4 lightProjection, mat4 lightView)
Parameters
| Type | Name | Description |
|---|---|---|
| mat4 | lightProjection | The light projection matrix. |
| mat4 | lightView | The light view matrix. |
Returns
| Type | Description |
|---|---|
| mat4 | The combined light space matrix. |
CalculatePitch(Vec3, Vec3)
Calculates the pitch angle from point1 to point2.
Declaration
public static float CalculatePitch(Vec3 point1, Vec3 point2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | point1 | The starting point. |
| Vec3 | point2 | The target point. |
Returns
| Type | Description |
|---|---|
| float | The pitch angle in degrees. |
CalculateScreenCorrection(float, float, float, float)
Calculates the screen correction factor based on screen dimensions and virtual dimensions, ensuring the content fits proportionally.
Declaration
public static float CalculateScreenCorrection(float screenWidth, float screenHeight, float virtualWidth, float virtualHeight)
Parameters
| Type | Name | Description |
|---|---|---|
| float | screenWidth | The width of the physical screen. |
| float | screenHeight | The height of the physical screen. |
| float | virtualWidth | The width of the virtual screen. |
| float | virtualHeight | The height of the virtual screen. |
Returns
| Type | Description |
|---|---|
| float | The correction factor for scaling the virtual screen to the physical screen. |
CalculateYaw(Vec3, Vec3)
Calculates the yaw angle from point1 to point2.
Declaration
public static float CalculateYaw(Vec3 point1, Vec3 point2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | point1 | The starting point. |
| Vec3 | point2 | The target point. |
Returns
| Type | Description |
|---|---|
| float | The yaw angle in degrees. |
ConvertBase64ToBitmap(string)
Converts a Base64 string to a Bitmap image.
Declaration
public static Bitmap ConvertBase64ToBitmap(string base64)
Parameters
| Type | Name | Description |
|---|---|---|
| string | base64 | The Base64 string to convert. |
Returns
| Type | Description |
|---|---|
| Bitmap | The Bitmap image decoded from the Base64 string. |
ConvertBitmapToBase64(Bitmap)
Converts a Bitmap image to a Base64 string.
Declaration
public static string ConvertBitmapToBase64(Bitmap bitmap)
Parameters
| Type | Name | Description |
|---|---|---|
| Bitmap | bitmap | The Bitmap image to convert. |
Returns
| Type | Description |
|---|---|
| string | The Base64 string representation of the Bitmap image. |
ConvertColor(Color, bool)
Converts a System.Drawing.Color into a float array.
Declaration
public static float[] ConvertColor(Color color, bool alpha = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | color | The color. |
| bool | alpha | Checks if the alpha gets converted |
Returns
| Type | Description |
|---|---|
| float[] | The float array representing the color. |
ConvertDrawingColor(float, float, float, float)
Converts float values to a System.Drawing.Color.
Declaration
public static Color ConvertDrawingColor(float a, float r, float g, float b)
Parameters
| Type | Name | Description |
|---|---|---|
| float | a | The alpha component. |
| float | r | The red component. |
| float | g | The green component. |
| float | b | The blue component. |
Returns
| Type | Description |
|---|---|
| Color | The System.Drawing.Color representation. |
ConvertToGlmMat4(Matrix4x4)
Converts a Matrix4x4 from the Assimp library to a mat4 from GLM library.
Declaration
public static mat4 ConvertToGlmMat4(Matrix4x4 matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | matrix | The Matrix4x4 to convert. |
Returns
| Type | Description |
|---|---|
| mat4 | A mat4 representing the converted matrix. |
CreateEmptyNormalMap(int, int)
Creates an empty normal map with the specified width and height.
Declaration
public static Bitmap CreateEmptyNormalMap(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width of the normal map. |
| int | height | The height of the normal map. |
Returns
| Type | Description |
|---|---|
| Bitmap | An empty normal map. |
CreateEmptyTexture(int, int)
Creates an empty texture with the specified width and height.
Declaration
public static Bitmap CreateEmptyTexture(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | The width of the texture. |
| int | height | The height of the texture. |
Returns
| Type | Description |
|---|---|
| Bitmap | An empty texture. |
CreateVertexColors(int, Color)
Declaration
public static float[] CreateVertexColors(int vertexCount, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| int | vertexCount | |
| Color | color |
Returns
| Type | Description |
|---|---|
| float[] |
EulerToQuaternion(Vec3)
Converts Euler angles to a quaternion.
Declaration
public static quat EulerToQuaternion(Vec3 euler)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | euler | The Euler angles vector. |
Returns
| Type | Description |
|---|---|
| quat | The quaternion representing the rotation. |
ExtractScaleFromMatrix(Matrix)
Extracts the scaling factors from a given transformation matrix.
Declaration
public static Vector3 ExtractScaleFromMatrix(Matrix matrix)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix | matrix | The transformation matrix from which to extract scale. |
Returns
| Type | Description |
|---|---|
| Vector3 | A vector representing the scale along the X, Y, and Z axes. |
ForwardVector(Vec3, Vec3, float)
Calculates the vector pointing forward from a given position and rotation.
Declaration
public static Vec3 ForwardVector(Vec3 v, Vec3 rotaion, float dist)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | v | The starting position vector. |
| Vec3 | rotaion | |
| float | dist | The distance to move in the forward direction. |
Returns
| Type | Description |
|---|---|
| Vec3 | The resulting position vector. |
GetBtTransform(GameElement, Vec3)
Declaration
public static Matrix GetBtTransform(GameElement element, Vec3 offsetLocation = default)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | |
| Vec3 | offsetLocation |
Returns
| Type | Description |
|---|---|
| Matrix |
GetCurrentTimeMillis()
Gets the current time in milliseconds.
Declaration
public static long GetCurrentTimeMillis()
Returns
| Type | Description |
|---|---|
| long | The current time in milliseconds. |
GetElementWorldLocation(GameElement)
Returns the world location for the game element.
Declaration
public static Vec3 GetElementWorldLocation(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| Vec3 | The world location of the game element. |
GetElementWorldRotation(GameElement)
Returns the world rotation for the game element.
Declaration
public static Vec3 GetElementWorldRotation(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| Vec3 | The world rotation of the game element. |
GetElementWorldScale(GameElement)
Returns the world scale for the game element.
Declaration
public static Vec3 GetElementWorldScale(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| Vec3 | The world scale of the game element. |
GetForwardDirection(Vec3)
Calculates the forward direction vector based on Euler angles.
Declaration
public static Vec3 GetForwardDirection(Vec3 eulerAngles)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | eulerAngles | The Euler angles representing rotation. |
Returns
| Type | Description |
|---|---|
| Vec3 | The forward direction vector. |
GetGLMQuat(Quaternion)
Converts an Assimp Quaternion to a quat from GLM library.
Declaration
public static quat GetGLMQuat(Quaternion pOrientation)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | pOrientation | The Quaternion to convert. |
Returns
| Type | Description |
|---|---|
| quat | A quat representing the converted quaternion. |
GetGLMVec(Vector3D)
Converts an Assimp Vector3D to a vec3 from GLM library.
Declaration
public static vec3 GetGLMVec(Vector3D vec)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3D | vec | The Vector3D to convert. |
Returns
| Type | Description |
|---|---|
| vec3 | A vec3 representing the converted vector. |
GetModelRotation(GameElement)
Returns the model rotation matrix relative to the world rotation.
Declaration
public static mat4 GetModelRotation(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| mat4 | The model rotation matrix. |
GetModelScale(GameElement)
Returns the model scale matrix relative to the world scale.
Declaration
public static mat4 GetModelScale(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| mat4 | The model scale matrix. |
GetModelSpaceLocation(GameElement, Vec3)
Converts the world transform to model space transform.
Declaration
public static Vec3 GetModelSpaceLocation(GameElement element, Vec3 worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
| Vec3 | worldPosition | The world position vector. |
Returns
| Type | Description |
|---|---|
| Vec3 | The model space location of the game element. |
GetModelSpaceRotation(GameElement, Vec3)
Converts the world rotation to the model space rotation.
Declaration
public static Vec3 GetModelSpaceRotation(GameElement element, Vec3 worldRotation)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
| Vec3 | worldRotation | The world rotation vector. |
Returns
| Type | Description |
|---|---|
| Vec3 | The model space rotation of the game element. |
GetModelSpaceScale(GameElement, Vec3)
Converts the world scale to the model space scale.
Declaration
public static Vec3 GetModelSpaceScale(GameElement element, Vec3 worldScale)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
| Vec3 | worldScale | The world scale vector. |
Returns
| Type | Description |
|---|---|
| Vec3 | The model space scale of the game element. |
GetModelTransformation(GameElement)
Returns the model transform matrix relative to the world location.
Declaration
public static mat4 GetModelTransformation(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| mat4 | The model transform matrix. |
GetParentModelView(GameElement)
Gets the transformation matrix for the parent model view.
Declaration
public static mat4 GetParentModelView(GameElement element)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | element | The game element. |
Returns
| Type | Description |
|---|---|
| mat4 | The transformation matrix for the parent model view. |
GetRandomColor()
Generates an random color
Declaration
public static Color GetRandomColor()
Returns
| Type | Description |
|---|---|
| Color | The color |
GetRandomColor(Color, Color)
Returns a random color between the given colors.
Declaration
public static Color GetRandomColor(Color colorA, Color colorB)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | colorA | The minimum color. |
| Color | colorB | The maximum color. |
Returns
| Type | Description |
|---|---|
| Color | A randomly generated color within the specified range. |
GetRandomColor(Color, Color, int)
Returns a random color between the given colors using a specified seed for reproducibility.
Declaration
public static Color GetRandomColor(Color colorA, Color colorB, int seed)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | colorA | The minimum color. |
| Color | colorB | The maximum color. |
| int | seed | The seed for the random number generator. |
Returns
| Type | Description |
|---|---|
| Color | A randomly generated color within the specified range and seed. |
GetRandomColor(int)
Generates an random color from an seed
Declaration
public static Color GetRandomColor(int seed)
Parameters
| Type | Name | Description |
|---|---|---|
| int | seed | The seed for the randomizer |
Returns
| Type | Description |
|---|---|
| Color | The color |
GetRelativePosition(GameElement, GameElement)
Gets the relative position of a child GameElement with respect to a parent GameElement.
Declaration
public static Vec3 GetRelativePosition(GameElement parent, GameElement child)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | parent | The parent GameElement. |
| GameElement | child | The child GameElement. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the relative position of the child. |
GetRelativePosition(GameElement, Camera)
Gets the relative position of a camera with respect to a parent GameElement.
Declaration
public static Vec3 GetRelativePosition(GameElement parent, Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | parent | The parent GameElement. |
| Camera | camera | The camera. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the relative position of the camera. |
GetRelativePosition(GameElement, Vec3)
Gets the relative position of a location with respect to a parent GameElement.
Declaration
public static Vec3 GetRelativePosition(GameElement parent, Vec3 location)
Parameters
| Type | Name | Description |
|---|---|---|
| GameElement | parent | The parent GameElement. |
| Vec3 | location | The location. |
Returns
| Type | Description |
|---|---|
| Vec3 | A Vec3 representing the relative position of the location. |
GetStringBounds(Vec3, string, float, float)
Gets the bounding rectangle of a string given its location, text, font size, and spacing.
Declaration
public static Rect GetStringBounds(Vec3 location, string text, float fontSize, float spacing)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | location | The location of the string. |
| string | text | The input string. |
| float | fontSize | The font size. |
| float | spacing | The character spacing. |
Returns
| Type | Description |
|---|---|
| Rect | The bounding rectangle of the string. |
GetStringHeight(string, float, float)
Gets the height of a string given the font size and spacing.
Declaration
public static float GetStringHeight(string text, float fontSize, float spacing)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The input string. |
| float | fontSize | The font size. |
| float | spacing | The line spacing. |
Returns
| Type | Description |
|---|---|
| float | The height of the string. |
GetStringWidth(string, float, float)
Gets the width of a string given the font size and spacing.
Declaration
public static float GetStringWidth(string text, float fontSize, float spacing)
Parameters
| Type | Name | Description |
|---|---|---|
| string | text | The input string. |
| float | fontSize | The font size. |
| float | spacing | The character spacing. |
Returns
| Type | Description |
|---|---|
| float | The width of the string. |
GetTransformedForwardVector(Vec3, float)
Calculates the transformed forward vector based on the given rotation and distance, using quaternion rotation to avoid gimbal lock issues.
Declaration
public static Vec3 GetTransformedForwardVector(Vec3 rotation, float dist)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | rotation | The rotation in degrees, specified as Euler angles (Pitch, Yaw, Roll). |
| float | dist | The distance by which the forward vector is scaled. |
Returns
| Type | Description |
|---|---|
| Vec3 | Returns the calculated forward vector as a Vec3, transformed according to the rotation and scaled by the specified distance. |
Remarks
This function is currently under testing and should be used if the original ForwardVector method causes gimbal lock issues.
GetTriangleIndex(Element3D, Vec3)
Gets the index of the triangle within a mesh that contains the specified hitpoint.
Declaration
public static int GetTriangleIndex(Element3D element, Vec3 hitpoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Element3D | element | The 3D element containing the mesh. |
| Vec3 | hitpoint | The point in space to check for containment within a triangle. |
Returns
| Type | Description |
|---|---|
| int | The index of the triangle containing the hitpoint, or -1 if not found. |
GetVMirroredPosition(Vec3, Camera)
Gets the vertically mirrored position of a reference vector relative to a camera.
Declaration
public static Vec3 GetVMirroredPosition(Vec3 vref, Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| Vec3 | vref | The reference vector. |
| Camera | camera | The camera used for mirroring. |
Returns
| Type | Description |
|---|---|
| Vec3 | The vertically mirrored position vector. |
GetVMirroredPosition(float, float, float, Camera)
Gets the vertically mirrored position of a reference vector relative to a camera.
Declaration
public static Vec3 GetVMirroredPosition(float x, float y, float z, Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The reference x vector. |
| float | y | The reference y vector |
| float | z | The reference z vector |
| Camera | camera | The camera used for mirroring. |
Returns
| Type | Description |
|---|---|
| Vec3 | The vertically mirrored position vector. |
IsPointInTriangle(Vector3, Vector3, Vector3, Vector3)
Checks if a given point is inside a specified triangle using barycentric coordinates.
Declaration
public static bool IsPointInTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | p | The point to test. |
| Vector3 | a | The first vertex of the triangle. |
| Vector3 | b | The second vertex of the triangle. |
| Vector3 | c | The third vertex of the triangle. |
Returns
| Type | Description |
|---|---|
| bool | True if the point is inside the triangle; otherwise, false. |
LerpColor(Color, Color, float)
Interpolates between an start and end color
Declaration
public static float[] LerpColor(Color startColor, Color endColor, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | startColor | The color start |
| Color | endColor | The color end |
| float | t | the time |
Returns
| Type | Description |
|---|---|
| float[] |
LookAt(Camera, Vec3)
Lets the camera look at a position.
Declaration
public static void LookAt(Camera camera, Vec3 targetPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera. |
| Vec3 | targetPosition | The target position. |
LookAtX(Camera, Vec3)
Adjusts the camera's rotation to look at a specified position along the X-axis.
Declaration
public static void LookAtX(Camera camera, Vec3 targetPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to adjust. |
| Vec3 | targetPosition | The position to look at. |
LookAtY(Camera, Vec3)
Adjusts the camera's rotation to look at a specified position along the Y-axis.
Declaration
public static void LookAtY(Camera camera, Vec3 targetPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The camera to adjust. |
| Vec3 | targetPosition | The position to look at. |
NormalizeAngle(float)
Normalizes an angle to be within the range of -180 to 180 degrees.
Declaration
public static float NormalizeAngle(float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| float | angle | The angle in degrees to normalize. |
Returns
| Type | Description |
|---|---|
| float | The normalized angle within the range -180 to 180. |
RayDirection(Camera, Viewport, float, float)
Calculates the direction of a ray in world space based on screen coordinates.
Declaration
public static Vec3 RayDirection(Camera camera, Viewport viewport, float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera object. |
| Viewport | viewport | The Viewport object. |
| float | x | X-coordinate on the screen. |
| float | y | Y-coordinate on the screen. |
Returns
| Type | Description |
|---|---|
| Vec3 | Direction of the ray as a Vec3. |
ToDegrees(float)
Converts radians to degrees.
Declaration
public static float ToDegrees(float radians)
Parameters
| Type | Name | Description |
|---|---|---|
| float | radians | The angle in radians. |
Returns
| Type | Description |
|---|---|
| float | The angle in degrees. |
ToRadians(float)
Converts degrees to radians.
Declaration
public static float ToRadians(float degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| float | degrees | The angle in degrees. |
Returns
| Type | Description |
|---|---|
| float | The angle in radians. |
TransformToWorldCords(Game, float, float)
Transforms screen coordinates to world coordinates in the context of a Game.
Declaration
public static Vec3 TransformToWorldCords(Game game, float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| Game | game | The Game object. |
| float | x | X-coordinate on the screen. |
| float | y | Y-coordinate on the screen. |
Returns
| Type | Description |
|---|---|
| Vec3 | World coordinates as a Vec3. |
TransformToWorldCords(Camera, Viewport, float, float)
Transforms screen coordinates to world coordinates in the context of a specific Camera and Viewport.
Declaration
public static Vec3 TransformToWorldCords(Camera camera, Viewport viewport, float x, float y)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera object. |
| Viewport | viewport | The Viewport object. |
| float | x | X-coordinate on the screen. |
| float | y | Y-coordinate on the screen. |
Returns
| Type | Description |
|---|---|
| Vec3 | World coordinates as a Vec3. |