Ejemplo n.º 1
0
void Pythagoras::draw(unsigned char* frame){
	if (!this->isCompleted)
		return;

	glm::vec2 A, B, C;
	glm::vec2 AB_outVector, AC_outVector, Hypo_outVector;
	std::vector<Line> lines;

	A = this->vertices.at(0);
	B = this->vertices.at(1);
	C = this->vertices.at(2);

	//this->rAn.push_back(Line(A, B));
	AB_outVector = -glm::normalize(B - A) * 3.0f * this->size;
	lines.push_back(Line(A, A + AB_outVector));
	lines.push_back(Line(C, C + AB_outVector));
	lines.push_back(Line(A + AB_outVector, C + AB_outVector));

	AC_outVector = -glm::normalize(C - A) * 4.0f * this->size;
	lines.push_back(Line(B, B + AC_outVector));
	lines.push_back(Line(A, A + AC_outVector));
	lines.push_back(Line(A + AC_outVector, B + AC_outVector));

	Hypo_outVector =  Transform(Transform::rotate(-90, 0)) * (-glm::normalize(B - C)  * 5.0f * this->size);
	lines.push_back(Line(B, B + Hypo_outVector));
	lines.push_back(Line(C, C + Hypo_outVector));
	lines.push_back(Line(C + Hypo_outVector, B + Hypo_outVector));
	//this->rAn.push_back(Line(t.vertices.at(0), t.vertices.at(1)));

	Triangle2D(A,B,C).draw(frame);
	for (auto p : lines)
		p.draw(frame);

	lines.clear();
}
Ejemplo n.º 2
0
void EarClipper::addTriangle(Graph<Point2D> &poly, const std::list<int>& remainingVertices, std::list<int>::iterator vertex, std::vector<Triangle2D> *triangles) {
    assert (remainingVertices.size() > 2);
    unsigned int a, b, c;

    b = *vertex;
    if (vertex == remainingVertices.begin()) {
        a = remainingVertices.back();
        c = *++vertex;
        --vertex;
    } else if (vertex == --remainingVertices.end()) {
        a = *--vertex;
        c = remainingVertices.front();
        ++vertex;
    } else {
        a = *--vertex;
        c = *++++vertex;
    }

    assert (a < poly.getVertexCount() && b < poly.getVertexCount() && c < poly.getVertexCount());

    poly.addEdge(a, c);
    std::cout << "Edge added: " << a << ' ' << c << ", ear clipped: " << b << std::endl;
    if (triangles != 0) {
        triangles->push_back(Triangle2D(poly.getVertex(a), poly.getVertex(b), poly.getVertex(c)));
    }
}
Ejemplo n.º 3
0
Graph <Point2D> EarClipper::triangulate(const Graph <Point2D> &arg, std::vector <Triangle2D> *triangles) {
    Graph <Point2D> result (arg);
    std::vector<bool> vertexStatus (arg.getVertexCount(), false); //1 - ear, 0 - not ear
    std::list<int> remainingVertices;
    short direction = determineDirection(arg);

    for (unsigned int i = 0; i < arg.getVertexCount(); ++i) {
        remainingVertices.push_back(i);
    }

    for (std::list<int>::iterator it = remainingVertices.begin(); it != remainingVertices.end(); ++it) {
        vertexStatus[*it] = isEar(arg, remainingVertices, it, direction);
    }

    std::list<int>::iterator currentVertex = remainingVertices.begin();
    while (remainingVertices.size() > 3) {
        bool earFound = false;

        for (unsigned int i = remainingVertices.size(); i > 0 && remainingVertices.size() > 3; --i) {
            if (vertexStatus[*currentVertex] == 1) {
                earFound = true;
                addTriangle(result, remainingVertices, currentVertex, triangles);

                std::list<int>::iterator vertexToRemove = currentVertex;

                if (++currentVertex == remainingVertices.end()) {
                    currentVertex = remainingVertices.begin();
                }
                remainingVertices.erase(vertexToRemove);
                vertexStatus[*currentVertex] = isEar(arg, remainingVertices, currentVertex, direction);

                if (currentVertex == remainingVertices.begin()) {
                    currentVertex = --remainingVertices.end();
                } else {
                    --currentVertex;
                }
                vertexStatus[*currentVertex] = isEar(arg, remainingVertices, currentVertex, direction);
            } else {
                if (++currentVertex == remainingVertices.end()) {
                    currentVertex = remainingVertices.begin();
                }
            }
        }

        if (!earFound) {
            result.connectVertices();
            triangles->clear();

            std::cerr << "Impossoble to triangulate\n";
            return result;
        }
    }

    if (triangles != 0 && remainingVertices.size() == 3) { //add remains to triangulation
        triangles->push_back(Triangle2D(arg.getVertex(*remainingVertices.begin()), arg.getVertex(*++remainingVertices.begin()),
                                        arg.getVertex(*--remainingVertices.end())));
    }

    if (triangles != 0) {
        if (validateTriangulation(arg, *triangles)) {
            std::cout << "Validation OK\n";
        } else {
            std::cerr << "Validation failed\n";
        }
    }

    return result;
}
Ejemplo n.º 4
0
/*
--------------------------------------------------------------------------------------------------
- constructor
--------------------------------------------------------------------------------------------------
*/
PlanesPhysicHandler::PlanesPhysicHandler(const std::string filename,
        LocalActorsHandler * LAH, ExternalActorsHandler * EAH)
    : _localAH(LAH), _externalAH(EAH)
{

    std::ifstream file(filename.c_str());
    if(!file.is_open())
        return;

    int sizePlanes, sizewallX, sizewallZ, sizeStairs, sizecornerStairs;
    file>>sizePlanes;
    file>>sizewallX;
    file>>sizewallZ;
    file>>sizeStairs;
    file>>sizecornerStairs;

    for(int i=0; i<sizePlanes; ++i)
    {
        NormalPlane np;
        file>>np.Layer;

        float sx, sz, ex, ez;
        file>>sx;
        file>>sz;
        file>>ex;
        file>>ez;
        np.Square._minX = MIN(sx, ex);
        np.Square._maxX = MAX(sx, ex);
        np.Square._minZ = MIN(sz, ez);
        np.Square._maxZ = MAX(sz, ez);

        file>>np.IsWater;
        _floors[np.Layer].push_back(np);
    }

    for(int i=0; i<sizewallX; ++i)
    {
        NormalPlane np;
        file>>np.Layer;

        float sx, sz, ex, ez;
        file>>sx;
        file>>sz;
        file>>ex;
        file>>ez;
        np.Square._minX = MIN(sx, ex);
        np.Square._maxX = MAX(sx, ex);
        np.Square._minZ = MIN(sz, ez);
        np.Square._maxZ = MAX(sz, ez);

        _wallsX[np.Layer].push_back(np);
    }

    for(int i=0; i<sizewallZ; ++i)
    {
        NormalPlane np;
        file>>np.Layer;

        float sx, sz, ex, ez;
        file>>sx;
        file>>sz;
        file>>ex;
        file>>ez;
        np.Square._minX = MIN(sx, ex);
        np.Square._maxX = MAX(sx, ex);
        np.Square._minZ = MIN(sz, ez);
        np.Square._maxZ = MAX(sz, ez);

        _wallsZ[np.Layer].push_back(np);
    }

    for(int i=0; i<sizeStairs; ++i)
    {
        StairPlane sp;
        file>>sp.C1.x;
        file>>sp.C1.y;
        file>>sp.C1.z;
        file>>sp.C2.x;
        file>>sp.C2.y;
        file>>sp.C2.z;
        file>>sp.C3.x;
        file>>sp.C3.y;
        file>>sp.C3.z;
        file>>sp.C4.x;
        file>>sp.C4.y;
        file>>sp.C4.z;

        sp.Normal = ((sp.C2 - sp.C1).cross(sp.C3-sp.C1)).unit();
        sp.D = sp.Normal.dot(sp.C1);


        // calculate min max X
        {
            sp.minX = sp.C1.x;
            sp.maxX = sp.C1.x;

            if(sp.C2.x > sp.maxX)
                sp.maxX = sp.C2.x;

            if(sp.C2.x < sp.minX)
                sp.minX = sp.C2.x;

            if(sp.C3.x > sp.maxX)
                sp.maxX = sp.C3.x;

            if(sp.C3.x < sp.minX)
                sp.minX = sp.C3.x;

            if(sp.C4.x > sp.maxX)
                sp.maxX = sp.C4.x;

            if(sp.C4.x < sp.minX)
                sp.minX = sp.C4.x;
        }


        // calculate min max Z
        {
            sp.minZ = sp.C1.z;
            sp.maxZ = sp.C1.z;

            if(sp.C2.z > sp.maxZ)
                sp.maxZ = sp.C2.z;

            if(sp.C2.z < sp.minZ)
                sp.minZ = sp.C2.z;

            if(sp.C3.z > sp.maxZ)
                sp.maxZ = sp.C3.z;

            if(sp.C3.z < sp.minZ)
                sp.minZ = sp.C3.z;

            if(sp.C4.z > sp.maxZ)
                sp.maxZ = sp.C4.z;

            if(sp.C4.z < sp.minZ)
                sp.minZ = sp.C4.z;
        }

        _stairs.push_back(sp);
    }

    for(int i=0; i<sizecornerStairs; ++i)
    {
        CornerStairPlane sp;
        file>>sp.C1.x;
        file>>sp.C1.y;
        file>>sp.C1.z;
        file>>sp.C2.x;
        file>>sp.C2.y;
        file>>sp.C2.z;
        file>>sp.C3.x;
        file>>sp.C3.y;
        file>>sp.C3.z;

        sp.tr_wh_y = Triangle2D(Point2D(sp.C1.x, sp.C1.z), Point2D(sp.C2.x, sp.C2.z), Point2D(sp.C3.x, sp.C3.z));

        sp.Normal = ((sp.C2 - sp.C1).cross(sp.C3-sp.C1)).unit();
        _corner_stairs.push_back(sp);
    }
}