void Plane::MakeGizmo()
{
	float lineSegmentLength = 300;
	glm::vec3 planeNormal(normal.x, normal.y, normal.z);
	glm::vec3 parallel1(0, 0, 0);
	glm::vec3 parallel2(0, 0, 0);


	if (planeNormal == glm::vec3(0, 0, 1))
		parallel1 = glm::vec3(0, 1, 0);
	else
		parallel1 = glm::vec3(0, 0, 1);

	//get vectors that are perpendecular to the plan
	parallel1 = glm::cross(planeNormal, parallel1);
	parallel2 = glm::cross(planeNormal, parallel1);

	glm::vec3 centrePoint = planeNormal * normal.w;
	parallel1 = glm::normalize(parallel1);
	parallel2 = glm::normalize(parallel2);

	glm::vec3 start = centrePoint + parallel1 * lineSegmentLength;
	glm::vec3 end = centrePoint - parallel1 * lineSegmentLength;
	Gizmos::addLine(start, end, color);

	start = centrePoint + parallel2 * lineSegmentLength;
	end = centrePoint - parallel2 * lineSegmentLength;
	Gizmos::addLine(start, end, color);
}
Beispiel #2
0
/**
 * Creates a line parallel to the given line e.
 * Out of the 2 possible parallels, the one closest to
 * the given coordinate is returned.
 *
 * @param coord Coordinate to define which parallel we want (typically a
 *              mouse coordinate).
 * @param distance Distance of the parallel.
 * @param number Number of parallels.
 * @param e Original entity.
 *
 * @return Pointer to the first created parallel or nullptr if no
 *    parallel has been created.
 */
RS_Line* RS_Creation::createParallelLine(const RS_Vector& coord,
                                         double distance, int number,
                                         RS_Line* e) {

	if (e==nullptr) {
		return nullptr;
    }

	double ang = e->getAngle1() + M_PI_2;
    RS_Vector p1, p2;
    RS_LineData parallelData;
	RS_Line* ret = nullptr;

	if (document && handleUndo) {
        document->startUndoCycle();
    }

    for (int num=1; num<=number; ++num) {

        // calculate 1st parallel:
        p1.setPolar(distance*num, ang);
        p1 += e->getStartpoint();
        p2.setPolar(distance*num, ang);
        p2 += e->getEndpoint();
		RS_Line parallel1(nullptr, RS_LineData(p1, p2));

        // calculate 2nd parallel:
        p1.setPolar(distance*num, ang+M_PI);
        p1 += e->getStartpoint();
        p2.setPolar(distance*num, ang+M_PI);
        p2 += e->getEndpoint();
		RS_Line parallel2(nullptr, RS_LineData(p1, p2));

        double dist1 = parallel1.getDistanceToPoint(coord);
        double dist2 = parallel2.getDistanceToPoint(coord);
        double minDist = std::min(dist1, dist2);

        if (minDist<RS_MAXDOUBLE) {
            if (dist1<dist2) {
                parallelData = parallel1.getData();
            } else {
                parallelData = parallel2.getData();
            }

            RS_Line* newLine = new RS_Line(container, parallelData);
			if (ret==nullptr) {
				ret = newLine;
			}
			setEntity(newLine);
        }
    }

	if (document && handleUndo) {
        document->endUndoCycle();
    }

    return ret;
}
Beispiel #3
0
/**
 * Creates a line parallel to the given line e.
 * Out of the 2 possible parallels, the one closest to
 * the given coordinate is returned.
 *
 * @param coord Coordinate to define which parallel we want (typically a
 *              mouse coordinate).
 * @param distance Distance of the parallel.
 * @param number Number of parallels.
 * @param e Original entity.
 *
 * @return Pointer to the first created parallel or NULL if no
 *    parallel has been created.
 */
RS_Line* RS_Creation::createParallelLine(const RS_Vector& coord,
        double distance, int number,
        RS_Line* e) {

    if (e==NULL) {
        return NULL;
    }

    double ang = e->getAngle1() + M_PI/2.0;
    RS_Vector p1, p2;
    RS_LineData parallelData;
    RS_Line* ret = NULL;

    if (document!=NULL && handleUndo) {
        document->startUndoCycle();
    }

    for (int num=1; num<=number; ++num) {

        // calculate 1st parallel:
        p1.setPolar(distance*num, ang);
        p1 += e->getStartpoint();
        p2.setPolar(distance*num, ang);
        p2 += e->getEndpoint();
        RS_Line parallel1(NULL, RS_LineData(p1, p2));

        // calculate 2nd parallel:
        p1.setPolar(distance*num, ang+M_PI);
        p1 += e->getStartpoint();
        p2.setPolar(distance*num, ang+M_PI);
        p2 += e->getEndpoint();
        RS_Line parallel2(NULL, RS_LineData(p1, p2));

        double dist1 = parallel1.getDistanceToPoint(coord);
        double dist2 = parallel2.getDistanceToPoint(coord);
        double minDist = std::min(dist1, dist2);

        if (minDist<RS_MAXDOUBLE) {
            if (dist1<dist2) {
                parallelData = parallel1.getData();
            } else {
                parallelData = parallel2.getData();
            }


            RS_Line* newLine = new RS_Line(container, parallelData);
            newLine->setLayerToActive();
            newLine->setPenToActive();
            if (ret==NULL) {
                ret = newLine;
            }
            if (container!=NULL) {
                container->addEntity(newLine);
            }
            if (document!=NULL && handleUndo) {
                document->addUndoable(newLine);
                //document->endUndoCycle();
            }
            if (graphicView!=NULL) {
                graphicView->drawEntity(newLine);
            }
        }
    }

    if (document!=NULL && handleUndo) {
        document->endUndoCycle();
    }

    return ret;
}