From 6e378740e24bb16da18f855fd054ffecdb8d8755 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 31 May 2009 10:53:03 +0100 Subject: [PATCH] Draw arrow for start location --- src/Map.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Map.cpp b/src/Map.cpp index f261703..5dfdb62 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -159,6 +159,7 @@ private: void readHeightMap(const string& aFileName); void tileVertices(int x, int y, int* indexes) const; void renderPickSector(Point botLeft, Point topRight); + void drawStartLocation() const; // Mesh modification void buildMesh(int id, Point botLeft, Point topRight); @@ -178,7 +179,7 @@ private: IQuadTreePtr myQuadTree; IFogPtr myFog; bool shouldDrawGridLines, inPickMode; - list> myDirtyTiles; + list > myDirtyTiles; }; Map::Map() @@ -364,6 +365,38 @@ void Map::highlightTile(IGraphicsPtr aContext, const Point& aPoint) const glPopName(); } +// Draw an arrow on the start location +void Map::drawStartLocation() const +{ + glPushAttrib(GL_ENABLE_BIT); + glPushMatrix(); + + glEnable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + + int indexes[4]; + tileVertices(myStartLocation.x, myStartLocation.y, indexes); + + float avgHeight = 0.0f; + for (int i = 0; i < 4; i++) + avgHeight += myHeightMap[indexes[i]].pos.y; + avgHeight /= 4.0f; + + glTranslatef(myStartLocation.x, avgHeight + 0.1f, myStartLocation.y); + + glColor4f(0.0f, 0.9f, 0.0f, 0.8f); + + glBegin(GL_TRIANGLES); + glNormal3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.5f, 0.0f, -0.5f); + glVertex3f(-0.5f, 0.0f, -0.5f); + glVertex3f(0.0f, 0.0f, 0.5f); + glEnd(); + + glPopMatrix(); + glPopAttrib(); +} + // Check to see if the given id contains a valid mesh and ensure the // array is large enough to hold it bool Map::haveMesh(int id, Point botLeft, Point topRight) @@ -600,6 +633,11 @@ void Map::renderSector(IGraphicsPtr aContext, int id, tile.track->setMark(); } + + // Draw the start location if it's on this tile + if (myStartLocation.x == x && myStartLocation.y == y + && shouldDrawGridLines) + drawStartLocation(); } } } -- 2.39.2