void Positioner::increment(long _change) { moveRelative(_change); }
void Positioner::moveAbsolute(long _position) { long change = _position - getPosition(); moveRelative(change); }
void Camera::moveRelative(float x, float y, float z) { moveRelative(vec3(x, y, z)); }
bool OrionMenuView::onEvent(M4EventType eventType, int param, int x, int y, bool &captureEvents) { static Common::Point movingPos(0, 0); static bool movingFlag = false; bool handledFlag = false; int localX, localY; MenuObjectsIterator i; if (!_screenFlags.visible) return false; if (!movingFlag) captureEvents = false; // If the escape key is pressed, then pass onto the Escape handler if (eventType == KEVENT_KEY) { if ((param == Common::KEYCODE_ESCAPE) && (_escapeHandler != NULL)) { // Execute the Escape handler function _currentItem = NULL; captureEvents = false; _escapeHandler(this); destroyView(); return true; } if (((param == Common::KEYCODE_RETURN) || (param == Common::KEYCODE_KP_ENTER)) && (_returnHandler != NULL)) { // Execute the Return handler function _currentItem = NULL; captureEvents = false; _returnHandler(this); return true; } MenuTextField *textItem = (MenuTextField *) getItem(SLTAG_TEXTFIELD); if (textItem && textItem->onEvent(KEVENT_KEY, param, x, y, _currentItem)) return true; } // Convert the screen position to a relative position within the menu surface localX = x - _coords.left; localY = y - _coords.top; // If there is an active object handling events, pass it on until it releases control if (_currentItem) { handledFlag = _currentItem->onEvent(eventType, param, localX, localY, _currentItem); if (_closeFlag) { // Dialog has been flagged to be closed captureEvents = false; destroyView(); return true; } if (_currentItem) { captureEvents = (Common::find(_menuObjects.begin(), _menuObjects.end(), _currentItem) != _menuObjects.end()); if (!captureEvents) // The menu object is no longer active, so reset current item _currentItem = NULL; } else { captureEvents = false; } if (handledFlag) return true; } if (eventType == KEVENT_KEY) { // Handle keypresses by looping through the item list to see if any of them want it for (i = _menuObjects.begin(); (i != _menuObjects.end()) && !handledFlag; ++i) { MenuObject *menuObj = *i; MenuObject *dummyItem; handledFlag = menuObj->onEvent(eventType, param, localX, localY, dummyItem); } return handledFlag; } else { // Handle mouse events by scanning the item list to see if the cursor is within any for (i = _menuObjects.begin(); (i != _menuObjects.end()) && !handledFlag; ++i) { MenuObject *menuObj = *i; if (menuObj->isInside(localX, localY)) { // Found an item, so pass it the event menuObj->onEvent(eventType, param, localX, localY, _currentItem); if (_closeFlag) { // Dialog has been flagged to be closed captureEvents = false; destroyView(); return true; } if (_currentItem) { captureEvents = (Common::find(_menuObjects.begin(), _menuObjects.end(), _currentItem) != _menuObjects.end()); if (!captureEvents) // The menu object is no longer active, so reset current item _currentItem = NULL; } else { captureEvents = false; } return true; } } } // None of the items have handled the event, so fall back on menu-wide event handling switch (eventType) { case MEVENT_LEFT_CLICK: case MEVENT_DOUBLECLICK: if (!_screenFlags.immovable) { // Move the entire dialog captureEvents = true; movingFlag = true; movingPos.x = x; movingPos.y = y; } break; case MEVENT_LEFT_DRAG: case MEVENT_DOUBLECLICK_DRAG: if (movingFlag) { moveRelative(x - movingPos.x, y - movingPos.y); movingPos.x = x; movingPos.y = y; } break; case MEVENT_LEFT_RELEASE: case MEVENT_DOUBLECLICK_RELEASE: captureEvents = false; movingFlag = false; break; default: break; } return true; }
int NodeClass::startTestProgram(int ID, double x_rel, double y_rel) { switch(ID) { case 1: configRecorder(moveRelative(0, 1, true) * 4); std::cout << "The coming program will last " << moveRelative(0, 1, true) * 4.0f << " seconds" << std::endl; //Test-drive a 1 m - square: forward, right .. moveRelative(0.7, 0); moveRelative(0, -0.7); moveRelative(-0.7, 0); moveRelative(0, 0.7); break; case 2: configRecorder(rotate(M_PI * 2, true) * 2); std::cout << "The coming program will last " << rotate(PI * 2.0f, true) * 2.0f << " seconds and is recorded" << std::endl; rotate(2.0f * PI); rotate(-2.0f * PI); break; case 3: std::cout << "The coming program will last " << rotate(PI / 2, true) << " seconds and is recorded" << std::endl; rotate(PI / 2); break; case 4: //square with forward and backward driving forward .. right ... moveRelative(0.7, 0); rotate(- M_PI / 2); moveRelative(0.7, 0); rotate(- M_PI / 2); moveRelative(0.7, 0); rotate(- M_PI / 2); moveRelative(0.7, 0); rotate(- M_PI / 2); break; case 99: std::cout << "The coming movement will last " << moveRelative(x_rel, y_rel, true) << " seconds" << std::endl; moveRelative(x_rel, y_rel); break; case 100: configRecorder(moveRelative(x_rel, y_rel, true)); std::cout << "The coming movement will last " << moveRelative(x_rel, y_rel, true) << " seconds and is recorded" << std::endl; moveRelative(x_rel, y_rel); } return 0; }
void Tank::Think(float time) { operationTimer-= time; float TANK_SPEED = mvelocity; Ogre::Quaternion rotYaw; if (Tankstate == 1) { if (operationTimer<=0) { operationTimer = operationCD; operation1 = rand()%4+1; operation2 = rand()%2+1; } switch (operation1) { case 1: rotYaw = Ogre::Quaternion(Ogre::Degree(manglularV), Ogre::Vector3::UNIT_Y); rotateTank(rotYaw); break; case 2: rotYaw = Ogre::Quaternion(Ogre::Degree(manglularV), Ogre::Vector3::UNIT_Y); rotateTank(rotYaw); break; case 3: if (mbarrelOrientation.y<0.4) { rotYaw = Ogre::Quaternion(Ogre::Degree(mBarrelAnglularV), Ogre::Vector3::UNIT_Y); rotateBarrel(rotYaw); } break; case 4: if (mbarrelOrientation.y>-0.4) { rotYaw = Ogre::Quaternion(Ogre::Degree(-mBarrelAnglularV), Ogre::Vector3::UNIT_Y); rotateBarrel(rotYaw); } break; default: break; } switch(operation2) { case 1: moveRelative(Ogre::Vector3(0, 0, -time * TANK_SPEED)); if (mTankManager->CheckCollision()) moveRelative(Ogre::Vector3(0, 0, time * TANK_SPEED)); break; case 2: moveRelative(Ogre::Vector3(0, 0, time * TANK_SPEED)); if (mTankManager->CheckCollision()) moveRelative(Ogre::Vector3(0, 0, -time * TANK_SPEED)); break; default: break; } buttonTimer -= time; if (buttonTimer <= 0) { buttonTimer = getFireCD(); mProjectileManager->Spawn(this); } } }