void Actor::setRot(const Math::Angle &pitchParam, const Math::Angle &yawParam, const Math::Angle &rollParam) { _pitch = pitchParam; setYaw(yawParam); _moveYaw = _yaw; _roll = rollParam; _turning = false; }
/* * Searches for the area with the most features visible between a given angle to the left and to the right. * @param[in] angle The maximum angle it will turn to the left and the right (in rad). * @param[in] speed Scale factor of the speed. * @param[in] deleteData If true, all old data of the odometer will be deleted beforehand. * @return The yaw value where the most features have been found. * */ double searchMaxFeatures(double angle, double speed = 1.0, bool deleteData = true) { double yaw, pitch, roll, yawBegin; odometer_.getBasis().getEulerYPR(yaw, pitch, roll); yawBegin = yaw; turnByAngle(angle, speed, deleteData); // Memorize at which node it started int nodeIdxBegin = odometer_.nodes_.size() - 1; turnByAngle(-2 * angle, speed, false); int nodeIdxEnd = odometer_.nodes_.size() - 1; // Turn back so the robot has the same orientation as in the beginning setYaw(yawBegin, speed, false); // Now search for the node with the most features and store its yaw unsigned int maxFeatures = 0, maxIndex; for (unsigned int i = nodeIdxBegin; i <= nodeIdxEnd; ++i) { if (odometer_.nodes_[i].stereoPoints_l_.size() > maxFeatures) { maxFeatures = odometer_.nodes_[i].stereoPoints_l_.size(); maxIndex = i; } } // Get yaw odometer_.transforms_[maxIndex].getBasis().getEulerYPR(yaw, pitch, roll); return yaw; }
void GameObject::setDirection(const Ogre::Vector3 direction) { Ogre::Radian r = initialForward.angleBetween(direction); Ogre::Vector3 initialRight = initialForward.crossProduct(Ogre::Vector3::UNIT_Y); if (initialRight.dotProduct(direction) > 0.f) r *= -1; setYaw(r); }
void Navigator_Dcm::updateFast(float dt) { if (_board->getMode() != AP_Board::MODE_LIVE) return; setTimeStamp(micros()); // if running in live mode, record new time stamp // use range finder if attached and close to the ground if (_rangeFinderDown != NULL && _rangeFinderDown->distance <= 695) { setAlt(_rangeFinderDown->distance); // otherwise if you have a baro attached, use it } else if (_board->baro) { /** * The altitued is read off the barometer by implementing the following formula: * altitude (in m) = 44330*(1-(p/po)^(1/5.255)), * where, po is pressure in Pa at sea level (101325 Pa). * See http://www.sparkfun.com/tutorials/253 or type this formula * in a search engine for more information. * altInt contains the altitude in meters. * * pressure input is in pascals * temp input is in deg C *10 */ _board->baro->Read(); // Get new data from absolute pressure sensor float reference = 44330 * (1.0 - (pow(_groundPressure.get()/101325.0,0.190295))); setAlt(_baroLowPass.update((44330 * (1.0 - (pow((_board->baro->Press/101325.0),0.190295)))) - reference,dt)); //_board->debug->printf_P(PSTR("Ground Pressure %f\tAltitude = %f\tGround Temperature = %f\tPress = %ld\tTemp = %d\n"),_groundPressure.get(),getAlt(),_groundTemperature.get(),_board->baro->Press,_board->baro->Temp); // last resort, use gps altitude } else if (_board->gps && _board->gps->fix) { setAlt_intM(_board->gps->altitude * 10); // gps in cm, intM in mm } // update dcm calculations and navigator data // _dcm.update_DCM_fast(); setRoll(_dcm.roll); setPitch(_dcm.pitch); setYaw(_dcm.yaw); setRollRate(_dcm.get_gyro().x); setPitchRate(_dcm.get_gyro().y); setYawRate(_dcm.get_gyro().z); setXAccel(_dcm.get_accel().x); setYAccel(_dcm.get_accel().y); setZAccel(_dcm.get_accel().z); /* * accel/gyro debug */ /* Vector3f accel = _board->imu->get_accel(); Vector3f gyro = _board->imu->get_gyro(); Serial.printf_P(PSTR("accel: %f %f %f gyro: %f %f %f\n"), accel.x,accel.y,accel.z,gyro.x,gyro.y,gyro.z); */ }
void Camera::rotateCamera(const Ogre::Vector3 &rot, bool adjust) { if (adjust) { setYaw(getYaw() + rot.z); setPitch(getPitch() + rot.x); } else { setYaw(rot.z); setPitch(rot.x); } Ogre::Quaternion xr(Ogre::Radian(getPitch() + Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_X); if (!mVanity.enabled && !mPreviewMode) { mCamera->getParentNode()->setOrientation(xr); } else { Ogre::Quaternion zr(Ogre::Radian(getYaw()), Ogre::Vector3::UNIT_Z); mCamera->getParentNode()->setOrientation(zr * xr); } }
void Camera::rotateCamera(float pitch, float yaw, bool adjust) { if (adjust) { pitch += getPitch(); yaw += getYaw(); } setYaw(yaw); setPitch(pitch); }
/* * Callback function of destination subscriber. * Sets dest_ to received pose. * @param[in] dest Pointer to received pose. * */ void destCallback(const geometry_msgs::Pose::ConstPtr& dest) { double destX = dest->position.x; double destY = dest->position.y; double currX = odometer_.getOrigin().getX(); double currY = odometer_.getOrigin().getY(); // Look towards destination lookTowards(destX, destY); // Search for area with most features between +-30 degrees double bestYaw = searchMaxFeatures(0.5, 0.8); double distance = getDistance(destX, destY); // If distance is further than 1m, go halfway first if (distance > 1.0) { // Get distance to destination and angle to the area with most features to plan path double yaw, pitch, roll, alpha; odometer_.getBasis().getEulerYPR(yaw, pitch, roll); alpha = bestYaw - yaw; // Get stopover point tf::Vector3 vec(destX - currX, destY - currY, 0.0); vec = vec.rotate(tf::Vector3(0, 0, 1), alpha); vec *= 0.5/cos(alpha); double midX = currX + vec.getX(); double midY = currY + vec.getY(); // Turn to area with most features and move to the point in mid distance setYaw(bestYaw); goTo(midX, midY); // Run sBA to optimize Pose odometer_.runSBA(50, false); // Recursively repeat until distance < 1m destCallback(dest); } else { setYaw(bestYaw); // Move to destination goTo(destX, destY); // Try to optimize pose again and correct position odometer_.runSBA(50, false); goTo(destX, destY); } }
void RoboState::odomCallback(const nav_msgs::Odometry::ConstPtr& msg) { // set odometry setXodom(msg->pose.pose.position.x); setYodom(msg->pose.pose.position.y); // convert from quaternions to angles tf::Quaternion q(msg->pose.pose.position.x, msg->pose.pose.position.y, msg->pose.pose.orientation.z,msg->pose.pose.orientation.w); tf::Matrix3x3 m(q); double roll, pitch, tempYaw; m.getRPY(roll, pitch, tempYaw); tempYaw*=ANGLE_CONVERT; // determine whether to send positive or negative angles bool isTempYawNeg = (tempYaw < 0); // we always want a positive yaw value (for consistency) if(getY() >= 0){ if(isTempYawNeg) setYaw(360+tempYaw); else setYaw(tempYaw); } // we always want a negative yaw value (for consistency) else{ if(isTempYawNeg) setYaw(tempYaw); else setYaw(-360+tempYaw); } //spams you /* // we do not want to get spammed with messages about yaw. ROS_INFO("The yaw was %f", getYaw()); if(getY() >= 0) ROS_INFO("The yaw is supposed to be positive."); else ROS_INFO("The yaw is supposed to be negative."); } */ }
// Manage physics from this loop // Please don't alter the Ogre scene manager directly. Instead use the designated methods (setPositionX, setPositionY, setPositionZ, setRoll, setPitch, setYaw, animate) void loop(Ogre::SceneManager* smgr){ int dir = 1; int timeStep = 10; while(true){ // If the message array has any elements, the render loop is applying changes from physics loop // If so, abort this timestep if((*::message).size() == 1){ continue; } Sleep(timeStep); Ogre::SceneManager::MovableObjectIterator iterator = smgr->getMovableObjectIterator("Entity"); while(iterator.hasMoreElements()){ // If the message array has any elements, the render loop is applying changes from physics loop // If so, abort this timestep if((*::message).size() == 1){ continue; } Ogre::Entity* entity = static_cast<Ogre::Entity*>(iterator.getNext()); // <>< <>< Make the cute fishy swim <>< <>< // This only moves fish if(entity->hasAnimationState("swim")){ Ogre::SceneNode* sceneNode = entity->getParentSceneNode(); // Update position Ogre::Vector3 pos = sceneNode->getPosition(); if(pos.x > 120){ dir = -1; setYaw(entity, 180); } if(pos.x < -120){ dir = 1; setYaw(entity, 180); } setPositionX(entity, sceneNode->getPosition().x + dir); animate(entity, "swim"); } } } }
void Player::deSerialize(std::istream &is, std::string playername) { Settings args; for(;;) { if(is.eof()) throw SerializationError (("Player::deSerialize(): PlayerArgsEnd of player \"" + playername + "\" not found").c_str()); std::string line; std::getline(is, line); std::string trimmedline = trim(line); if(trimmedline == "PlayerArgsEnd") break; args.parseConfigLine(line); } //args.getS32("version"); // Version field value not used std::string name = args.get("name"); updateName(name.c_str()); setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e){ hp = 20; } try{ m_breath = args.getS32("breath"); }catch(SettingNotFoundException &e){ m_breath = 11; } inventory.deSerialize(is); if(inventory.getList("craftpreview") == NULL) { // Convert players without craftpreview inventory.addList("craftpreview", 1); bool craftresult_is_preview = true; if(args.exists("craftresult_is_preview")) craftresult_is_preview = args.getBool("craftresult_is_preview"); if(craftresult_is_preview) { // Clear craftresult inventory.getList("craftresult")->changeItem(0, ItemStack()); } } // Set m_last_* checkModified(); }
void Camera::lookAt(QVector3D lookPos) { // Reconstruct pitch/yaw from the look direction const QVector3D lookDir= (lookPos - _position).normalized(); const float theta= acosf(lookDir.y()); const float phi= atan2f(lookDir.z(), lookDir.x()); setPitch(90.0f - (theta * 180.0f / M_PI)); setYaw (90.0f - (phi * 180.0f / M_PI)); }
/** * update attitude * * @param * void * * @return * void * */ void attitudeUpdate(){ float yrpAttitude[3]; float pryRate[3]; float xyzAcc[3]; float xComponent[3]; float yComponent[3]; float zComponent[3]; float xyzMagnet[3]; #if CHECK_ATTITUDE_UPDATE_LOOP_TIME struct timeval tv_c; static struct timeval tv_l; unsigned long timeDiff=0; gettimeofday(&tv_c,NULL); timeDiff=GET_USEC_TIMEDIFF(tv_c,tv_l); _DEBUG(DEBUG_NORMAL,"attitude update duration=%ld us\n",timeDiff); UPDATE_LAST_TIME(tv_c,tv_l); #endif getYawPitchRollInfo(yrpAttitude, pryRate, xyzAcc, xComponent, yComponent, zComponent,xyzMagnet); setYaw(yrpAttitude[0]); setRoll(yrpAttitude[1]); setPitch(yrpAttitude[2]); setYawGyro(-pryRate[2]); setPitchGyro(pryRate[0]); setRollGyro(-pryRate[1]); setXAcc(xyzAcc[0]); setYAcc(xyzAcc[1]); setZAcc(xyzAcc[2]); setXGravity(zComponent[0]); setYGravity(zComponent[1]); setZGravity(zComponent[2]); setVerticalAcceleration(deadband((getXAcc() * zComponent[0] + getYAcc() * zComponent[1] + getZAcc() * zComponent[2] - 1.f) * 100.f,3.f) ); setXAcceleration(deadband((getXAcc() * xComponent[0] + getYAcc() * xComponent[1] + getZAcc() * xComponent[2]) * 100.f,3.f) ); setYAcceleration(deadband((getXAcc() * yComponent[0] + getYAcc() * yComponent[1] + getZAcc() * yComponent[2]) * 100.f,3.f) ); _DEBUG(DEBUG_ATTITUDE, "(%s-%d) ATT: Roll=%3.3f Pitch=%3.3f Yaw=%3.3f\n", __func__, __LINE__, getRoll(), getPitch(), getYaw()); _DEBUG(DEBUG_GYRO, "(%s-%d) GYRO: Roll=%3.3f Pitch=%3.3f Yaw=%3.3f\n", __func__, __LINE__, getRollGyro(), getPitchGyro(), getYawGyro()); _DEBUG(DEBUG_ACC, "(%s-%d) ACC: x=%3.3f y=%3.3f z=%3.3f\n", __func__, __LINE__, getXAcc(), getYAcc(), getZAcc()); }
void Collectible::onPrepare( float dt ) { //update yaw setYaw(getYaw() + (SPIN_SPEED * dt)); //get bullet representation btMotionState *ms = getRigidBody()->getMotionState(); btTransform transform = getRigidBody()->getWorldTransform(); //update bullet representation btQuaternion q = btQuaternion(getYaw(), getPitch(), 0.0f); transform *= btTransform(q); ms->setWorldTransform(transform); }
void Player::deSerialize(std::istream &is, std::string playername) { Settings args; if (!args.parseConfigLines(is, "PlayerArgsEnd")) { throw SerializationError("PlayerArgsEnd of player " + playername + " not found!"); } m_dirty = true; //args.getS32("version"); // Version field value not used std::string name = args.get("name"); strlcpy(m_name, name.c_str(), PLAYERNAME_SIZE); setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e) { hp = PLAYER_MAX_HP; } try{ m_breath = args.getS32("breath"); }catch(SettingNotFoundException &e) { m_breath = PLAYER_MAX_BREATH; } inventory.deSerialize(is); if(inventory.getList("craftpreview") == NULL) { // Convert players without craftpreview inventory.addList("craftpreview", 1); bool craftresult_is_preview = true; if(args.exists("craftresult_is_preview")) craftresult_is_preview = args.getBool("craftresult_is_preview"); if(craftresult_is_preview) { // Clear craftresult inventory.getList("craftresult")->changeItem(0, ItemStack()); } } }
void Player::deSerialize(std::istream &is) { Settings args; for(;;) { if(is.eof()) throw SerializationError ("Player::deSerialize(): PlayerArgsEnd not found"); std::string line; std::getline(is, line); std::string trimmedline = trim(line); if(trimmedline == "PlayerArgsEnd") break; args.parseConfigLine(line); } //args.getS32("version"); // Version field value not used std::string name = args.get("name"); updateName(name.c_str()); setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); try{ craftresult_is_preview = args.getBool("craftresult_is_preview"); }catch(SettingNotFoundException &e){ craftresult_is_preview = true; } try{ hp = args.getS32("hp"); }catch(SettingNotFoundException &e){ hp = 20; } inventory.deSerialize(is, m_gamedef); }
void LocalPlayer::applyControl(float dtime) { // Clear stuff swimming_up = false; // Random constants f32 walk_acceleration = 4.0 * BS; f32 walkspeed_max = 4.0 * BS; setPitch(control.pitch); setYaw(control.yaw); v3f move_direction = v3f(0,0,1); move_direction.rotateXZBy(getYaw()); v3f speed = v3f(0,0,0); bool free_move = g_settings->getBool("free_move"); bool fast_move = g_settings->getBool("fast_move"); bool continuous_forward = g_settings->getBool("continuous_forward"); if(free_move || is_climbing) { v3f speed = getSpeed(); speed.Y = 0; setSpeed(speed); } // Whether superspeed mode is used or not bool superspeed = false; // If free movement and fast movement, always move fast if(free_move && fast_move) superspeed = true; // Auxiliary button 1 (E) if(control.aux1) { if(free_move) { // In free movement mode, aux1 descends v3f speed = getSpeed(); if(fast_move) speed.Y = -20*BS; else speed.Y = -walkspeed_max; setSpeed(speed); } else if(is_climbing) { v3f speed = getSpeed(); speed.Y = -3*BS; setSpeed(speed); } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" if(fast_move) superspeed = true; } } if(continuous_forward) speed += move_direction; if(control.up) { if(continuous_forward) superspeed = true; else speed += move_direction; } if(control.down) { speed -= move_direction; } if(control.left) { speed += move_direction.crossProduct(v3f(0,1,0)); } if(control.right) { speed += move_direction.crossProduct(v3f(0,-1,0)); } if(control.jump) { if(free_move) { v3f speed = getSpeed(); if(fast_move) speed.Y = 20*BS; else speed.Y = walkspeed_max; setSpeed(speed); } else if(touching_ground) { v3f speed = getSpeed(); /* NOTE: The d value in move() affects jump height by raising the height at which the jump speed is kept at its starting value */ speed.Y = 6.5*BS; setSpeed(speed); } // Use the oscillating value for getting out of water // (so that the player doesn't fly on the surface) else if(in_water) { v3f speed = getSpeed(); speed.Y = 1.5*BS; setSpeed(speed); swimming_up = true; } else if(is_climbing) { v3f speed = getSpeed(); speed.Y = 3*BS; setSpeed(speed); } } // The speed of the player (Y is ignored) if(superspeed) speed = speed.normalize() * walkspeed_max * 5.0; else if(control.sneak) speed = speed.normalize() * walkspeed_max / 3.0; else speed = speed.normalize() * walkspeed_max; f32 inc = walk_acceleration * BS * dtime; // Faster acceleration if fast and free movement if(free_move && fast_move) inc = walk_acceleration * BS * dtime * 10; // Accelerate to target speed with maximum increment accelerate(speed, inc); }
//----------------------------------------------------------------------------------------------------------- ObjectPose::ObjectPose(float x, float y, float yaw) { setX(x); setY(y); setYaw(yaw); }
void PlayerSAO::setYawAndSend(const float yaw) { setYaw(yaw); m_env->getGameDef()->SendMovePlayer(m_peer_id); }
void Actor::update(uint frameTime) { // Snap actor to walkboxes if following them. This might be // necessary for example after activating/deactivating // walkboxes, etc. if (_constrain && !_walking) { g_grim->getCurrSet()->findClosestSector(_pos, NULL, &_pos); } if (_turning) { float turnAmt = g_grim->getPerSecond(_turnRate) * 5.f; Math::Angle dyaw = _moveYaw - _yaw; dyaw.normalize(-180); // If the actor won't turn because the rate is set to zero then // have the actor turn all the way to the destination yaw. // Without this some actors will lock the interface on changing // scenes, this affects the Bone Wagon in particular. if (turnAmt == 0 || turnAmt >= fabsf(dyaw.getDegrees())) { setYaw(_moveYaw); _turning = false; } else if (dyaw > 0) { setYaw(_yaw + turnAmt); } else { setYaw(_yaw - turnAmt); } _currTurnDir = (dyaw > 0 ? 1 : -1); } if (_walking) { updateWalk(); } if (_walkChore.isValid()) { if (_walkedCur) { if (!_walkChore.isPlaying()) { _walkChore.playLooping(true); } if (_restChore.isPlaying()) { _restChore.stop(true); } } else { if (_walkedLast && _walkChore.isPlaying()) { _walkChore.stop(true); if (!_restChore.isPlaying()) { _restChore.playLooping(true); } } } } if (_leftTurnChore.isValid()) { if (_walkedCur || _walkedLast) _currTurnDir = 0; if (_restChore.isValid()) { if (_currTurnDir != 0) { if (getTurnChore(_currTurnDir)->isPlaying() && _restChore.isPlaying()) { _restChore.stop(true, 500); } } else if (_lastTurnDir != 0) { if (!_walkedCur && getTurnChore(_lastTurnDir)->isPlaying()) { _restChore.playLooping(true); } } } if (_lastTurnDir != 0 && _lastTurnDir != _currTurnDir) { getTurnChore(_lastTurnDir)->stop(true); } if (_currTurnDir != 0 && _currTurnDir != _lastTurnDir) { getTurnChore(_currTurnDir)->playLooping(true, 500); } } else { _currTurnDir = 0; } // The rest chore might have been stopped because of a // StopActorChore(nil). Restart it if so. if (!_walkedCur && _currTurnDir == 0 && !_restChore.isPlaying()) { _restChore.playLooping(true); } _walkedLast = _walkedCur; _walkedCur = false; _lastTurnDir = _currTurnDir; _currTurnDir = 0; // Update lip syncing if (_lipSync) { int posSound; // While getPosIn60HzTicks will return "-1" to indicate that the // sound is no longer playing, it is more appropriate to check first if (g_grim->getSpeechMode() != GrimEngine::TextOnly && g_sound->getSoundStatus(_talkSoundName.c_str())) posSound = g_sound->getPosIn60HzTicks(_talkSoundName.c_str()); else posSound = -1; if (posSound != -1) { int anim = _lipSync->getAnim(posSound); if (_talkAnim != anim) { if (anim != -1) { if (_talkChore[anim].isValid()) { stopMumbleChore(); if (_talkAnim != -1) { _talkChore[_talkAnim].stop(); } // Run the stop_talk chore so that it resets the components // to the right visibility. stopTalking(); _talkAnim = anim; _talkChore[_talkAnim].play(); } else if (_mumbleChore.isValid() && !_mumbleChore.isPlaying()) { _mumbleChore.playLooping(); _talkAnim = -1; } } else { stopMumbleChore(); if (_talkAnim != -1) _talkChore[_talkAnim].stop(); _talkAnim = 0; stopTalking(); } } } } frameTime = (uint)(frameTime * _timeScale); for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->setPosRotate(_pos, _pitch, _yaw, _roll); int marker = c->update(frameTime); if (marker > 0) { costumeMarkerCallback(marker); } } for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->animate(); } for (Common::List<Costume *>::iterator i = _costumeStack.begin(); i != _costumeStack.end(); ++i) { Costume *c = *i; c->moveHead(_lookingMode, _lookAtVector); } }
void Server::handleCommand_PlayerPos(NetworkPacket* pkt) { const auto peer_id = pkt->getPeerId(); auto & packet = *(pkt->packet); auto player = m_env->getPlayer(pkt->getPeerId()); if (!player) { m_con.DisconnectPeer(pkt->getPeerId()); return; } auto playersao = player->getPlayerSAO(); if (!playersao) { m_con.DisconnectPeer(pkt->getPeerId()); return; } // If player is dead we don't care of this packet if (player->hp != 0 && playersao->m_ms_from_last_respawn > 1000) player->setPosition(packet[TOSERVER_PLAYERPOS_POSITION].as<v3f>()); player->setSpeed(packet[TOSERVER_PLAYERPOS_SPEED].as<v3f>()); player->setPitch(modulo360f(packet[TOSERVER_PLAYERPOS_PITCH].as<f32>())); player->setYaw(modulo360f(packet[TOSERVER_PLAYERPOS_YAW].as<f32>())); u32 keyPressed = packet[TOSERVER_PLAYERPOS_KEY_PRESSED].as<u32>(); player->keyPressed = keyPressed; { std::lock_guard<Mutex> lock(player->control_mutex); player->control.up = (bool)(keyPressed & 1); player->control.down = (bool)(keyPressed & 2); player->control.left = (bool)(keyPressed & 4); player->control.right = (bool)(keyPressed & 8); player->control.jump = (bool)(keyPressed & 16); player->control.aux1 = (bool)(keyPressed & 32); player->control.sneak = (bool)(keyPressed & 64); player->control.LMB = (bool)(keyPressed & 128); player->control.RMB = (bool)(keyPressed & 256); } auto old_pos = playersao->m_last_good_position; if(playersao->checkMovementCheat()) { // Call callbacks m_script->on_cheat(playersao, "moved_too_fast"); SendMovePlayer(peer_id); } else if (playersao->m_ms_from_last_respawn > 3000) { auto dist = (old_pos / BS).getDistanceFrom(playersao->m_last_good_position / BS); if (dist) stat.add("move", playersao->getPlayer()->getName(), dist); } if (playersao->m_ms_from_last_respawn > 2000) { auto obj = playersao; // copypasted from server step: auto uptime = m_uptime.get(); if (!obj->m_uptime_last) // not very good place, but minimum modifications obj->m_uptime_last = uptime - 0.1; if (uptime - obj->m_uptime_last > 0.5) { obj->step(uptime - obj->m_uptime_last, true); //todo: maybe limit count per time obj->m_uptime_last = uptime; } } /*infostream<<"Server::ProcessData(): Moved player "<<peer_id<<" to " <<"("<<position.X<<","<<position.Y<<","<<position.Z<<")" <<" pitch="<<pitch<<" yaw="<<yaw<<std::endl;*/ }
void Viewport::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_Up: if (event->modifiers() & Qt::ShiftModifier) /* move camera z-down */ if (event->modifiers() & Qt::AltModifier) pan(QVector3D(0, 0, -1 / (8 * log(scale)))); /* camera zoom in */ else setScale(scale * 1.1); /* move camera y-down */ else if (event->modifiers() & Qt::AltModifier) pan(QVector3D(0, -1 / (8 * log(scale)), 0)); /* rotate camera up */ else setPitch(fmin(0, fmin(M_PI, pitch + M_PI/16))); break; case Qt::Key_Down: if (event->modifiers() & Qt::ShiftModifier) /* move camera z-up */ if (event->modifiers() & Qt::AltModifier) pan(QVector3D(0, 0, 1 / (8 * log(scale)))); /* camera zoom out */ else setScale(scale * 0.9); /* move camera y-up */ else if (event->modifiers() & Qt::AltModifier) pan(QVector3D(0, 1 / (8 * log(scale)), 0)); /* rotate camera down */ else setPitch(fmin(0, fmax(-M_PI, pitch - M_PI/16))); break; case Qt::Key_Right: /* move camera left */ if (event->modifiers() & Qt::AltModifier) pan(QVector3D(-1 / (8 * log(scale)), 0, 0)); /* move camera counter-clockwise */ else setYaw(fmod(yaw - M_PI / (8 * log(scale)), 2*M_PI)); break; case Qt::Key_Left: /* move camera right */ if (event->modifiers() & Qt::AltModifier) pan(QVector3D(1 / (8 * log(scale)), 0, 0)); /* move camera clockwise */ else setYaw(fmod(yaw + M_PI / (8 * log(scale)), 2*M_PI)); break; /* hierarchical add menu */ case Qt::Key_A: if (event->modifiers() & Qt::ShiftModifier) { QObject* w = this; while (!dynamic_cast<MainWindow*>(w)) w = w->parent(); Q_ASSERT(w); QMenu* m = new QMenu(static_cast<MainWindow*>(w)); static_cast<MainWindow*>(w)->populateMenu(m, false, this); m->exec(QCursor::pos()); delete m; } break; /* spacebar menu */ case Qt::Key_Space: break; default: QGraphicsView::keyPressEvent(event); break; } }
void LocalPlayer::applyControl(float dtime, ClientEnvironment *env) { // Clear stuff swimming_vertical = false; setPitch(control.pitch); setYaw(control.yaw); // Nullify speed and don't run positioning code if the player is attached if(isAttached) { setSpeed(v3f(0,0,0)); return; } v3f move_direction = v3f(0,0,1); move_direction.rotateXZBy(getYaw()); v3f speedH = v3f(0,0,0); // Horizontal (X, Z) v3f speedV = v3f(0,0,0); // Vertical (Y) bool fly_allowed = m_gamedef->checkLocalPrivilege("fly"); bool fast_allowed = m_gamedef->checkLocalPrivilege("fast"); free_move = fly_allowed && g_settings->getBool("free_move"); bool fast_move = fast_allowed && g_settings->getBool("fast_move"); // When aux1_descends is enabled the fast key is used to go down, so fast isn't possible bool fast_climb = fast_move && control.aux1 && !g_settings->getBool("aux1_descends"); bool continuous_forward = g_settings->getBool("continuous_forward"); bool fast_pressed = false; bool always_fly_fast = g_settings->getBool("always_fly_fast"); // Whether superspeed mode is used or not superspeed = false; if (always_fly_fast && free_move && fast_move) superspeed = true; // Old descend control if(g_settings->getBool("aux1_descends")) { // If free movement and fast movement, always move fast if(free_move && fast_move) superspeed = true; // Auxiliary button 1 (E) if(control.aux1) { if(free_move) { // In free movement mode, aux1 descends if(fast_move) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; } else if(in_liquid || in_liquid_stable) { speedV.Y = -movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { speedV.Y = -movement_speed_climb; } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" if(fast_allowed) superspeed = true; } } } // New minecraft-like descend control else { // Auxiliary button 1 (E) if(control.aux1) { if(!is_climbing) { // aux1 is "Turbo button" if(fast_allowed) superspeed = true; } if(fast_allowed) fast_pressed = true; } if(control.sneak) { if(free_move) { // In free movement mode, sneak descends if (fast_move && (control.aux1 || always_fly_fast)) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; } else if(in_liquid || in_liquid_stable) { if(fast_climb) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { if(fast_climb) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_climb; } } } if (continuous_forward) speedH += move_direction; if (control.up) { if (continuous_forward) { if (fast_move) superspeed = true; } else { speedH += move_direction; } } if(control.down) { speedH -= move_direction; } if(control.left) { speedH += move_direction.crossProduct(v3f(0,1,0)); } if(control.right) { speedH += move_direction.crossProduct(v3f(0,-1,0)); } if(control.jump) { if (free_move) { if (g_settings->getBool("aux1_descends") || always_fly_fast) { if (fast_move) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; } else { if(fast_move && control.aux1) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; } } else if(m_can_jump) { /* NOTE: The d value in move() affects jump height by raising the height at which the jump speed is kept at its starting value */ v3f speedJ = getSpeed(); if(speedJ.Y >= -0.5 * BS) { speedJ.Y = movement_speed_jump * physics_override_jump; setSpeed(speedJ); MtEvent *e = new SimpleTriggerEvent("PlayerJump"); m_gamedef->event()->put(e); } } else if(in_liquid) { if(fast_climb) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { if(fast_climb) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_climb; } } // The speed of the player (Y is ignored) if(superspeed || (is_climbing && fast_climb) || ((in_liquid || in_liquid_stable) && fast_climb) || fast_pressed) speedH = speedH.normalize() * movement_speed_fast; else if(control.sneak && !free_move && !in_liquid && !in_liquid_stable) speedH = speedH.normalize() * movement_speed_crouch; else speedH = speedH.normalize() * movement_speed_walk; // Acceleration increase f32 incH = 0; // Horizontal (X, Z) f32 incV = 0; // Vertical (Y) if((!touching_ground && !free_move && !is_climbing && !in_liquid) || (!free_move && m_can_jump && control.jump)) { // Jumping and falling if(superspeed || (fast_move && control.aux1)) incH = movement_acceleration_fast * BS * dtime; else incH = movement_acceleration_air * BS * dtime; incV = 0; // No vertical acceleration in air // better air control when falling fast float speed = m_speed.getLength(); if (!superspeed && speed > movement_speed_fast && (control.down || control.up || control.left || control.right)) { v3f rotate = move_direction * (speed / (movement_fall_aerodynamics * BS)); if(control.up) rotate = rotate.crossProduct(v3f(0,1,0)); if(control.down) rotate = rotate.crossProduct(v3f(0,-1,0)); if(control.left) rotate *=-1; m_speed.rotateYZBy(rotate.X); m_speed.rotateXZBy(rotate.Y); m_speed.rotateXYBy(rotate.Z); m_speed = m_speed.normalize() * speed * (1-speed*0.00001); // 0.998 if (m_speed.Y) return; } } else if (superspeed || (is_climbing && fast_climb) || ((in_liquid || in_liquid_stable) && fast_climb)) incH = incV = movement_acceleration_fast * BS * dtime; else incH = incV = movement_acceleration_default * BS * dtime; // Accelerate to target speed with maximum increment INodeDefManager *nodemgr = m_gamedef->ndef(); Map *map = &env->getMap(); v3s16 p = floatToInt(getPosition() - v3f(0,BS/2,0), BS); float slippery = 0; try { slippery = itemgroup_get(nodemgr->get(map->getNode(p)).groups, "slippery"); } catch (...) {} accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed, slippery); accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed); }
Rotate::Rotate(unsigned int order) : Ambisonic(order) { setYaw(0.); }
void LocalPlayer::applyControl(float dtime) { // Clear stuff swimming_up = false; // Random constants f32 walk_acceleration = 4.0 * BS; f32 walkspeed_max = 4.0 * BS; setPitch(control.pitch); setYaw(control.yaw); // Nullify speed and don't run positioning code if the player is attached if(isAttached) { setSpeed(v3f(0,0,0)); return; } v3f move_direction = v3f(0,0,1); move_direction.rotateXZBy(getYaw()); v3f speed = v3f(0,0,0); bool fly_allowed = m_gamedef->checkLocalPrivilege("fly"); bool fast_allowed = m_gamedef->checkLocalPrivilege("fast"); bool free_move = fly_allowed && g_settings->getBool("free_move"); bool fast_move = fast_allowed && g_settings->getBool("fast_move"); bool continuous_forward = g_settings->getBool("continuous_forward"); if(free_move || is_climbing) { v3f speed = getSpeed(); speed.Y = 0; setSpeed(speed); } // Whether superspeed mode is used or not bool superspeed = false; // Old descend control if(g_settings->getBool("aux1_descends")) { // If free movement and fast movement, always move fast if(free_move && fast_move) superspeed = true; // Auxiliary button 1 (E) if(control.aux1) { if(free_move) { // In free movement mode, aux1 descends v3f speed = getSpeed(); if(fast_move) speed.Y = -20*BS; else speed.Y = -walkspeed_max; setSpeed(speed); } else if(is_climbing) { v3f speed = getSpeed(); speed.Y = -3*BS; setSpeed(speed); } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" if(fast_move) superspeed = true; } } } // New minecraft-like descend control else { // Auxiliary button 1 (E) if(control.aux1) { if(!is_climbing) { // aux1 is "Turbo button" if(fast_move) superspeed = true; } } if(control.sneak) { if(free_move) { // In free movement mode, sneak descends v3f speed = getSpeed(); if(fast_move && control.aux1) speed.Y = -20*BS; else speed.Y = -walkspeed_max; setSpeed(speed); } else if(is_climbing) { v3f speed = getSpeed(); speed.Y = -3*BS; setSpeed(speed); } } } if(continuous_forward) speed += move_direction; if(control.up) { if(continuous_forward) superspeed = true; else speed += move_direction; } if(control.down) { speed -= move_direction; } if(control.left) { speed += move_direction.crossProduct(v3f(0,1,0)); } if(control.right) { speed += move_direction.crossProduct(v3f(0,-1,0)); } if(control.jump) { if(free_move) { v3f speed = getSpeed(); if(g_settings->getBool("aux1_descends")) { if(fast_move) speed.Y = 20*BS; else speed.Y = walkspeed_max; } else { if(fast_move && control.aux1) speed.Y = 20*BS; else speed.Y = walkspeed_max; } setSpeed(speed); } else if(m_can_jump) { /* NOTE: The d value in move() affects jump height by raising the height at which the jump speed is kept at its starting value */ v3f speed = getSpeed(); if(speed.Y >= -0.5*BS) { speed.Y = 6.5*BS; setSpeed(speed); MtEvent *e = new SimpleTriggerEvent("PlayerJump"); m_gamedef->event()->put(e); } } // Use the oscillating value for getting out of water // (so that the player doesn't fly on the surface) else if(in_water) { v3f speed = getSpeed(); speed.Y = 1.5*BS; setSpeed(speed); swimming_up = true; } else if(is_climbing) { v3f speed = getSpeed(); speed.Y = 3*BS; setSpeed(speed); } } // The speed of the player (Y is ignored) if(superspeed) speed = speed.normalize() * walkspeed_max * 5.0; else if(control.sneak && !free_move) speed = speed.normalize() * walkspeed_max / 3.0; else speed = speed.normalize() * walkspeed_max; f32 inc = walk_acceleration * BS * dtime; // Faster acceleration if fast and free movement if(free_move && fast_move && superspeed) inc = walk_acceleration * BS * dtime * 10; // Accelerate to target speed with maximum increment accelerate(speed, inc); }
void LocalPlayer::applyControl(float dtime) { // Clear stuff swimming_vertical = false; setPitch(control.pitch); setYaw(control.yaw); // Nullify speed and don't run positioning code if the player is attached if(isAttached) { setSpeed(v3f(0,0,0)); return; } v3f move_direction = v3f(0,0,1); move_direction.rotateXZBy(getYaw()); v3f speedH = v3f(0,0,0); // Horizontal (X, Z) v3f speedV = v3f(0,0,0); // Vertical (Y) bool fly_allowed = m_gamedef->checkLocalPrivilege("fly"); bool fast_allowed = m_gamedef->checkLocalPrivilege("fast"); bool free_move = fly_allowed && g_settings->getBool("free_move"); bool fast_move = fast_allowed && g_settings->getBool("fast_move"); // When aux1_descends is enabled the fast key is used to go down, so fast isn't possible bool fast_climb = fast_move && control.aux1 && !g_settings->getBool("aux1_descends"); bool continuous_forward = g_settings->getBool("continuous_forward"); bool always_fly_fast = g_settings->getBool("always_fly_fast"); // Whether superspeed mode is used or not bool superspeed = false; if (always_fly_fast && free_move && fast_move) superspeed = true; // Old descend control if(g_settings->getBool("aux1_descends")) { // If free movement and fast movement, always move fast if(free_move && fast_move) superspeed = true; // Auxiliary button 1 (E) if(control.aux1) { if(free_move) { // In free movement mode, aux1 descends if(fast_move) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; } else if(in_liquid || in_liquid_stable) { speedV.Y = -movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { speedV.Y = -movement_speed_climb; } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" if(fast_move) superspeed = true; } } } // New minecraft-like descend control else { // Auxiliary button 1 (E) if(control.aux1) { if(!is_climbing) { // aux1 is "Turbo button" if(fast_move) superspeed = true; } } if(control.sneak) { if(free_move) { // In free movement mode, sneak descends if (fast_move && (control.aux1 || always_fly_fast)) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; } else if(in_liquid || in_liquid_stable) { if(fast_climb) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { if(fast_climb) speedV.Y = -movement_speed_fast; else speedV.Y = -movement_speed_climb; } } } if (continuous_forward) speedH += move_direction; if (control.up) { if (continuous_forward) { if (fast_move) superspeed = true; } else { speedH += move_direction; } } if(control.down) { speedH -= move_direction; } if(control.left) { speedH += move_direction.crossProduct(v3f(0,1,0)); } if(control.right) { speedH += move_direction.crossProduct(v3f(0,-1,0)); } if(control.jump) { if (free_move) { if (g_settings->getBool("aux1_descends") || always_fly_fast) { if (fast_move) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; } else { if(fast_move && control.aux1) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; } } else if(m_can_jump) { /* NOTE: The d value in move() affects jump height by raising the height at which the jump speed is kept at its starting value */ v3f speedJ = getSpeed(); if(speedJ.Y >= -0.5 * BS) { speedJ.Y = movement_speed_jump * physics_override_jump; setSpeed(speedJ); MtEvent *e = new SimpleTriggerEvent("PlayerJump"); m_gamedef->event()->put(e); } } else if(in_liquid) { if(fast_climb) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_walk; swimming_vertical = true; } else if(is_climbing) { if(fast_climb) speedV.Y = movement_speed_fast; else speedV.Y = movement_speed_climb; } } // The speed of the player (Y is ignored) if(superspeed || (is_climbing && fast_climb) || ((in_liquid || in_liquid_stable) && fast_climb)) speedH = speedH.normalize() * movement_speed_fast; else if(control.sneak && !free_move && !in_liquid && !in_liquid_stable) speedH = speedH.normalize() * movement_speed_crouch; else speedH = speedH.normalize() * movement_speed_walk; // Acceleration increase f32 incH = 0; // Horizontal (X, Z) f32 incV = 0; // Vertical (Y) if((!touching_ground && !free_move && !is_climbing && !in_liquid) || (!free_move && m_can_jump && control.jump)) { // Jumping and falling if(superspeed || (fast_move && control.aux1)) incH = movement_acceleration_fast * BS * dtime; else incH = movement_acceleration_air * BS * dtime; incV = 0; // No vertical acceleration in air } else if (superspeed || (is_climbing && fast_climb) || ((in_liquid || in_liquid_stable) && fast_climb)) incH = incV = movement_acceleration_fast * BS * dtime; else incH = incV = movement_acceleration_default * BS * dtime; // Accelerate to target speed with maximum increment accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed); accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed); }
Turn::Turn(Robot *robot, double yaw) : Behavior(robot) { setYaw(yaw); }