src/canvas.cpp

changeset 1199
613a981223a6
parent 1187
46dc716238fd
equal deleted inserted replaced
1198:f7151e4cd90f 1199:613a981223a6
96 void Canvas::drawFixedCameraBackdrop() 96 void Canvas::drawFixedCameraBackdrop()
97 { 97 {
98 // Find the top left corner of the grid 98 // Find the top left corner of the grid
99 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); 99 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0}));
100 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); 100 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()}));
101 qreal gridSize = grid()->coordinateSnap(); 101 qreal gridSize = Grid::coordinateSnap();
102 glEnable(GL_LINE_STIPPLE); 102 glEnable(GL_LINE_STIPPLE);
103 glBegin(GL_LINES); 103 glBegin(GL_LINES);
104 104
105 switch (grid()->type()) 105 switch (Grid::type())
106 { 106 {
107 case Grid::Cartesian: 107 case Grid::Cartesian:
108 { 108 {
109 qreal x0 = sign(topLeft.x()) * (fabs(topLeft.x()) - fmod(fabs(topLeft.x()), gridSize)); 109 qreal x0 = sign(topLeft.x()) * (fabs(topLeft.x()) - fmod(fabs(topLeft.x()), gridSize));
110 qreal y0 = sign(topLeft.y()) * (fabs(topLeft.y()) - fmod(fabs(topLeft.y()), gridSize)); 110 qreal y0 = sign(topLeft.y()) * (fabs(topLeft.y()) - fmod(fabs(topLeft.y()), gridSize));
146 } 146 }
147 break; 147 break;
148 148
149 case Grid::Polar: 149 case Grid::Polar:
150 { 150 {
151 const QPointF pole = grid()->pole(); 151 const QPointF pole = Grid::pole();
152 const qreal size = grid()->coordinateSnap(); 152 const qreal size = Grid::coordinateSnap();
153 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0})); 153 Vertex topLeft = currentCamera().idealize(currentCamera().convert2dTo3d({0, 0}));
154 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()})); 154 Vertex bottomRight = currentCamera().idealize(currentCamera().convert2dTo3d({width(), height()}));
155 QPointF topLeft2d {topLeft.x(), topLeft.y()}; 155 QPointF topLeft2d {topLeft.x(), topLeft.y()};
156 QPointF bottomLeft2d {topLeft.x(), bottomRight.y()}; 156 QPointF bottomLeft2d {topLeft.x(), bottomRight.y()};
157 QPointF bottomRight2d {bottomRight.x(), bottomRight.y()}; 157 QPointF bottomRight2d {bottomRight.x(), bottomRight.y()};
169 // Is the pole at (0, 0)? If so, then don't render the polar axes above the real ones. 169 // Is the pole at (0, 0)? If so, then don't render the polar axes above the real ones.
170 bool poleIsOrigin = isZero(pole.x()) and isZero(pole.y()); 170 bool poleIsOrigin = isZero(pole.x()) and isZero(pole.y());
171 glColor4f(0, 0, 0, 0.25); 171 glColor4f(0, 0, 0, 0.25);
172 172
173 // Render the axes 173 // Render the axes
174 for (int i = 0; i < grid()->polarDivisions() / 2; ++i) 174 for (int i = 0; i < Grid::polarDivisions() / 2; ++i)
175 { 175 {
176 qreal azimuth = (2.0 * pi) * i / grid()->polarDivisions(); 176 qreal azimuth = (2.0 * pi) * i / Grid::polarDivisions();
177 177
178 if (not poleIsOrigin or not isZero(fmod(azimuth, pi / 2))) 178 if (not poleIsOrigin or not isZero(fmod(azimuth, pi / 2)))
179 { 179 {
180 QPointF extremum = {cos(azimuth) * 10000, sin(azimuth) * 10000}; 180 QPointF extremum = {cos(azimuth) * 10000, sin(azimuth) * 10000};
181 QPointF A = pole + extremum; 181 QPointF A = pole + extremum;
189 { 189 {
190 if (not isZero(radius)) 190 if (not isZero(radius))
191 { 191 {
192 Vertex points[48]; 192 Vertex points[48];
193 193
194 for (int i = 0; i < grid()->polarDivisions(); ++i) 194 for (int i = 0; i < Grid::polarDivisions(); ++i)
195 { 195 {
196 qreal azimuth = (2.0 * pi) * i / grid()->polarDivisions(); 196 qreal azimuth = (2.0 * pi) * i / Grid::polarDivisions();
197 QPointF point = pole + QPointF {radius * cos(azimuth), radius * sin(azimuth)}; 197 QPointF point = pole + QPointF {radius * cos(azimuth), radius * sin(azimuth)};
198 points[i] = currentCamera().realize({point.x(), point.y(), 999}); 198 points[i] = currentCamera().realize({point.x(), point.y(), 999});
199 } 199 }
200 200
201 for (int i = 0; i < grid()->polarDivisions(); ++i) 201 for (int i = 0; i < Grid::polarDivisions(); ++i)
202 { 202 {
203 glVertex(points[i]); 203 glVertex(points[i]);
204 glVertex(ring(points, grid()->polarDivisions())[i + 1]); 204 glVertex(ring(points, Grid::polarDivisions())[i + 1]);
205 } 205 }
206 } 206 }
207 } 207 }
208 } 208 }
209 break; 209 break;
272 } 272 }
273 273
274 void Canvas::mouseMoveEvent(QMouseEvent* event) 274 void Canvas::mouseMoveEvent(QMouseEvent* event)
275 { 275 {
276 // Calculate 3d position of the cursor 276 // Calculate 3d position of the cursor
277 m_position3D = currentCamera().convert2dTo3d(mousePosition(), grid()); 277 m_position3D = currentCamera().convert2dTo3d(mousePosition(), true);
278 278
279 if (not m_currentEditMode->mouseMoved(event)) 279 if (not m_currentEditMode->mouseMoved(event))
280 GLRenderer::mouseMoveEvent(event); 280 GLRenderer::mouseMoveEvent(event);
281 } 281 }
282 282

mercurial