src/editmodes/abstractEditMode.cpp

changeset 1390
3eace926af7f
parent 1326
69a90bd2dba2
child 1419
f7c53002a990
equal deleted inserted replaced
1389:3fb8ad4d27b1 1390:3eace926af7f
312 QPointF point = grid()->snap(line.p2()); 312 QPointF point = grid()->snap(line.p2());
313 result.setCoordinate(relativeX, point.x()); 313 result.setCoordinate(relativeX, point.x());
314 result.setCoordinate(relativeY, point.y()); 314 result.setCoordinate(relativeY, point.y());
315 } 315 }
316 316
317 return result; 317 return projectToDrawPlane(result);
318 } 318 }
319 319
320 /* 320 /*
321 * No draw mode can operate on the free camera, since 3D ⟷ 2D point conversions are not possible with it. 321 * No draw mode can operate on the free camera, since 3D ⟷ 2D point conversions are not possible with it.
322 */ 322 */
347 * The editing mode is to call finishDraw with the prepared model. 347 * The editing mode is to call finishDraw with the prepared model.
348 * 348 *
349 * TODO: the two method names are too similar and should be renamed. 349 * TODO: the two method names are too similar and should be renamed.
350 */ 350 */
351 void AbstractDrawMode::endDraw() {} 351 void AbstractDrawMode::endDraw() {}
352
353 /*
354 * Sets the depth value of the vertex so that it's in the draw plane.
355 */
356 Vertex AbstractDrawMode::projectToDrawPlane(const Vertex& vertex) const
357 {
358 Axis localx, localy;
359 renderer()->getRelativeAxes(localx, localy);
360 Axis localz = renderer()->getRelativeZ();
361 Line line;
362 line.v_1 = line.v_2 = vertex;
363 line.v_1[localz] = 1;
364 line.v_2[localz] = -1;
365 Plane::IntersectionResult intersection = renderer()->drawPlane().intersection(line);
366
367 if (intersection.intersected)
368 return intersection.vertex;
369 else
370 return vertex;
371 }

mercurial