void testUpdateVelocity() { double velocity; printf("*** Testing updateVelocity... ***\n\n"); /* Test 1: -1.0 and -0.5 */ printf("TEST 1: Inputing -1 and -0.5\n"); velocity = updateVelocity(-1.0, -0.5); printf(" Expect: %f\n", -1.5); printf(" Got: %f\n", velocity); /* Compare to see if output velocity and the expected are equal. * See the description of the compareDoubles function below. */ if (compareDoubles(velocity, -1.5, .000001)) { printf(" Pass\n"); } else { printf(" FAIL\n"); } /* Test 2: 0.0 and 0.0 */ printf("TEST 2: Inputing 0.0 and 0.0\n"); velocity = updateVelocity(0.0, 0.0); printf(" Expect: %f\n", 0.0); printf(" Got: %f\n", velocity); if (compareDoubles(velocity, 0.0, .000001)) { printf(" Pass\n"); } else { printf(" FAIL\n"); } /* Test 3: -100.23 and 1.1 */ printf("TEST 3: Inputing -100.23 and 1.1\n"); velocity = updateVelocity(-100.23, 1.1); printf(" Expect: %f\n", -99.13); printf(" Got: %f\n", velocity); if (compareDoubles(velocity, -99.13, .000001)) { printf(" Pass\n"); } else { printf(" FAIL\n"); } }
void TankJoyStick::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event) { auto orilocation = Director::getInstance()->convertToGL((touch->getLocationInView())); auto location = convertToNodeSpaceAR(orilocation); //CCLOG("move to,oriPos(%f,%f),pos:(%f,%f)",orilocation.x,orilocation.y,location.x,location.y); updateVelocity(location); }
// Runs every frame void PlayerController::update() { // Time between frames const double time = glfwGetTime(); const double deltaT = time - m_lastFrameTime; // Update velocity updateVelocity(deltaT); // Check for bounding boxes glm::vec3 prevPos = m_camera.position(); /* if (isOutsideWorld() ) { isInsideCity(); }*/ if (isOutsideBoundingBox() && !isOutsideWorld()) { updatePosition(deltaT); } if (isOutsideWorld() || !isOutsideBoundingBox()){ // glm::vec3 camPos = m_camera.position(); // glm::vec3 resetPosition = glm::vec3(camPos.x - 0.1f, camPos.y - 0.1f, camPos.z); m_camera.setPosition(prevPos); } // Update time m_lastFrameTime = time; }
void PianorollEditor::updateSelection() { QList<QGraphicsItem*> items = gv->scene()->selectedItems(); if (items.size() == 1) { PianoItem* item = static_cast<PianoItem*>(items[0]); if (item->type() == PianoItemType) { Note* note = item->note(); pitch->setEnabled(true); pitch->setValue(note->pitch()); veloType->setEnabled(true); velocity->setEnabled(true); updateVelocity(note); } } else if (items.size() == 0) { velocity->setValue(0); velocity->setEnabled(false); pitch->setValue(0); pitch->setEnabled(false); veloType->setEnabled(false); veloType->setCurrentIndex(int(MScore::USER_VAL)); } else { velocity->setEnabled(true); velocity->setValue(0); velocity->setReadOnly(false); pitch->setEnabled(true); pitch->setDeltaMode(true); pitch->setValue(0); veloType->setEnabled(true); veloType->setCurrentIndex(int(MScore::OFFSET_VAL)); } }
void DrumrollEditor::updateSelection() { QList<QGraphicsItem*> items = gv->scene()->selectedItems(); if (items.size() == 1) { QGraphicsItem* item = items[0]; Note* note = static_cast<Note*>(item->data(0).value<void*>()); pitch->setEnabled(true); pitch->setValue(note->pitch()); veloType->setEnabled(true); velocity->setEnabled(true); updateVelocity(note); } else if (items.size() == 0) { velocity->setValue(0); velocity->setEnabled(false); pitch->setValue(0); pitch->setEnabled(false); veloType->setEnabled(false); veloType->setCurrentIndex(int(Note::ValueType::OFFSET_VAL)); } else { velocity->setEnabled(true); velocity->setValue(0); velocity->setReadOnly(false); pitch->setEnabled(true); pitch->setDeltaMode(true); pitch->setValue(0); veloType->setEnabled(true); veloType->setCurrentIndex(int(Note::ValueType::OFFSET_VAL)); } }
//----------------------------------------------------------------------------- void Rigid::integrate(F32 delta) { // Update Angular position F32 angle = angVelocity.len(); if (angle != 0.0f) { QuatF dq; F32 sinHalfAngle; mSinCos(angle * delta * -0.5f, sinHalfAngle, dq.w); sinHalfAngle *= 1.0f / angle; dq.x = angVelocity.x * sinHalfAngle; dq.y = angVelocity.y * sinHalfAngle; dq.z = angVelocity.z * sinHalfAngle; QuatF tmp = angPosition; angPosition.mul(tmp, dq); angPosition.normalize(); // Rotate the position around the center of mass Point3F lp = linPosition - worldCenterOfMass; dq.mulP(lp,&linPosition); linPosition += worldCenterOfMass; } // Update angular momentum angMomentum = angMomentum + torque * delta; // Update linear position, momentum linPosition = linPosition + linVelocity * delta; linMomentum = linMomentum + force * delta; linVelocity = linMomentum * oneOverMass; // Update dependent state variables updateInertialTensor(); updateVelocity(); updateCenterOfMass(); }
void Sprite::update(Uint32 ticks) { const static float speedLoss = JSONGamedata::getInstance().getFloat("sprite.speedLoss"); updateVelocity(ticks); Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001 * scale; setPosition(getPosition() + incr); if ( Y() < 0) { velocityY( abs( velocityY() * speedLoss) ); } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() * speedLoss) ); } if ( X() < 0) { velocityX( abs( velocityX() * speedLoss) ); } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() * speedLoss) ); } if(Planets::getInstance().checkForCollision(this)){ //velocityY( -velocityY() * speedLoss ); //velocityX( -velocityX() * speedLoss ); } }
void dtCollisionAvoidance::doUpdate(const dtCrowdQuery& query, const dtCrowdAgent& oldAgent, dtCrowdAgent& newAgent, const dtCollisionAvoidanceParams& currentParams, dtCollisionAvoidanceParams& newParams, float /*dt*/) { m_velocitySamplesCount = 0; addObtacles(oldAgent, query); updateVelocity(oldAgent, newAgent, currentParams, newParams); }
void simulateFluids(void) { // simulate fluid advectVelocity(dvfield, (float *)vxfield, (float *)vyfield, DIM, RPADW, DIM, DT); diffuseProject(vxfield, vyfield, CPADW, DIM, DT, VIS); updateVelocity(dvfield, (float *)vxfield, (float *)vyfield, DIM, RPADW, DIM); advectParticles(vbo, dvfield, DIM, DIM, DT); }
// ------------- update void EyeLinker::update(){ updateVelocity(); updateParameters(); updatePhysics(); updateEye(); updateFading(); updateFireworks(); }
void GLFluids::simulateFluids(void) { // simulate fluid advectVelocity(dvfield, (float *)vxfield, (float *)vyfield, DIM, RPADW, DIM, DT); diffuseProject(vxfield, vyfield, CPADW, DIM, DT, VIS, planr2c, planc2r); updateVelocity(dvfield, (float *)vxfield, (float *)vyfield, DIM, RPADW, DIM); advectParticles(cuda_vbo_resource, dvfield, DIM, DIM, DT); }
void EyeLinker::setPos(ofVec2f _pos){ float s = 0.9; if(counter==0){ posPrev = _pos; } pos = pos * s + (1-s) * _pos; counter++; updateVelocity(); }
void UAVSimulation::update3DOF(const double& timestep) { if (timestep <= 0) return; //! Wind effects m_velocity(2) = m_wind(2); calcUAV2AirData(); //========================================================================== //! Aircraft Dynamics //========================================================================== integratePosition(timestep); /* //for debug double vt_velocity1[6] = {m_velocity(0), m_velocity(1), m_velocity(2), m_velocity(3), m_velocity(4), m_velocity(5)}; */ //! Command effect //! - Airspeed command m_airspeed = m_airspeed_cmd; //! - Roll command m_position(3) = m_bank_cmd; //! Turn rate m_velocity(5) = m_g * std::tan(m_position(3))/m_airspeed; /* //for debug double vt_velocity2[6] = {m_velocity(0), m_velocity(1), m_velocity(2), m_velocity(3), m_velocity(4), m_velocity(5)}; */ updateVelocity(); /* //for debug double vt_velocity2[6] = {m_velocity(0), m_velocity(1), m_velocity(2), m_velocity(3), m_velocity(4), m_velocity(5)}; if (std::abs(vt_velocity1[0] - vt_velocity2[0]) > 0.5*m_airspeed*timestep/m_speed_time_cst || std::abs(vt_velocity1[1] - vt_velocity2[1]) > 0.5*m_airspeed*timestep/m_speed_time_cst) { std::cout << "Time step: " << timestep << std::endl; std::cout << "Velocity difference: " << vt_velocity1[0]-vt_velocity2[0] << ", " << vt_velocity1[1]-vt_velocity2[1] << std::endl; std::cout << "Heading: " << DUNE::Math::Angles::degrees(vt_position1[5]) << "º" << std::endl; } */ /* //for debug double vt_velocity3[6] = {m_velocity(0), m_velocity(1), m_velocity(2), m_velocity(3), m_velocity(4), m_velocity(5)}; std::cout << "Prev velocity: " << vt_velocity1[0] << ", " << vt_velocity1[1] << std::endl; std::cout << "Int velocity: " << vt_velocity2[0] << ", " << vt_velocity2[1] << std::endl; std::cout << "New velocity: " << vt_velocity3[0] << ", " << vt_velocity3[1] << std::endl; */ }
/// -------------------- Update -------------------- /// void MotionerIMU::update() { updateSerial(); updateValues(); const bool ret = updateVelocity(); // updateCAN(); }
void QKineticScrollerPrivate::handleDrag(const QPointF &position, qint64 timestamp) { Q_Q(QKineticScroller); QPointF deltaPixel = position - lastPosition; qint64 deltaTime = timestamp - lastTimestamp; if (axisLockThreshold) { int dx = qAbs(deltaPixel.x()); int dy = qAbs(deltaPixel.y()); if (dx || dy) { bool vertical = (dy > dx); qreal alpha = qreal(vertical ? dx : dy) / qreal(vertical ? dy : dx); //qKSDebug() << "QKS::handleDrag() -- axis lock:" << alpha << " / " << axisLockThreshold << "- isvertical:" << vertical << "- dx:" << dx << "- dy:" << dy; if (alpha <= axisLockThreshold) { if (vertical) deltaPixel.setX(0); else deltaPixel.setY(0); } } } // calculate velocity (if the user would release the mouse NOW) updateVelocity(deltaPixel, deltaTime); // restrict velocity, if content is not scrollable QPointF maxPos = q->maximumContentPosition(); bool canScrollX = maxPos.x() || (hOvershootPolicy == QKineticScroller::OvershootAlwaysOn); bool canScrollY = maxPos.y() || (vOvershootPolicy == QKineticScroller::OvershootAlwaysOn); if (!canScrollX) { deltaPixel.setX(0); releaseVelocity.setX(0); } if (!canScrollY) { deltaPixel.setY(0); releaseVelocity.setY(0); } // if (firstDrag) { // // Do not delay the first drag // setContentPositionHelper(q->contentPosition() - overshootDistance - deltaPixel); // dragDistance = QPointF(0, 0); // } else { dragDistance += deltaPixel; // } if (canScrollX) lastPosition.setX(position.x()); if (canScrollY) lastPosition.setY(position.y()); lastTimestamp = timestamp; }
void CFootBotUN::updateNavigation() { printf("UPDATE Navigation with state %d\n", state); if (state == ARRIVED_AT_TARGET) { agent->desideredAngle = CRadians::ZERO; agent->desideredSpeed = 0; agent->desideredVelocity = CVector2(0, 0); } else { updateDesideredVelocity(); } agent->updateVelocity(); updateVelocity(); }
void PSO::Swarm::run(int numEvals, int slowdown, int vflag, ostream* out, ostream* hist) { int numIt = numEvals / swarm.size(); for (int i(0); i < numIt; ++i) { if (slowdown) { for (int j(0); j < numParams; ++j) { if (phiPf[j] > phiPi[j]) phiP[j] = phiPi[j] + (phiPf[j]-phiPi[j])*((1.*numIt-i)/numIt); if (phiGf[j] > phiGi[j]) phiG[j] = phiGi[j] + (phiGf[j]-phiGi[j])*((1.*numIt-i)/numIt); if (omegaf[j] > omegai[j]) omega[j] = omegai[j] + (omegaf[j]-omegai[j])*((1.*numIt-i)/numIt); } } updateVelocity(); updatePosition(); evaluate(); if (hist != NULL) { for (int id(0); id < swarmSize; ++id) { *hist << setw(4) << id << " " << scientific << (*swarm[id]) << endl; } } if (out != NULL) { *out << setw(6) << i*swarm.size() << " "; // *out << scientific << *swarm[bestParticle] << endl; *out << scientific << bestVal << " " << bestPos << endl; } if (vflag) { cerr << "["; int progress = i/(numIt/30); for (int a(0); a < progress; ++a) cerr << "="; for (int a(progress); a < 30; ++a) cerr << " "; cerr << "] " << i << "/" << numIt << " best = " << bestPos << ", fx = " << scientific << bestVal << fixed << " \r"; } /* if (vflag) { cerr << "[" << i << "] best solution: " << bestVal; cerr << " at x = ("; for (size_t j(0); j < bestPos.size(); ++j) { cerr << bestPos[j]; if (j < bestPos.size()-1) cerr << ","; } cerr << ")" << endl; } */ } if (vflag) cerr << endl; }
void Item::processTick(const Move* move) { Parent::processTick(move); // if (mCollisionObject && !--mCollisionTimeout) mCollisionObject = 0; // Warp to catch up to server if (delta.warpTicks > 0) { delta.warpTicks--; // Set new pos. MatrixF mat = mObjToWorld; mat.getColumn(3,&delta.pos); delta.pos += delta.warpOffset; mat.setColumn(3,delta.pos); Parent::setTransform(mat); // Backstepping delta.posVec.x = -delta.warpOffset.x; delta.posVec.y = -delta.warpOffset.y; delta.posVec.z = -delta.warpOffset.z; } else { if (isServerObject() && mAtRest && (mStatic == false && mDataBlock->sticky == false)) { if (++mAtRestCounter > csmAtRestTimer) { mAtRest = false; mAtRestCounter = 0; setMaskBits(PositionMask); } } if (!mStatic && !mAtRest && isHidden() == false) { updateVelocity(TickSec); updateWorkingCollisionSet(isGhost() ? sClientCollisionMask : sServerCollisionMask, TickSec); updatePos(isGhost() ? sClientCollisionMask : sServerCollisionMask, TickSec); } else { // Need to clear out last updatePos or warp interpolation delta.posVec.set(0,0,0); } } }
// update〜系関数をまとめる void update(float bar_move) { // もし失敗していたら if(miss) { // 落下させる setForce(0, 0.3); } // 失敗していない場合は else { // バーの動きと逆方向に力がかかる(すべるような動き) setForce(-bar_move, 0); updateForce(); } updateVelocity(); updatePos(); }
void AirPlane::update(float restTime) { if(life) { updateVelocity(restTime); updatePosition(restTime); collisionBox.updateCollisionBoxPos(currentPosition); if(currentPosition.X()<0 || currentPosition.X() >mapX*mapScale || currentPosition.Z()>0 || currentPosition.Z()<(-mapZ*mapScale)) life = false; if(!collisionBox.isLife()) { life = false; printf("airPlane die\n"); } } }
void PianorollEditor::veloTypeChanged(int val) { QList<QGraphicsItem*> items = gv->scene()->selectedItems(); if (items.size() != 1) return; QGraphicsItem* item = items[0]; if (item->type() != PianoItemType) return; Note* note = static_cast<PianoItem*>(item)->note(); if (Note::ValueType(val) == note->veloType()) return; _score->undo()->beginMacro(); _score->undo(new ChangeVelocity(note, Note::ValueType(val), note->veloOffset())); _score->undo()->endMacro(_score->undo()->current()->childCount() == 0); updateVelocity(note); }
void SWSolver::advanceTimestep(){ //std::cout << "advecting eta..." << std::endl; advect(ETA); //std::cout << "advecting velocity_x..." << std::endl; advect(VELOCITY_X); //std::cout << "advecting velocity_y..." << std::endl; advect(VELOCITY_Y); //std::cout << "updating heights..." << std::endl; updateHeight(); //std::cout << "updating velocities..." << std::endl; updateVelocity(); //std::cout << "setting boundaries..." << std::endl; setBoundary(); }
bool TankJoyStick::onTouchBegin(cocos2d::Touch *touch, cocos2d::Event *event) { auto orilocation = Director::getInstance()->convertToGL(touch->getLocationInView()); auto location = convertToNodeSpaceAR(orilocation); if (location.x < -radius || location.x > radius || location.y<-radius || location.y>radius) { return false; } else { float dsq = location.x*location.x+location.y*location.y; if (dsq<radiusSqr) { updateVelocity(location); } } return true; }
void MouseCtrl::velocityGetDisplace(int &displaceX, int &displaceZ, int *accl, double *velocity, int *AcclZeroC, bool isGyroMoved, int period, bool updateX, bool updateZ){ double second = period / 1000.0; double lastVX = velocity[0]; double lastVZ = velocity[2]; updateVelocity(accl, velocity, AcclZeroC, isGyroMoved, second, updateX, updateZ); //若上一次的速度跟此次一樣 表示此次的accl為0 所以不計算位移量 if( lastVX != velocity[0] ){ displaceX = (2*(velocity[0])*second); }else{ displaceX = 0; } if( lastVZ != velocity[2] ){ displaceZ = 0 - (2*(velocity[2])*second); //Z軸的移動成反方向 }else{ displaceZ = 0; } }
void Camera::updatePosition(const glm::vec3 &direction, float elapsedTimeSec) { // Moves the camera using Newton's second law of motion. Unit mass is // assumed here to somewhat simplify the calculations. The direction vector // is in the range [-1,1]. float length2 = glm::dot( m_currentVelocity,m_currentVelocity ); if ( length2 < 1e-10 ) { // Only move the camera if the velocity vector is not of zero length. // Doing this guards against the camera slowly creeping around due to // floating point rounding errors. glm::vec3 displacement = (m_currentVelocity * elapsedTimeSec) + (0.5f * m_acceleration * elapsedTimeSec * elapsedTimeSec); // Floating point rounding errors will slowly accumulate and cause the // camera to move along each axis. To prevent any unintended movement // the displacement vector is clamped to zero for each direction that // the camera isn't moving in. Note that the updateVelocity() method // will slowly decelerate the camera's velocity back to a stationary // state when the camera is no longer moving along that direction. To // account for this the camera's current velocity is also checked. if (direction.x == 0.0f && closeEnough(m_currentVelocity.x, 0.0f)) displacement.x = 0.0f; if (direction.y == 0.0f && closeEnough(m_currentVelocity.y, 0.0f)) displacement.y = 0.0f; if (direction.z == 0.0f && closeEnough(m_currentVelocity.z, 0.0f)) displacement.z = 0.0f; move( displacement.x, displacement.y, displacement.z ); } // Continuously update the camera's velocity vector even if the camera // hasn't moved during this call. When the camera is no longer being moved // the camera is decelerating back to its stationary state. updateVelocity(direction, elapsedTimeSec); }
void PianorollEditor::updateSelection() { QList<QGraphicsItem*> items = gv->scene()->selectedItems(); if (items.size() == 1) { PianoItem* item = static_cast<PianoItem*>(items[0]); if (item->type() == PianoItemType) { Note* note = item->note(); NoteEvent* event = item->event(); pitch->setEnabled(true); pitch->setValue(note->pitch()); onTime->setValue(event->ontime()); tickLen->setValue(event->len()); updateVelocity(note); } } bool b = items.size() != 0; velocity->setEnabled(b); pitch->setEnabled(b); veloType->setEnabled(b); onTime->setEnabled(b); tickLen->setEnabled(b); }
void GOBall::tick() { GameObject::tick(); if (!m_Alive) return; m_ScoreObject->updateScore(m_Score); jump(); updateVelocity(); // sync the position of the physics and graphics objects CPhysicsObject* physicsComponent = (CPhysicsObject*)getComponent(CPhysicsObject::classTypeID()); b2Body* body = physicsComponent->getBody(); b2Vec2 position = body->GetPosition(); float32 angle = body->GetAngle(); if (position.y < -200) spawn(); CGraphicsObject* graphicsComponent = (CGraphicsObject*)getComponent(CGraphicsObject::classTypeID()); graphicsComponent->setPosition(position.x, position.y, 0.0f); }
void SchoolFish::onUpdate(float dt) { BBGE_PROF(SchoolFish_onUpdate); /* Quad::onUpdate(dt); return; */ /* if (dsq->continuity.form == FORM_BEAST) this->activationType = ACT_CLICK; else this->activationType = ACT_NONE; */ /* if (burstDelay == 0) { maxSpeedLerp = 2; Vector v = getNormal(); vel = 0; v *= -5000; vel += v; //float t = (100 + rand()%100)/100.0; float t = 2; maxSpeedLerp.interpolateTo(1, t); burstDelay = 10;// + (rand()%100)/100.0; //rotateToVec(v, 0, 90); //rotation.interpolateTo(0, 1); if (v.x > 0 && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (v.x < 0 && isfh()) { flipHorizontal(); flipDelay = 0.5; } } else */ { burstDelay -= dt; if (burstDelay < 0) { burstDelay = 0; } } if (stickToNaijasHead && alpha.x < 0.1) stickToNaijasHead = false; if (this->layer < LR_ENTITIES) { //debugLog("background fish!"); /* setDamageTarget(DT_AVATAR_SHOCK, false); setDamageTarget(DT_AVATAR_BITE, false); setDamageTarget(DT_AVATAR_VOMIT, false); setDamageTarget(DT_AVATAR_ENERGYBLAST, false); */ setEntityType(ET_NEUTRAL); collideRadius = 0; } if (getState() == STATE_DEAD) { FlockEntity::onUpdate(dt); respawnTimer -= dt; if (!(dsq->game->avatar->position - this->position).isLength2DIn(2000)) { if (respawnTimer < 0) { respawnTimer = 0; perform(STATE_IDLE); } } } else { /* if (layer == LR_ENTITIES || layer == LR_ENTITIES2) { rippleTimer -= dt; if (rippleTimer < 0) { if (core->afterEffectManager) core->afterEffectManager->addEffect(new ShockEffect(Vector(core->width/2, core->height/2),position,0.04,0.06,15,0.2f)); rippleTimer = 0.5; } } */ FlockEntity::onUpdate(dt); if (dsq->game->isValidTarget(this, 0)) dsq->game->handleShotCollisions(this); /* soundDelay -= dt; if (soundDelay <= 0) { //sound(swimSound, 1000 + rand()%100); soundDelay = 4+(rand()%50)/100.0; } */ /* 1. if distance_to(closest_boid) <= too_close then set direction away from closest_boid 2. speed_of_neighbors := average(speed(x), for all x where distance_to(x) <= neighborhood_size) direction_of_neighbors := avg(direction(x), for all x where distance_to(x) <= neighborhood_size) if speed < speed_of_neighbors then increase speed if speed > speed_of_neighbors then decrease speed turn towards direction_of_neighbors 3. position_of_neighbors := avg(position(x), for all x where distance_to(x) <= neighborhood_size) turn towards position_of_neighbors */ float seperation = 1; float alignment = 0; float cohesion = 0.75; /* FlockPiece flock; getFlockInRange(160, &flock); */ // if flock in 160 ? if (true) { VectorSet newDirection; if (avoidTime>0) { avoidTime -= dt; if (avoidTime<0) avoidTime=0; } Vector dir = getFlockHeading(); Vector accumulator; applyCohesion(accumulator); applyAlignment(accumulator, dir); // alignment applySeparation(accumulator); applyAvoidance(accumulator); updateVelocity(accumulator); /* if (dsq->game->isValidTarget(this, 0)) doSpellAvoidance(dt, 96, dodgeAbility); */ Vector lastPosition = position; Vector newPosition = position + (vel*velocityScale*dt) + vel2*dt; position = newPosition; if (dsq->game->isObstructed(position)) { position = lastPosition; /* position = Vector(newPosition.x, lastPosition.y); if (dsq->game->isObstructed(position)) { position = Vector(lastPosition.x, newPosition.y); if (dsq->game->isObstructed(position)) { position = lastPosition; } } */ } //updateCurrents(dt); updateVel2(dt); /* if (flipDelay > 0) { flipDelay -= dt; if (flipDelay < 0) { flipDelay = 0; } } */ flipDelay = 0; //dir.normalize2D(); if (flipDelay <= 0) { const float amt = 0; /* if (fabs(dir.x) > fabs(dir.y)) { if (dir.x > amt && !isfh()) { flipHorizontal(); flipDelay = 0.5; } if (dir.x < -amt && isfh()) { flipHorizontal(); flipDelay = 0.5; } } */ if (vel.x > amt && !isfh()) { flipHorizontal(); } if (vel.x < -amt && isfh()) { flipHorizontal(); } } //rotateToVec(accumulator, 5, 90); float angle = atan(dir.y/dir.x); angle = ((angle*180)/3.14); if (angle > 45) angle = 45; if (angle < -45) angle = -45; rotation = Vector(0,0,angle); //rotation.interpolateTo(Vector(0, 0, angle), 0); } } }
//normal update call void CloudsVisualSystemFlocking::selfUpdate(){ if(bUpdateAcc) updateAcceleration(); if(bUpdateVel) updateVelocity(); if(bUpdatePos) updatePosition(); }
void stepNetwork(void) { int i, k, pi, pi2, nbytes, newfd; char remoteIP[INET6_ADDRSTRLEN]; struct sockaddr_storage remoteaddr; socklen_t addrlen; struct timeval tv; if(getDeathMessage(sendbuf)) { for(k = 0; k < conf.maxPlayers; ++k) { if(connection[k].socket && !connection[k].bot) { snd(connection[k].socket, "\r\n"); snd(connection[k].socket, sendbuf); snd(connection[k].socket, "\r\n> "); } } } tv.tv_sec = 0; tv.tv_usec = 1; readfds = master; if(select(fdmax + 1, &readfds, NULL, NULL, &tv) == -1) { print_error("select"); exit(5); } for(i = 0; i <= fdmax; ++i) { if(FD_ISSET(i, &readfds)) { if(i == listener) { addrlen = sizeof remoteaddr; newfd = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen); if(newfd == -1) { print_error("accept"); } else { getnameinfo((struct sockaddr *)&remoteaddr, addrlen, remoteIP, sizeof remoteIP, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV); for(k = 0; k < conf.maxPlayers; ++k) { if(connection[k].socket == 0) { connection[k].socket = newfd; playerJoin(k); updateName(k, "Anonymous"); allSendPlayerPos(k); break; } } if(k == conf.maxPlayers) { close(newfd); printf("new connection from %s on socket %d refused: max connections\n", remoteIP, newfd); } else { FD_SET(newfd, &master); if(newfd > fdmax) { fdmax = newfd; } printf("new connection from %s on socket %d accepted\n", remoteIP, newfd); snd(newfd, WELCOME); } } } else { if((nbytes = recv(i, buf, sizeof buf, 0)) <= 0) { if(nbytes == 0) { printf("socket %d hung up\n", i); } else { print_error("recv"); } for(k = 0; k < conf.maxPlayers; ++k) { if(connection[k].socket == i) { disconnectPlayer(k); allSendPlayerLeave(k); break; } } close(i); FD_CLR(i, &master); } else { pi = -1; for(k = 0; k < conf.maxPlayers; ++k) { if(connection[k].socket == i) { pi = k; break; } } for(k = 0; k < nbytes && pi >= 0; ++k) { unsigned char c = buf[k]; if(c != '\r' && c != '\n') { if(isprint(c) && connection[pi].msgbufindex < 128 - 2) { connection[pi].msgbuf[connection[pi].msgbufindex++] = c; } } else { if(connection[pi].msgbufindex == 0) { continue; } connection[pi].msgbuf[connection[pi].msgbufindex] = '\0'; connection[pi].msgbuf[connection[pi].msgbufindex + 1] = '\0'; connection[pi].msgbufindex = 0; if(connection[pi].echo) { snd(i, connection[pi].msgbuf); snd(i, "\r\n"); } if(!overdrive)printf("%16s (%d): \"%s\"\n", getPlayer(pi)->name, pi, connection[pi].msgbuf); switch(connection[pi].msgbuf[0]) { case 'n': { updateName(pi, connection[pi].msgbuf + 2); break; } case 'v': { updateVelocity(pi, atof(connection[pi].msgbuf + 2)); break; } case 'z': { updateZoom(atof(connection[pi].msgbuf + 2)); break; } case 'c': { clearTraces(pi); break; } case 'o': { overdrive = !overdrive; break; } case 'b': { connection[pi].bot = !connection[pi].bot; if(connection[pi].bot) { sendOwnId(i, pi); for(pi2 = 0; pi2 < conf.maxPlayers; ++pi2) { if(connection[pi2].socket) { sendPlayerPos(i, pi2); } } } break; } case 'f': { toggleFps(); break; } case 'i': { if(strcmp("init", connection[pi].msgbuf) == 0) { reinitialize(); } break; } case 'x': { if(strcmp("xit", connection[pi].msgbuf) == 0) { exit(0); } break; } case 'e': { connection[pi].echo = !connection[pi].echo; break; } case 'q': { disconnectPlayer(pi); allSendPlayerLeave(pi); break; } case 'r': { validateOld(pi); break; } default: { updateAngle(pi, atof(connection[pi].msgbuf)); break; } } if(connection[pi].socket && !connection[pi].bot) { snd(i, "> "); } } } } } } } for(k = 0; k < conf.maxPlayers; ++k) { if(getPlayer(k)->active && getPlayer(k)->timeoutcnt > 2) { disconnectPlayer(k); allSendPlayerLeave(k); } } }