当前位置: 首页>>代码示例>>C++>>正文


C++ Entity::GetInterpolatedTransform方法代码示例

本文整理汇总了C++中Entity::GetInterpolatedTransform方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::GetInterpolatedTransform方法的具体用法?C++ Entity::GetInterpolatedTransform怎么用?C++ Entity::GetInterpolatedTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Entity的用法示例。


在下文中一共展示了Entity::GetInterpolatedTransform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

// Weapon Update
void Weapon::Update(float aStep)
{
	// get controller
	const Controller *controller = Database::controller.Get(mControlId);
	if (!controller)
		return;

	// advance fire timer
	mTimer += aStep;

	// get template data
	const WeaponTemplate &weapon = Database::weapontemplate.Get(mId);

	// get trigger value
	float fire = controller->mFire[mChannel];
	bool trigger;
	switch (weapon.mTrigger)
	{
	default:
	case WeaponTemplate::TRIGGER_HOLD: trigger = fire != 0; break;
	case WeaponTemplate::TRIGGER_PRESS: trigger = fire != 0 && mPrevFire == 0; break;
	case WeaponTemplate::TRIGGER_RELEASE: trigger = fire == 0 && mPrevFire != 0; break;
	}
	mPrevFire = fire;

	// if triggered...
	if (trigger)
	{
		// if not busy
		if (mBurst <= 0 && mTimer > -0.001f && (!weapon.mTrack || mTrack < weapon.mTrack))
		{
			// if firing on this phase...
			if (mPhase == 0)
			{
				Resource *resource = NULL;

				// if using ammo
				if (weapon.mCost)
				{
					// ammo resource (if any)
					resource = Database::resource.Get(mAmmo).Get(weapon.mType);
				}

				// if enough ammo...
				if (!resource || weapon.mCost <= resource->GetValue())
				{
					// deduct ammo
					if (resource)
						resource->Add(mId, -weapon.mCost);

					// start a new burst
					mTimer -= weapon.mBurstStart;
					mBurst = weapon.mBurstLength;
				}
				else
				{
					// start "empty" sound cue
					PlaySoundCue(mId, 0x18a7beee /* "empty" */);
				}

				// wrap around
				mPhase = weapon.mCycle - 1;
			}
			else
			{
				// advance phase
				--mPhase;

				// wait for next phase
				mTimer -= weapon.mDelay / weapon.mCycle;
			}
		}
	}

	// if ready to fire...
	while (mBurst > 0 && mTimer > -0.001f && (!weapon.mTrack || mTrack < weapon.mTrack))
	{
		// deduct a burst
		--mBurst;

		// get the entity
		Entity *entity = Database::entity.Get(mId);

		// start the "fire" sound cue
		PlaySoundCue(mId, 0x8eab16d9 /* "fire" */);

		// interpolated transform
		Transform2 basetransform(entity->GetInterpolatedTransform(mTimer / aStep));

		for (int salvo = 0; salvo < weapon.mSalvoShots; ++salvo)
		{
			// get local position
			Transform2 position(weapon.mOffset);

			// apply transform offset
			Transform2 transform(position * basetransform);

			if (weapon.mRecoil)
			{
//.........这里部分代码省略.........
开发者ID:Fissuras,项目名称:videoventure,代码行数:101,代码来源:WeaponOriginal.cpp

示例2: Update

// spawner update
void Spawner::Update(float aStep)
{
	// get the spawner template
	const SpawnerTemplate &spawner = Database::spawnertemplate.Get(mId);

	// skip if limit reached
	if (spawner.mTrack && mTrack >= spawner.mTrack)
		return;

	// advance the timer
	mTimer += aStep;

	// if the timer elapses...
	while (mTimer > 0.0f)
	{
		// get the spawner entity
		Entity *entity = Database::entity.Get(mId);
		if (!entity)
			return;

		// TO DO: consolidate this with similar spawn patterns (Graze, Weapon)

		// interpolated transform
		Transform2 transform(entity->GetInterpolatedTransform(mTimer / aStep));

		// apply transform offset
		transform = spawner.mOffset * transform;

		// apply transform scatter
		if (spawner.mScatter.a)
			transform.a += Random::Value(0.0f, spawner.mScatter.a);
		if (spawner.mScatter.p.x)
			transform.p.x += Random::Value(0.0f, spawner.mScatter.p.x);
		if (spawner.mScatter.p.y)
			transform.p.y += Random::Value(0.0f, spawner.mScatter.p.y);

		// get local velocity
		Transform2 velocity(entity->GetOmega(), transform.Unrotate(entity->GetVelocity()));

		// apply velocity inherit
		velocity.a *= spawner.mInherit.a;
		velocity.p.x *= spawner.mInherit.p.x;
		velocity.p.y *= spawner.mInherit.p.y;

		// apply velocity add
		velocity.a += spawner.mVelocity.a;
		velocity.p.x += spawner.mVelocity.p.x;
		velocity.p.y += spawner.mVelocity.p.y;

		// apply velocity variance
		if (spawner.mVariance.a)
			velocity.a += Random::Value(0.0f, spawner.mVariance.a);
		if (spawner.mVariance.p.x)
			velocity.p.x += Random::Value(0.0f, spawner.mVariance.p.x);
		if (spawner.mVariance.p.y)
			velocity.p.y += Random::Value(0.0f, spawner.mVariance.p.y);

		// get world velocity
		velocity.p = transform.Rotate(velocity.p);

		// apply fractional turn (HACK)
		transform.a += velocity.a * (aStep - mTimer);
		transform.p += velocity.p * (aStep - mTimer);

		// instantiate the spawn entity
		if (unsigned int spawnId = Database::Instantiate(spawner.mSpawn, Database::owner.Get(mId), mId, transform.a, transform.p, velocity.p, velocity.a, false))
		{
			// if the spawner has a team...
			unsigned int team = Database::team.Get(mId);
			if (team)
			{
				// propagate team to spawned item
				Database::team.Put(spawnId, team);
			}

			// activate
			Database::Activate(spawnId);

			// set fractional turn
			if (Renderable *renderable = Database::renderable.Get(spawnId))
				renderable->SetFraction(mTimer / aStep);

			// if tracking....
			if (spawner.mTrack)
			{
				// add a tracker
				Database::spawnertracker.Put(spawnId, SpawnerTracker(mId));
			}
		}

		// set the timer
		mTimer -= spawner.mCycle;

		// if tracking....
		if (spawner.mTrack)
		{
			// stop if out of slots
			if (mTrack >= spawner.mTrack)
				break;
//.........这里部分代码省略.........
开发者ID:Fissuras,项目名称:videoventure,代码行数:101,代码来源:Spawner.cpp


注:本文中的Entity::GetInterpolatedTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。