2D。
我使用一系列中点坐标对应材质渲染位置,
GL11.glPushMatrix();
GL11.glTranslatef(x, y, 0);
GL11.glRotatef(angle + 90f, 0, 0, 1);
GL11.glEnable(GL11.GL_TEXTURE_2D);
sprite.bindTexture();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4ub((byte) color.getRed(),
(byte) color.getGreen(),
(byte) color.getBlue(),
(byte) ((float) color.getAlpha() * alphaMult));
GL11.glBegin(GL11.GL_QUAD_STRIP);
{
float texProgress = 1f;
float ftAngle;
float diffAngle = MathUtils.getShortestRotation(this.angle, 270f);
List<Vector2f> offsetPoints = VectorUtils.rotateAroundPivot(tentacleMiddlePoints, loc, diffAngle);
for (int i = 0; i < segments - 1; i++) {
float x0, x1, y0, y1;
Vector2f vi = offsetPoints.get(i);
Vector2f vii = offsetPoints.get(i + 1);
if (i == 0) {
ftAngle = 270f;
} else {
ftAngle = VectorUtils.getAngle(vi, vii);
}
Vector2f leftV = MathUtils.getPointOnCircumference(vi, halfWidth, ftAngle + 90f);
Vector2f rightV = MathUtils.getPointOnCircumference(vi, halfWidth, ftAngle - 90f);
x0 = leftV.x - x;
y0 = leftV.y - y;
x1 = rightV.x - x;
y1 = rightV.y - y;
GL11.glTexCoord2f(0f, texProgress);
GL11.glVertex2f(x0, y0);
GL11.glTexCoord2f(1f, texProgress);
GL11.glVertex2f(x1, y1);
texProgress -= texPerSegment;
if (texProgress < 0f) {
break;
}
}
}
GL11.glEnd();
GL11.glPopMatrix();
现在出现一种情况,如果我这一系列点靠的太近,或者连成的直线拐了个180°甚至360°的大弯,那么渲染的图片明显有一部分时重叠的(颜色很亮的长条),这应该怎么解决?从源头入手删掉几个点吗?但这样的话算法又是什么?