int main(int argc, char* argv[]) {
    parse_parameter(argc, argv);

    // prepare some info outside the loop
    int fd;
    CvFont font;
    cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.7, 0.7, 0, 2); // 0 shear, 3 px wide

    int set_quality[3] = {CV_IMWRITE_JPEG_QUALITY, quality,  0};
    char capture_title[55];
    IplImage* frame;
    CvMat cvmat;

    // startup
    char dev[20];
    sprintf(dev,"/dev/video%i",device);
    fd = open(dev, O_RDWR);
    if (fd == -1) {
        perror("Opening video device");
        return 1;
    }
    if(setup_cam(fd)) {
        return 1;
    }
    if(init_mmap(fd)) {
        return 1;
    }

    // define buffer and activate streaming on the cam
    struct v4l2_buffer buf = {0};
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    buf.memory = V4L2_MEMORY_MMAP;
    buf.index = 0;
    if(-1 == xioctl(fd, VIDIOC_STREAMON, &buf.type)) {
        perror("Start Capture");
        return 1;
    }

    // loop fps measurement
    uint32_t start_time = time(0);
    uint32_t image_count = 0;

    //for(int i=0; i<100; i++){
    /// run forever
    while(1) {
        if(capture_image(fd,&font,set_quality,frame,&cvmat,capture_title,&buf,&start_time,&image_count)) {
            return 1;
        }
    }

    // todo, close gracefully
    printf("closing fd\n");
    close(fd);
    return 0;
}
Beispiel #2
0
void player_update(struct player *player, struct world *world) {
	player->yvel -= 0.005;

	float old_x = player->x, old_y = player->y, old_z = player->z;
	player->x += player->xvel;
	player->y += player->yvel;
	player->z += player->zvel;

	struct world_object *object = world->objects->next;
	struct collide_event *events = NULL;
	while (object != world->objects) {
		if (object->type == WORLD_FLOOR) {
			struct world_floor *floor = (struct world_floor*)object;
			if (old_y > floor->y && player->y < floor->y &&
			    old_x > floor->x1 &&
			    old_x < floor->x2 &&
			    old_z > floor->z1 &&
			    old_z < floor->z2) {
				events = add_collide_event(events, object);
			}
		} else if (object->type == WORLD_WALL) {
			struct world_wall *wall = (struct world_wall*)object;
			if (wall->same_x) {
				if (player->y + 0.3 > wall->y1 &&
				    player->y       < wall->y2 &&
				    old_z > wall->z1 &&
				    old_z < wall->z2) {
					if ((player->x > wall->x1 &&
					     old_x     < wall->x1) ||
					    (player->x < wall->x1 &&
					     old_x     > wall->x1)) {
						events = add_collide_event(events, object);
					}
				}
			} else {
				if (player->y + 0.30 > wall->y1 &&
				    player->y + 0.01 < wall->y2 &&
				    old_x > wall->x1 &&
				    old_x < wall->x2) {
					if ((player->z > wall->z1 &&
					     old_z     < wall->z1) ||
					    (player->z < wall->z1 &&
					     old_z     > wall->z1)) {
						events = add_collide_event(events, object);
					}
				}
			}
		}
		object = object->next;
	}

	player->on_ground = 0;

	struct collide_event *next_event;
	while (events) {
		next_event = events->next;
		struct world_object *collide = events->object;
		if (collide->type == WORLD_FLOOR) {
			struct world_floor *floor = (struct world_floor*)collide;
			player->yvel = 0;
			player->on_ground = 1;
			player->y = 0.001 + floor->y;
		} else if (collide->type == WORLD_WALL) {
			struct world_wall *wall = (struct world_wall*)collide;
			if (wall->same_x) {
				player->x = old_x;
			} else {
				player->z = old_z;
			}
		}
		free(events);
		events = next_event;
	}

	player->cam.x = player->x;
	player->cam.y = player->y + 0.4;
	player->cam.z = player->z;
	
	player->cam.xang = player->xang;
	player->cam.yang = player->yang;

	setup_cam(&player->cam);
}