本文整理汇总了C++中GEdge::ComputeLine方法的典型用法代码示例。如果您正苦于以下问题:C++ GEdge::ComputeLine方法的具体用法?C++ GEdge::ComputeLine怎么用?C++ GEdge::ComputeLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GEdge
的用法示例。
在下文中一共展示了GEdge::ComputeLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WalkEdges
void WalkEdges(const GEdge e1, const GEdge e2, const GPaint &paint) {
const GBitmap &bm = GetInternalBitmap();
int h = bm.fHeight;
int w = bm.fWidth;
GASSERT(e1.p1.y() == e2.p1.y());
int startY = Clamp(static_cast<int>(e1.p1.y() + 0.5f), 0, h-1);
GASSERT(e1.p2.y() == e2.p2.y());
int endY = Clamp(static_cast<int>(e1.p2.y() + 0.5f), 0, h-1);
if(endY == startY) {
return;
}
GASSERT(endY > startY);
// Initialize to NAN
float m1 = 0.0f/0.0f, b1;
float m2 = 0.0f/0.0f, b2;
bool vert1 = e1.ComputeLine(m1, b1);
bool vert2 = e2.ComputeLine(m2, b2);
if(m1 == 0 || m2 == 0) {
return;
}
// Collinear?
if(vert2 && vert1 && e1.p1.x() == e2.p1.x()) {
return;
} else if(m1 == m2 && b1 == b2) {
return;
}
float stepX1 = vert1? 0 : 1/m1;
float stepX2 = vert2? 0 : 1/m2;
GPoint p1, p2;
float sY = static_cast<float>(startY) + 0.5f;
if(vert1) {
p1.set(e1.p1.x(), sY);
} else {
p1.set((sY - b1) / m1, sY);
}
if(vert2) {
p2.set(e2.p1.x(), sY);
} else {
p2.set((sY - b2) / m2, sY);
}
// Make sure that p1 is always less than p2 to avoid
// doing a min/max in the inner loop
if(p1.x() > p2.x()) {
std::swap(p1, p2);
std::swap(stepX1, stepX2);
}
GPixel color = ColorToPixel(paint.getColor());
BlendFunc blend = GetBlendFunc(eBlendOp_SrcOver);
uint32_t nSteps = endY - startY;
for(uint32_t i = 0; i < nSteps; i++) {
// Since we haven't implemented clipping yet, take care
// not to go beyond our bounds...
const int x1 = Clamp<int>(p1.fX + 0.5f, 0, w-1);
const int x2 = Clamp<int>(p2.fX + 0.5f, 0, w-1);
GPixel *row = GetRow(bm, startY + i);
for(int x = x1; x < x2; x++) {
row[x] = blend(row[x], color);
}
p1.fX += stepX1;
p2.fX += stepX2;
}
}