예제 #1
0
vsVector2D
vsVector2D::NormalisedSafe()
{
	if ( SqLength() > 0.f )
		return Normalised();
	return *this;
}
예제 #2
0
mlFloat mlVector3D::AngleToVector(const mlVector3D &v) const
{
    mlVector3D normalized = Normalised();
    mlVector3D vNormalized = v.Normalised();
    mlFloat fDot = normalized * vNormalized;
    mlFloat fAngle = mlArcCos(fDot);

    return fAngle;
}
예제 #3
0
파일: widget.cpp 프로젝트: spetz911/CG
double CosV(Vector v1,Vector v2)
{
    v1 = Normalised(v1);
    v2 = Normalised(v2);
    return (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z);
}
예제 #4
0
파일: widget.cpp 프로젝트: spetz911/CG
void Widget::paintEvent(QPaintEvent *event)
{
    QPainter p(this);
    int i, j;
    float dot[4];
    float ox, oy;

    ox=this->width()/2;
    oy=this->height()/2;


   // p.setRenderHint(QPainter::Antialiasing, true);

    
    //  p.drawLine(1*quads,20,30,100);

    //    Matrix4f_set_E(Glob);


    /*
        Normals[normals++] = norm;
        Normals[normals++] = norm;
        Normals[normals++] = norm;
    */


    for (i=0;i<quads;i++) // Foreach vertex
    {
        //Point_copy(Vert[i], Quads[i]);

        // Vert[i][0]-= 0.5;
        // Vert[i][1]-= 0.5;
        // Vert[i][2]-= 0.5;

        //
        Point_mul(Vert[i], Glob, Quads[i]);
        //Point_copy(Vert[i], dot);
        Vert[i][0] += moveX;
        Vert[i][1] += moveY;
        Vert[i][2] += moveZ;

    }

    normals = 0;
    for(i=0;i<quads/4;i++) // Foreach polygon
    {
        Vector norm;
        norm = Normalize(Vert[4*i], Vert[4*i+1], Vert[4*i+2]);

        Normals[normals++] = norm;


        // Is visible?
        //       Point p1,p2;
        //        Point_minus( p1, Vert[Poly[i][1]],Vert[Poly[i][0]]);
        //      Point_minus( p2, Vert[Poly[i][2]],Vert[Poly[i][1]]);

        //if (Point_vec(p1,p2)<0)
        if ((norm.z)>0)continue;

        /*        p.drawLine(ox+77*Vert[Poly[0][0] ][0],oy-77*Vert[Poly[0][0] ][1],
                   ox+77*Vert[Poly[0][1] ][0],oy-77*Vert[Poly[0][1] ][1]);
        p.drawLine(ox+77*Vert[1][0],oy-77*Vert[1][1],
                   ox+77*Vert[0][0],oy-77*Vert[0][1]);*/
        //    ox-=7;
        //  oy-=7;
        //p.drawLine(10,20,30,100);
        for(j=0;j<4;j++) //Foreach point
        {
       //     p.drawLine(ox+Vert[4*i+j][0], oy-Vert[4*i+j][1],
       //                ox+Vert[4*i+(j+1)%4][0], oy-Vert[4*i+(j+1)%4][1]);
        }

        // R = lamp, V = view;



        //R.x = 2.0*CosV(norm,light)*Modul(light)*norm.x-light.x;
        //R.y = 2.0*CosV(norm,light)*Modul(light)*norm.y-light.y;
        //R.z = 2.0*CosV(norm,light)*Modul(light)*norm.z-light.z;

        // Always A,B = max(0,(A,B))!
        //Set V, H, L, N

        Vector N(-norm.x, -norm.y, -norm.z);
        Vector L;
        Vector V(0, 0, -1);
        N = Normalised(N);
        L = Normalised(light);
        V = Normalised(V);
        Vector H( L.x+V.x, L.y+V.y, L.z+V.z);
        H = Normalised(H);

        double G, D, F, K;
        double HN = CosV(H, N);
        double HN2= HN*HN;
        double VH = CosV(V, H);
        double VN = CosV(V, N);
        double LN = CosV(L, N);
        double m  = ui->val_m->value() *0.01;
        double f0 = ui->val_f0->value()*0.01;

        G = min(1, min( 2*HN*VN/VH, 2*HN*LN/VH ));

        D = exp( HN2-1/(m*m*HN2) ) / (4*m*m* HN2*HN2) ;

        //F = 1/(1 + CosV(V,N));
        F = f0 + (1-f0)*pow( 1-VN ,5);

        K = G*D*F/( VN*LN);
        K = max(0,K);

        //  qDebug() << normal.x  << normal.x  << normal.x
        SetColor(CosV(norm,light), K);
        //color = color_anbient;
        p.setPen(Qt::NoPen);
        p.setBrush(color);

        QPointF MMM[4];
        for(int k=0; k<4; k++)
        {
            MMM[k].setX( ox+Vert[4*i+k][0]);
            MMM[k].setY( oy-Vert[4*i+k][1]);
        }

        //  MMM[2] = ox+Vert[4*i+(j+1)%4][0];
        //  MMM[3] = oy-Vert[4*i+(j+1)%4][1];

        p.drawPolygon(MMM, 4);

    }
}