Beispiel #1
0
void runStraight(float x, float y, float speed) {
  typeCoordinate start = GetCoordinate();
  if(GoalInFront(x,y) == true)
	return;
  sleepSafe(FRONT_SIGHT_LENGTH);  
  typeCoordinate nowp;
  int tempTime = 500;
  int  nearTime = 0;
  while (1) {	
	//	for(i = 0;i < 1; i++){
	while(1){
	  if(sleepSafe(FRONT_SIGHT_LENGTH) == 0)
		break;
	}
	SetLeftWheelGivenSpeed(speed);
	SetRightWheelGivenSpeed(speed);
	vTaskDelay(tempTime - nearTime);
	if(GoalInFront(x,y) == true)
	  return;
	//	}
	nowp =  GetCoordinate();
	if(nowp.x >= x)
	  return;
	float dist = getDistance2(nowp.x, nowp.y, x, y);
	if(dist >= 0.06)
	{
	  rotateTo(x,y,ANGLESPEED,0);	
	}
	else {
	  rotateTo(x,y,ANGLESPEED,1);	
	  //	  nearTime = 200;
	}
  }  /* end of while */
} /*end of ControlRobotgo2Position*/
void CharacterMovement::move( float time )
{
	if( !_moving )
	{
		return;
	}

	rotateTo(_destination);
	QVector3D position = _position;
	if( _distance <= 0 /*&& transitionToStop == false*/ )
	{
		//if this node isn't the last
		if( !_moveList.empty() )
		{
			_destination = _moveList[0];
			_distance = UtilFunctions::calculateDistance( position, _destination );
			if( _distance > 0.000001f )
			{
				// compute direction vector
				rotateTo(_destination);
			}

			// delete the first node on the list
			_moveList.erase( _moveList.begin() );
		}
		else
		{
			// the player arrive to last destination
			this->stopMoving();
		}
	}

	QVector3D dir = (_direction * _speed) * time;
	if( _distance > 0.000001f )//&& animationState->getAnimationName() != "Bow" )
	{
		Ogre::Real newDistance = dir.length();
		// Update player's position
		// interpolate linearly
		if( newDistance > _distance )
		{
			position = _destination;
			_distance = 0;
		}
		else
		{
			_distance -= newDistance;
			position += dir;
		}
		_position = position;
		_node->setPosition( UtilFunctions::qVector3dToOgreVector3( _position ) );
	}
	else
	{
//		if( transitionToStop )
		{
			_position = position;
			_node->setPosition( UtilFunctions::qVector3dToOgreVector3( _position ) );
		}
	}
}
Beispiel #3
0
 inline void insert(int loc, int value) {
     rotateTo(loc, 0);
     rotateTo(loc + 1, root);
     newNode(dealTree, value);
     fa[dealTree] = child[root][1];
     pushUp(child[root][1]);
     pushUp(root);
 }
Beispiel #4
0
 inline void add(int left, int right, int cnt_value) {
     rotateTo(left - 1, 0);
     rotateTo(right + 1, root);
     value[dealTree] += cnt_value; 
     add_lazy[dealTree] += cnt_value;
     min_number[dealTree] += cnt_value;
     pushUp(child[root][1]);
     pushUp(root);
 }
Beispiel #5
0
void specialRun(float x, float y,float speed) {
  rotateTo(x,y,ANGLESPEED,ROTATE_ACCURATE); 
  
  int cell = 6;
  float speedL = speed;
  float speedR = speed;
  
  if(GoalInFront(x,y,0) == true)
	return;
  
  typeCoordinate nowp = getNowPos(x,y);
  while (1) {		
	float dist = getDistance2(nowp.x, nowp.y, x, y);	
	if (dist < MIN_RANGE) break;		
	
	while((dist <= 0.06)){
	  rotateTo(x,y,FASTSPEED,ROTATE_ACCURATE); 
	  rotateToSafe(x,y);
	  SetLeftWheelGivenSpeed(speedL);
	  SetRightWheelGivenSpeed(speedR);
	  vTaskDelay(300);
	  if((GoalInFront(x,y,0) == true))
		return;
	}
	
	rotateToSafe(x,y);
	whichSide(x, y);
	SetLeftWheelGivenSpeed(speed);
	SetRightWheelGivenSpeed(speed);
	vTaskDelay(300);
	 if((GoalInFront(x,y,0) == true))
		return;
	int side = whichSide(x, y);
	if (side == RIGHT_HAND) { // right side
	  speedL = speed;
	  speedR = speed + cell;
	} else if (side == LEFT_HAND) { // left side
	  speedL = speed + cell;
	  speedR = speed;
	} else {
	  speedL = speedR = speed;
	}
	
	rotateToSafe(x,y);
	
	SetLeftWheelGivenSpeed(30);
	SetRightWheelGivenSpeed(30);
	vTaskDelay(300);
	if((GoalInFront(x,y,0) == true))
	  return;
	nowp = getNowPos(x,y);
  }
} /*end of ControlRobotgo2Position*/
Beispiel #6
0
void Robot::drawMap()
{
    getImage();
    char filename[20];
    strcpy(filename, "0.png");
    for(int i=0; i<12; i++)
    {
        getImage();
        filename[0] = (char)(i+'0');
        filename[5] = '\0';
        cvSaveImage(filename, image_r);
        adjustWorldCoordinate(image_r,0);
        cvWaitKey(100);
        worldMap.updateMap(image_r);
        locateOwnGate();
        turnRight(30);
    }

    getImage();
    adjustWorldCoordinate(image_r,2);
    adjustWorldCoordinate(image_r,1);
    rotateTo(cv::Point2f(0,1));
    /*moveForward(200, 20);
    for(int i=0;i<12;i++)
    {
        getImage();
        adjustWorldCoordinate(image_r,0);
        worldMap.updateMap(image_r);
        turnRight(30);
    }
    getImage();
    adjustWorldCoordinate(image_r,2);
    adjustWorldCoordinate(image_r,1);
    rotateTo(cv::Point2f(0,1));*/
}
Beispiel #7
0
void Robot::spin() {//S型过人
    cv::Point2f robot_coord(x, y);
    std::vector<cv::Point2f> ans = findMulBall();
    cv::Point2f ball1 = ans[0];
    cv::Point2f ball2 = ans[1];
    //printf("%f %f\n %f %f\n", ball1.x, ball1.y, ball2.x, ball2.y);
    float delta =  30;
    float r12 =  cal_distance(ball1, ball2) / 2;
    float rspin = (delta * delta + r12 * r12) / (2 * delta);
    rspin += 10;//误差修正
    float disr1 =  cal_distance(ball1, robot_coord);
    int  inrspin = 0;
    while(inrspin < rspin)
        inrspin++;
    //printf("rspin:%f, disr1:%f, inrspin:%d\n", rspin, disr1, inrspin);
    cv::Point2f rto1 = ball1 - robot_coord;
    cv::Point2f b1to2 = ball2 - ball1;

    float arc = asin(r12 / rspin);
    cv::Point2f pturn1(ball1.x -  b1to2.x * 0.5, ball1.y - b1to2.y *0.5);

    moveTo(pturn1, 20);
    cv::Point2f robotPosition(x,y);
    cv::Point2f dir= ball1 - robotPosition;
    float dir_len = length(dir);
    if (dir_len <= 0)
        return;
    cv::Point2f new_dir = dir*(1/dir_len);
    rotateTo(new_dir);
    turnRight(arc * 180 / M_PI);
    moveRotate(true, rspin, arc * 2 + 0.2);//误差修正
    moveRotate(false, rspin, arc * 2 + 0.2);
}
void BasicScreenObject::rotateTo(float _x, float _y, float _z, float _slerptime, float (ofxTransitions::*ease) (float,float,float,float), float delay) {
	qx.makeRotate(_x, ofVec3f(1,0,0));
	qy.makeRotate(_y, ofVec3f(0,1,0));
	qz.makeRotate(_z, ofVec3f(0,0,1));
	endquat = qx*qy*qz;
	endquat.normalize();
	rotateTo(endquat, _slerptime, ease, delay);
}
Beispiel #9
0
//you may want to lock the rendere before using and unlock after using me
void draw()
{
	if(!node)
	{
		node = manager->addAnimatedMeshSceneNode(mesh);
		rotateTo(irr::core::vector3d<irr::f32>(0.0f,0.0f,0.0f));
	}
}
Beispiel #10
0
void runStraight(float x, float y, float speed) {
  float speedL = speed;
  float speedR = speed;
  typeCoordinate start = GetCoordinate();
  SetLeftWheelGivenSpeed(1);
  SetRightWheelGivenSpeed(1);
  vTaskDelay(500);
  SetLeftWheelGivenSpeed(3);
  SetRightWheelGivenSpeed(3);
  vTaskDelay(500);
  SetLeftWheelGivenSpeed(5);
  SetRightWheelGivenSpeed(5);
  vTaskDelay(500);
  SetLeftWheelGivenSpeed(10);
  SetRightWheelGivenSpeed(10);
  vTaskDelay(300);
  SetLeftWheelGivenSpeed(15);
  SetRightWheelGivenSpeed(15); 
  vTaskDelay(300);
  SetLeftWheelGivenSpeed(20);
  SetRightWheelGivenSpeed(20);
  typeCoordinate nowp = GetCoordinate();
  while (1) {
	sleepSafe(FRONT_SIGHT_LENGTH);  
	int side = whichSide(start.x,start.y, x, y, nowp.x, nowp.y);
	float dist = getDistance2(nowp.x, nowp.y, x, y);
	if (dist >= 0.08){
	  rotateTo(x,y,ANGLESPEED,2); 
	  //#ifdef CONFIG_ROBOT1	  
	  //	  	rotateTo(posM.x,posM1.y,ANGLESPEED,2); 
	  //#elif defined(CONFIG_ROBOT2)
	  //		rotateTo(posM.x,posM2.y,ANGLESPEED,2); 
	  //#elif defined(CONFIG_ROBOT3)
	  //		rotateTo(posM.x,posM3.y,ANGLESPEED,2);	
	  //#elif defined(CONFIG_ROBOT4)
	  //		rotateTo(posM.x,posM4.y,ANGLESPEED,2);
	  //#endif		
	}
	if (side == -2 || dist < EPS) break;
	if (side == -1) { // right side
	  speedL = speed;
	  speedR = speed+3;
	} else if (side == 1) { // left side
	  speedL = speed+3;
	  speedR = speed;
	} else {
	  speedL = speedR = speed;
	}
	SetLeftWheelGivenSpeed(speedL);
	SetRightWheelGivenSpeed(speedR);
	vTaskDelay(300);
	nowp = GetCoordinate();
  }
#ifdef DEBUG
  halt(2);
#endif
}
Beispiel #11
0
void Robot::moveTo(const cv::Point2f& wCoord,float max_speed)
{
    cv::Point2f robotPosition(x,y);
    cv::Point2f delta = wCoord - robotPosition;
    float delta_len = length(delta);
    if (delta_len <= 0)
        return;
    cv::Point2f new_dir = delta*(1/delta_len);

    rotateTo(new_dir);
    moveForward(delta_len,max_speed);
}
Beispiel #12
0
ILModel(irr::scene::ISceneManager *mngr, irr::c8 *fName, irr::core::vector3d<irr::f32> position, irr::core::vector3d<irr::f32> rotation)
{
	manager = mngr;
	mesh = mngr->getMesh(fName);
	node = 0;
	defaultXRotation = 0.0f;
	defaultYRotation = 0.0f;
	defaultZRotation = -90.0f;
	node = manager->addAnimatedMeshSceneNode(mesh);
	node->setPosition(rightToLeft(position));
	rotateTo(rotation);
}
Beispiel #13
0
void cUnit::updateFacing()
{
	if (orderCounter == 0) { return; }
	float angle;

	if (order[0].type == ORDER_MOVETO) {
		angle = math.getAngle(pos.x, pos.y, order[0].targetPos.x, order[0].targetPos.y);
	}
	else {
		angle = math.getAngle(pos.x, pos.y, game.getUnit(order[0].targetObject).pos.x, game.getUnit(order[0].targetObject).pos.y);
	}
	rotateTo(math.convertAngle(angle));
}
Beispiel #14
0
ILModel(irr::scene::ISceneManager *mngr, irr::c8 *fName, bool displayNow)
{
	manager = mngr;
	mesh = mngr->getMesh(fName);
	node = 0;
	defaultXRotation = 0.0f;
	defaultYRotation = 0.0f;
	defaultZRotation = -90.0f;
	if(displayNow)
	{
		node = manager->addAnimatedMeshSceneNode(mesh);
		rotateTo(irr::core::vector3d<irr::f32>(0.0f,0.0f,0.0f));
	}
}
//handle mouse move events
//
void
SystemTopologyDrawing::mouseMoveEvent( QMouseEvent* event )
{
    if ( event->buttons() & Qt::LeftButton )
    {
        //if mouse is left-clicked and moved while shift is pressed, then
        //move the topology
        if ( shiftPressed )
        {
            moveTo( event->pos() );
        }
        //if mouse is left-clicked and moved while control is pressed,
        //then increase the plane distance
        else if ( controlPressed )
        {
            int planeDistance = transform->getPlaneDistance();
            planeDistance += ( int )event->pos().y() - lastPoint.y();
            if ( planeDistance <= 0.0 )
            {
                planeDistance = 1;
            }
            lastPoint = event->pos();
            transform->setPlaneDistance( planeDistance );
            draw();
        }
        //if mouse is left-clicked and moved, rotate the topology
        else
        {
            rotateTo( event->pos() );
        }
        event->accept();
    }
    else if ( event->buttons() & Qt::RightButton )
    {
        //if mouse is right-clicked and moved, then change the item for
        //which the info box is displayed
        lastPoint = event->pos();
        draw();
        event->accept();
    }
    else
    {
        event->ignore();
    }
}
Beispiel #16
0
void runStraight(float x, float y, float speed, int flag) {
  float speedL = speed;
  float speedR = speed;
  typeCoordinate start = GetCoordinate();
  
  typeCoordinate nowp = GetCoordinate();
  while (1) {	
	int side = whichSide(start.x,start.y, x, y, nowp.x, nowp.y);
	float dist = getDistance2(nowp.x, nowp.y, x, y);	
	
	while(1){
	  if(sleepSafe(FRONT_SIGHT_LENGTH) == 0)
		break;
	}
	while(dist <= 0.10){
	  rotateTo(x,y,ANGLESPEED,1); 
	  SetLeftWheelGivenSpeed(speedL);
	  SetRightWheelGivenSpeed(speedR);
	  vTaskDelay(300);
	  if(GoalInFront(x,y) == true)
		return;
	}
	if (side == -2 || dist < EPS) break;
	if (side == -1) { // right side
	  speedL = speed;
	  speedR = speed+5;
	} else if (side == 1) { // left side
	  speedL = speed+5;
	  speedR = speed;
	} else {
	  speedL = speedR = speed;
	}
	SetLeftWheelGivenSpeed(speedL);
	SetRightWheelGivenSpeed(speedR);
	vTaskDelay(300);
	
	nowp = GetCoordinate();
  }
#ifdef DEBUG
  halt(2);
#endif
}
void CharacterMovement::moveTo()
{
	qDebug() << "[CharacterMovement::moveTo]";
	// Get current position
	_position = UtilFunctions::ogreVector3ToQVector3d( _node->getPosition() );

	// clear the list of point
//	_moveList.clear();

	// Compute distance to new location
	_distance = UtilFunctions::calculateDistance( _position, _destination );
	qDebug() << "[CharacterMovement::moveTo] - Distance:" << _distance << "Pos:" << _position << "Dest:" << _destination;
	if( _distance > 0.000001f )
	{
		// compute direction vector
		_direction = _destination - _position;
		_direction.normalize();
		_moving = true;
		rotateTo(_destination);
		qDebug() << "[CharacterMovement::moveTo] - Emited startedMoving";
		emit startedMoving();
	}
}
Beispiel #18
0
u8 rotateToSafe(float x,float y){
    u8 flag = 0;
    u8 i = 0;
	float dir;
    typeCoordinate c;
	for (i = 0; i < ROBOTS; i++){
	  /*if check itself,then return*/
	  //add code here
	  if((i+1) == rbID)
		continue;
	  if (bCastInfo[i].nodeID == (i+1)) {
		//get my information
		dir = bCastInfo[i].angle2n;
        c.x  = bCastInfo[i].rpos.locationX;
        c.y  = bCastInfo[i].rpos.locationY;
		
		float interAngle = 0;
		int leftOrRight = 0;
		if (ObjectInFront(dir, c, &interAngle,FRONT_SIGHT_LENGTH,&leftOrRight) == true){
		  flag++;
//		  halSetLedStatus(LED_BLUE, LED_ON);  
		  if((leftOrRight == -1)){
			  ControlRobotRotate(-(interAngle+FOV+EYEANGLE), FASTSPEED);
		  }else if((leftOrRight == 1)){
			  ControlRobotRotate(-(FOV-interAngle+EYEANGLE), FASTSPEED);
		  }else{
			 ControlRobotRotate(-(FOV + EYEANGLE), FASTSPEED);
		  }
		}
	  }
   } /* end of for*/
   if( flag == 3){  //have 3 robots in front of it. 
	  halt(2);
	  rotateTo(x,y,ANGLESPEED,ROTATE_ACCURATE);	
   }
   return flag;
}
Beispiel #19
0
	// -------------------------------------------------------
	// 
	// -------------------------------------------------------
	void MoveByAction::update(SpriteArray& array,float dt,ActionEventBuffer& buffer) {	
		if (_buffer.size > 0) {
			for (int i = 0; i < _buffer.size; ++i) {
				Vector2f p = array.getPosition(_ids[i]);
				p += _velocities[i] * dt;
				if (isOutOfBounds(p, _velocities[i])) {
					if (_bounce[i]) {
						if (p.y < m_BoundingRect.bottom || p.y > m_BoundingRect.top) {
							_velocities[i].y *= -1.0f;
						}
						if (p.x < m_BoundingRect.left || p.x > m_BoundingRect.right ) {
							_velocities[i].x *= -1.0f;
						}
						rotateTo(array, i);
						p += _velocities[i] * dt * 1.5f;
					}
					else {
						buffer.add(_ids[i], AT_MOVE_BY, array.getType(_ids[i]));
					}
				}
				array.setPosition(_ids[i], p);
			}
		}
	}
Beispiel #20
0
 inline int query(int left, int right) {
     rotateTo(left - 1, 0);
     rotateTo(right + 1, root);
     return min_number[dealTree];
 }
void BasicScreenObject::rotateTo(ofQuaternion _quat, float _slerptime, float (ofxTransitions::*ease) (float,float,float,float)) {
	rotateTo(_quat, _slerptime, ease, 0);
}
Beispiel #22
0
 inline void deleteNode(int loc) {
     rotateTo(loc - 1, 0);
     rotateTo(loc + 1, root);
     deleteTree(dealTree);
 }
Beispiel #23
0
void rotateFastTo(float x, float y, float speed,int flag) {
  rotateTo(x,y,FASTSPEED,ROTATE_ACCURATE);
  rotateTo(x,y,ANGLESPEED,ROTATE_ACCURATE);
}
Beispiel #24
0
bool SessionManager::rotate( bool audio )
{
    return rotateTo( "", audio );
}
LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_CREATE:
		{
			_splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle);
			return TRUE;
		}

		case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
				case ROTATION_A_GAUCHE:
				{
					rotateTo(DIRECTION::LEFT);
					break;
				}
				case ROTATION_A_DROITE:
				{
					rotateTo(DIRECTION::RIGHT);
					break;
				}
			}
			return TRUE;
		}

		case WM_RESIZE_CONTAINER:
		{
			RECT rc0, rc1;
			getClientRect(rc0);

			rc1.top = rc0.top += _y;
			rc1.bottom = rc0.bottom;
			rc1.left = rc0.left += _x;
			rc1.right = rc0.right;

			if (_dwSplitterStyle & SV_VERTICAL)
			{
				if (wParam != 0)
				{
					rc0.right = int(wParam);

					rc1.left = int(wParam) + _x + _splitter.getPhisicalSize();
					rc1.right = rc1.right - rc1.left + _x;
				}
			}
			else //SV_HORIZONTAL
			{
				if (lParam != 0)
				{
					rc0.bottom = int(lParam);

					rc1.top   = int(lParam) + _y + _splitter.getPhisicalSize();
					rc1.bottom = rc1.bottom - rc1.top + _y;
				}
			}
			_pWin0->reSizeTo(rc0);
			_pWin1->reSizeTo(rc1);

			::InvalidateRect(_splitter.getHSelf(), NULL, TRUE);
			return TRUE;
		}

		case WM_DOPOPUPMENU:
		{
			if ((_splitterMode != SplitterMode::LEFT_FIX) && (_splitterMode != SplitterMode::RIGHT_FIX) )
			{
				POINT p;
				::GetCursorPos(&p);

				if (!_hPopupMenu)
				{
					_hPopupMenu = ::CreatePopupMenu();
					::InsertMenu(_hPopupMenu, 1, MF_BYPOSITION, ROTATION_A_GAUCHE, TEXT("Rotate to left"));
					::InsertMenu(_hPopupMenu, 0, MF_BYPOSITION, ROTATION_A_DROITE, TEXT("Rotate to right"));
				}

				::TrackPopupMenu(_hPopupMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
			}
			return TRUE;
		}

		case WM_GETSPLITTER_X:
		{
			switch (_splitterMode)
			{
				case SplitterMode::LEFT_FIX:
				{
					return MAKELONG(_pWin0->getWidth(), static_cast<std::uint8_t>(SplitterMode::LEFT_FIX));
				}

				case SplitterMode::RIGHT_FIX:
				{
					int x = getWidth()-_pWin1->getWidth();
					if (x < 0)
						x = 0;
					return MAKELONG(x, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
				}
				default:
					break;
			}
			return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
		}

		case WM_GETSPLITTER_Y:
		{
			switch (_splitterMode)
			{
				case SplitterMode::LEFT_FIX:
				{
					return MAKELONG(_pWin0->getHeight(), static_cast<std::uint8_t>(SplitterMode::LEFT_FIX));
				}
				case SplitterMode::RIGHT_FIX:
				{
					int y = getHeight()-_pWin1->getHeight();
					if (y < 0)
						y = 0;
					return MAKELONG(y, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
				}
				default:
					break;
			}
			return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
		}

		case WM_LBUTTONDBLCLK:
		{
			POINT pt;
			::GetCursorPos(&pt);
			::ScreenToClient(_splitter.getHSelf(), &pt);

			HWND parent = ::GetParent(getHSelf());

			Window* targetWindow = (this->isVertical())
				? (pt.x < 0 ? _pWin0 : _pWin1)
				: (pt.y < 0 ? _pWin0 : _pWin1);

			::SendMessage(parent, NPPM_INTERNAL_SWITCHVIEWFROMHWND, 0, (LPARAM)targetWindow->getHSelf());
			::SendMessage(parent, WM_COMMAND, IDM_FILE_NEW, 0);
			return TRUE;
		}

		default:
			return ::DefWindowProc(_hSelf, message, wParam, lParam);
	}
}
Beispiel #26
0
void ControlRobotgo2Position(float x, float y, float speed,int flag) {
  //float speedL = speed;
  //float speedR = speed;
  typeCoordinate start = GetCoordinate();
  if(GoalInFront(x,y,0) == true)
	return;
  SetLeftWheelGivenSpeed(1);
  SetRightWheelGivenSpeed(1);
  vTaskDelay(500);
  
  if(GoalInFront(x,y,0) == true)
	return;
  SetLeftWheelGivenSpeed(3);
  SetRightWheelGivenSpeed(3);
  vTaskDelay(500);
  
  if(GoalInFront(x,y,0) == true)
	return;
  rotateToSafe(x,y);
  SetLeftWheelGivenSpeed(5);
  SetRightWheelGivenSpeed(5);
  vTaskDelay(500);
  
  if(GoalInFront(x,y,0) == true)
	return;
  rotateToSafe(x,y);
  SetLeftWheelGivenSpeed(10);
  SetRightWheelGivenSpeed(10);
  vTaskDelay(300);
  
  if(GoalInFront(x,y,0) == true)
	return;
  rotateToSafe(x,y);
  SetLeftWheelGivenSpeed(15);
  SetRightWheelGivenSpeed(15); 
  vTaskDelay(200);
  
  if(GoalInFront(x,y,0) == true)
	return;
  rotateToSafe(x,y);
  SetLeftWheelGivenSpeed(20);
  SetRightWheelGivenSpeed(20);
  rotateToSafe(x,y);
  if(GoalInFront(x,y,0) == true)
	return;
  u8 i = 0;
  while (1) {	
	for(i = 0;i < CHECK; i++){
	  rotateToSafe(x,y);  
	  SetLeftWheelGivenSpeed(30);
	  SetRightWheelGivenSpeed(30);
	  vTaskDelay(300);
	  if(GoalInFront(x,y,0) == true)
		return;
	}
    rotateTo(x,y,FASTSPEED,ROTATE_LARGER_15);	
	//go to target point
	SetLeftWheelGivenSpeed(30);
	SetRightWheelGivenSpeed(30);
	vTaskDelay(300);
	if(GoalInFront(x,y,0) == true)
	  return;
 }  /* end of while */
} /*end of ControlRobotgo2Position*/
Beispiel #27
0
// Rotate the object by a specific angle (radians)
void Rect::rotate(float _angle)
{
	rotateTo(angle + _angle);
}
Beispiel #28
0
void ShipSprite::updateByModel() {
    rotateTo(model->rotateType);
    moveToMatrixPos(model->pos);
}
LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_CREATE :
			_splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle);
			return TRUE;

		case WM_COMMAND :
		{
			switch (LOWORD(wParam))
			{
				case ROTATION_A_GAUCHE:
					rotateTo(LEFT);
					return TRUE;
				case ROTATION_A_DROITE:
					rotateTo(RIGHT);
					return TRUE;
			}
			return TRUE;
		}
		case WM_RESIZE_CONTAINER :
		{
			RECT rc0, rc1;
			getClientRect(rc0);

			rc1.top = rc0.top += _y;
			rc1.bottom = rc0.bottom;
			rc1.left = rc0.left += _x;
			rc1.right = rc0.right;

			if (_dwSplitterStyle & SV_VERTICAL)
			{
				if (wParam != 0)
				{
					rc0.right = int(wParam);

					rc1.left = int(wParam) + _x + _splitter.getPhisicalSize();
					rc1.right = rc1.right - rc1.left + _x;
				}
			}
			else //SV_HORIZONTAL
			{
				if (lParam != 0)
				{
					rc0.bottom = int(lParam);

					rc1.top   = int(lParam) + _y + _splitter.getPhisicalSize();
					rc1.bottom = rc1.bottom - rc1.top + _y;
				}
			}
			_pWin0->reSizeTo(rc0);
			_pWin1->reSizeTo(rc1);

			::InvalidateRect(_splitter.getHSelf(), NULL, TRUE);
			return TRUE;
		}

		case WM_DOPOPUPMENU :
		{
			if ((_splitterMode != LEFT_FIX) && (_splitterMode != RIGHT_FIX) )
			{
				POINT p;
				::GetCursorPos(&p);

				if (!_hPopupMenu)
				{
					POINT p;
					::GetCursorPos(&p);
					_hPopupMenu = ::CreatePopupMenu();
					::InsertMenu(_hPopupMenu, 1, MF_BYPOSITION, ROTATION_A_GAUCHE, TEXT("Rotate to left"));
					::InsertMenu(_hPopupMenu, 0, MF_BYPOSITION, ROTATION_A_DROITE, TEXT("Rotate to right"));
				}

				::TrackPopupMenu(_hPopupMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
			}
			return TRUE;
		}

		case WM_GETSPLITTER_X :
        {
            if (_splitterMode == LEFT_FIX)
                return MAKELONG(_pWin0->getWidth(), LEFT_FIX);
            else if (_splitterMode == RIGHT_FIX)
            {
                int x = getWidth()-_pWin1->getWidth();
                if (x < 0)
                    x = 0;
                return MAKELONG(x, RIGHT_FIX);
            }
            else
			    return MAKELONG(0, DYNAMIC);

        }

		case WM_GETSPLITTER_Y :
        {
            if (_splitterMode == LEFT_FIX)
                return MAKELONG(_pWin0->getHeight(), LEFT_FIX);
            else if (_splitterMode == RIGHT_FIX)
            {
                int y = getHeight()-_pWin1->getHeight();
                if (y < 0)
                    y = 0;
                return MAKELONG(y, RIGHT_FIX);
            }
            else
			    return MAKELONG(0, DYNAMIC);
        }

		default :
			return ::DefWindowProc(_hSelf, message, wParam, lParam);
	}
}
Beispiel #30
0
 inline void reverse(int left, int right) {
     rotateTo(left - 1, 0);
     rotateTo(right + 1, root);
     swap(child[dealTree][0], child[dealTree][1]);
     reverse_lazy[dealTree] ^= 1;
 }