Gl Graph

Gl Graph Source of map3d.cpp


#include "map3d.h"
#include "glscene.h"
Map3D::Map3D()
{
}
 
Map3D::Map3D(std::string * filename, std::string * format, int maxline,std::unordered_map<std::string, std::string> * args)
    : MapAbstract(filename, format, maxline,args)
{
    squaresize=1.0f;
    glquaddata=GlQuadData(args);
}
 
void Map3D::processVertexColor(Vec3f &vecin,Vec3f &vecout)
{
    vecout=Vec3f(0,0,0);
}
 
void Map3D::drawMap()
{
    shader.enable();
    setMinMax();
    shader.setUniform(getMaxSize(), squaresize);
    glquaddata.draw();
    shader.disable();
}
 
void Map3D::setMinMax()
{
    shader.setMinMaxx(getMinX(), getMaxX());
    shader.setMinMaxy(getMinY(), getMaxY());
    shader.setMinMaxz(getMinZ(), getMaxZ());
}
 
void Map3D::draw()
{
    lock();
    if (glScene->getPolygonMode()==GL_LINE)
    {
        // hidden line removal based on polygon offset
        drawMap();
 
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glPolygonOffset(1.0,2.0);
        glColor3f(0.0, 0.0, 0.0);
        glquaddata.draw();
        glDisable(GL_POLYGON_OFFSET_LINE);
    } else
        drawMap();
    unlock();
}
 
void Map3D::onButtonUp()
{
    squaresize=squaresize*1.2;
    glScene->setReDraw();
}
 
void Map3D::onButtonDown()
{
    squaresize=squaresize*(1.0/1.2);
    glScene->setReDraw();
}
 
 
void Map3D::onClick(Vec3f &point,Vec3f &xvect,Vec3f &yvect,Vec3f &zvect)
{
    float normeX=xvect.fastLength();
    float normeXSquare=normeX*normeX;
    float normeY=yvect.fastLength();
    float normeYSquare=normeY*normeY;
    int nbMatch=0;
 
    Vec3f color=Vec3f(0.4f,0.4f,0.4f);
    GlColorQuad quadColor(color,color,color,color);
    for (unsigned int i=0; i<quadlist.size(); i++)
    {
        Vec3f center= (1.0/4.0f)*(quadlist[i].pts1+quadlist[i].pts2+quadlist[i].pts3+quadlist[i].pts4);
 
        Vec3f OP = center-point;
        Vec3f projToNormal = OP.dot(zvect)*zvect;
        Vec3f projToPlane = OP-projToNormal;
 
        if ( fabsf(projToPlane.dot(xvect)) < normeXSquare)
            if ( fabsf(projToPlane.dot(yvect)) < normeYSquare)
            {
                nbMatch++;
                glquaddata.setQuadColorData(i,quadColor);
            }
    }
}
 
 
void Map3D::init()
{
    MapAbstract::init();
    shader.init(this->glVersion);
}
 
 
void Map3D::onFileClose()
{
    MapAbstract::onFileClose();
 
}