예제 #1
0
void
scrollable_widget_rep::handle_get_coord4 (get_coord4_event ev) {
  if      (ev->which == "visible") {
    ev->c1= scx - get_dx (grav, w);
    ev->c2= scy - get_dy (grav, h) - h;
    ev->c3= scx - get_dx (grav, w) + w;
    ev->c4= scy - get_dy (grav, h);
  }
  else if (ev->which == "extents") {
    ev->c1= ex1; ev->c2= ey1;
    ev->c3= ex2; ev->c4= ey2;
  }
  else attribute_widget_rep::handle_get_coord4 (ev);
}
예제 #2
0
파일: sdlstuff.c 프로젝트: rdebath/sgt
int setup(void)
{
#ifdef PS2
    evfd = open("/dev/ps2event", O_RDONLY);
    if (evfd < 0) { perror("/dev/ps2event: open"); return 1; }
    ioctl(evfd, PS2IOC_ENABLEEVENT, PS2EV_VSYNC);
    dx = get_dx();
    dy = get_dy();
#endif /* PS2 */

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    cleaned_up = 0;
    atexit(cleanup);

    /*
     * Set the video mode up.
     */
    screen = SDL_SetVideoMode(SCR_WIDTH*XMULT, SCR_HEIGHT*YMULT,
			      8, SDL_SWSURFACE);
    if (!screen) {
	printf("SDL screen initialisation error: %s\n", SDL_GetError());
	return 1;
    }
    SDL_ShowCursor(SDL_DISABLE);
}
예제 #3
0
void callback_ir(const ir_converter::DistanceConstPtr& distances)
{
    if (_correct_theta)
    {
        _ir_dist += pack_matrix(distances);
        ++_iteration_theta;

        if (_iteration_theta >= _max_iterations()) {

            _ir_dist /= _iteration_theta;

            double dx = robot::ir::offset_front_left_forward + robot::ir::offset_rear_left_forward;
            double dy = get_dy(_ir_dist);

            if(isnan(dy))
                return;

            double angle = atan(dy/dx);

            double new_theta = (_heading*M_PI_2) + angle;

            ROS_INFO("corrected theta %.3lf -> %.3lf", RAD2DEG(_theta), RAD2DEG(new_theta));
            _theta = new_theta;

            _correct_theta = false;
            _iteration_theta = 0;
        }
    }
    else
    {
        _ir_dist = pack_matrix(distances);
    }
}
float AbstractFormConfigurationTuple::get_absolute_area_improvement()
{
	float sum_of_areas_of_boxes_of_contained_forns = 0;
	for (int i=0; i<abstract_form_configs.size(); ++i)
	{
		sum_of_areas_of_boxes_of_contained_forns += abstract_form_configs[i].get_dx() * abstract_form_configs[i].get_dy();
	}

	return sum_of_areas_of_boxes_of_contained_forns - get_dx() * get_dy();
}
예제 #5
0
void view::rtransform(int& x, int& y) {
    int dx = - get_dx();
    int dy = - get_dy();
    double scale = 1.0 / get_scale();

    x += dx;
    y += dy;

    x *= scale;
    y *= scale;
}
예제 #6
0
void view::transform(int& x, int& y) {
    int dx = get_dx();
    int dy = get_dy();
    double scale = get_scale();

    x *= scale;
    y *= scale;

    x += dx;
    y += dy;
}
예제 #7
0
void view::transform(int& x, int& y, int& w, int& h, int& r) {
    int dx = get_dx();
    int dy = get_dy();
    double scale = get_scale();

    x *= scale;
    y *= scale;
    w *= scale;
    h *= scale;
    r *= scale;

    x += dx;
    y += dy;
}
예제 #8
0
void callback_turn_done(const std_msgs::BoolConstPtr& done)
{
    double dx = robot::ir::offset_front_left_forward + robot::ir::offset_rear_left_forward;
    double dy = get_dy(_ir_dist);

    if(isnan(dy))
        return;

    double angle = atan(dy/dx);

    if (RAD2DEG(std::abs(angle)) < 10.0 && std::abs(_turn_accum) < 20.0) {
        ROS_INFO("Attempt to correct theta by using ir sensors");
        _correct_theta = _enable_theta_correction();
        _correct_lateral = _enable_lateral_correction();
    }

}
/**
 * @brief Recursive function to generate a maze.
 *
 * @param[in] cx Starting x-coordinate.
 * @param[in] cy Starting y-coordinate.
 */
void RecursiveBacktracker::carve_passages_from(int cx, int cy)
{
    int i, nx, ny, directions[] = {N, S, E, W};
    shuffle_array(directions, NUM_DIRECTIONS);

    for (i = 0; i < NUM_DIRECTIONS; i++)
    {
        nx = cx + get_dx(directions[i]);
        ny = cy + get_dy(directions[i]);

        if ((nx >= 0 && nx < WIDTH) && (ny >= 0 && ny < HEIGHT)
            && maze->grid[nx][ny] == 0)
        {
            maze->grid[cx][cy] |= directions[i];
            maze->grid[nx][ny] |= get_opposite(directions[i]);

            carve_passages_from(nx, ny);
        }
    }
}
예제 #10
0
파일: sdlstuff.c 프로젝트: rdebath/sgt
int main(int argc, char **argv)
{
    SDL_Surface *screen;
    SDL_AudioSpec audio_wanted;
    int frame;
    int evfd;
    int x, y;

    evfd = open("/dev/ps2event", O_RDONLY);
    if (evfd < 0) { perror("/dev/ps2event: open"); return 1; }
    ioctl(evfd, PS2IOC_ENABLEEVENT, PS2EV_VSYNC);

    dx = get_dx();
    dy = get_dy();
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
    atexit(cleanup);

    if (argc > 1 && !strcmp(argv[1], "-j")) {
	int i;
	SDL_Event event;
	SDL_Joystick *joystick;

	printf("%d joysticks were found.\n\n", SDL_NumJoysticks() );
	printf("The names of the joysticks are:\n");
	for (i=0; i < SDL_NumJoysticks(); i++) {
	    printf("    %s\n", SDL_JoystickName(i));
	}

	joystick = SDL_JoystickOpen(0);
	printf("Joystick 0 has %d axes\n", SDL_JoystickNumAxes(joystick));
	printf("Joystick 0 has %d buttons\n", SDL_JoystickNumButtons(joystick));
	printf("Joystick 0 has %d balls\n", SDL_JoystickNumBalls(joystick));
	printf("Joystick 0 has %d hats\n", SDL_JoystickNumHats(joystick));

	while(SDL_WaitEvent(&event)) {
	    switch(event.type) {
	      case SDL_JOYAXISMOTION:
		printf("Axis %d %d\n", event.jaxis.axis, event.jaxis.value);
		break;
	      case SDL_JOYBUTTONDOWN:
		printf("Button %d down\n", event.jbutton.button);
		break;
	      case SDL_JOYBUTTONUP:
		printf("Button %d up\n", event.jbutton.button);
		break;
	      case SDL_KEYDOWN:
		goto done;
		break;
	    }
	}
	done:

	return 0;
    }

    /*
     * Set the audio device up.
     */
    audio_wanted.freq = 22050;
    audio_wanted.format = AUDIO_S8;
    audio_wanted.channels = 1;    /* 1 = mono, 2 = stereo */
    audio_wanted.samples = 1024;  /* Good low-latency value for callback */
    audio_wanted.callback = fill_audio;
    audio_wanted.userdata = NULL;
    if ( SDL_OpenAudio(&audio_wanted, NULL) < 0 ) {
        fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
        return 1;
    }

    /*
     * Set the video mode up.
     */
    screen = SDL_SetVideoMode(SCR_WIDTH*XMULT, SCR_HEIGHT*YMULT,
			      8, SDL_SWSURFACE);
    if (!screen) {
	printf("SDL screen initialisation error: %s\n", SDL_GetError());
	return 1;
    }
    SDL_ShowCursor(SDL_DISABLE);

    if (SDL_MUSTLOCK(screen))
	SDL_LockSurface(screen);
    for (x = 0; x < SCR_WIDTH*XMULT; x++) {
	for (y = 0; y < SCR_HEIGHT*YMULT; y++) {
	    putpixel(screen, x, y,
		     SDL_MapRGB(screen->format, (x*10)&255,
				(y*10)&255, ((x+y+frame)*10)&255));
	}
    }
    if (SDL_MUSTLOCK(screen))
	SDL_UnlockSurface(screen);

    SDL_PauseAudio(0);

    for (frame = 1; frame < 256; frame++) {
	SDL_Rect r1 = { 0, 0, SCR_WIDTH*XMULT-1, SCR_HEIGHT*YMULT };
	SDL_Rect r2 = { 1, 0, SCR_WIDTH*XMULT-1, SCR_HEIGHT*YMULT };
	
	if (SDL_MUSTLOCK(screen))
	    SDL_LockSurface(screen);
//	for (x = 0; x < SCR_WIDTH*XMULT; x++) {
	    for (y = 0; y < SCR_HEIGHT*YMULT; y++) {
		memmove(screen->pixels + y * screen->pitch,
			screen->pixels + y * screen->pitch + screen->format->BytesPerPixel,
			(SCR_WIDTH*XMULT-1) * screen->format->BytesPerPixel);
		putpixel(screen, SCR_WIDTH*XMULT-1, y, 0);
		//putpixel(screen, x, y, (x==SCR_WIDTH*XMULT-1 ? 0 :
		//			getpixel(screen, x+1, y)));
	    }
//	}
	if (SDL_MUSTLOCK(screen))
	    SDL_UnlockSurface(screen);
	//SDL_UpdateRect(screen, frame*2, 0, 2, SCR_HEIGHT*YMULT);
	SDL_Flip(screen);
	{
	    long long t = bigclock();
	    ioctl(evfd, PS2IOC_WAITEVENT, PS2EV_VSYNC);
	    sparetime += bigclock() - t;
	}
    }

    return 0;
}
예제 #11
0
void sprite_move(sprite_t *p_sprite, dir_t dir)
{
  p_sprite->pt.x += get_dx(dir)*TILE_W;
  p_sprite->pt.y += get_dy(dir)*TILE_H;
}