Предыдущая Следующая
Vector3.Up);
proj = Matrix.CreatePerspectiveFieldOfView(FOV, aspectRatio, nearClip,
farClip);
for (int i = 0; ball.Length > i;
{
world = Matrix.CreateTranslation(ball[i].position); ball[i].DrawModel(world, view, proj);
}
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
cursor.DrawSprite(spriteBatch);
spriteBatch.End();
break;
}
case CurentGameState.GameOverScreen:
{
break;
}
case CurentGameState.VictoryScreen:
{
break;
} }
base.Draw(gameTime);
}
/// <summary> /// Движение мячей /// <summary> void MoveBall()
{
for (int i = 0; ball.Length > i;
{
ball[i].position.Y -= ball[i].speed;
}
}
/// <summary> /// Клик мышей /// <summary>
void MouseClickO {
mouseState = Mouse.GetState(); cursor.spritePosition.X = mouseState.X; cursor.spritePosition.Y = mouseState.Y;
for (int i = 0; bb.Length > i; {
bb[i].Center = ball[i].position; bb[i].Radius = ball[i].radius;
}
Ray pickRay = GetPickRay();
for (int i = 0; ball.Length > i;
{
Nullable<float> resultO = pickRay.Intersects(bb[0]); if (resultO.HasValue == true)
{
ball[0].position.X = rand.Next(-(rand.Next(0, 80)), rand.Next(0, 80));
ball[0].position.Y = rand.Next(0, 80); ball[0].position.Z = -(rand.Next(20, 150));
}
Nullable<float> resultl = pickRay.Intersects(bb[1]); if (resultl.HasValue == true)
{
ball[1].position.X = rand.Next(-(rand.Next(0, 80)), rand.Next(0, 80));
ball[1].position.Y = rand.Next(0, 80); ball[1].position.Z = -(rand.Next(20, 150));
}
Nullable<float> result2 = pickRay.Intersects(bb[2]); if (result2.HasValue == true)
{
ball[2].position.X = rand.Next(-(rand.Next(0, 80)), rand.Next(0, 80));
ball[2].position.Y = rand.Next(0, 80); ball[2].position.Z = -(rand.Next(20, 150));
}
}
}
/// <summary>
/// Преобразовываем координаты мыши /// <summary> Ray GetPickRay()
{
mouseState = Mouse.GetState(); int mouseX = mouseState.X; int mouseY = mouseState.Y;
Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, 0f); Vector3 farsource = new Vector3((float)mouseX, (float)mouseY, 1f);
316 Стреляем по целям
// мировая матрица
world = Matrix.CreateTranslation(0, 0, 0); // матрица вида
view = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 150.0f), Vector3.Zero,
Vector3.Up);
// матрица проекции
proj = Matrix.CreatePerspectiveFieldOfView(FOV, aspectRatio, nearClip,
farClip);
// ближняя точка
Vector3 nearPoint = graphics.GraphicsDevice.Viewport.Unproject(nearsource, proj, view, world); // дальняя точка
Vector3 farPoint = graphics.GraphicsDevice.Viewport.Unproject(farsource, proj, view, world); Предыдущая Следующая
|