Дорого времени суток! Есть код который отображает 3д модель в центре. Хотелось бы поворачивать камеру вокруг этой модели по горизонтали всё норм поворачивается, однако по вертикали нет либо вообще ничего не происходит либо поворачивается но не так как должна. Код | using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media;
namespace planet { /// <summary> /// This is the main type for your game /// </summary> public class Main : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; GraphicsAdapter adapter; Matrix view, projection; Vector3 cameraPosition, cameraTarget; Model model; SpriteFont font;
public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here adapter = graphics.GraphicsDevice.Adapter;
graphics.PreferredBackBufferHeight = adapter.CurrentDisplayMode.Height; graphics.PreferredBackBufferWidth = adapter.CurrentDisplayMode.Width; graphics.IsFullScreen = true; graphics.ApplyChanges();
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, adapter.CurrentDisplayMode.AspectRatio, 1, 1000);
cameraPosition = new Vector3(0, 0, 100);
cameraTarget = Vector3.Zero;
base.Initialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here model = this.Content.Load<Model>("Farmhouse FBX");
font = this.Content.Load<SpriteFont>("SpriteFont"); }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit();
// TODO: Add your update logic here KeyboardState keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); }
if (keyboardState.IsKeyDown(Keys.NumPad4)) { cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateRotationY(MathHelper.PiOver4 / 60)); }
if (keyboardState.IsKeyDown(Keys.NumPad8)) { cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateRotationX(MathHelper.PiOver4 / 60)); }
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black);
// TODO: Add your drawing code here Matrix[] destinationBoneTransforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(destinationBoneTransforms);
foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting();
effect.World = destinationBoneTransforms[mesh.ParentBone.Index] * Matrix.Identity; effect.View = view; effect.Projection = projection; }
mesh.Draw(); }
spriteBatch.Begin(); spriteBatch.DrawString(font, String.Format("Camera position: x - {0}, y - {1}, z - {2}", cameraPosition.X, cameraPosition.Y, cameraPosition.Z), new Vector2(10, 10), Color.Yellow); spriteBatch.DrawString(font, String.Format("Camera target: x - {0}, y - {1}, z - {2}", cameraTarget.X, cameraTarget.Y, cameraTarget.Z), new Vector2(10, 26), Color.Yellow); spriteBatch.End();
base.Draw(gameTime); } } }
|
подскажите пожалуйста что не так?
|