void Jets::update(Uint32 ticks) { int deviation = getRandomFactorBetween(0,200); int length = sqrt((playerX+deviation - X())*(playerX+deviation-X()) + (playerY+deviation-Y())*(playerY+deviation-Y())); velocityX(throttleX*(playerX - X())/length); velocityY(throttleY*(playerY - Y())/length); int delta_x = playerX - X(); int delta_y = playerY - Y(); angle = -(atan2(delta_y, delta_x)*180.0000)/3.142 ; Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if(getRotate()) angle += getRotationSpeed() % 360; if ( Y() < 0) { velocityY( abs( velocityY() ) ); } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); } if ( X() < 0) { velocityX( abs( velocityX() ) ); } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); } }
void Player::control(sf::Keyboard::Key key) { sf::Vector2f velocity = getVelocity(); //Go up direction = sf::Vector2f(0, 0); if (key == sf::Keyboard::W || key == sf::Keyboard::Up) { velocity += sf::Vector2f(0, -1 * terminalVelocity); direction.y = -1; } //Go down if (key == sf::Keyboard::S || key == sf::Keyboard::Down) { velocity += sf::Vector2f(0, terminalVelocity); direction.y = 1; } //Go left if (key == sf::Keyboard::A || key == sf::Keyboard::Left) { direction.x = -1; velocity += sf::Vector2f(-1 * terminalVelocity, 0); } //Go right if (key == sf::Keyboard::D || key == sf::Keyboard::Right) { direction.x = 1; velocity += sf::Vector2f(terminalVelocity, 0); } setVelocity(velocity); }
void TwoWaySprite::update(Uint32 ticks) { advanceFrame(ticks); Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if ( Y() < 0) { velocityY( abs( velocityY() ) ); } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); } if ( X() < 0) { velocityX( abs( velocityX() ) ); flipX = 1; } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); flipX = -1; } }
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 ); } }
AudioSource* AudioSource::clone(NodeCloneContext &context) const { GP_ASSERT(_buffer); ALuint alSource = 0; AL_CHECK( alGenSources(1, &alSource) ); if (AL_LAST_ERROR()) { GP_ERROR("Error generating audio source."); return NULL; } AudioSource* audioClone = new AudioSource(_buffer, alSource); _buffer->addRef(); audioClone->setLooped(isLooped()); audioClone->setGain(getGain()); audioClone->setPitch(getPitch()); audioClone->setVelocity(getVelocity()); if (Node* node = getNode()) { Node* clonedNode = context.findClonedNode(node); if (clonedNode) { audioClone->setNode(clonedNode); } } return audioClone; }
//----------------------------------------------------------------------------- // // VActorPhysicsController::preTickUpdate( pDelta ); // // ... // //----------------------------------------------------------------------------- void VActorPhysicsController::preTickUpdate( const F32 &pDelta ) { // Pop Delta. mInterpController.popDelta(); switch( mControlState ) { case k_PathControlState : { AssertFatal( isPathing(), "VActorPhysicsController::preTickUpdate() - Invalid Path State." ); // Fetch Mount Velocity. const VectorF &mountVelocity = mMountedPath->getMountVelocity( mObject->getMountNode() ); // Use X & Y Velocity. VectorF velocity = getVelocity(); velocity.x = mountVelocity.x; velocity.y = mountVelocity.y; // Apply Updates. setVelocity( velocity ); } break; } // Update Move State. updateMoveState(); }
void Particle::setInit(ofPoint _pos, ofPoint _vel, vector<float> _colMults) { pos = _pos; vel=_vel; for (int i; i<6; i++) { float col=_colMults[i]; cols.push_back(col); } //rotSeed = ofRandomf()*50; rotSeed = 0; breakCounter = 90; velMag; ofPoint velToColor = getVelocity(); velMag = velToColor.length(); colorMap = ofMap(velMag,1.5,4.5, 255,0, true); if (velMag > 2.5) { isLeaf = true; } else { isLeaf = false; } breakPoint = getBreakPoint(); //breakPoint = getBreakPoint()*getBreakPoint()*0.1; cout << "Break: " << breakPoint << endl; tailWidth = ofRandom(1,3); }
Firebug::Firebug() { int upMargin = 19; mSpriteSize = sf::Vector2f(48,48-upMargin); setVelocity((float)(( rand() % 10 ) + 35),100.f); mBasicVelocity = getVelocity(); mIsAttacking=false; Animation roll(sf::seconds(0.5)); for(int i=0;i<4;i++) roll.addFrame(sf::IntRect(mSpriteSize.x*i, mSpriteSize.y*2+upMargin*3, mSpriteSize.x,mSpriteSize.y)); mAnimation.addAnimation("roll",roll); Animation walk(sf::seconds(0.6f)); walk.addFrame(sf::IntRect(0, 0+upMargin, mSpriteSize.x,mSpriteSize.y)); walk.addFrame(sf::IntRect(0, mSpriteSize.y+upMargin*2, mSpriteSize.x,mSpriteSize.y)); walk.addFrame(sf::IntRect(mSpriteSize.x, mSpriteSize.y+upMargin*2, mSpriteSize.x,mSpriteSize.y)); mAnimation.addAnimation("walk",walk); mAnimation.playAnimation("walk"); if((rand() % 2)) mIsMovingLeft=true; else mIsMovingRight=true; }
virtual void process(YSE::SOUND_STATUS & intent) { // assert(intent != YSE::SS_STOPPED); if (intent == YSE::SS_WANTSTOPLAY) { ramp.set(1, 10); intent = YSE::SS_PLAYING; } else if (intent == YSE::SS_WANTSTOSTOP) { ramp.setIfNew(0, 200); } // generate tone with frequency and velocity out = generator[2](getFrequency() * 3); out *= 0.3; out += generator[1](getFrequency() * 2); out *= 0.6; out += generator[0](getFrequency()); out *= getVelocity() * 0.1f; ramp.update(); if (intent == YSE::SS_WANTSTOSTOP && ramp.getValue() <= 0) { intent = YSE::SS_STOPPED; } out *= ramp; // copy buffer to all channels (YSE creates the buffer vector for your dsp, according to // the channels chosen for the current output device for (UInt i = 0; i < samples.size(); i++) { samples[i] = out; } }
TrainerSprite::TrainerSprite(const std::string& name, int noFrames, cocos2d::Point pos) : MySprite::MySprite(name, noFrames, pos), moveLeft(false), moveRight(false), moveUp(false), moveDown(false), saveVelocity( getVelocity() ) { cocos2d::EventListenerKeyboard* l = cocos2d::EventListenerKeyboard::create(); l->onKeyPressed = [this](cocos2d::EventKeyboard::KeyCode keyCode,cocos2d::Event* event) { switch(keyCode) { case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_A: moveLeft = true; break; case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_D: moveRight = true; break; case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_S: moveDown = true; break; case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_W: moveUp = true; break; case cocos2d::EventKeyboard::KeyCode::KEY_SPACE: default: break; } }; l->onKeyReleased = [this](cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event){ switch(keyCode) { case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_A: moveLeft = false; break; case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_D: moveRight = false; break; case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_S: moveDown = false; break; case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_W: moveUp = false; break; default: break; } }; cocos2d::Director::getInstance()->getEventDispatcher()-> addEventListenerWithFixedPriority(l, 1); }
void Bullet::update(Uint32 ticks, bool isPaused) { if(isPaused){ return; } Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); }
LLVector3 LLWind::getVelocityNoisy(const LLVector3 &pos_region, const F32 dim) { static const LLCachedControl<bool> wind_enabled("WindEnabled",false); if(!wind_enabled) { return LLVector3(0.f, 0.f, 0.f); } // Resolve a value, using fractal summing to perturb the returned value LLVector3 r_val(0,0,0); F32 norm = 1.0f; if (dim == 8) { norm = 1.875; } else if (dim == 4) { norm = 1.75; } else if (dim == 2) { norm = 1.5; } F32 temp_dim = dim; while (temp_dim >= 1.0) { LLVector3 pos_region_scaled(pos_region * temp_dim); r_val += getVelocity(pos_region_scaled) * (1.0f/temp_dim); temp_dim /= 2.0; } return r_val * (1.0f/norm) * WIND_SCALE_HACK; }
LLVector3 LLWind::getVelocityNoisy(const LLVector3 &pos_region, const F32 dim) { // Resolve a value, using fractal summing to perturb the returned value LLVector3 r_val(0,0,0); F32 norm = 1.0f; if (dim == 8) { norm = 1.875; } else if (dim == 4) { norm = 1.75; } else if (dim == 2) { norm = 1.5; } F32 temp_dim = dim; while (temp_dim >= 1.0) { LLVector3 pos_region_scaled(pos_region * temp_dim); r_val += getVelocity(pos_region_scaled) * (1.0f/temp_dim); temp_dim /= 2.0; } return r_val * (1.0f/norm) * WIND_SCALE_HACK; }
void Particle::update(float timeSinceLastUpdate) { const Point &position = getPosition(); const Vector3D &velocity = getVelocity(); // decrease lifetime _lifetime -= timeSinceLastUpdate; // compute new position float speed = sqrt( velocity.x*velocity.x + velocity.y*velocity.y + velocity.z*velocity.z ); if ( speed < 0.1 ) { setVelocity( Vector3D( 0.0, 0.0, 0.0 ) ); } Point newPosition( position.x + velocity.x * timeSinceLastUpdate, position.y + velocity.y * timeSinceLastUpdate + 0.5 * GRAVITATIONAL_ACCELARATION * timeSinceLastUpdate * timeSinceLastUpdate, position.z + velocity.z * timeSinceLastUpdate ); Vector3D newVelocity( velocity.x, velocity.y + GRAVITATIONAL_ACCELARATION * timeSinceLastUpdate, velocity.z ); // reflect and slow down the particle, if it hits the ground if( newPosition.y < _radius) { newVelocity = Vector3D(newVelocity.x * 0.4, -newVelocity.y * 0.4, newVelocity.z * 0.4); newPosition = Point(newPosition.x, 0.0 + _radius, newPosition.z); } // update configuration setPosition( newPosition ); setVelocity( newVelocity ); }
Meteor::Meteor(const std::string& name) : Drawable(name, Vector2f(getVariation(name,"/startLoc/x", Gamedata::getInstance().getXmlInt(name+"/minDist"), Gamedata::getInstance().getXmlInt(name+"/maxDist") ), Gamedata::getInstance().getXmlInt(name+"/startLoc/y") ), Vector2f(Gamedata::getInstance().getXmlInt(name+"/speedX"), Gamedata::getInstance().getXmlInt(name+"/speedY") ) ), explosion(NULL), zoom(Gamedata::getInstance().getRandFloat( 0.2, 1.0 )), frame( FrameFactory::getInstance().getFrame(name) ), frameWidth(frame->getWidth()), frameHeight(frame->getHeight()), worldWidth(Gamedata::getInstance().getXmlInt("world/width")), worldHeight(Gamedata::getInstance().getXmlInt("world/height")), hasExploded( false ) { Vector2f change = getVelocity()*zoom; //This step was done in the constructor as an assignment statement because the zoom factor which is a part of this class can setVelocity( change ); //only be initialized after the base class members are initialized thus preventing us from directly initializing the velocity //according to the size of the meteor to produce the depth effect. }
void Ball::move(float delta) { this->setPosition(getPosition() + getVelocity() * delta); auto bBox = getBoundingBox(); auto ballRight = bBox.getMaxX(); auto ballLeft = bBox.getMinX(); if (ballRight > VisibleRect::right().x) { setPosition(Point(VisibleRect::right().x - radius(), getPosition().y) ); _velocity.x *= -1; } else if (ballLeft < VisibleRect::left().x) { setPosition(Point(VisibleRect::left().x + radius(), getPosition().y) ); _velocity.x *= -1; } if (getPosition().y > VisibleRect::top().y - radius()) { setPosition(Point(getPosition().x, VisibleRect::top().y - radius())); _velocity.y *= -1; } else if (getPosition().y < VisibleRect::bottom().y + radius()) { setPosition(Point(getPosition().x, VisibleRect::bottom().y + radius())); _velocity.y *= -1; } }
void Meteor::update(Uint32 ticks) { if ( explosion ) { explosion->update(ticks); if ( explosion->chunkCount() == 0 ) { delete explosion; explosion = NULL; } return; } Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if ( X() < 0) { velocityX( abs( velocityY() ) ); } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); } if ( Y() > worldHeight-frameHeight) { Y(0); //wraparound on X-axis X( Gamedata::getInstance().getRandInRange(0, worldWidth-frameWidth) ); } }
void Sprite::update(Uint32 ticks) { Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); /* if ( Y() < 0) { velocityY( abs( velocityY() ) ); //delete this; } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); //delete this; } if ( X() < 0) { velocityX( abs( velocityX() ) ); //delete this; } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); //delete this; }*/ }
bool CollisionObject::isCollisionWithTileRight() { // iterate through collision layers for (std::vector<TileLayer*>::const_iterator it = m_pCollisionLayers->begin(); it != m_pCollisionLayers->end(); ++it) { TileLayer* pTileLayer = (*it); std::vector<std::vector<int>> tiles = pTileLayer->getTileIDs(); // get this layers position Vector2D layerPos = pTileLayer->getPosition(); int x, y, tileColumn, tileRow, tileid = 0; // calculate position on tile map x = layerPos.getX() / pTileLayer->getTileSize(); y = layerPos.getY() / pTileLayer->getTileSize(); if (getVelocity().getX() > 0) //dreta { tileColumn = ((getPosition().getX() + Camera::Instance()->getPosition().getX() + getWidth()) / pTileLayer->getTileSize()); tileRow = (getPosition().getY() / pTileLayer->getTileSize()); tileid = tiles[tileRow+y][tileColumn + x];//Li restem 1 a la y perque quan estiguem asobre la plataforma no ens doni colisio } if (tileid != 0) // if the tile id not blank then collide { return true; } } return false; }
void FlyingVehicle::updateEmitter(bool active,F32 dt,ParticleEmitterData *emitter,S32 idx,S32 count) { if (!emitter) return; for (S32 j = idx; j < idx + count; j++) if (active) { if (mDataBlock->jetNode[j] != -1) { if (!bool(mJetEmitter[j])) { mJetEmitter[j] = new ParticleEmitter; mJetEmitter[j]->onNewDataBlock(emitter,false); mJetEmitter[j]->registerObject(); } MatrixF mat; Point3F pos,axis; mat.mul(getRenderTransform(), mShapeInstance->mNodeTransforms[mDataBlock->jetNode[j]]); mat.getColumn(1,&axis); mat.getColumn(3,&pos); mJetEmitter[j]->emitParticles(pos,true,axis,getVelocity(),(U32)(dt * 1000)); } } else { for (S32 j = idx; j < idx + count; j++) if (bool(mJetEmitter[j])) { mJetEmitter[j]->deleteWhenEmpty(); mJetEmitter[j] = 0; } } }
void PxcFsApplyJointDrives(PxcFsData& matrix, const Vec3V* Q) { typedef PxcArticulationFnsSimd<PxcArticulationFnsSimdBase> Fns; PX_ASSERT(matrix.linkCount<=PXC_ARTICULATION_MAX_SIZE); const PxcFsRow* rows = getFsRows(matrix); const PxcFsRowAux* aux = getAux(matrix); const PxcFsJointVectors* jointVectors = getJointVectors(matrix); PxcSIMDSpatial Z[PXC_ARTICULATION_MAX_SIZE]; PxcSIMDSpatial dV[PXC_ARTICULATION_MAX_SIZE]; Vec3V SZminusQ[PXC_ARTICULATION_MAX_SIZE]; PxMemZero(Z, matrix.linkCount*sizeof(PxcSIMDSpatial)); for(PxU32 i=matrix.linkCount;i-->1;) Z[matrix.parent[i]] += propagateDrivenImpulse(rows[i], jointVectors[i], SZminusQ[i], Z[i], Q[i]); dV[0] = Fns::multiply(getRootInverseInertia(matrix), -Z[0]); for(PxU32 i=1;i<matrix.linkCount;i++) dV[i] = Fns::propagateVelocity(rows[i], jointVectors[i], SZminusQ[i], dV[matrix.parent[i]], aux[i]); PxcSIMDSpatial* V = getVelocity(matrix); for(PxU32 i=0;i<matrix.linkCount;i++) V[i] += dV[i]; }
//------------------------------------------- void BlockBehaviourAir::update(float dt) { //simply negate sideways movement and allow gravity to do its thing auto vel = getVelocity(); vel.x *= getFriction(); setVelocity(vel); sf::Int32 cat = getParentCategory(); if (cat & (Category::CarriedOne | Category::CarriedTwo)) { //can't carry blocks which are in the air Event e; e.type = Event::Player; e.player.action = Event::PlayerEvent::Dropped; e.player.playerId = (cat & (Category::CarriedOne)) ? Category::PlayerOne : Category::PlayerTwo; e.player.positionX = 0.f; e.player.positionY = 0.f; raiseEvent(e); } if (getFootSenseMask() == CollisionWorld::Body::Type::Water) //touches water only { setBehaviour<BlockBehaviourWater>(); Event e; e.type = Event::Block; e.block.action = Event::BlockEvent::HitWater; auto pos = getBody()->getCentre(); e.block.positionX = pos.x; e.block.positionY = pos.y; raiseEvent(e); } }
bool Player::collided(Object* collider) { // Grab information about the collision :NOTE: Could be done in a better way, ie collided has that information as a parameter Collision collision = polyCollision(collider->getBody(), this->getBody()); // True if the player is on the ground // Needs to check the y velocity because the objects can still be inside each other, but on their way of separating, might take 2-4 frames for them to be 100% separated if(collision.pushY < 0 && getVelocity().y > 0) { // Test of collided with self or the weapon :NOTE: Check against itself shouldn't be needed if(collider != this && collider->getParent() != this) { if(mInAir) { mInAir = false; mAnimation->setFrame(0); } } } if(collider->getType() == PARTICLE) { mStunned = true; mStunnedCounter = 0.30f; } return true; }
void Hero::update(Uint32 ticks) { if ( explosion ) { explosion->update(ticks); if ( explosion->chunkCount() == 0 ) { delete explosion; explosion = NULL; } return; } if(special != NULL) { special->advanceFrame(ticks); special->setPosition(this->getPosition()-Vector2f(20,50)); } advanceFrame(ticks); Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if ( Y() <= 0) { velocityY( abs( velocityY() ) ); } if ( Y() >= worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); } if ( X() <= 0) { velocityX( abs( velocityX() ) ); right = true; } if ( X() >= worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); right = false; } }
void Bee::seek(sf::Vector2f pos) { if (!mSeeking) return; b2Vec2 physPos = mB2Body->GetPosition(); b2Vec2 currentVelocity = getVelocity(); sf::Vector2f previousRenderPos = mSprite.getPosition(); float mapHeight = previousRenderPos.y + mPreviousPosition.y * PX_PER_M; b2Vec2 differenceVector( pos.x / PX_PER_M - physPos.x, mapHeight / PX_PER_M - pos.y / PX_PER_M - physPos.y); //Vector normalization float mag = sqrt(pow(differenceVector.x, 2) + pow(differenceVector.y, 2)); b2Vec2 directionVector( differenceVector.x / mag, differenceVector.y / mag); b2Vec2 movementVector( directionVector.x * mMoveVelocity, directionVector.y * mMoveVelocity); //Steering behaviour b2Vec2 steeringVector( (movementVector.x - currentVelocity.x) / mSteering, (movementVector.y - currentVelocity.y) / mSteering); b2Vec2 seekVector( currentVelocity.x + steeringVector.x, currentVelocity.y + steeringVector.y); setVelocity(seekVector); }
void OverheadPlayer::accelerateCenter(b2Vec2 force) { b2Vec2 velocity = getVelocity(); if(velocity.x > speedLimit) { setVelocity(b2Vec2(speedLimit, velocity.y)); if(force.x > 0.f) force.x = 0.f; } else if(velocity.x < speedLimit*-1) { setVelocity(b2Vec2(speedLimit*-1, velocity.y)); if(force.x < 0.f) force.x = 0.f; } if(velocity.y > speedLimit) { setVelocity(b2Vec2(velocity.x, speedLimit)); if(force.y > 0.f) force.y = 0.f; } else if(velocity.y < speedLimit*-1) { setVelocity(b2Vec2(velocity.x, speedLimit*-1)); if(force.y < 0.f) force.y = 0.f; } Entity::accelerateCenter(force); }
void Player::onDestroy() { gdata.audio->playSound("explosion"); explode_emitter.pos = getAbsolutePosition(); explode_emitter.enabled = true; explode_emitter.v = getVelocity(); draw_player = false; m_active = false; if (!gdata.show_progress) { if (m_type != GHOST_PLAYER) { cout << "you died" << endl; gdata.countdown = 2.f; } } // a bit dodgey but oh well else { if (!gdata.replay_level) { AchievementBar* a = new AchievementBar; a->init(); a->setText("Die after completing a level"); gdata.achieves.push_back(a); } } deletePhysicsObject(); }
/** Resolve collision with an immovable object Computes & applies the collision impulse needed to keep the body from penetrating the given surface. */ bool Rigid::resolveCollision(const Point3F& p, const Point3F &normal) { atRest = false; Point3F v,r; getOriginVector(p,&r); getVelocity(r,&v); F32 n = -mDot(v,normal); if (n >= 0.0f) { // Collision impulse, straight forward force stuff. F32 d = getZeroImpulse(r,normal); F32 j = n * (1.0f + restitution) * d; Point3F impulse = normal * j; // Friction impulse, calculated as a function of the // amount of force it would take to stop the motion // perpendicular to the normal. Point3F uv = v + (normal * n); F32 ul = uv.len(); if (ul) { uv /= -ul; F32 u = ul * getZeroImpulse(r,uv); j *= friction; if (u > j) u = j; impulse += uv * u; } // applyImpulse(r,impulse); } return true; }
void MultiSprite::update(Uint32 ticks) { if ( explosion ) { explosion->update(ticks); if ( explosion->chunkCount() == 0 ) { delete explosion; explosion = NULL; } return; } advanceFrame(ticks); Vector2f incr = getVelocity() * static_cast<float>(ticks) * 0.001; setPosition(getPosition() + incr); if ( Y() < 0) { velocityY( abs( velocityY() ) ); } if ( Y() > worldHeight-frameHeight) { velocityY( -abs( velocityY() ) ); } if ( X() < 0) { velocityX( abs( velocityX() ) ); } if ( X() > worldWidth-frameWidth) { velocityX( -abs( velocityX() ) ); } }
void AnimateableCharacter::update(Ogre::Real timeSinceLastFrame) { updatePosition(timeSinceLastFrame); if (mClipTo) clipToTerrainHeight(); Ogre::Vector3 velocity = getVelocity(); // Current velocity of agent Ogre::Real speed = velocity.length(); if(speed > 0.15) { //mAnimState->setEnabled(true); //mAnimState->addTime(mAnimSpeedScale * speed * timeSinceLastFrame); if(speed > 0/*0.8*/) { // Avoid jitter (TODO keep this?) // Rotate to look in walking direction Ogre::Vector3 src = getLookingDirection(); src.y = 0; // Ignore y direction velocity.y = 0; velocity.normalise(); mNode->rotate(src.getRotationTo(velocity)); } } else { // Assume character has stopped mAnimState->setEnabled(false); mAnimState->setTimePosition(0); } }