Fix corner case with straight track
authorNick Gasson <nick@nickg.me.uk>
Thu, 9 Apr 2009 08:47:52 +0000 (09:47 +0100)
committerNick Gasson <nick@nickg.me.uk>
Thu, 9 Apr 2009 08:47:52 +0000 (09:47 +0100)
src/Editor.cpp
src/Map.cpp

index 0ad4c140e55c6406851d0a59f02d2d9d9321f47b..d257230811c6d9f9eae103e355309361f4d28056 100644 (file)
@@ -57,10 +57,17 @@ private:
    // Variables for dragging track segments
    Point<int> myDragBegin, myDragEnd;
    bool amDragging;
+
+   // Different tools the user can be using
+   enum Tool {
+      TRACK_TOOL, RAISE_TOOL
+   };
+   Tool myTool;
 };
 
 Editor::Editor()
-   : myPosition(2.0, -8.0, -10.0), amDragging(false)
+   : myPosition(2.0, -8.0, -10.0), amDragging(false),
+     myTool(TRACK_TOOL)
 {
    myMap = makeEmptyMap(32, 32);
 }
@@ -178,11 +185,20 @@ void Editor::drawDraggedTrack()
       }
    }
 
+   log() << "xlen=" << xlen << ", ylen=" << ylen;
+
+   // Corner case where track is connected at right angles (so the
+   // track doesn't actually join)
+   if (straight == ALONG_X && xlen == 0 && ylen > xlen)
+      straight = ALONG_Y;
+   else if (straight == ALONG_Y && ylen == 0 && xlen > ylen)
+      straight = ALONG_X;
+
    // The radius is the length of the shorter side
    // If it's equal to 1 then the track is straight
    // Otherwise it curves towards myDragEnd at the end
-   int radius = (xlen > ylen ? ylen : xlen) + 1;
-   int length = (xlen > ylen ? xlen : ylen) + 1;
+   int radius = (straight == ALONG_X ? ylen : xlen) + 1;
+   int length = (straight == ALONG_X ? xlen : ylen) + 1;
 
    // The length of the straight track until it starts to curve away
    int straightLen = radius == 1 ? length : length - radius;
index 2f7aa5c2f51451bfbaf37e2714feba657885ca40..351c8897317661731ed57d574e5fb41afa6a39c0 100644 (file)
@@ -245,7 +245,9 @@ void Map::highlightTile(IGraphicsPtr aContext, const Point<int>& aPoint) const
 // Render a small part of the map as directed by the quad tree
 void Map::renderSector(IGraphicsPtr aContext,
                        Point<int> botLeft, Point<int> topRight)
-{   
+{
+   glEnable(GL_CULL_FACE);
+   
    for (int x = topRight.x-1; x >= botLeft.x; x--) {
       for (int y = botLeft.y; y < topRight.y; y++) {
          // Name this tile