src/invert.cpp

changeset 21
0133e565e072
parent 19
ed9685f44ab3
child 24
1a0faaaceb84
equal deleted inserted replaced
20:cef43609a374 21:0133e565e072
18 18
19 #include "main.h" 19 #include "main.h"
20 #include "model.h" 20 #include "model.h"
21 #include "matrix.h" 21 #include "matrix.h"
22 #include "gl/common.h" 22 #include "gl/common.h"
23 #include "invert.h"
23 24
24 #if 0 25 #if 0
25 /* 26 /*
26 * Returns whether or not the document is flat. 27 * Returns whether or not the document is flat.
27 * If it is flat, the result is stored in *axis. 28 * If it is flat, the result is stored in *axis.
70 #endif 71 #endif
71 72
72 /* 73 /*
73 * Returns a matrix that causes a flip on the given dimension. 74 * Returns a matrix that causes a flip on the given dimension.
74 */ 75 */
75 Matrix4x4 flipmatrix(Axis dimension) 76 Matrix4x4 math::flipmatrix(const Axis dimension)
76 { 77 {
77 Matrix4x4 result = identity4x4; 78 Matrix4x4 result = identity4x4;
78 switch (dimension) 79 result(static_cast<int>(dimension), static_cast<int>(dimension)) = -1;
79 {
80 case X:
81 result(0, 0) = -1;
82 break;
83 case Y:
84 result(1, 1) = -1;
85 break;
86 case Z:
87 result(2, 2) = -1;
88 break;
89 }
90 return result; 80 return result;
91 } 81 }
92 82
93 #if 0 83 #if 0
94 /* 84 /*
141 #endif 131 #endif
142 132
143 /* 133 /*
144 * Inverts the winding of a polygon. 134 * Inverts the winding of a polygon.
145 */ 135 */
146 void invertPolygon(gl::Polygon& polygon) 136 void gl::invert(gl::Polygon& polygon)
147 { 137 {
148 switch (polygon.numPolygonVertices()) 138 switch (polygon.numPolygonVertices())
149 { 139 {
150 case 2: 140 case 2:
151 case 3: 141 case 3:
142 // 0 1 => 1 0
143 // 0 1 2 => 1 0 2
152 std::swap(polygon.vertices[0], polygon.vertices[1]); 144 std::swap(polygon.vertices[0], polygon.vertices[1]);
153 break; 145 break;
154
155 case 4: 146 case 4:
147 // 0 1 2 3 => 0 3 2 1
156 std::swap(polygon.vertices[1], polygon.vertices[3]); 148 std::swap(polygon.vertices[1], polygon.vertices[3]);
157 break; 149 break;
158 } 150 }
159 } 151 }

mercurial