Exemplo n.º 1
0
void Objecte::aplicaTGCentrat(mat4 m)
{
    // Metode a implementar

    calculCapsa3D();

    point4 centro = calcularCentre();

    mat4 TGCentrada = (Translate(centro) * m * Translate(-centro));

    aplicaTG(TGCentrada);

    calculCapsa3D();

}
Exemplo n.º 2
0
void Roda::aplicaTGCentrat(mat4 m){
    // calculamos el centro
    calculCapsa3D();
    point4 centre = calculCentre();

    // tenim en conte que es posible que les rodes estiguin rotades respecte les y
    mat4 transform_centrada = ( Translate(centre) * RotateY(angle_gir) * m * RotateY(-angle_gir) * Translate(-centre) );

    // aplicmos las transformaciones
    aplicaTG(transform_centrada);

}
Exemplo n.º 3
0
void Roda::aplicaTGCentrat(mat4 m){
    // calculamos el centro
    calculCapsa3D();
    point4 centre = calculCentre();

    mat4 m1 = RotateY(-angle_gir - angle_cotxe);
    mat4 m2 = RotateY(angle_gir + angle_cotxe);

    // tenim en conte que es posible que les rodes estiguin rotades respecte les y
    mat4 transform_centrada = ( Translate(centre) * m2 * m * m1 * Translate(-centre) );

    // aplicamos las transformaciones
    aplicaTG(transform_centrada);

    // apliquem les transformacions a les normals
    aplicaTGNormals(m2 * m * m1);
}
Exemplo n.º 4
0
ConjuntBoles::ConjuntBoles() : Objecte(NumVerticesCB)
{
    int id_bola[15] = {1,11,3,6,8,14,13,15,4,9,7,2,10,5,12};
    int id = 0;
    float x, z, i;

    for (z = 2.0; z < 7.0; z++)
    {
        for (x = 0.0 - i; x < i + 0.6; x+=1.2)
        {
            bola = new Bola(id_bola[id], x, 1.2, z);
            boles.push_back(bola);
            id++;
        }
        i = i + 0.6;
    }

    calculCapsa3D();

}
Exemplo n.º 5
0
void Objecte::readObj(QString filename)
{

    FILE *fp = fopen(filename.toLocal8Bit(),"rb");
    if (!fp)
    {
        cout << "No puc obrir el fitxer " << endl;
    }
    else {

        while (true)
        {
            char *comment_ptr = ReadFile::fetch_line (fp);

            if (comment_ptr == (char *) -1)  /* end-of-file */
                break;

            /* did we get a comment? */
            if (comment_ptr) {
                //make_comment (comment_ptr);
                continue;
            }

            /* if we get here, the line was not a comment */
            int nwords = ReadFile::fetch_words();

            /* skip empty lines */
            if (nwords == 0)
                continue;

            char *first_word = ReadFile::words[0];

            if (!strcmp (first_word, "v"))
            {
                if (nwords < 4)
                {
                    fprintf (stderr, "Too few coordinates: '%s'", ReadFile::str_orig);
                    exit (-1);
                }
                QString sx(ReadFile::words[1]);
                QString sy(ReadFile::words[2]);
                QString sz(ReadFile::words[3]);
                double x = sx.toDouble();
                double y = sy.toDouble();
                double z = sz.toDouble();

                if (nwords == 5)
                {
                    QString sw(ReadFile::words[4]);
                    double w = sw.toDouble();
                    x/=w;
                    y/=w;
                    z/=w;
                }
                // S'afegeix el vertex a l'objecte
                vertexs.push_back(point4(x, y, z, 1));

            }
            else if (!strcmp (first_word, "vn")) {
            }
            else if (!strcmp (first_word, "vt")) {
            }
            else if (!strcmp (first_word, "f")) {
                // S'afegeix la cara a l'objecte
                // A modificar si es vol carregar mes de un objecte
                construeix_cara (&ReadFile::words[1], nwords-1, this, 0);
            }
            // added
            else if (!strcmp (first_word, "mtllib")) {
                //read_mtllib (&words[1], nwords-1, matlib, filename);
            }
            else if (!strcmp (first_word, "usemtl")) {
                //int size = strlen(words[1])-1;
                //while (size && (words[1][size]=='\n' || words[1][size]=='\r') ) words[1][size--]=0;
                //currentMaterial = matlib.index(words[1]);
            }
            // fadded
            else {
                //fprintf (stderr, "Do not recognize: '%s'\n", str_orig);
            }
        }
    }

    capsa = calculCapsa3D();
}