Предыдущая Следующая
}
world = Matrix.CreateTranslation(stadium.position); stadium.DrawModel(world, view, proj);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
cursor.DrawSprite(spriteBatch);
spriteBatch.End();
break;
}
328 Формируем трехмерную сцену
Небо и тучи 329
case CurentGameState.GameOverScreen:
break;
}
case CurentGameState.VictoryScreen:
і
break;
} }
base.Draw(gameTime);
}
/// <summary> /// Движение мячей /// <summary> void MoveBall()
і
for (int i = Ü; ball.Length > i;
і
if (ball[i].position.Y < -32)
і
ball[i].position.Y = ball[i].position.Y;
else
і
ball[i].position.Y -= ball[i].speed;
і
ball[O].position.X = rand.Next(-(rand.Next(O, BO)),
ball[O].position.Y = rand.Next(O, BO);
ball[O].position.Z = rand.Next(-(rand.Next(O, 50)),
}
Nullable<float> resultl = pickRay.Intersects(bb[l]);
if (resultl.HasValue == true)
і
ball[1].position.X = rand.Next(-(rand.Next(O, BO)),
ball[1].position.Y = rand.Next(0, BO);
ball[1].position.Z = rand.Next(-(rand.Next(O, 50)),
}
Nullable<float> result2 = pickRay.Intersects(bb[2]);
if (result2.HasValue == true)
і
ball[2].position.X = rand.Next(-(rand.Next(O, BO)),
ball[2].position.Y = rand.Next(0, BO);
ball[2].position.Z = rand.Next(-(rand.Next(O, 50)),
} }
rand.Next(0, BO));
rand.Next(0, 150));
rand.Next(0, BO));
rand.Next(0, 150));
rand.Next(0, B0));
rand.Next(0, 150));
}
/// <summary>
/// Преобразовываем координаты /// <summary> Ray GetPickRay()
і
mouseState = Mouse.GetState(); int mouseX = mouseState.X; int mouseY = mouseState.Y;
}
/// <summary> /// Клик мышью /// <summary> void MouseClick()
і
mouseState = Mouse.GetState(); cursor.spritePosition.X = mouseState.X; cursor.spritePosition.Y = mouseState.Y;
for (int i = Ü; bb.Length > i;
і
bb[i].Center = ball[i].position; bb[i].Radius = ball[i].radius;
if (iriouseState.LeftButton == ButtonState.Pressed)
і
Ray pickRay = GetPickRay();
Nullable<float> resultÜ = pickRay.Intersects(bb[Ü]); if (resultÜ.HasValue == true)
Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, Üf); Vector3 farsource = new Vector3((float)mouseX, (float)mouseY, lf);
world = Matrix.CreateTranslation(Ü, Ü, Ü);
view = Matrix.CreateLookAt(camera, Vector3.Zero, Vector3.Up);
proj = Matrix.CreatePerspectiveFieldOfView(FOV, aspectRatio, nearClip,
farClip);
Vector3 nearPoint = graphics.GraphicsDevice.Viewport.Unproject(nearsource, proj, view, world); Предыдущая Следующая
|