From be1ecc3378ce8adf707bc4a150f12914452faa95 Mon Sep 17 00:00:00 2001 From: Nick Gasson <nick@nickg.me.uk> Date: Fri, 10 Apr 2009 12:15:07 +0100 Subject: [PATCH] Fix rendering of curved track with GL_CULL_FACE --- src/Editor.cpp | 25 ++++++++++++++++++++++++- src/TrackCommon.cpp | 29 +++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/Editor.cpp b/src/Editor.cpp index bef7529..fbcded1 100644 --- a/src/Editor.cpp +++ b/src/Editor.cpp @@ -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 diff --git a/src/TrackCommon.cpp b/src/TrackCommon.cpp index 26ab02b..eadc4c6 100644 --- a/src/TrackCommon.cpp +++ b/src/TrackCommon.cpp @@ -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(); } -- 2.39.5