struct mrpt::opengl::TTriangle

A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex.

Note that not all the fields must be filled in, it depends on the consumer of the structure.

The structure is memory packed to 1-byte, to ensure it can be used in GPU memory vertex arrays without unexpected paddings.

See also:

opengl::Scene, CSetOfTexturedTriangles

#include <mrpt/opengl/TTriangle.h>

struct TTriangle
{
    // structs

    struct Vertex;

    //
fields

    std::array<Vertex, 3> vertices;

    // construction

    TTriangle();
    TTriangle(const mrpt::math::TPolygon3D& p);
    TTriangle(const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2, const mrpt::math::TPoint3Df& p3);
    TTriangle(const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2, const mrpt::math::TPoint3Df& p3, const mrpt::math::TVector3Df& n1, const mrpt::math::TVector3Df& n2, const mrpt::math::TVector3Df& n3);

    //
methods

    const float& x(size_t i) const;
    const float& y(size_t i) const;
    const float& z(size_t i) const;
    const uint8_t& r(size_t i) const;
    const uint8_t& g(size_t i) const;
    const uint8_t& b(size_t i) const;
    const uint8_t& a(size_t i) const;
    const float& u(size_t i) const;
    const float& v(size_t i) const;
    float& x(size_t i);
    float& y(size_t i);
    float& z(size_t i);
    uint8_t& r(size_t i);
    uint8_t& g(size_t i);
    uint8_t& b(size_t i);
    uint8_t& a(size_t i);
    float& u(size_t i);
    float& v(size_t i);
    mrpt::math::TPoint3Df& vertex(size_t i);
    const mrpt::math::TPoint3Df& vertex(size_t i) const;
    void setColor(const mrpt::img::TColor& c);
    void setColor(const mrpt::img::TColorf& c);
    void computeNormals();
    void readFrom(mrpt::serialization::CArchive& i);
    void writeTo(mrpt::serialization::CArchive& o) const;
};

Construction

TTriangle(const mrpt::math::TPoint3Df& p1, const mrpt::math::TPoint3Df& p2, const mrpt::math::TPoint3Df& p3)

Constructor from 3 points (default normals are computed)

TTriangle(
    const mrpt::math::TPoint3Df& p1,
    const mrpt::math::TPoint3Df& p2,
    const mrpt::math::TPoint3Df& p3,
    const mrpt::math::TVector3Df& n1,
    const mrpt::math::TVector3Df& n2,
    const mrpt::math::TVector3Df& n3
    )

Constructor from 3 points and its 3 normals.

Methods

void setColor(const mrpt::img::TColor& c)

Sets the color of all vertices.

void computeNormals()

Compute the three normals from the cross-product of “v01 x v02”.

Note that using this default normals will not lead to interpolated lighting in the fragment shaders, since all vertex are equal; a derived class should use custom, more accurate normals to enable soft lighting.