Documentation for module: Graphics

Former-commit-id: 1757c33318443aade1dc38e16d053240d7dc885c
This commit is contained in:
Gawaboumga
2016-05-30 14:21:36 +02:00
parent 7721fd2284
commit 2c941827ed
94 changed files with 4858 additions and 504 deletions

View File

@@ -8,6 +8,10 @@
namespace Nz
{
/*!
* \brief Constructs a Sprite object by default
*/
inline Sprite::Sprite() :
m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
@@ -16,6 +20,12 @@ namespace Nz
SetDefaultMaterial();
}
/*!
* \brief Constructs a Sprite object with a reference to a material
*
* \param material Reference to a material
*/
inline Sprite::Sprite(MaterialRef material) :
m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
@@ -24,6 +34,12 @@ namespace Nz
SetMaterial(std::move(material), true);
}
/*!
* \brief Constructs a Sprite object with a pointer to a texture
*
* \param texture Pointer to a texture
*/
inline Sprite::Sprite(Texture* texture) :
m_color(Color::White),
m_textureCoords(0.f, 0.f, 1.f, 1.f),
@@ -32,6 +48,12 @@ namespace Nz
SetTexture(texture, true);
}
/*!
* \brief Constructs a Sprite object by assignation
*
* \param sprite Sprite to copy into this
*/
inline Sprite::Sprite(const Sprite& sprite) :
InstancedRenderable(sprite),
m_color(sprite.m_color),
@@ -41,26 +63,52 @@ namespace Nz
{
}
/*!
* \brief Gets the color of the sprite
* \return Current color
*/
inline const Color& Sprite::GetColor() const
{
return m_color;
}
/*!
* \brief Gets the material of the sprite
* \return Current material
*/
inline const MaterialRef& Sprite::GetMaterial() const
{
return m_material;
}
/*!
* \brief Gets the size of the sprite
* \return Current size
*/
inline const Vector2f& Sprite::GetSize() const
{
return m_size;
}
/*!
* \brief Gets the texture coordinates of the sprite
* \return Current texture coordinates
*/
inline const Rectf& Sprite::GetTextureCoords() const
{
return m_textureCoords;
}
/*!
* \brief Sets the color of the billboard
*
* \param color Color for the billboard
*/
inline void Sprite::SetColor(const Color& color)
{
m_color = color;
@@ -68,6 +116,10 @@ namespace Nz
InvalidateVertices();
}
/*!
* \brief Sets the default material of the sprite (just default material)
*/
inline void Sprite::SetDefaultMaterial()
{
MaterialRef material = Material::New();
@@ -77,6 +129,13 @@ namespace Nz
SetMaterial(std::move(material));
}
/*!
* \brief Sets the material of the sprite
*
* \param material Material for the sprite
* \param resizeSprite Should sprite be resized to the material size (diffuse map)
*/
inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite)
{
m_material = std::move(material);
@@ -88,6 +147,12 @@ namespace Nz
}
}
/*!
* \brief Sets the size of the sprite
*
* \param size Size for the sprite
*/
inline void Sprite::SetSize(const Vector2f& size)
{
m_size = size;
@@ -97,11 +162,25 @@ namespace Nz
InvalidateVertices();
}
/*!
* \brief Sets the size of the sprite
*
* \param sizeX Size in X for the sprite
* \param sizeY Size in Y for the sprite
*/
inline void Sprite::SetSize(float sizeX, float sizeY)
{
SetSize(Vector2f(sizeX, sizeY));
}
/*!
* \brief Sets the texture of the sprite
*
* \param texture Texture for the sprite
* \param resizeSprite Should sprite be resized to the texture size
*/
inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite)
{
if (!m_material)
@@ -115,12 +194,27 @@ namespace Nz
m_material->SetDiffuseMap(std::move(texture));
}
/*!
* \brief Sets the texture coordinates of the sprite
*
* \param coords Texture coordinates
*/
inline void Sprite::SetTextureCoords(const Rectf& coords)
{
m_textureCoords = coords;
InvalidateVertices();
}
/*!
* \brief Sets the texture rectangle of the sprite
*
* \param rect Rectangles symbolizing the size of the texture
*
* \remark Produces a NazaraAssert if material is invalid
* \remark Produces a NazaraAssert if material has no diffuse map
*/
inline void Sprite::SetTextureRect(const Rectui& rect)
{
NazaraAssert(m_material, "Sprite has no material");
@@ -128,12 +222,19 @@ namespace Nz
Texture* diffuseMap = m_material->GetDiffuseMap();
float invWidth = 1.f/diffuseMap->GetWidth();
float invHeight = 1.f/diffuseMap->GetHeight();
float invWidth = 1.f / diffuseMap->GetWidth();
float invHeight = 1.f / diffuseMap->GetHeight();
SetTextureCoords(Rectf(invWidth*rect.x, invHeight*rect.y, invWidth*rect.width, invHeight*rect.height));
SetTextureCoords(Rectf(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height));
}
/*!
* \brief Sets the current sprite with the content of the other one
* \return A reference to this
*
* \param sprite The other Sprite
*/
inline Sprite& Sprite::operator=(const Sprite& sprite)
{
InstancedRenderable::operator=(sprite);
@@ -143,18 +244,29 @@ namespace Nz
m_textureCoords = sprite.m_textureCoords;
m_size = sprite.m_size;
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
// We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated
InvalidateBoundingVolume();
InvalidateVertices();
return *this;
}
/*!
* \brief Invalidates the vertices
*/
inline void Sprite::InvalidateVertices()
{
InvalidateInstanceData(0);
}
/*!
* \brief Creates a new sprite from the arguments
* \return A reference to the newly created sprite
*
* \param args Arguments for the sprite
*/
template<typename... Args>
SpriteRef Sprite::New(Args&&... args)
{