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


C++ PhysicalObject::GetNode方法代码示例

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


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

示例1: Fire

void Weapon::Fire()
{
	if (m_fCurrentCooldown <= 0.0f)
	{
		m_fCurrentCooldown = m_fCooldown;

		PhysicalObject *pOwner = GetOwner();
		
		if (pOwner)
		{
			Node			*pSourceNode = pOwner->GetNode();
			
			if (pSourceNode)
			{
				Projectile *pNewProjectile = new Projectile(GetNode());
				VECTOR3 vDirection;

				Matrix44 mat = pSourceNode->m_PosQuat.quat.ToMatrix();

				float yDisp = -(pSourceNode->m_vScale.y / 2.0f + pNewProjectile->GetNode()->m_vScale.y / 2.0f);

				if (pSourceNode->GetNodeFlags() & NODE_RENDER_UPSIDEDOWN)
				{
					yDisp *= -1.0f;
				}

				pNewProjectile->GetNode()->m_PosQuat.pos.x = mat.m[4] * yDisp + pSourceNode->m_PosQuat.pos.x;
				pNewProjectile->GetNode()->m_PosQuat.pos.y = mat.m[5] * yDisp + pSourceNode->m_PosQuat.pos.y;
				pNewProjectile->GetNode()->m_PosQuat.pos.z = mat.m[6] * yDisp + pSourceNode->m_PosQuat.pos.z;

				//calculate actual firing direction based on aim, and weapon spread
				int dwRandom = GenerateRandomInt(9);
				float fSpread = 0.0f;
				if (dwRandom < 7)
				{
					fSpread = GenerateRandomFloat(0.05f);
				}
				else if (dwRandom < 9)
				{
					fSpread = GenerateRandomFloat(0.15f) + 0.05f;
				}
				else
				{
					fSpread = GenerateRandomFloat(0.30f) + 0.2f;
				}
				
				if (GenerateRandomInt(1))
				{
					fSpread = -fSpread;
				}
				
				fSpread = fSpread * m_fFiringSpread;
				float fCos = cos(fSpread);
				float fSin = sin(fSpread);
				
				//vDirection.x = fCos * m_vAim.x + fSin * m_vAim.x;
				//vDirection.y = fCos * m_vAim.y - fSin * m_vAim.y;
				vDirection.x = fCos * m_vAim.x - fSin * m_vAim.y;
				vDirection.y = fSin * m_vAim.x + fCos * m_vAim.y;
				vDirection.z = 0.0f;

				NormalizeVECTOR3(vDirection);

				pNewProjectile->GetNode()->m_PosQuat.pos.z = pSourceNode->m_PosQuat.pos.z;
				pNewProjectile->SetMaxSpeed(m_fSpeed);

				pNewProjectile->SetVelocity(VECTOR3(m_fSpeed * vDirection.x, m_fSpeed * vDirection.y, m_fSpeed * vDirection.z));
				pNewProjectile->SetCreator(pOwner);
				pNewProjectile->SetWeapon(this);

				Quat *quat = &(pNewProjectile->GetNode()->m_PosQuat.quat);
				Quat rotation;
				rotation.CreateFromRotationRADIANS(fSpread, 0.0f, 0.0f, 1.0f);
				*quat = rotation * *quat;

				TestFireEvent *pTestFireEvent = new TestFireEvent();
				pTestFireEvent->SetProjectile(pNewProjectile);
				gEventManager()->AddEvent(pTestFireEvent);
				pTestFireEvent->Release();
				pNewProjectile->Release();	
			}
		}
	}
}
开发者ID:scottrick,项目名称:dgame,代码行数:84,代码来源:Weapon.cpp


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