Represents triangle. When triangle is ready to be drawn(after its vertex transformation) call Prepare()
method to pre-calculate all required values(don't call it for each drawing point). When drawing each point(pixel) of the triangle, call CalculateWeight(...)
method supplying it with current point coordinates. It calculates weight for the point which are used in interpolation. It returns false if the point is out of triangle. You may omit point drawing in this case. After it you may use interpolation methods to calculate proper values like color, texture coordinates, and so on.
You can find more information in comments below.
template<unsigned char Channels, class ChannelType, class PointType, class FloatType>
struct TTriangle
{
public:
TVertex<Channels, ChannelType, PointType, FloatType> Vertex1; // First vertex
TVertex<Channels, ChannelType, PointType, FloatType> Vertex2; // Second vertex
TVertex<Channels, ChannelType, PointType, FloatType> Vertex3; // Third vertex
void Prepare(); // Calculate private values, required for interpolation. Should be called after triangle transformation
bool CalculateWeights(const math::TPoint<FloatType> &p); // Calculate weight for sepcified point(required for interpolation). Return false if point is outside triangle
FloatType Interpolate(const FloatType v1, const FloatType v2, const FloatType v3); // Calculate interpolated value for 3 values corresponding to each triangle vertex. CalculateWeight should be called first
void InterpolateColor(TPixel<Channels, ChannelType> &dst); // Calculate interpolated color for the point specified in CalculateWeight method
void InterpolateTexCoord(math::TPoint<FloatType> &dst); // Calculate interpolated texture coordinates for the point specified in CalculateWeight method
};
Namespace: | nitisa::graphics |
Include: | Nitisa/Modules/Graphics/Triangle.h |