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 ); }
void HRVOAgent::updateDesideredVelocity() { setup(); _HRVOAgent->computeNewVelocity(); CVector2 newVelocity(_HRVOAgent->newVelocity_.x(),_HRVOAgent->newVelocity_.y()); desideredAngle=(newVelocity.Angle()-angle).SignedNormalize(); desideredSpeed=abs(_HRVOAgent->newVelocity_); }
void PlatformsCharacterRbDemo::moveVerticalPlatform() { const hkReal velAplitude = 3.0f; const hkReal velOmega = 1.0f; hkVector4 newVelocity; newVelocity = m_verPlatform->getLinearVelocity(); newVelocity(2) = velAplitude*cos(velOmega*m_time); m_verPlatform->setLinearVelocity(newVelocity); }
DOUBLE2 MassProjList::HandleCircularCollision(DOUBLE2 otherCirclePos,DOUBLE2 otherCircleVelocity, double radius, double mass) { DOUBLE2 velocity(0,0), newVelocity(0,0); velocity=otherCircleVelocity; for (int count=0; count < MAX_MASSPROJECTILES; ++count) { if (m_MassProjectilePtrArr[count] != nullptr) { newVelocity=m_MassProjectilePtrArr[count]->HandleCircularCollision(otherCirclePos,velocity ,radius, mass ); if (newVelocity!=DOUBLE2(0,0)) velocity= newVelocity; } } return velocity; }
/** * This function builds up a matrix describing the movement of the * camera over dTime seconds. */ Matrix& CameraControl::calculateDeltaMatrix( float dTime ) { BW_GUARD; Matrix m; deltaMatrix_.setIdentity(); strafeRate_ += strafeRateVel_; strafeRate_ = strafeRate_ > 0.0f ? strafeRate_ : 0.0f; if (0) // turning left { m.setRotateY( DEG_TO_RAD(60.f*dTime)); deltaMatrix_.postMultiply(m); } if (0) // turning right { m.setRotateY( -DEG_TO_RAD(60.f*dTime)); deltaMatrix_.postMultiply(m); } if (0) // rolling left { m.setRotateZ( -DEG_TO_RAD(60.f*dTime)); deltaMatrix_.postMultiply(m); } if (0) // rolling right { m.setRotateZ( DEG_TO_RAD(60.f*dTime)); deltaMatrix_.postMultiply(m); } Vector3 newNudge( xNudge_ + xVel_, yNudge_ + yVel_, zNudge_ + zVel_ ); newNudge *= strafeRate_; CameraControl::nudge( newNudge ); // Update nudge and velocity. float halfLife = cameraMass() * 0.1f; if ( halfLife > 0.0 ) { float x = nudge().x == 0.0f ? Math::decay( velocity().x, nudge().x, halfLife * 0.3f, dTime ) : Math::decay( velocity().x, nudge().x, halfLife, dTime ); float y = nudge().y == 0.0f ? Math::decay( velocity().y, nudge().y, halfLife * 0.3f, dTime ) : Math::decay( velocity().y, nudge().y, halfLife, dTime ); float z = nudge().z == 0.0f ? Math::decay( velocity().z, nudge().z, halfLife * 0.3f, dTime ) : Math::decay( velocity().z, nudge().z, halfLife, dTime ); Vector3 newVelocity( x, y, z ); CameraControl::velocity( newVelocity ); } else { CameraControl::velocity( nudge() ); } // CameraControl::velocity( nudge() ); // Update position. m.setTranslate( velocity() * dTime ); deltaMatrix_.postMultiply( m ); return deltaMatrix_; }
void SteeringVehicle::update(const float currentTime, const float elapsedTime) { SimpleVehicle::update(currentTime, elapsedTime); Vector3 pos = mCreature->getPosition(); setPosition(pos); OgreNewt::Body* body = mCreature->getActor()->getPhysicalThing()->_getBody(); // Get the velocity vector mCurrentVelocity = body->getVelocity(); // enforce speed limit // newVelocity = newVelocity.truncateLength(maxSpeed()); // update speed setSpeed(mCurrentVelocity.length()); Vector3 newVelocity(mCurrentVelocity); // regenerate local space(by default: align vehicle's forward axis with // new velocity, but this behavior may be overridden by derived classes.) // use future orientation or not?? Quaternion orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y); Vector3 newUnitForward = orientation*Vector3::NEGATIVE_UNIT_Z; regenerateOrthonormalBasisUF(newUnitForward); // only process if mMovingCreature not NULL if (mController == NULL || mCreature->getQueryFlags() & QUERYFLAG_PLAYER) { mCurrentForce = Vector3::ZERO; return; } // calculate the result of the force Vector3 result = mCurrentForce;// + mCurrentVelocity; mDebugSteer = mCurrentForce; // @todo remove this if (mCreature->getAu() <= 6) mCreature->modifyAu(20,true); AbstractMovement* mov_drehen = mController->getMovementFromId(CreatureController::MT_DREHEN); Real vel_drehen(0); Radian max_drehen = Degree(0); if (mov_drehen->calculateBaseVelocity(vel_drehen)) { max_drehen = Degree(vel_drehen * 360 * elapsedTime); } Ogre::Quaternion future_orientation(mController->getYaw(), Ogre::Vector3::UNIT_Y); Ogre::Vector3 creatureDirection = future_orientation * Ogre::Vector3::NEGATIVE_UNIT_Z; Radian yaw(0); creatureDirection.y = result.y = 0; yaw = creatureDirection.getRotationTo(result, Ogre::Vector3::UNIT_Y).getYaw(); if (yaw > Radian(0) && yaw > max_drehen) yaw = max_drehen; if (yaw < Radian(0) && yaw < -max_drehen) yaw = -max_drehen; Ogre::Vector3 direction(Ogre::Vector3::ZERO); Ogre::Vector3 rotation(0,yaw.valueRadians(),0); CreatureController::MovementType movement = CreatureController::MT_STEHEN; if (result != Ogre::Vector3::ZERO) { direction.z = -1; movement = CreatureController::MT_GEHEN; } mController->setMovement(movement, direction, rotation); LOG_DEBUG(Logger::AI, "SteeringVehicle: mController->setMovement " + Ogre::StringConverter::toString(movement) + ", " + Ogre::StringConverter::toString(direction) + ", " + Ogre::StringConverter::toString(rotation)); mCurrentForce = Ogre::Vector3::ZERO; }