Пример #1
0
void
fruitapp::cursor::sampler::react(
	fruitlib::scenic::events::update const &)
{
	if(
		!sge::timer::reset_when_expired(
			update_timer_))
		return;

	fcppt::optional::maybe_void(
		cursor_.position(),
		[
			this
		](
			sge::input::cursor::position const _position
		)
		{
			positions_.push_back(
				transform_position(
					_position,
					target_.viewport().get()));

			if(positions_.size() > sample_count_.get())
				positions_.pop_front();
		}
	);
}
Пример #2
0
void get_tracker_point(const onit_point *P, int i, float p[3])
{
    float t[3];

    // Convert from millimeters to feet.

    t[0] = P[i].world_p[0] * 0.00328084;
    t[1] = P[i].world_p[1] * 0.00328084;
    t[2] = P[i].world_p[2] * 0.00328084;

    // Apply the configuration transformation.

    transform_position(p, t, 0);
}
Пример #3
0
int get_tracker_sensor(unsigned int id, float p[3], float R[16])
{
    static float last_p[ 3];
    static float last_R[16];

    /* Check for an active tracker. */

    if (tracker != (struct tracker_header *) (-1))
    {
        if (id < tracker->count)
        {
            /* Return the rotation and orientation of sensor ID. */

            struct sensor *S =
                (struct sensor *)((unsigned char *) tracker
                                  + tracker->offset
                                  + tracker->size * id);
            transform_rotation(R, S->r, id);
            transform_position(p, S->p, id);

            return 1;
        }
    }

    /* Recieve messages on the tracker socket.  Return the most recent. */

    if (id == 0 && sock != INVALID_SOCKET)
    {
        struct message mesg;
        struct timeval zero = { 0, 0 };

        int count = 0;

        fd_set fds;

        FD_ZERO(&fds);
        FD_SET(sock, &fds);

        while (select(sock + 1, &fds, NULL, NULL, &zero) > 0)
        {
            if (FD_ISSET(sock, &fds))
            {
                int s = recv(sock, (void *) &mesg, sizeof (struct message), 0);

                if ((s >= 3 * sizeof (float)))
                {
                    float q[3];
                    /*
                                        q[0] = net_to_host_float(mesg.x);
                                        q[1] = net_to_host_float(mesg.y);
                                        q[2] = net_to_host_float(mesg.z);
                    */
                    q[0] =  mesg.x;
                    q[1] =  mesg.y;
                    q[2] = -mesg.z;

                    transform_position(p, q, id);

                    q[1] += 3.0;

                    printf("%+8.3f %+8.3f %+8.3f  ", q[0], q[1], q[2]);
                    printf("%+8.3f %+8.3f %+8.3f\n", p[0], p[1], p[2]);

                    memcpy(last_p, p, 3 * sizeof (float));
                }
                if ((s >= 6 * sizeof (float)))
                {
                    /*
                                        float q[3];

                                        q[0] = net_to_host_float(mesg.rx);
                                        q[1] = net_to_host_float(mesg.ry);
                                        q[2] = net_to_host_float(mesg.rz);
                    */
                    /*
                                        q[0] = mesg.rx;
                                        q[1] = mesg.ry;
                                        q[2] = mesg.rz;

                                        transform_rotation(R, q, id);
                    */
                    load_idt(R);

                    memcpy(last_R, R, 16 * sizeof (float));
                }
            }

            count++;

            FD_ZERO(&fds);
            FD_SET(sock, &fds);
        }

        if (count) return 1;
    }

    memcpy(p, last_p,  3 * sizeof (float));
    memcpy(R, last_R, 16 * sizeof (float));

    return 0;
}