Example #1
0
//------------------------------------------------------------------------------
// drawFunc()
//------------------------------------------------------------------------------
void Polygon::drawFunc()
{
    BEGIN_DLIST
    unsigned int nv = getNumberOfVertices();
    const osg::Vec3* vertices = getVertices();

    if (nv >= 2) {

        // Draw with texture
        unsigned int ntc = getNumberOfTextureCoords();
        if (ntc > 0 && hasTexture()) {
            const osg::Vec2* texCoord = getTextureCoord();
            unsigned int tc = 0; // texture count
            glBegin(GL_POLYGON);
            for (unsigned int i = 0; i < nv; i++) {
                if (tc < ntc)  {
                    lcTexCoord2v(texCoord[tc++].ptr());
                }
                lcVertex3v( vertices[i].ptr() );
            }
            glEnd();

        }

        // Draw without texture
        else {
            // get our color gradient, because if we have one, instead of a regular color, we will
            // override it here and set it on a per vertex level.
            ColorGradient* colGradient = dynamic_cast<ColorGradient*>(getColor());
            glBegin(GL_POLYGON);
            osg::Vec3* ptr = nullptr;
            for (unsigned int i = 0; i < nv; i++) {
                if (colGradient != nullptr) {
                    Basic::Color* col = colGradient->getColorByIdx(i+1);
                    if (col != nullptr)
                       glColor4f(static_cast<GLfloat>(col->red()), static_cast<GLfloat>(col->green()),
                                 static_cast<GLfloat>(col->blue()), static_cast<GLfloat>(col->alpha()));
                }
                // if we have a material name, we will set up like we have a material
                if (getMaterialName() != nullptr) {
                    //lcVertex3v( vertices[i].ptr() );
                    ptr = const_cast<osg::Vec3*>(reinterpret_cast<const osg::Vec3*>(vertices[i].ptr()));

                    if (ptr != nullptr) {
                        calcNormal();
                        lcNormal3(norm.x(), norm.y(), -(norm.z()));
                        lcVertex3(ptr->x(), ptr->y(), ptr->z());
                    }
                }
                else {
                    lcVertex3v(vertices[i].ptr());
                }
            }
            glEnd();
        }
    }
    END_DLIST
}
	void initParticle(SmokeParticle* p) override {
		p->a = 0;
		p->size = linearRand<float>(.3,.6);
		p->r = 0;
		p->g = 0;
		p->b = 0;
		startGrad.getColor(&p->r,linearRand<float>(0,1));
		p->pos = pos.getRandomSpherePosition();
		p->life = life.getRandomLifetime();
		p->startLife = p->life;
		p->speed = speed.getRandVelocitySpread();
		p->a = 0;
	}
Example #3
0
bool Scene::rendu() const{
    QTime timer;

    ColorGradient grad;
    grad.createDefaultHeatMapGradient();

    for(unsigned int ic = 0;  ic < cameras.size(); ic++)
    {
        const Camera& c = cameras[ic];
        int _lu = c.getLu(), _lv = c.getLv();
        std::cout << "ic: " << ic << //"   origine: " << c.getOrigine() <<
                     "  lu: " << _lu << "  lv: " << _lv << std::endl;
        int pourcent2 = -1;
        QImage *imEffetAtmos = new QImage(_lu, _lv, QImage::Format_RGB888);
        QImage *imocclusion = new QImage(_lu, _lv, QImage::Format_RGB888);
        QImage *img = new QImage(_lu, _lv, QImage::Format_RGB888);
        QImage eric(_lu, _lv, QImage::Format_RGB888);
        timer.start();
#ifdef QT_NO_DEBUG
        #pragma omp parallel for schedule(dynamic,1)
#endif
        for(int y = 0; y < _lv ; y++){      // pour chaque ligne de l'image
            int pourcent = 100 * y / (_lv - 1);
            if(pourcent != pourcent2)            {
                pourcent2 = pourcent;
                std::cout << "\r" << ic << " Rendering: " << pourcent << "% ";  // barre de progression
            }
            else
                std::cerr << ".  \b\b";

            for(int x = 0; x < _lu ; x++){  // pour chaque pixel de la ligne
                Rayon ray(c.getOrigine(),c.vecScreen(x,y));   //rayon correspondant au pixel

                float dist;
                int i;
                float oclu;
                float effetAtmos;
                if(!intersect(ray, dist, i)){
                    img->setPixel(x, y, default_color.rgba());
                    imEffetAtmos->setPixel(x,y,default_color.rgba());
                }
                else
                {
                    vec3 color = calculPixel(ray, dist, c.getOrigine(),oclu);
                    color = calculEffetAtmospherique(color, ciel->color, dist, effetAtmos);
                    imEffetAtmos->setPixel(x,y,qRgb(255,255*(1-effetAtmos),255*(1-effetAtmos)));
                    imocclusion->setPixel(x,y,qRgb(255*(1-oclu),0,0));
                    img->setPixel(x,y, qRgb(color.r*255,color.g*255,color.b*255));
                }
                float r,v,b;
                grad.getColorAtValue(i/255.0f,r,v,b);
                eric.setPixel(x,y, qRgb(r*255,v*255,b*255));
            }
        }
        if(ic<10)        {
            std::cout << std::endl;
            int time = timer.elapsed();
            std::cout << time/1000 << "." << time%1000<< " secondes" << std::endl;
            //std::cout << (100.f*nbpixrouge) / (_lu*_lv) << "%" << std::endl;
            img->save(("test000" + std::to_string(ic) + ".png").c_str());
            eric.save(("eric" + std::to_string(ic) + ".png").c_str());
            imocclusion->save(("oclu000" + std::to_string(ic) + ".png").c_str());
            imEffetAtmos->save(("EffetAtmos" + std::to_string(ic) + ".png").c_str());

            std::cout << ("test000" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else if(ic<100)        {
            img->save(("test00" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test00" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else if(ic<1000)        {
            img->save(("test0" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test0" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else    {
            img->save(("test" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        delete img;
        delete imocclusion;
    }
    return true;
}
Example #4
0
bool Scene::rendu(){
    QTime timer;

    ColorGradient grad;
    grad.createDefaultHeatMapGradient();

    for(unsigned int ic = 0;  ic < cameras.size(); ic++)
    {
        Camera* c = cameras[ic];
        int _lu = c->getLu(), _lv = c->getLv();
        int pourcent2 = -1;
        QImage *img = new QImage(_lu, _lv, QImage::Format_RGB888);
        QImage eric(_lu, _lv, QImage::Format_RGB888);
        timer.start();
        #pragma omp parallel for schedule(dynamic,1)
        for(int y = 0; y < _lv ; y++){      // pour chaque ligne de l'image
            int pourcent = 100 * y / (_lv - 1);
            if(pourcent != pourcent2)            {
                pourcent2 = pourcent;
                std::cout << "\r" << ic << " Rendering: " << pourcent << "% ";  // barre de progression
            }
            for(int x = 0; x < _lu ; x++){  // pour chaque pixel de la ligne
                Rayon ray(c->getOrigine(),c->vecScreen(x,y));   //rayon correspondant au pixel
                bool touche = false;


                Vector3D p = c->getOrigine();
                int i;
                float dist = 0;
                for(i = 0;  i < 128;    i++)
                {
                    if(node->inOut(p)){
                        touche = true;
                        break;
                    }
                    float d = node->distance(p)+0.05f;
                    dist += d;
                    if(dist > 9999) //si on va trop loin, on arrête la progression.
                        break;
                    p += ray.getDirection()*(d);

                }
                if(!touche)
                    img->setPixel(x, y, default_color.rgba());
                else
                {
                    #if 0
                        img->setPixel(x,y, qRgb(dist*17, dist*19, dist*23));
                    #else

                        const Vector3D& dRay = ray.getDirection();
                        const Vector3D p(ray.getOrigine()+dRay*dist);
                        const Vector3D n(node->getNormal(p));

                        double norm = -dRay.dotProduct(n);    //le rayon va normalement dans le sens inverse de la normal du triangle qu'il touche,

                        QRgb color;
                        if(norm <= 0)
                            color = qRgb(0,0,0); //Black
                        else
                        {
                            float c = 255*norm;
                            color = qRgb(roundf(c),roundf(c), roundf(c)); // Grey
                        }
                        img->setPixel(x,y, color);

                    #endif
                }

                float r,v,b;
                grad.getColorAtValue(i/128.0f,r,v,b);
                eric.setPixel(x,y, qRgb(r*255,v*255,b*255));
            }
        }
        if(ic<10)        {
            std::cout << std::endl;
            int time = timer.elapsed();
            std::cout << time/1000 << "." << time%1000<< " secondes" << std::endl;
            //std::cout << (100.f*nbpixrouge) / (_lu*_lv) << "%" << std::endl;
            img->save(("test000" + std::to_string(ic) + ".png").c_str());
            eric.save(("eric" + std::to_string(ic) + ".png").c_str());


            std::cout << ("test000" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else if(ic<100)        {
            img->save(("test00" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test00" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else if(ic<1000)        {
            img->save(("test0" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test0" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        else    {
            img->save(("test" + std::to_string(ic) + ".png").c_str());
            std::cout << ("test" + std::to_string(ic) + ".png").c_str() << std::endl;
        }
        delete img;
    }
    return true;
}
Example #5
0
// Draw function
void Quad::drawFunc()
{
    bool ok = false;

    // Draw with texture
    const unsigned int nv = getNumberOfVertices();
    if (nv > 3) {
        if (!strip) {
            int rem = nv % 4;
            if (rem != 0) std::cerr << "Quad::drawFunc() - Quad have to have multiple of 4 vertices, add or remove vertices!!" << std::endl;
            else {
                BEGIN_DLIST
                glBegin(GL_QUADS);
                ok = true;
            }
        }
        else {
            int rem = nv % 2;
            if (rem != 0) std::cerr << "Quad::drawFunc() - quad strips have to have multiple of 2 vertices, add or remove vertices!!" << std::endl;
            else {
                BEGIN_DLIST
                glBegin(GL_QUAD_STRIP);
                ok = true;
            }
        }

        if (ok) {
            // get our regular vertices here
            const osg::Vec3* v = getVertices();

            const unsigned int ntc = getNumberOfTextureCoords();
            // draw with texture
            if (ntc > 0 && hasTexture()) {
                const osg::Vec2* texCoord = getTextureCoord();
                unsigned int tc = 0; // texture count
                for (unsigned int i = 0; i < nv; i++) {
                    // add our textures coordinates
                    if (tc < ntc)  lcTexCoord2v(texCoord[tc++].ptr());
                    // now our vertices
                    lcVertex3v( v[i].ptr() );
                }

            }
            // draw without texture
            else {
                // get our color gradient and apply it (if we have one)
                ColorGradient* colGradient = dynamic_cast<ColorGradient*>(getColor());

                for (unsigned int i = 0; i < nv; i++) {
                    if (colGradient != nullptr) {
                        Basic::Color* col = colGradient->getColorByIdx(i+1);
                        if (col != nullptr)
                            glColor4f(static_cast<GLfloat>(col->red()),
                                      static_cast<GLfloat>(col->green()),
                                      static_cast<GLfloat>(col->blue()),
                                      static_cast<GLfloat>(col->alpha()));
                    }
                    // now add our vertex
                    lcVertex3v( v[i].ptr() );
                }
            }
            glEnd();
            END_DLIST
        }
    }

    else std::cerr << "Quad::drawFunc() - Quad or QuadStrip needs at least 4 vertices!" << std::endl;