コード例 #1
0
ファイル: scene_builder.hpp プロジェクト: kspangsege/archon
inline void SpatialSceneBuilder::rotate(double angle, double x, double y, double z)
{
    do_rotate(math::Rotation3(math::Vec3(x,y,z), angle));
}
コード例 #2
0
ファイル: main.c プロジェクト: subogero/fbv
int show_image(char *filename)
{
	int (*load)(char *, unsigned char *, unsigned char **, int, int);

	unsigned char * image = NULL;
	unsigned char * alpha = NULL;

	int c, ret;
	int x_size, y_size, screen_width, screen_height;
	int x_pan, y_pan, x_offs, y_offs, refresh = 1;
	int delay = opt_delay, retransform = 1;

	int transform_stretch = opt_stretch, transform_enlarge = opt_enlarge;
	int transform_cal = (opt_stretch == 2), transform_iaspect = opt_ignore_aspect;
	int transform_rotation = 0;

	struct image i;

#ifdef FBV_SUPPORT_PNG
	if(fh_png_id(filename))
	if(fh_png_getsize(filename, &x_size, &y_size) == FH_ERROR_OK)
	{
		load = fh_png_load;
		goto identified;
	}
#endif

#ifdef FBV_SUPPORT_JPEG
	if(fh_jpeg_id(filename))
	if(fh_jpeg_getsize(filename, &x_size, &y_size) == FH_ERROR_OK)
	{
		load = fh_jpeg_load;
		goto identified;
	}
#endif

#ifdef FBV_SUPPORT_BMP
	if(fh_bmp_id(filename))
	if(fh_bmp_getsize(filename, &x_size, &y_size) == FH_ERROR_OK)
	{
		load = fh_bmp_load;
		goto identified;
	}
#endif
	fprintf(stderr, "%s: Unable to access file or file format unknown.\n", filename);
	return(1);

identified:

	if(!(image = (unsigned char*)malloc(x_size * y_size * 3)))
	{
		fprintf(stderr, "%s: Out of memory.\n", filename);
		goto error;
	}

	if(load(filename, image, &alpha, x_size, y_size) != FH_ERROR_OK)
	{
		fprintf(stderr, "%s: Image data is corrupt?\n", filename);
		goto error;
	}

	if(!opt_alpha)
	{
		free(alpha);
		alpha = NULL;
	}

	if(getCurrentRes(&screen_width, &screen_height))
		goto error;
	i.do_free = 0;
	while(1)
	{
		if(retransform)
		{
			if(i.do_free)
			{
				free(i.rgb);
				free(i.alpha);
			}
			i.width = x_size;
			i.height = y_size;
			i.rgb = image;
			i.alpha = alpha;
			i.do_free = 0;

			if(transform_rotation)
				do_rotate(&i, transform_rotation);

			if(transform_stretch)
				do_fit_to_screen(&i, screen_width, screen_height, transform_iaspect, transform_cal);

			if(transform_enlarge)
				do_enlarge(&i, screen_width, screen_height, transform_iaspect);

			x_pan = y_pan = 0;
			refresh = 1; retransform = 0;
			if(opt_clear)
			{
				printf("\033[H\033[J");
				fflush(stdout);
			}
			if(opt_image_info)
				printf("fbv - The Framebuffer Viewer\n%s\n%d x %d\n", filename, x_size, y_size);
		}
		if(refresh)
		{
			if(i.width < screen_width)
				x_offs = (screen_width - i.width) / 2;
			else
				x_offs = 0;

			if(i.height < screen_height)
				y_offs = (screen_height - i.height) / 2;
			else
				y_offs = 0;

			if(fb_display(i.rgb, i.alpha, i.width, i.height, x_pan, y_pan, x_offs, y_offs))
				goto error;
			refresh = 0;
		}
		if(delay)
		{
			struct timeval tv;
			fd_set fds;
			tv.tv_sec = delay / 10;
			tv.tv_usec = (delay % 10) * 100000;
			FD_ZERO(&fds);
			FD_SET(0, &fds);

			if(select(1, &fds, NULL, NULL, &tv) <= 0)
				break;
			delay = 0;
		}

		c = getchar();
		switch(c)
		{
			case EOF:
			case 'q':
				ret = 0;
				goto done;
			case ' ': case 10: case 13:
				goto done;
			case '>': case '.':
				ret = 1;
				goto done;
			case '<': case ',':
				ret = -1;
				goto done;
			case 'r':
				refresh = 1;
				break;
			case 'a': case 'D':
				if(x_pan == 0) break;
				x_pan -= i.width / PAN_STEPPING;
				if(x_pan < 0) x_pan = 0;
				refresh = 1;
				break;
			case 'd': case 'C':
				if(x_offs) break;
				if(x_pan >= (i.width - screen_width)) break;
				x_pan += i.width / PAN_STEPPING;
				if(x_pan > (i.width - screen_width)) x_pan = i.width - screen_width;
				refresh = 1;
				break;
			case 'w': case 'A':
				if(y_pan == 0) break;
				y_pan -= i.height / PAN_STEPPING;
				if(y_pan < 0) y_pan = 0;
				refresh = 1;
				break;
			case 'x': case 'B':
				if(y_offs) break;
				if(y_pan >= (i.height - screen_height)) break;
				y_pan += i.height / PAN_STEPPING;
				if(y_pan > (i.height - screen_height)) y_pan = i.height - screen_height;
				refresh = 1;
				break;
			case 'f':
				transform_stretch = !transform_stretch;
				retransform = 1;
				break;
			case 'e':
				transform_enlarge = !transform_enlarge;
				retransform = 1;
				break;
			case 'k':
				transform_cal = !transform_cal;
				retransform = 1;
				break;
			case 'i':
				transform_iaspect = !transform_iaspect;
				retransform = 1;
				break;
			case 'p':
				transform_cal = 0;
				transform_iaspect = 0;
				transform_enlarge = 0;
				transform_stretch = 0;
				retransform = 1;
				break;
			case 'n':
				transform_rotation -= 1;
				if(transform_rotation < 0)
					transform_rotation += 4;
				retransform = 1;
				break;
			case 'm':
				transform_rotation += 1;
				if(transform_rotation > 3)
					transform_rotation -= 4;
				retransform = 1;
				break;
		}
	}// while(1)

done:
	if(opt_clear)
	{
		printf("\033[H\033[J");
		fflush(stdout);
	}

error:
	free(image);
	free(alpha);
	if(i.do_free)
	{
		free(i.rgb);
		free(i.alpha);
	}
	return ret;
}
コード例 #3
0
ファイル: main.c プロジェクト: koura-h/compostela
int
main(int argc, char** argv)
{
    sc_follow_context *cxt = NULL;

    int ret, ch, epfd;
    sc_log_message *resp;
    char *conf = NULL;

    struct option long_opts[] = {
        { "config", 2, NULL, 0 },
        { "server-port", 2, NULL, 0 },
        { "server-addr", 2, NULL, 0 },
        { "help", 2, NULL, 0 },
    };

    while ((ch = getopt_long(argc, argv, "c:p:s:h", long_opts, NULL)) != -1) {
        switch (ch) {
	case 'c':
	    conf = strdup(optarg);
	    break;
        case 'p':
            g_config_server_port = strtoul(optarg, NULL, 10);
            break;
        case 's':
            g_config_server_address = strdup(optarg);
            break;
        case 'h':
        default:
            usage();
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    load_config_file((conf ? conf : DEFAULT_CONF));
    free(conf);

    if (!g_config_server_address) {
        az_log(LOG_DEBUG, "error: server address is not assigned.");
        exit(1);
    }

    g_connection = sc_aggregator_connection_new(g_config_server_address, g_config_server_port);
    sc_aggregator_connection_open(g_connection);
    az_log(LOG_DEBUG, "conn = %p", g_connection);

#if 0
    g_conn_controller = setup_server_unix_socket(PATH_CONTROL);
#else
    g_conn_controller = setup_server_unix_socket(g_config_control_path ? g_config_control_path : PATH_CONTROL);
#endif

    do_rotate(g_connection);
    set_rotation_timer();
    set_sigpipe_handler();

    epfd = setup_epoll(&g_conn_controller, 1);

    while (1) {
        az_list* li;
	int sl = 1, rc = 0;
        cxt = NULL;

        if (do_server_socket(epfd, &g_conn_controller, 1) > 0) {
            sl = 0;
        }

	for (li = g_context_list; li; li = li->next) {
            resp = NULL;
            cxt = li->object;
            ret = _run_follow_context(cxt, &resp);
	    if (ret > 0) {
	        if (ret == ERR_MUST_RECONNECT) {
		    rc = 1;
		}
	    } else if (ret == -1) {
	        // error occurred
	        perror("_run_follow_context");
                az_log(LOG_DEBUG, "cxt = %p, cxt->_fd = %d, cxt->displayName = %s", cxt, cxt->_fd, cxt->displayName);
	        // exit(1);
                g_context_list = az_list_delete(g_context_list, cxt);
                sc_follow_context_destroy(cxt);
	    } else {
	        // in proceessed any bytes.
	        sl = 0;
	    }

            // here, we proceed response from aggregator
            sc_log_message_destroy(resp);
	}

	if (rc) {
	    for (li = g_context_list; li; li = li->next) {
                cxt = li->object;
                // haha
                sc_follow_context_reset(cxt);
            }
	    sc_aggregator_connection_open(g_connection);
	}

	if (sl > 0) {
	    sleep(sl);
	    continue;
	}
    }
}
コード例 #4
0
ファイル: scene_builder.hpp プロジェクト: kspangsege/archon
inline void SpatialSceneBuilder::rotate(math::Rotation3 r)
{
    do_rotate(r);
}
コード例 #5
0
ファイル: main.c プロジェクト: kaihs/fbvs
int show_image(char *devicename)
{

	unsigned char * image = NULL;
	unsigned char * alpha = NULL;

	int x_size, y_size, screen_width, screen_height;
	int x_pan, y_pan, x_offs, y_offs, refresh = 1, ret = 1;
	int retransform = 1;

	int transform_stretch = opt_stretch, transform_enlarge = opt_enlarge, transform_cal = (opt_stretch == 2),
	    transform_iaspect = opt_ignore_aspect, transform_rotation = 0;

	struct image i;
	
	memset(&i,0, sizeof(i));

	if(fh_png_load(&image, &alpha, &x_size, &y_size) != FH_ERROR_OK) {
		fprintf(stderr, "Image data is corrupt?\n");
		goto error_mem;
	}

	if(!opt_alpha) {
		free(alpha);
		alpha = NULL;
	}



	getCurrentRes(devicename, &screen_width, &screen_height);
	i.do_free = 0;
	if(retransform) {
		if(i.do_free) {
			free(i.rgb);
			free(i.alpha);
		}
		i.width = x_size;
		i.height = y_size;
		i.rgb = image;
		i.alpha = alpha;
		i.do_free = 0;


		if(transform_rotation)
			do_rotate(&i, transform_rotation);

		if(transform_stretch)
			do_fit_to_screen(&i, screen_width, screen_height, transform_iaspect, transform_cal);

		if(transform_enlarge)
			do_enlarge(&i, screen_width, screen_height, transform_iaspect);

		x_pan = y_pan = 0;
		refresh = 1;
		retransform = 0;
	}
	if(refresh) {
		if(i.width < screen_width)
			x_offs = (screen_width - i.width) / 2;
		else
			x_offs = 0;

		if(i.height < screen_height)
			y_offs = (screen_height - i.height) / 2;
		else
			y_offs = 0;

		fb_display(devicename, i.rgb, i.alpha, i.width, i.height, x_pan, y_pan, x_offs, y_offs);
		refresh = 0;
	}



error_mem:
	free(image);
	free(alpha);
	if(i.do_free) {
		free(i.rgb);
		free(i.alpha);
	}
	return(ret);

}
コード例 #6
0
static char *new_game_desc(const game_params *params, random_state *rs,
			   char **aux, int interactive)
{
    int *grid;
    int w = params->w, h = params->h, n = params->n, wh = w*h;
    int i;
    char *ret;
    int retlen;
    int total_moves;

    /*
     * Set up a solved grid.
     */
    grid = snewn(wh, int);
    for (i = 0; i < wh; i++)
	grid[i] = ((params->rowsonly ? i/w : i) + 1) * 4;

    /*
     * Shuffle it. This game is complex enough that I don't feel up
     * to analysing its full symmetry properties (particularly at
     * n=4 and above!), so I'm going to do it the pedestrian way
     * and simply shuffle the grid by making a long sequence of
     * randomly chosen moves.
     */
    total_moves = params->movetarget;
    if (!total_moves)
        /* Add a random move to avoid parity issues. */
        total_moves = w*h*n*n*2 + random_upto(rs, 2);

    do {
        int *prevmoves;
        int rw, rh;                    /* w/h of rotation centre space */

        rw = w - n + 1;
        rh = h - n + 1;
        prevmoves = snewn(rw * rh, int);
        for (i = 0; i < rw * rh; i++)
            prevmoves[i] = 0;

        for (i = 0; i < total_moves; i++) {
            int x, y, r, oldtotal, newtotal, dx, dy;

            do {
                x = random_upto(rs, w - n + 1);
                y = random_upto(rs, h - n + 1);
                r = 2 * random_upto(rs, 2) - 1;

                /*
                 * See if any previous rotations has happened at
                 * this point which nothing has overlapped since.
                 * If so, ensure we haven't either undone a
                 * previous move or repeated one so many times that
                 * it turns into fewer moves in the inverse
                 * direction (i.e. three identical rotations).
                 */
                oldtotal = prevmoves[y*rw+x];
                newtotal = oldtotal + r;
                
                /*
                 * Special case here for w==h==n, in which case
                 * there is actually no way to _avoid_ all moves
                 * repeating or undoing previous ones.
                 */
            } while ((w != n || h != n) &&
                     (abs(newtotal) < abs(oldtotal) || abs(newtotal) > 2));

            do_rotate(grid, w, h, n, params->orientable, x, y, r);

            /*
             * Log the rotation we've just performed at this point,
             * for inversion detection in the next move.
             * 
             * Also zero a section of the prevmoves array, because
             * any rotation area which _overlaps_ this one is now
             * entirely safe to perform further moves in.
             * 
             * Two rotation areas overlap if their top left
             * coordinates differ by strictly less than n in both
             * directions
             */
            prevmoves[y*rw+x] += r;
            for (dy = -n+1; dy <= n-1; dy++) {
                if (y + dy < 0 || y + dy >= rh)
                    continue;
                for (dx = -n+1; dx <= n-1; dx++) {
                    if (x + dx < 0 || x + dx >= rw)
                        continue;
                    if (dx == 0 && dy == 0)
                        continue;
                    prevmoves[(y+dy)*rw+(x+dx)] = 0;
                }
            }
        }

        sfree(prevmoves);

    } while (grid_complete(grid, wh, params->orientable));

    /*
     * Now construct the game description, by describing the grid
     * as a simple sequence of integers. They're comma-separated,
     * unless the puzzle is orientable in which case they're
     * separated by orientation letters `u', `d', `l' and `r'.
     */
    ret = NULL;
    retlen = 0;
    for (i = 0; i < wh; i++) {
        char buf[80];
        int k;

        k = sprintf(buf, "%d%c", grid[i] / 4,
		    (char)(params->orientable ? "uldr"[grid[i] & 3] : ','));

        ret = sresize(ret, retlen + k + 1, char);
        strcpy(ret + retlen, buf);
        retlen += k;
    }
    if (!params->orientable)
	ret[retlen-1] = '\0';	       /* delete last comma */

    sfree(grid);
    return ret;
}
コード例 #7
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void do_dame(void)
{
    do_rotate(dame_data, sizeof(dame_data)/sizeof(GLfloat));
}
コード例 #8
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void do_loper(void)
{
    do_rotate(loper_data, sizeof(loper_data)/sizeof(GLfloat));
}
コード例 #9
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void do_paard(void)
{
    do_rotate(paard_data, sizeof(paard_data)/sizeof(GLfloat));
    do_solid(paard_data2, sizeof(paard_data2)/sizeof(GLfloat), 0.08);
}
コード例 #10
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void do_toren(void)
{
    int i;
    GLfloat a1, a2, c1, s1, c2, s2, h1, h2;
    do_rotate(toren_data, sizeof(toren_data)/sizeof(GLfloat));
    h1 = buf[9];
    h2 = buf[9] + buf[9] - buf[3];
    for (i=0;i<ACC;i++)
    {
	if ((i*8/ACC)%2)
	{
	    a1 = ((GLfloat) i)*M_PI*2/ACC;
	    s1 = cos(a1);
	    c1 = sin(a1);
	    a2 = ((GLfloat) i+1)*M_PI*2/ACC;
	    s2 = cos(a2);
	    c2 = sin(a2);

	    glBegin(GL_QUADS);
	    glNormal3f(c1, 0.0, s1);
	    glVertex3f(0.143*c1, h1, 0.143*s1);
	    glVertex3f(0.143*c1, h2, 0.143*s1);
	    glNormal3f(c2, 0.0, s2);
	    glVertex3f(0.143*c2, h2, 0.143*s2);
	    glVertex3f(0.143*c2, h1, 0.143*s2);
	    glEnd();

	    glBegin(GL_QUADS);
	    glNormal3f(0.0, 1.0, 0.0);
	    glVertex3f(0.143*c1, h2, 0.143*s1);
	    glVertex3f(0.190*c1, h2, 0.190*s1);
	    glVertex3f(0.190*c2, h2, 0.190*s2);
	    glVertex3f(0.143*c2, h2, 0.143*s2);
	    glEnd();

	    glBegin(GL_QUADS);
	    glNormal3f(c1, 0.0, s1);
	    glVertex3f(0.190*c1, h1, 0.190*s1);
	    glVertex3f(0.190*c1, h2, 0.190*s1);
	    glNormal3f(c2, 0.0, s2);
	    glVertex3f(0.190*c2, h2, 0.190*s2);
	    glVertex3f(0.190*c2, h1, 0.190*s2);
	    glEnd();
	}
    }
    for (i=0;i<ACC;i++)
    {
	if (!((i*8) % ACC))
	{
	    a1 = ((GLfloat) i)*M_PI*2/ACC;
	    s1 = cos(a1);
	    c1 = sin(a1);
	    glBegin(GL_QUADS);
	    glNormal3f(s1, 0.0, -c1);
	    glVertex3f(c1*0.143, h1, s1*0.143);
	    glVertex3f(c1*0.190, h1, s1*0.190);
	    glVertex3f(c1*0.190, h2, s1*0.190);
	    glVertex3f(c1*0.143, h2, s1*0.143);
	    glEnd();
	}
    }
}
コード例 #11
0
ファイル: chess.c プロジェクト: AlexGreulich/HRTFVR
void do_pion(void)
{
    do_rotate(pion_data, sizeof(pion_data)/sizeof(GLfloat));
}