Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::SubTexture2D Class Reference

Represents a sub-region of a 2D texture, useful for sprite sheets. More...

#include <SubTexture2D.h>

Public Member Functions

glm::vec2 * GetTexCoords ()
 Returns the texture coordinates of the sub-texture.
 
const Ref< Texture2D > GetTexture ()
 Returns the underlying texture of the sub-texture.
 
 SubTexture2D (const Ref< Texture2D > &texture, const glm::vec2 &min, const glm::vec2 &max)
 Constructs a SubTexture2D from the given texture and texture coordinates.
 

Static Public Member Functions

static Ref< SubTexture2D > CreateFromCoords (const Ref< Texture2D > &texture, const glm::vec2 &coords, const glm::vec2 &cellSize, const glm::vec2 &spriteSize={1, 1})
 Creates a SubTexture2D from a grid of cells within the given texture.
 

Private Attributes

glm::vec2 m_TexCoords [4]
 The texture coordinates of the sub-texture.
 
Ref< Texture2D > m_Texture
 The underlying texture of the sub-texture.
 

Detailed Description

Represents a sub-region of a 2D texture, useful for sprite sheets.

Constructor & Destructor Documentation

◆ SubTexture2D()

Muto::SubTexture2D::SubTexture2D ( const Ref< Texture2D > &  texture,
const glm::vec2 &  min,
const glm::vec2 &  max 
)

Constructs a SubTexture2D from the given texture and texture coordinates.

Parameters
textureThe texture from which the sub-texture is derived.
minThe minimum texture coordinates (bottom-left).
maxThe maximum texture coordinates (top-right).
10 {
11 m_TexCoords[0] = { min.x, min.y };
12 m_TexCoords[1] = { max.x, min.y };
13 m_TexCoords[2] = { max.x, max.y };
14 m_TexCoords[3] = { min.x, max.y };
15 }
glm::vec2 m_TexCoords[4]
The texture coordinates of the sub-texture.
Definition SubTexture2D.h:41
Ref< Texture2D > m_Texture
The underlying texture of the sub-texture.
Definition SubTexture2D.h:39
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References SubTexture2D().

Referenced by SubTexture2D().

Member Function Documentation

◆ CreateFromCoords()

Ref< SubTexture2D > Muto::SubTexture2D::CreateFromCoords ( const Ref< Texture2D > &  texture,
const glm::vec2 &  coords,
const glm::vec2 &  cellSize,
const glm::vec2 &  spriteSize = {1, 1} 
)
static

Creates a SubTexture2D from a grid of cells within the given texture.

Parameters
textureThe texture from which the sub-texture is derived.
coordsThe coordinates of the cell in the grid.
cellSizeThe size of each cell in the grid.
spriteSizeThe size of the sprite in cells (default is 1x1).
18 {
19 glm::vec2 min = { (coords.x * cellSize.x) / texture->GetWidth(), (coords.y * cellSize.y) / texture->GetHeight() };
20 glm::vec2 max = { ((coords.x + spriteSize.x) * cellSize.x) / texture->GetWidth(), ((coords.y + spriteSize.y) * cellSize.y) / texture->GetHeight() };
21
23 }

◆ GetTexCoords()

glm::vec2 * Muto::SubTexture2D::GetTexCoords ( )
inline

Returns the texture coordinates of the sub-texture.

28{ return m_TexCoords; }

◆ GetTexture()

const Ref< Texture2D > Muto::SubTexture2D::GetTexture ( )
inline

Returns the underlying texture of the sub-texture.

26{ return m_Texture; }

Member Data Documentation

◆ m_TexCoords

glm::vec2 Muto::SubTexture2D::m_TexCoords[4]
private

The texture coordinates of the sub-texture.

◆ m_Texture

Ref<Texture2D> Muto::SubTexture2D::m_Texture
private

The underlying texture of the sub-texture.


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