2015-02-22 3 views
0

Итак, я пытаюсь создать интерактивную среду с использованием 3D-модели. У меня есть модель и камера, движущиеся с фиксированным увеличением оси Z, но через 3 или около того секунды модель просто исчезает. Не уверен, что происходит, помощь очень ценится.Монусированная неподвижная движущаяся модель исчезает

Код моей игры размещен ниже.

namespace model_viewer 
{ 
/// <summary> 
/// This is the main type for your game 
/// </summary> 
public class Game1 : Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 

    //Loads the ship 
    Model Ship; 

    //Moves the ship and the camera together 
    float moveCamera; 
    float moveShip; 

    //moves the ship in the user's direction 
    float keyMoveX; 
    float keyMoveY; 

    public Game1() 
     : base() 
    { 
     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() 
    { 
     moveCamera = -3; 

     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); 


     Ship = Content.Load<Model>("Graphics/Ship"); 


     // TODO: use this.Content to load your game content here 
    } 

    /// <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) 
    { 
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) 
      Exit(); 

     moveCamera += 0.005f; 
     moveShip += 0.005f; 

     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.CornflowerBlue); 

     Matrix proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1, 0.1f, 10000.0f); 
     Matrix view = Matrix.CreateLookAt(
      new Vector3(0, 0, moveCamera), 
      Vector3.Zero, 
      Vector3.Up); 


      float scale = 1.0f/Ship.Meshes[0].BoundingSphere.Radius; 
      Matrix world = Matrix.CreateScale(scale) * Matrix.CreateRotationY(MathHelper.ToRadians(180)) * Matrix.CreateTranslation(new Vector3(0, 0, moveShip)); 

      Ship.Draw(world, view, proj); 


      // TODO: Add your drawing code here 

      base.Draw(gameTime); 
    } 
} 

}

ответ

0

Я нашел ответ, моя матрица «вид» была ориентирована на точку, которая не двигалась с моей моделью и вращалась, чтобы просмотреть точку.

+0

Рассмотрите возможность улучшения этого ответа, разместив исправление, пожалуйста, здесь, чтобы другие могли наслаждаться. Вы никогда не знаете, другие могут столкнуться с чем-то похожим – MickyD

Смежные вопросы