void gotoCoords(float newX, float newZ, float newO) { /* This is a work-in-progress!!!! This will go to the specified coordinates and rotate to the specified angle, assuming the PID is working correctly. This is a very systematic function, only use when absolutely necessary! */ while (readValues('o') != 90) { // very low tolerance rotateWithOrientation(1, 25); // very slow, and low rotation to insure accuracy } if (newX < x) { while (readValues('x') > newX) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newX > x) { while (readValues('x') < newX) moveWithDirection(1, -25); } while (readValues('o') != 0) { rotateWithOrientation(1, 25); } if (newZ < z) { while (readValues('z') > newZ) moveWithDirection(1, -25); // Low and slow is the way to go! } else if (newZ > z) { while (readValues('z') < newZ) moveWithDirection(1, -25); } while (readValues('o') != newO) rotateWithOrientation(1, 25); setCoords(newX, newZ, newO); }
void SimpleMoveComponent::moveTo(CCPoint to) { CCPoint pos=((CCNode*)m_pOwner)->getPosition(); float dx=to.x-pos.x; float dy=to.y-pos.y; CCLOG("moveTo:%f,%f, diff:%f,%f",to.x,to.y,dx,dy); if(dx>0 || dy>0){ float s=sqrtf(dx*dx+dy*dy); float directionX=dx/s; float directionY=dy/s; m_directionFlagX=dx>0?1:dx<0?-1:0; m_directionFlagY=dy>0?1:dy<0?-1:0; setTo(to); moveWithDirection(directionX, directionY,true); } }
/** * 按指定方向偏移量,这里不考虑速度叠加. */ void SimpleMoveComponent::moveWithDirection(float directionX ,float directionY) { moveWithDirection(directionX, directionY, false); }
void SimpleMoveComponent::moveWithDirection(float direction) { moveWithDirection(direction,false); }