private Texture texture = TextureStore.getTexture("graphics/hud/line32x32.png");
private void renderArrow(Vector2f from, Vector2f to, float startWidth, Color color, float maxAlpha) {
float dist = Utils.getDistance(from, to);
Vector2f dir = Vector2f.sub(from, to, new Vector2f());
if (dir.x != 0 || dir.y != 0) {
dir.normalise();
} else {
return;
}
float arrowHeadLength = Math.min(startWidth * 0.4f * 3f, dist * 0.5f);
dir.scale(arrowHeadLength);
Vector2f arrowEnd = Vector2f.add(to, dir, new Vector2f());
// main body of the arrow
renderFan(from.x, from.y, arrowEnd.x, arrowEnd.y, startWidth, startWidth * 0.4f, color,
//0f, maxAlpha * 0.5f, maxAlpha);
maxAlpha * 0.2f, maxAlpha * 0.67f, maxAlpha);
// arrowhead, tapers to a width of 0
renderFan(arrowEnd.x, arrowEnd.y, to.x, to.y, startWidth * 0.4f * 3f, 0f, color,
maxAlpha, maxAlpha, maxAlpha);
}
private void renderFan(float x1, float y1, float x2, float y2, float startWidth, float endWidth, Color color, float edge1, float mid, float edge2) {
//HudRenderUtils.renderFan(texture, x1, y1, x2, y2, startWidth, endWidth, color, edge1, mid, edge2, false);
edge1 *= 0.4f;
edge2 *= 0.4f;
mid *= 0.4f;
boolean additive = true;
//additive = false;
renderFan(texture, x1, y1, x2, y2, startWidth, endWidth, color, edge1, mid, edge2, additive);
renderFan(texture, x1 + 0.5f, y1 + 0.5f, x2 + 0.5f, y2 + 0.5f, startWidth, endWidth, color, edge1, mid, edge2, additive);
renderFan(texture, x1 - 0.5f, y1 - 0.5f, x2 - 0.5f, y2 - 0.5f, startWidth, endWidth, color, edge1, mid, edge2, additive);
}
public static void renderFan(Texture texture, float x1, float y1, float x2, float y2,
float startWidth, float endWidth, Color color,
float edge1, float mid, float edge2, boolean additive) {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_TEXTURE_2D);
texture.bind();
GL11.glEnable(GL11.GL_BLEND);
if (additive) {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
} else {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
Vector2f v1 = new Vector2f(x2 - x1, y2 - y1);
Utils.normalise(v1);
v1.set(v1.y, -v1.x);
Vector2f v2 = new Vector2f(v1);
v1.scale(startWidth * 0.5f);
v2.scale(endWidth * 0.5f);
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
{
// center
GL11.glColor4ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue(), (byte)((float)color.getAlpha() * mid));
GL11.glTexCoord2f(0.5f, 0.5f);
GL11.glVertex2f((x2 + x1) * 0.5f, (y2 + y1) * 0.5f);
// start
GL11.glColor4ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue(), (byte)((float)color.getAlpha() * edge1));
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x1 - v1.x, y1 - v1.y);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(x1 + v1.x, y1 + v1.y);
// end
GL11.glColor4ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue(), (byte)((float)color.getAlpha() * edge2));
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(x2 + v2.x, y2 + v2.y);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(x2 - v2.x, y2 - v2.y);
// wrap back around to start
GL11.glColor4ub((byte)color.getRed(), (byte)color.getGreen(), (byte)color.getBlue(), (byte)((float)color.getAlpha() * edge1));
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(x1 - v1.x, y1 - v1.y);
}
GL11.glEnd();
GL11.glPopMatrix();
}