本文整理汇总了C++中TimeDuration::realSeconds方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeDuration::realSeconds方法的具体用法?C++ TimeDuration::realSeconds怎么用?C++ TimeDuration::realSeconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeDuration
的用法示例。
在下文中一共展示了TimeDuration::realSeconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: apply
void AccelerateAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime)
{
// basic physics
// v = a t
// d = v t
// d = 1/2 a t^2
// delta_d = 1/2 a t^2 - 1/2 a (t-delta_t)^2 : 6 *, 2 -
// alternate forms (thanks to wolfram alpha)
// delta_d = -1/2 a delta_t (delta_t - 2 t) : 4 *, 1 - (using this one)
// delta_d = a delta_t t - (a delta_t^2)/2 : 4 *, 1 /, 1 -
// delta_d = 1/2 a delta_t (2 t - delta_t) : 4 *, 1 -
elapsedTime += deltaTime;
double delta_t = deltaTime.realSeconds();
double t = elapsedTime.realSeconds();
Point position = target->position();
currentSpeed = t * yPixelsPerSecondSquared;
if( (useMaxSpeed && (currentSpeed <= maxSpd)) || (!useMaxSpeed))
{
position.y() += -.5 * yPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);
}
else
{
position.y() += maxSpd *delta_t;
}
position.x() += -.5 * xPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);
target->setPosition(position);
}
示例2: interactWithOtherTruck
void OpponentAI::interactWithOtherTruck(const Rectangle& truckRect, const Rectangle& opRect, const TimeDuration& deltaTime)
{
if (getTruckController()->isDestroyed()) {
return;
}
// if we are out of armor, avoid collisions, but still shoot.
if(getTruckController()->getTruck()->truckParams.truckArmor <= 0)
{
if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect))
{
if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds())
{
setInteracted(true);
shoot = true;
getTruckController()->getShotGun().shoot();
getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast);
// TODO: If we want, this is where an opponent shotgun sound would go
}
}
return;
}
// else we have armor, so try to attack
if (isOpponentLeft(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect))
{
if (truckRect.left - opRect.right < hitRange)
{
getTruckController()->getTruck()->setInputLeft(true);
setInteracted(true);
//LOGI("Hit left");
}
}
else if (isOpponentRight(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect))
{
if (opRect.left - truckRect.right < hitRange)
{
getTruckController()->getTruck()->setInputRight(true);
setInteracted(true);
//LOGI("Hit right");
}
}
else if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect))
{
if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds())
{
setInteracted(true);
shoot = true;
getTruckController()->getShotGun().shoot();
getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast);
// TODO: If we want to, this is where an opponent shotgun sound would go.
}
}
}
示例3: apply
void FPSAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime)
{
++m_framesPassed;
m_timeElapsed += deltaTime;
TimeDuration desiredUpdatePeriod = Time::microseconds(250000);
if( (m_timeElapsed > desiredUpdatePeriod) && (m_framesPassed > 3) )
{
boost::intrusive_ptr<Label> label = boost::dynamic_pointer_cast<Label>(target);
if( label )
{
float fps = m_framesPassed / m_timeElapsed.realSeconds();
label->setText( m_prefix + String(fps).substring(0,4) );
}
m_timeElapsed = TimeDuration(fmod(m_timeElapsed.realSeconds(), desiredUpdatePeriod.realSeconds()));
m_framesPassed = 0;
}
}