bool GHOST_NDOFManagerUnix::processEvents() { bool anyProcessed = false; if (m_available) { spnav_event e; #ifdef USE_FINISH_GLITCH_WORKAROUND bool motion_test = false; #endif while (spnav_poll_event(&e)) { switch (e.type) { case SPNAV_EVENT_MOTION: { /* convert to blender view coords */ GHOST_TUns64 now = m_system.getMilliSeconds(); const short t[3] = {(short)e.motion.x, (short)e.motion.y, (short)-e.motion.z}; const short r[3] = {(short)-e.motion.rx, (short)-e.motion.ry, (short)e.motion.rz}; updateTranslation(t, now); updateRotation(r, now); #ifdef USE_FINISH_GLITCH_WORKAROUND motion_test = true; #endif break; } case SPNAV_EVENT_BUTTON: GHOST_TUns64 now = m_system.getMilliSeconds(); updateButton(e.button.bnum, e.button.press, now); break; } anyProcessed = true; } #ifdef USE_FINISH_GLITCH_WORKAROUND if (motion_test_prev == true && motion_test == false) { GHOST_TUns64 now = m_system.getMilliSeconds(); const short v[3] = {0, 0, 0}; updateTranslation(v, now); updateRotation(v, now); anyProcessed = true; } motion_test_prev = motion_test; #endif } return anyProcessed; }
void HexagonGame::update(float mFrameTime) { if(!hasDied) { manager.update(mFrameTime); updateLevelEvents(mFrameTime); if(timeStop <= 0) { currentTime += mFrameTime / 60.0f; incrementTime += mFrameTime / 60.0f; } else timeStop -= 1 * mFrameTime; updateIncrement(); updateLevel(mFrameTime); updateRadius(mFrameTime); if(!getBlackAndWhite()) styleData.update(mFrameTime); } else setRotationSpeed(getRotationSpeed() / 1.001f); updateKeys(); if(!getNoRotation()) updateRotation(mFrameTime); if(mustRestart) newGame(levelData.getId(), false); }
void NAMESPACE::Trackball::update(uint x, uint y) { if (m_Locked) return; if (m_Status & TRANSLATING) updateTranslation(x, y); if (m_Status & ROTATING) updateRotation(x, y); if (m_Status & ZOOMING) updateZoom(x, y); }
void Broadcaster::gyroCallback(const geometry_msgs::Vector3::ConstPtr& msg) { dt = ros::Time::now().toSec() - prevt; gyro.setX(msg->x); gyro.setY(msg->y); gyro.setZ(msg->z); angularVel.setX(gyro.x()); angularVel.setY(gyro.y()); angularVel.setZ(gyro.z()); filterCoeff = timeConst / (timeConst + dt); // Use accelerometer and magnetometer data to correct gyro drift correctOrientation(); updateRotation(); prevt = ros::Time::now().toSec(); // std::cout << "angularVel x: " << angularVel.x() << std::endl; // std::cout << "angularVel y: " << angularVel.y() << std::endl; // std::cout << "angularVel z: " << angularVel.z() << std::endl; // std::cout << "----" << std::endl; }
void CameraNodeObject::setZoom(qreal z) { m_zoom = z; m_node->resetOrientation(); m_camera->setPosition(initialPosition * (1 / m_zoom)); updateRotation(); }
void ofxGameCamera::loadCameraPosition() { ofxXmlSettings loadPosition; if(loadPosition.loadFile(cameraPositionFile)){ loadPosition.pushTag("camera"); loadPosition.pushTag("position"); // tig: defaulting with floats so as to get floats back. setPosition(ofVec3f(loadPosition.getValue("X", 0.), loadPosition.getValue("Y", 0.), loadPosition.getValue("Z", 0.))); targetNode.setPosition(getPosition()); loadPosition.popTag(); loadPosition.pushTag("rotation"); targetXRot = rotationX = loadPosition.getValue("X", 0.); targetYRot = rotationY = loadPosition.getValue("Y", 0.); targetZRot = rotationZ = loadPosition.getValue("Z", 0.); float fov = loadPosition.getValue("FOV", -1); if(fov != -1){ setFov(fov); } loadPosition.popTag(); loadPosition.popTag(); //pop camera; updateRotation(); } else{ ofLog(OF_LOG_ERROR, "ofxGameCamera: couldn't load position!"); } }
void Animation::update(float dt) { if (m_pastStartTime < m_startAfterSeconds && isRunning()) { m_pastStartTime += dt; return; } if (!isRunning() || m_parent == nullptr) { return; } bool updatedSome{ false }; if (m_isRotationRunning) { updateRotation(dt); updatedSome = true; } if (m_isMovementRunning) { updateMovement(dt); updatedSome = true; } // When there was an update and the animation is not running anymore, the // animation was completed if (updatedSome && !isRunning()) { if (m_onAnimationCompleted) { m_onAnimationCompleted(); } } }
Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<const Resource::BulletShape> shape, btCollisionWorld* world) : mCanWaterWalk(false), mWalkingOnWater(false) , mCollisionObject(0), mForce(0.f, 0.f, 0.f), mOnGround(false) , mInternalCollisionMode(true) , mExternalCollisionMode(true) , mCollisionWorld(world) { mPtr = ptr; mHalfExtents = shape->mCollisionBoxHalfExtents; mMeshTranslation = shape->mCollisionBoxTranslate; // Use capsule shape only if base is square (nonuniform scaling apparently doesn't work on it) if (std::abs(mHalfExtents.x()-mHalfExtents.y())<mHalfExtents.x()*0.05 && mHalfExtents.z() >= mHalfExtents.x()) { // Could also be btCapsuleShapeZ, but the movement solver seems to have issues with it (jumping on slopes doesn't work) mShape.reset(new btCylinderShapeZ(toBullet(mHalfExtents))); } else mShape.reset(new btBoxShape(toBullet(mHalfExtents))); mCollisionObject.reset(new btCollisionObject); mCollisionObject->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT); mCollisionObject->setActivationState(DISABLE_DEACTIVATION); mCollisionObject->setCollisionShape(mShape.get()); mCollisionObject->setUserPointer(static_cast<PtrHolder*>(this)); updateRotation(); updateScale(); updatePosition(); updateCollisionMask(); }
// Pitch +ve up, yaw +ve right, Roll +ve right void Camera::setRotation( float pitch, float yaw, float roll ) { m_cameraUpVector = QVector4D(0.0, 1.0, 0.0, 0.0 ); m_cameraForwardVector = QVector4D(0.0, 0.0, -1.0, 0.0 ); m_cameraRightVector = QVector4D(1.0, 0.0, 0.0, 0.0 ); updateRotation( pitch, yaw, roll ); }
void OgreLightNode::setPosition(const float &x, const float &y, const float &z) { m_position.x = x; m_position.y = y; m_position.z = z; m_light->setPosition(m_position); updateRotation(); }
void Camera::update(const GameTime& gameTime) { Vector2 mouseMovement = Mouse::getMovement(); yaw(mouseMovement.x * mouseSpeed); pitch(mouseMovement.y * mouseSpeed); Matrix m = Matrix::createFromAxisAngle(Vector3::up, rotationX); Vector3 forward = Vector3::transform(Vector3::forward, m); Vector3 right = Vector3::transform(Vector3::right, m); Vector3 direction; if (Keyboard::isKeyDown(buttonMoveForward)) direction += forward; if (Keyboard::isKeyDown(buttonMoveBackward)) direction -= forward; if (Keyboard::isKeyDown(buttonMoveRight)) direction += right; if (Keyboard::isKeyDown(buttonMoveLeft)) direction -= right; if (Keyboard::isKeyDown(buttonMoveUp)) direction += Vector3::up; if (Keyboard::isKeyDown(buttonMoveDown)) direction -= Vector3::up; float speed = rotationSpeed * gameTime.elapsed; //if (Keyboard::isKeyDown(buttonLookDown)) // pitch(speed); //if (Keyboard::isKeyDown(buttonLookUp)) // pitch(-speed); //if (Keyboard::isKeyDown(buttonLookRight)) // yaw(speed); //if (Keyboard::isKeyDown(buttonLookLeft)) // yaw(-speed); float modifier = 1.0f; if (Keyboard::isKeyDown(buttonMoveFast)) modifier *= moveFast; if (Keyboard::isKeyDown(buttonMoveSlow)) modifier *= moveSlow; position += Vector3::normalize(direction) * movementSpeed * modifier * gameTime.elapsed; updateRotation(); }
void OgreLightNode::setPosition(QVector3D p) { m_position.x = p.x(); m_position.y = p.y(); m_position.z = p.z(); //m_node->resetOrientation(); m_light->setPosition(m_position);// * (1 / m_zoom)); updateRotation(); }
Camera::Camera(float fov, int width, int height, float near, float far) : WorldObject(nullptr) { projection = glm::perspective(fov, (float)width / (float)height, near, far); translation_speed = 10.f; // units/s rotation_speed = 90.f; // deg/s mouse_sensitivity = 45.f; updateRotation(0,0); }
/** * Met le viseur du joueur a jour * * @param viseurPosition Nouvelle position du viseur */ void Player::setViseurPosition(irr::core::vector3df viseurPosition) { boost::mutex::scoped_lock l(mutexPlayer); viseurRay.end = viseurPosition; // On a modifié la position du viseur, il faut ré-orienter le joueur l.unlock(); updateRotation(); }
YaRotation::YaRotation(QObject* parent) : QObject(parent) , rotationTimer_(0) , rotation_(0) { rotationTimer_ = new QTimer(this); rotationTimer_->setSingleShot(false); rotationTimer_->setInterval(100); connect(rotationTimer_, SIGNAL(timeout()), SLOT(updateRotation())); }
void Camera::look(const Vector3& direction) { Vector3 d = Vector3::normalize(direction); Vector3 vx = Vector3::normalize(Vector3(d.x, 0, d.z)); rotationX = std::acos(MathHelper::clamp(Vector3::dot(Vector3::forward, vx), -1.0f, 1.0f)); rotationY = std::acos(MathHelper::clamp(Vector3::dot(vx, d), -1.0f, 1.0f)); rotationX *= (direction.x < 0) ? -1 : 1; rotationY *= (direction.y < 0) ? 1 : -1; updateRotation(); }
void CTrackerMainWindow::applySettings() { setCursor(Qt::WaitCursor); setEnabled(false); ui.lStatus->setText("Initializing..."); setupUDP(); setupFOB(); updateRotation(); ui.btnApply->setEnabled(true); setEnabled(true); unsetCursor(); }
//-------------------------------------------------------------- void MultiTouchActions::update(){ if (objTouch.size() != 0){ updateTime(); updateTranslate(); if (objTouch.size() > 1){ updateRotation(); updateScale(); }else{ deltaDeg = 0; } }else{ reset(); } }
void Player::updateSelf( const double & delta ) { mAliveTimer += delta; mKillTimer += delta; mTorchTimer += delta; mUsageText = ""; if( mTextTime > 0.0f && !mTextMessage.isEmpty() ) { mTextZoom += delta*10; mTextFade -= delta*50; mTextTime -= delta; } else { mTextFade = 0.0f; } if( mGodMode ) { setState( ALIVE ); setLife( 100 ); } switch( state() ) { case SPAWNING: setState( ALIVE ); break; case ALIVE: updateRotation( delta ); updatePosition( delta ); updateTarget( delta ); updateTorch( delta ); if( mCurrentWeapon ) { mCurrentWeapon->setPosition( QVector3D(-0.5f,-0.5f-0.1*QVector3D::dotProduct(QVector3D(0,1,0),direction()), 0.5f ) ); } break; case DYING: setState( DEAD ); drawMessage( "GAME OVER!" ); break; case DEAD: break; } }
/** Rotates a specific relative angle and updates current rotation * * @TODO fix code so that it constantly updates rotation. Currently it only * updates the rotation once it has rotated through the entire angle. This * could be problematic if the system is interrupted, because it won't * update the current rotation * @TODO fix glitchiness of motor encoders * @TODO make the code smarter? maybe we can set some vars or something to make * the code structure a bit less complex. * */ void Helm::rotate( float theta ) { // reset encoders to get a fresh relative reading resetEncoders(); // rotation is clockwise if (theta > 0) { leftMotor .setSpeed(-MOTOR_SPEED); rightMotor.setSpeed( MOTOR_SPEED); usleep(MOTOR_PAUSE); float distance = degToArcLength( theta ); while ( (leftMotor.getSpeed() != 0) || (rightMotor.getSpeed() != 0) ) { if ( ( convertToCm( MAX_VALUE - leftEncoder.getPosition() ) >= distance ) && (leftMotor.getSpeed() != 0) ) leftMotor .setSpeed(0); if ( ( convertToCm( rightEncoder.getPosition() ) >= distance ) && (rightMotor.getSpeed() != 0) ) rightMotor.setSpeed(0); } } // rotation is counterclockwise if (theta < 0) { leftMotor .setSpeed( MOTOR_SPEED); rightMotor.setSpeed(-MOTOR_SPEED); usleep(MOTOR_PAUSE); float distance = degToArcLength( theta ); while ( (leftMotor.getSpeed() != 0) || (rightMotor.getSpeed() != 0) ) { if ( ( convertToCm( leftEncoder.getPosition() ) >= abs(distance) ) && (leftMotor.getSpeed() != 0) ) leftMotor .setSpeed(0); if ( ( convertToCm( MAX_VALUE - rightEncoder.getPosition() ) >= abs(distance) ) && (rightMotor.getSpeed() != 0) ) rightMotor.setSpeed(0); } } // update the current rotation updateRotation( theta ); // glitch compensator usleep(MOTOR_PAUSE); }
void Camera::handleMouse(float delta) { auto takingCursorInput = InputHandler::getMouseButtonstate(GLFW_MOUSE_BUTTON_RIGHT) != GLFW_RELEASE; if (takingCursorInput != oldTakingCursorInput) { oldTakingCursorInput = takingCursorInput; glfwSetInputMode(InputHandler::active_window, GLFW_CURSOR, takingCursorInput ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL); } if (takingCursorInput) { auto coord = InputHandler::getMouseDelta(); coord.x *= mouse_sensitivity * delta; coord.y *= mouse_sensitivity * delta; updateRotation((float) coord.x , (float)coord.y); } }
void Bird::update(){ if (game.state == Game::reset) reset(); else if (game.state == Game::waiting) return; if (jump_timer > 0) jump_timer--; if (ypos < 185) move(0, -v_speed); if (game.state == Game::playing){ handleInput(); if (ypos >= 185) die(); } v_speed -= gravity; clampSpeed(); updateRotation(); }
void HexagonGame::update(float mFT) { if(!assets.pIsLocal() && Config::isEligibleForScore()) { assets.playedSeconds += mFT / 60.f; if(assets.playedSeconds >= 60.f) { assets.playedSeconds = 0; Online::trySendMinutePlayed(); } } updateFlash(mFT); effectTimelineManager.update(mFT); if(!status.hasDied) { manager.update(mFT); updateEvents(mFT); updateTimeStop(mFT); updateIncrement(); if(mustChangeSides && !manager.hasEntity(HGGroup::Wall)) sideChange(getRnd(levelStatus.sidesMin, levelStatus.sidesMax + 1)); updateLevel(mFT); if(Config::getBeatPulse()) updateBeatPulse(mFT); if(Config::getPulse()) updatePulse(mFT); if(!Config::getBlackAndWhite()) styleData.update(mFT, pow(difficultyMult, 0.8f)); } else levelStatus.rotationSpeed *= 0.99f; if(Config::get3D()) update3D(mFT); if(!Config::getNoRotation()) updateRotation(mFT); overlayCamera.update(mFT); backgroundCamera.update(mFT); for(auto& c : depthCameras) c.update(mFT); if(status.mustRestart) { changeLevel(restartId, restartFirstTime); if(!assets.pIsLocal() && Config::isEligibleForScore()) { Online::trySendRestart(); } } if(!status.scoreInvalid && Config::getOfficial() && fpsWatcher.isLimitReached()) invalidateScore(); fpsWatcher.update(); }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ if(bMouseInputEnabled){ if(!bDistanceSet){ setDistance(getImagePlaneDistance(viewport), true); } rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height); if (bMouseInputEnabled) { updateMouse(); } if (bDoRotate) { updateRotation(); }else if (bDoTranslate) { updateTranslation(); } } }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ viewport = getViewport(this->viewport); if(!bDistanceSet && bAutoDistance){ setDistance(getImagePlaneDistance(viewport), true); } if(bMouseInputEnabled){ if(events->getMousePressed()) prevMouse = glm::vec2(events->getMouseX(),events->getMouseY()); if (bDoRotate) { updateRotation(); }else if (bDoTranslate || bDoScrollZoom || bIsBeingScrolled) { updateTranslation(); bDoScrollZoom = false; } } }
AzimuthZenithController::AzimuthZenithController(ViewModel& view, QObject *parent) : ViewpointController(view, parent), m_azimuth(s_defaultAzimuth), m_zenith(s_defaultZenith), m_targetAzimuth(s_defaultAzimuth), m_targetZenith(s_defaultZenith), m_azimuthAnimation(this, "azimuth"), m_zenithAnimation(this, "zenith"), m_zoomAnimation(this, "zoom"), m_dragStart(), m_isDragging(false) { m_azimuthAnimation.setDuration(200); m_zenithAnimation.setDuration(200); m_zoomAnimation.setDuration(200); m_targetZoom = zoom(); updateRotation(); }
/** * Updates the body's angular velocity and rotation from the given angular momentum vector. * * @param [in,out] body The body to update. * @param [in] angularMomentum angular momentum vector. */ void updateAngularVelocity(DYN_Body *body, const double *angularMomentum) { double tmp[3]; double momentOfInertia; double rotationAxis[3]; memcpy(tmp, angularMomentum, sizeof(tmp)); ALG_solveSystem3(rotationAxis, body->orientation, angularMomentum); ALG_normalizeVector(rotationAxis); ALG_transform(tmp, rotationAxis, body->staticAttributes->intertiaTensor); momentOfInertia = ALG_dotProduct(rotationAxis, tmp); assert(fabs(momentOfInertia) > 1e-9); memcpy(body->angularVelocity, angularMomentum, sizeof(*angularMomentum) * 3); ALG_scale(body->angularVelocity, 1.0/momentOfInertia); body->momentOfInertia = momentOfInertia; updateRotation(body); }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ if(!bDistanceSet && bAutoDistance){ setDistance(getImagePlaneDistance(viewport), true); } if(bMouseInputEnabled){ rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height); if(ofGetMousePressed()) prevMouse = ofVec2f(ofGetMouseX(),ofGetMouseY()); if (bDoRotate) { updateRotation(); }else if (bDoTranslate || bDoScrollZoom) { updateTranslation(); bDoScrollZoom = false; } } }
void DYN_addBody( DYN_Context *context, const DYN_Body *body, const DYN_BodyStaticAttributes *attribs ) { if (context->bodyCount == context->bodiesAllocated) { if (!context->bodiesAllocated) { context->bodiesAllocated = 20; } else { context->bodiesAllocated <<= 1; } context->bodies = realloc( context->bodies, sizeof(DYN_Body) * context->bodiesAllocated ); context->staticAttributes = realloc( context->staticAttributes, sizeof(DYN_BodyStaticAttributes) * context->bodiesAllocated ); // Update static attribute pointers { int i; for (i = 0; i < context->bodyCount; i++) { context->bodies[i].staticAttributes = &context->staticAttributes[i]; } } } context->bodies[context->bodyCount] = *body; context->staticAttributes[context->bodyCount] = *attribs; { DYN_Body *addedbody = &context->bodies[context->bodyCount]; addedbody->staticAttributes = &context->staticAttributes[context->bodyCount]; addedbody->colliding = 0; updateMomentOfInertia(addedbody); updateRotation(addedbody); } context->bodyCount++; }
//---------------------------------------- void ofEasyCam::update(ofEventArgs & args){ if(!bDistanceSet && bAutoDistance){ setDistance(getImagePlaneDistance(viewport), true); } if(bMouseInputEnabled){ rotationFactor = sensitivityRot * 180 / min(viewport.width, viewport.height); if (bMouseInputEnabled) { updateMouse(); } if (bDoRotate) { // <>< # Added extra boolean bRotation. Now you can disable the camera rotation/oll with disableRotation() if(bRotation) updateRotation(); // updateRotation(); <-- PREVIOUS LINE }else if (bDoTranslate) { updateTranslation(); } } }