Example #1
0
void MainWindow::Shot()
{
	if (fGunAnim) return;
	PlaySound("gun.wav", NULL, SND_ASYNC|SND_FILENAME|SND_NODEFAULT);
	fGunAnim = true;
	fShowMuzzleFlash = true;

	Matrix44f camView = camera.GetViewMatrix();
	for (int i = 0; i < numTargets; i++) 
	{
		if (targets[i].fShot) continue;

		Model *m = targets[i].model;
		Matrix44f mat = (camView * m->GetTransformRef()).GetInverse();

		Point3f p1 = Point3f(Point4f(0, 0, -3, 1) * mat);
		Point3f p2 = Point3f(Point4f(0, 0, -4, 1) * mat);
		Ray ray(p1, p2 - p1);

		if (m->meshes[1]->boundingBox.Intersects(ray) &&
			m->meshes[1]->boundingSphere.Intersects(ray)) {
			targets[i].fShot = targets[i].fAnim = true;
			break;
		}
	}
}