Exemplo n.º 1
0
void TagScrollView::zoom_out()
{
    // safeguard
    QSize new_size = 0.8 * widget()->size();
    if( qMin( new_size.width(), new_size.height() ) < 10 ) {
        return;
    }

    scale_by( 0.8 ); // = 1 / 1.25
}
Exemplo n.º 2
0
void TagScrollView::zoom_in()
{
    // safeguard
    QSize new_size = 1.25 * widget()->size();
    if( qMax( new_size.width(), new_size.height() ) > 10 * qMax( size().width(), size().height() ) ) {
        return;
    }

    scale_by( 1.25 );
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
	// Initialize randomness
	srand(time(NULL));
	// 7 parameters are required.
	if (argc != 13) {
		fprintf(stderr, "Usage: %s obj-file sx sy sz tx ty tz rx ry rz focal-dist hiding\n", argv[0]);
		return 0;
	}
	
	unsigned int i, j;

	double sx = atof( argv[2] );
	double sy = atof( argv[3] );
	double sz = atof( argv[4] );
	double tx = atof( argv[5] );
	double ty = atof( argv[6] );
	double tz = atof( argv[7] );
	double rx = atof( argv[8] );
	double ry = atof( argv[9] );
	double rz = atof( argv[10] );
	double fd = atof( argv[11] );

	int hiding = atoi( argv[12] );

	matrix_double scale = scale_by(sx, sy, sz);
	matrix_double tras = traslate(tx, ty, tz);
	matrix_double rot = rotate(rx, ry, rz);
	matrix_double proj = projection(fd);
	
	file_data vnf = readobj(argv[1]);

	// int p;
	// for (p = 0; p < vnf.vertices.num_elems; p++) {
	// 	point3d t = (vnf.vertices.data)[p];
	// 	fprintf(stderr, "(%f,%f,%f)\n", t.x, t.y, t.z);
	// }

	// Join all the transformations in a single matrix
	// Operation order: Scaling, rotation, traslation and projection
	matrix_double t1 = product(proj, tras);
	matrix_double t2 = product(t1, rot);
	matrix_double t3 = product(t2, scale);

	apply_matrix(t3, vnf.vertices);
		
	dispose_matrix(&t3);
	dispose_matrix(&t2);
	dispose_matrix(&t1);
	dispose_matrix(&scale);
	dispose_matrix(&tras);
	dispose_matrix(&rot);
	dispose_matrix(&proj);

	// Projection sets w = z, so divide everything by w.
	for (i = 0; i < vnf.vertices.num_elems; i++) {
		point3d tmp = (vnf.vertices.data)[i];
		tmp.x /= tmp.w;
		tmp.y /= tmp.w;
		tmp.z /= tmp.w;
		(vnf.vertices.data)[i] = tmp;
	}

	// The camera normal (taking advantage of perspective projection)
	vector camera_normal = new_vector( new_point3d(0.0, 0.0, 0.0, 1.0), new_point3d(0.0, 0.0, 1.0, 1.0) );

	// The z-buffer
	double **zbuf = calloc(HEIGHT, sizeof *zbuf);
	for (i = 0; i < HEIGHT; i++) {
		zbuf[i] = calloc(WIDTH, sizeof **zbuf);
		for (j = 0; j < WIDTH; j++)
			zbuf[i][j] = DBL_MAX;
	}
	
	color c = new_color( 255, 255, 255 );

	point center = { WIDTH >> 1, HEIGHT >> 1 };
	int invertX = 0, invertY = 1;
	
	raster tmp = new_raster(WIDTH, HEIGHT, 3);
	for (i = 0; i < vnf.faces.num_elems; i++) {
		point3d v1 = (vnf.vertices.data)[((vnf.faces.data)[i].v1) - 1];
		point3d v2 = (vnf.vertices.data)[((vnf.faces.data)[i].v2) - 1];
		point3d v3 = (vnf.vertices.data)[((vnf.faces.data)[i].v3) - 1];

		point pt[3] = { new_point(v1.x, v1.y), new_point(v2.x, v2.y), new_point(v3.x, v3.y) };

		for (j = 0; j < 3; j++)
			pt[j] = raster_translate(pt[j], center, invertX, invertY);

		// Hiding faces using face normals
		if (hiding == 1) {			
			vector va = new_vector( v1, v2 );
			vector vb = new_vector( v1, v3 );

			vector vn = vector_crossproduct( va, vb );

			if ( abs(vector_angle(vn, camera_normal)) < 90.0 ) continue;
		}

		// Drawing the face
		for (j = 0; j < 3; j++) {

			int curr = j;
			int next = (j+1) % 3;

			point ps = pt[curr];
			point pe = pt[next];

			// Use z-buffering if allowed
			// if (hiding == 2)
			// 	put_line_z(tmp, new_line( ps, pe ), c, bresenham, zbuf, vertices[3][curr], vertices[3][next]);
			// else
			put_line(tmp, new_line( ps, pe ), c, bresenham);
			
		}

		// Filling the face using a random, eye-pleasing colour
		color cr = { ((rand() % 255) + 255) >> 1, ((rand() % 255) + 255) >> 1, ((rand() % 255) + 255) >> 1 };
		// if (hiding == 2)
		// 	fill_face_z(tmp, pt[0], pt[1], pt[2], cr, zbuf, vertices[3][j], vertices[3][(j+1) % 3]);
		// elseelse
			fill_face(tmp, pt[0], pt[1], pt[2], cr);

	}
	raster_out(tmp);
	dispose_raster(tmp);

	for (i = 0; i < HEIGHT; i++) free(zbuf[i]);
	free(zbuf);

	free(vnf.vertices.data);
	free(vnf.faces.data);

	return 0;
}
Exemplo n.º 4
0
    int gauss_jordan_elimination( const matrix<T1,D1,A1>& A, matrix<T2,D2,A2>& x, const matrix<T3,D3,A3>& b )
    {
        typedef matrix<T1,D1,A1>                    matrix_type;
        typedef typename matrix_type::size_type     size_type;
        typedef typename matrix_type::value_type    value_type;
        typedef typename matrix_type::range_type    range_type;
        assert( A.row() == A.col() );
        assert( A.row() == b.row() );
        matrix_type a( A || b ); // a -- [A:b]
        const size_type n = b.row();
        const size_type m = b.col();

        struct abs_compare
        {
            bool operator()( value_type x, value_type y ) const 
            { return std::abs(x) < std::abs(y); }
        };
        struct scale_by
        {
            value_type factor;
            scale_by( value_type f ) : factor( f ) {}
            void operator()( value_type& x ) const
            { x /= factor; }
        };
        struct ratio_by
        {
            value_type ratio;
            ratio_by( value_type r ) : ratio(r) {}
            value_type operator()( value_type x, value_type y ) const
            { return x - y * ratio; }
        };

        for ( size_type i = 0; i < n; ++i )
        {
            //find max element
            const size_type
            //p = std::distance( a.col_begin( i ), std::max_element( a.col_begin( i ) + i, a.col_end( i ), []( value_type x, value_type y ) { return std::abs( x ) < std::abs( y );} ) );
            p = std::distance( a.col_begin( i ), std::max_element( a.col_begin( i ) + i, a.col_end( i ), abs_compare() ) );

            //swap row i and row p
            if ( p != i )
            { std::swap_ranges( a.row_begin( i ) + i, a.row_end( i ), a.row_begin( p ) + i ); }

            const value_type factor = a[i][i];
            if ( factor == value_type() ) return 1; // fail to solve

            //eliminate
            //std::for_each( a.row_rbegin( i ), a.row_rend( i ) - i, [factor]( value_type & x ) { x /= factor; } );
            std::for_each( a.row_rbegin( i ), a.row_rend( i ) - i, scale_by(factor) );

            for ( size_type j = 0; j < n; ++j )
            {
                if ( i == j )
                { continue; }

                const value_type ratio = a[j][i];
                //std::transform( a.row_rbegin( j ), a.row_rend( j ) - i, a.row_rbegin( i ), a.row_rbegin( j ), [ratio]( value_type x, value_type y ) { return x - y * ratio; } );
                std::transform( a.row_rbegin( j ), a.row_rend( j ) - i, a.row_rbegin( i ), a.row_rbegin( j ), ratio_by(ratio) );
            }
        }

        x = matrix_type( a, range_type( 0, n ), range_type( n, m + n ) );

        return 0;
    }
Exemplo n.º 5
0
Transformation Boonas::us(float x, Transformation matrix)
{
	return matrix * scale_by(x, x, x);
}
Exemplo n.º 6
0
Transformation Boonas::zs(float x, Transformation matrix)
{
	return matrix * scale_by(1, 1, x);
}
Exemplo n.º 7
0
Transformation Boonas::xs(float x, Transformation matrix)
{
	return matrix * scale_by(x, 1, 1);
}