Skip to content

Core.Utilities.UVHelper

Dennis Steffen edited this page Jan 4, 2026 · 1 revision

This is a documentation overview for the UVHelper.cs file within the Meatcorps.Engine.Core.Utilities namespace.


UVHelper Utility

The UVHelper is a static utility class that provides a set of predefined Vector2 constants representing common points in UV Coordinate Space.

In computer graphics, UV coordinates (also known as normalized texture coordinates) typically range from 0.0 to 1.0. These constants are primarily used for texture mapping, sprite rendering, and UI alignment where (0,0) represents the top-left corner and (1,1) represents the bottom-right corner of a texture or a container.

API Reference

Constant Vector Value (X, Y) Description
LeftTop (0.0, 0.0) The origin point (top-left).
RightTop (1.0, 0.0) The top-right corner.
RightBottom (1.0, 1.0) The bottom-right corner.
LeftBottom (0.0, 1.0) The bottom-left corner.
Center (0.5, 0.5) The exact center of the texture.
Top (0.5, 0.0) The middle point of the top edge.
Bottom (0.5, 1.0) The middle point of the bottom edge.
Left (0.0, 0.5) The middle point of the left edge.
Right (1.0, 0.5) The middle point of the right edge.

Use Cases

  1. Texture Sampling: Providing specific offsets to shaders or sampling functions to fetch data from the center or edges of a texture.
  2. Sprite Origins/Pivots: Setting the anchor point of a sprite. For example, using UVHelper.Center to rotate a sprite around its middle.
  3. UI Alignment: Defining where a UI element should be anchored relative to its parent container.
  4. Vertex Buffers: Quickly populating UV arrays when generating procedural meshes or quads.

Examples

1. Setting a Sprite Pivot

If you are using a rendering engine where you can specify the origin of a sprite (like RayLib), you can use UVHelper to ensure the sprite rotates around its center.

using Meatcorps.Engine.Core.Utilities;
using System.Numerics;

public void DrawPlayer(Vector2 position, float rotation)
{
    // Uses (0.5, 0.5) to ensure the sprite is drawn centered on 'position'
    // and rotates around its own center.
    Vector2 pivot = UVHelper.Center;
    
    // Engine specific draw call logic...
    Render(position, rotation, pivot);
}

2. Procedural Quad Generation

When creating a simple 2D quad (two triangles), you need to map the four corners of the texture to the four vertices of the quad.

using Meatcorps.Engine.Core.Utilities;

public Vertex[] CreateQuadVertices()
{
    return new Vertex[]
    {
        new Vertex { Position = new(-0.5f, -0.5f), UV = UVHelper.LeftTop },
        new Vertex { Position = new( 0.5f, -0.5f), UV = UVHelper.RightTop },
        new Vertex { Position = new( 0.5f,  0.5f), UV = UVHelper.RightBottom },
        new Vertex { Position = new(-0.5f,  0.5f), UV = UVHelper.LeftBottom }
    };
}

3. Comparison with Direction

Note that UVHelper differs from Direction.cs. While Direction uses a coordinate system centered at (0,0) with values from -1 to 1 (useful for movement), UVHelper uses a coordinate system starting at (0,0) with values from 0 to 1 (standard for textures).

Concept Center Point Range
Direction (0, 0) -1 to 1
UVHelper (0.5, 0.5) 0 to 1

Clone this wiki locally