Exemplo n.º 1
0
void Projectile::Refresh(const float &fDeltaTime)
{
	PhysicalObject::Refresh(fDeltaTime);

	//rotate the projectile based on the direction it is traveling

	//update the rotation for debug visual display
	Quat *quat = &(GetNode()->m_PosQuat.quat);
	Quat rotation;
	rotation.CreateFromRotationRADIANS(fDeltaTime * 0.75f * PI, m_vVelocity.x, m_vVelocity.y, m_vVelocity.z);
	*quat = rotation * *quat;
}
Exemplo n.º 2
0
void NothingScene::HandleMouseMove(const int &dwX, const int &dwY, const int &dwDeltaX, const int &dwDeltaY)
{	
	//update the rotation for debug display based on the mouse movement!
	Quat *quat = &(m_PosQuat.quat);
	Quat rotation;
	VECTOR3 axis; 	
	axis.x = (float) dwDeltaY;	
	axis.y = (float) dwDeltaX;	

	rotation.CreateFromRotationRADIANS(PI / 360.0f * (float)(abs(dwDeltaX) + abs(dwDeltaY)), axis.x, axis.y, axis.z);
	*quat = rotation * *quat;
}
Exemplo n.º 3
0
void TestObject::Refresh(const float &fDeltaTime)
{
	return; //no rotating for now

	VECTOR3 *pos = &(m_pNode->m_PosQuat.pos);
	Quat *quat = &(m_pNode->m_PosQuat.quat);

	goto hacky;

	//update the position with some crappy bouncing thing
	if (bXUp)
	{
		pos->x += 0.05f;

		if (pos->x > 2.0f)
		{
			bXUp = !bXUp;
		}
	}
	else
	{
		pos->x -= 0.05f;

		if (pos->x < -2.0f)
		{
			bXUp = !bXUp;
		}
	}

hacky:
	//update the rotation!
	//rotate by small amount every time
	Quat rotation;

	VECTOR3 axis;
	axis.x = 0.1f;
	axis.y = 1.0f;
	axis.z = 0.2f;
	//NormalizeVECTOR3(axis);

	rotation.CreateFromRotationRADIANS(0.02f, axis.x, axis.y, axis.z);
	*quat = rotation * *quat;
}
Exemplo n.º 4
0
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();	
			}
		}
	}
}