Fix rendering of curved track with GL_CULL_FACE
authorNick Gasson <nick@nickg.me.uk>
Fri, 10 Apr 2009 11:15:07 +0000 (12:15 +0100)
committerNick Gasson <nick@nickg.me.uk>
Fri, 10 Apr 2009 11:15:07 +0000 (12:15 +0100)
src/Editor.cpp
src/TrackCommon.cpp

index bef75299a2dabd2ed2ee7814814af38f795cd75b..fbcded175acaa9a97cea76b2a08a0afe3ec169e5 100644 (file)
@@ -196,7 +196,30 @@ void Editor::drawDraggedCurve(int xLength, int yLength)
 
    Track::Direction dir = guessTrackDirection();
 
-   
+   // If we a drawing along the X axis then the track must curve to the
+   // Y axis somewhere
+   // If X is the longer dimension then the curve is at the end after
+   // a straight section, otherwise the curve is at the beginning
+   if (dir == Axis::X) {
+      if (xLength > yLength) {
+         log() << "Curve X->Y at end";
+      }
+      else {
+         log() << "Curve X->Y at start";
+      }
+   }
+   else {
+      // Otherwise the track must curve to the X axis
+      if (yLength > xLength) {
+         log() << "Curve Y->X at end";
+      }
+      else {
+         log() << "Curve Y->X at start";
+      }
+   }
+
+   ITrackSegmentPtr curve = makeCurvedTrack();
+   myMap->setTrackAt(myDragBegin, curve);
 }
 
 // Called when the user has finished dragging a rectangle for track
index 26ab02bdf69547d8c7134997448e1b8d5c400e10..eadc4c6417caa3e19517ebce0469f631d45784d4 100644 (file)
@@ -148,27 +148,31 @@ static void makeCurveRail(double baseRadius, double startAngle,
    glBegin(GL_QUADS);
    for (double theta = startAngle; theta < finishAngle; theta += step) {
       glNormal3d(0.0, 1.0, 0.0);
-      glVertex3d(R * cos(theta), 0.1, R * sin(theta));
-      glNormal3d(0.0, 1.0, 0.0);
-      glVertex3d(R * cos(theta + step), 0.1, R * sin(theta + step));
-      glNormal3d(0.0, 1.0, 0.0);
+      glVertex3d(r * cos(theta), 0.1, r * sin(theta)); 
       glVertex3d(r * cos(theta + step), 0.1, r * sin(theta + step));
-      glNormal3d(0.0, 1.0, 0.0);
-      glVertex3d(r * cos(theta), 0.1, r * sin(theta));
+      glVertex3d(R * cos(theta + step), 0.1, R * sin(theta + step));
+      glVertex3d(R * cos(theta), 0.1, R * sin(theta));
    }
    glEnd();
 
+   // I really have no idea how to compute the normals here!
+   glPushAttrib(GL_ENABLE_BIT);
+   glDisable(GL_CULL_FACE);
+
    // Outer edge
    glBegin(GL_QUADS);
    for (double theta = startAngle; theta < finishAngle; theta += step) {
-      glNormal3d(cos(theta), 0.0, sin(theta));
-      glVertex3d(R * cos(theta), 0.1, R * sin(theta));
       glNormal3d(cos(theta), 0.0, sin(theta));
       glVertex3d(R * cos(theta), 0.0, R * sin(theta));
+      
       glNormal3d(cos(theta + step), 0.0, sin(theta + step));
       glVertex3d(R * cos(theta + step), 0.0, R * sin(theta + step));
-      glNormal3d(cos(theta + step), 0.1, sin(theta + step));
+      
+      glNormal3d(cos(theta + step), 0.0, sin(theta + step));
       glVertex3d(R * cos(theta + step), 0.1, R * sin(theta + step));
+      
+      glNormal3d(cos(theta), 0.0, sin(theta));
+      glVertex3d(R * cos(theta), 0.1, R * sin(theta));      
    }
    glEnd();
 
@@ -177,15 +181,20 @@ static void makeCurveRail(double baseRadius, double startAngle,
    for (double theta = startAngle; theta < finishAngle; theta += step) {
       glNormal3d(-cos(theta), 0.0, -sin(theta));
       glVertex3d(r * cos(theta), 0.1, r * sin(theta));
+      
       glNormal3d(-cos(theta), 0.0, -sin(theta));
       glVertex3d(r * cos(theta), 0.0, r * sin(theta));
+      
       glNormal3d(-cos(theta + step), 0.0, -sin(theta + step));
       glVertex3d(r * cos(theta + step), 0.0, r * sin(theta + step));
-      glNormal3d(-cos(theta + step), 0.1, -sin(theta + step));
+      
+      glNormal3d(-cos(theta + step), 0.0, -sin(theta + step));
       glVertex3d(r * cos(theta + step), 0.1, r * sin(theta + step));
    }
    glEnd();
 
+   glPopAttrib();
+
    glPopMatrix();
 }