Skip to content

Commit

Permalink
Testbed flag to flip the Y axis
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-dejoue committed Apr 24, 2022
1 parent c908312 commit 50cf6d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 9 additions & 0 deletions testbed/data/y.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-2.0 3.0
-1.0 3.0
0.0 1.0
1.0 3.0
2.0 3.0
0.5 0.0
0.5 -3.0
-0.5 -3.0
-0.5 0.0
13 changes: 9 additions & 4 deletions testbed/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const double rotations_per_tick = 0.2;
constexpr int default_window_width = 800;
constexpr int default_window_height = 600;

// Flip Y axis
constexpr bool flag_flip_y = false;

/// Screen center x
double cx = 0.0;
/// Screen center y
Expand Down Expand Up @@ -387,12 +390,13 @@ void MainLoop(const double zoom)
}
}

void ResetZoom(double zoom, double cx, double cy, double width, double height)
void ResetZoom(double zoom, double cx, double cy, double width, double height, bool flag_flip_y)
{
double left = -width / zoom;
double right = width / zoom;
double bottom = -height / zoom;
double top = height / zoom;
double flip_y = flag_flip_y ? -1.0 : 1.0;

// Reset viewport
glLoadIdentity();
Expand All @@ -401,7 +405,8 @@ void ResetZoom(double zoom, double cx, double cy, double width, double height)

// Reset ortho view
glOrtho(left, right, bottom, top, 1.0, -1.0);
glTranslated(-cx, -cy, 0.0);
glTranslated(-cx, flip_y * -cy, 0.0);
glScaled(1.0, flip_y, 1.0);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glLoadIdentity();
Expand All @@ -415,7 +420,7 @@ void Draw(const double zoom)
// reset zoom
Point center = Point(cx, cy);

ResetZoom(zoom, center.x, center.y, (double)default_window_width, (double)default_window_height);
ResetZoom(zoom, center.x, center.y, (double)default_window_width, (double)default_window_height, flag_flip_y);

for (int i = 0; i < triangles.size(); i++) {
Triangle& t = *triangles[i];
Expand Down Expand Up @@ -456,7 +461,7 @@ void DrawMap(const double zoom)
// reset zoom
Point center = Point(cx, cy);

ResetZoom(zoom, center.x, center.y, (double)default_window_width, (double)default_window_height);
ResetZoom(zoom, center.x, center.y, (double)default_window_width, (double)default_window_height, flag_flip_y);

list<Triangle*>::iterator it;
for (it = map.begin(); it != map.end(); it++) {
Expand Down

0 comments on commit 50cf6d7

Please sign in to comment.