Skip to content

Commit

Permalink
Add north arrow for rotating map
Browse files Browse the repository at this point in the history
  • Loading branch information
daveyliam committed Nov 24, 2013
1 parent 3976657 commit ffe73b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
24 changes: 14 additions & 10 deletions Render.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,6 @@ public static void drawTexturedRect(double x, double y, double w, double h, doub
}
}

// note that the coords must be in the correct sequence, following the perimeter of the quad,
// and in anticlockwise order.
// otherwise one or both of the triangles that make the quad will not be rendered.
// 1 +------+ 4 2 +------+ 1 1 +------+ 2
// | | | | | |
// | | | | | |
// 2 +------+ 3 3 +------+ 4 3 +------+ 4
// works works fails
//

public static void drawArrow(double x, double y, double angle, double length) {
// angle the back corners will be drawn at relative to the pointing angle
double arrowBackAngle = 0.75D * Math.PI;
Expand All @@ -194,6 +184,20 @@ public static void drawArrow(double x, double y, double angle, double length) {
GL11.glDisable(GL11.GL_BLEND);
}

public static void drawTriangle(double x1, double y1, double x2, double y2, double x3, double y3) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tes = Tessellator.instance;
tes.startDrawing(GL11.GL_TRIANGLES);
tes.addVertex(x1, y1, zDepth);
tes.addVertex(x2, y2, zDepth);
tes.addVertex(x3, y3, zDepth);
tes.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
}

public static void drawRect(double x, double y, double w, double h) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_TEXTURE_2D);
Expand Down
9 changes: 8 additions & 1 deletion map/MapRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ public void draw() {
// draw player arrow
Render.setColour(this.mapMode.playerArrowColour);
Render.drawArrow(arrow.x, arrow.y, this.mw.playerHeading, this.mapMode.playerArrowSize);


// draw north arrow
if (this.mapMode.rotate) {
Render.setColour(this.mapMode.borderColour);
double r = this.mapMode.h / 2.0;
Render.drawTriangle(4.0, -r, 0.0, -r - 4.0, -4.0, -r);
}

// draw overlays from registered providers
//for (IMwDataProvider provider : MwAPI.getDataProviders())
IMwDataProvider provider = MwAPI.getCurrentDataProvider();
Expand Down

0 comments on commit ffe73b6

Please sign in to comment.