Exemple #1
0
void TuioContainer::update (TuioTime ttime, float xp, float yp) {
	lastPoint = &path.back();
	TuioPoint::update(ttime,xp, yp);

	TuioTime diffTime = currentTime - lastPoint->getTuioTime();
	float dt = diffTime.getTotalMilliseconds()/1000.0f;
	float dx = xpos - lastPoint->getX();
	float dy = ypos - lastPoint->getY();
	float dist = sqrt(dx*dx+dy*dy);
	float last_motion_speed = motion_speed;
	float last_x_speed = x_speed;
	float last_y_speed = y_speed;

	x_speed = dx/dt;
	y_speed = dy/dt;
	motion_speed = dist/dt;
	motion_accel = (motion_speed - last_motion_speed)/dt;
	x_accel = (x_speed - last_x_speed)/dt;
	y_accel = (y_speed - last_y_speed)/dt;

	TuioPoint p(currentTime,xpos,ypos);
	path.push_back(p);
    if (path.size()>MAX_PATH_SIZE) path.pop_front();

	if (motion_accel>0) state = TUIO_ACCELERATING;
	else if (motion_accel<0) state = TUIO_DECELERATING;
	else state = TUIO_STOPPED;
}
Exemple #2
0
TuioPoint TuioContainer::predictPosition() {
	/*if (path.size()>1) {
		std::list<TuioPoint>::iterator iter = path.end();
		std::advance(iter, -2);
		
		TuioTime diffTime = currentTime - (*iter).getTuioTime();
		float dt = diffTime.getTotalMilliseconds()/1000.0f;
		
		float tx = x_speed * dt;
		float ty = y_speed * dt;
		
		float nx = xpos+tx-tx*x_accel*dt;
		float ny = ypos+ty-ty*y_accel*dt;
		
		//if (xposFilter && yposFilter) {
		//	nx = xposFilter->filter(nx,dt);
		//	ny = yposFilter->filter(ny,dt);
		//	//std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
		//}
		
		//std::cout << nx << " " << ny << std::endl;
		return TuioPoint(nx,ny);
	} else return TuioPoint(xpos,ypos);*/
	
	TuioTime diffTime = currentTime - lastPoint->getTuioTime();
	float dt = diffTime.getTotalMilliseconds()/1000.0f;
	
	float tx = x_speed * dt;
	float ty = y_speed * dt;
	
	float nx = xpos+tx-tx*x_accel*dt;
	float ny = ypos+ty-ty*y_accel*dt;
	
	//if (xposFilter && yposFilter) {
	//	nx = xposFilter->filter(nx,dt);
	//	ny = yposFilter->filter(ny,dt);
	//	//std::cout << dt << " " << xp << " " << xpos << " " << yp << " " << ypos << std::endl;
	//}
	
	//std::cout << nx << " " << ny << std::endl;
	return TuioPoint(nx,ny);

	
}
Exemple #3
0
void TuioBlob::update (TuioTime ttime, float xp, float yp, float a, float w, float h, float f) {
	TuioPoint lastPoint = path.back();
	TuioContainer::update(ttime,xp,yp);
	
	TuioTime diffTime = currentTime - lastPoint.getTuioTime();
	float dt = diffTime.getTotalMilliseconds()/1000.0f;
	float last_rotation_speed = rotation_speed;
	
	float prev_angle = angle_sum;
	float da = a-angle;
	if (da > M_PI/2.0f) angle_sum += (da-2*M_PI);
	else if (da < M_PI/-2.0f) angle_sum += (da+2*M_PI);
	else angle_sum += da;
	
	if (angleFilter) angle_sum = angleFilter->filter(angle_sum,dt);
	if (fabs(angle_sum-prev_angle)<angleThreshold) angle_sum = prev_angle;
	
	int m = floor(angle_sum/(2*M_PI));
	angle = angle_sum-(m*(2*M_PI));
	
	da = (angle-a)/(2*M_PI);
	if (da > 0.75f) da-=1.0f;
	else if (da < -0.75f) da+=1.0f;
	
	if (widthFilter && heightFilter) {
		w = widthFilter->filter(w,dt);
		h = heightFilter->filter(h,dt);
	}
	
	float dw = fabs(width - w);
	float dh = fabs(height - h);
	if ((dw>sizeThreshold) || (dh>sizeThreshold)) {
		width = w;
		height = h;
	}
	
	area = f;
	
	rotation_speed = (float)da/dt;
	rotation_accel =  (rotation_speed - last_rotation_speed)/dt;
	
	if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
Exemple #4
0
void TuioObject::update (TuioTime ttime, float xp, float yp, float a) {
	TuioPoint lastPoint = path.back();
	TuioContainer::update(ttime,xp,yp);
	
	TuioTime diffTime = currentTime - lastPoint.getTuioTime();
	float dt = diffTime.getTotalMilliseconds()/1000.0f;
	float last_angle = angle;
	float last_rotation_speed = rotation_speed;
	angle = a;
	
	double da = (angle-last_angle)/(2*M_PI);
	if (da > 0.75f) da-=1.0f;
	else if (da < -0.75f) da+=1.0f;
	
	rotation_speed = (float)da/dt;
	rotation_accel =  (rotation_speed - last_rotation_speed)/dt;
	
	if ((rotation_accel!=0) && (state==TUIO_STOPPED)) state = TUIO_ROTATING;
}
void  IupTuioListener::refresh(TuioTime frameTime) 
{
  if (this->changed)
  {
    Ihandle* ih_canvas = IupGetAttributeHandle(this->ih, "TARGETCANVAS");
    if (!ih_canvas)
      ih_canvas = this->ih;

    this->changed = 0;

    IFniiis cb = (IFniiis)IupGetCallback(ih_canvas, "TOUCH_CB");
    IFniIIII mcb = (IFniIIII)IupGetCallback(ih_canvas, "MULTITOUCH_CB");
    if (cb || mcb)
    {
      this->client->lockCursorList();
      this->locked = 1;
    }

    if (this->debug)
      printf("IupTuioClient-RefreshChanged(time=%d)\n", (int)frameTime.getTotalMilliseconds());
  }
}
Exemple #6
0
void Tuio2Dump::tuioRefresh(TuioTime frameTime) {
	std::cout << "refresh " << frameTime.getFrameID() << " "<< frameTime.getTotalMilliseconds() << std::endl;
	std::cout << std::flush;
}