Esempio n. 1
0
 internal bool RemoveModel(QuadTreeModelInfo modelInfo)
 {
     if (_models.Contains(modelInfo)) {
         _models.Remove(modelInfo);
         return true;
     }
     return false;
 }
Esempio n. 2
0
        internal bool AddModel(QuadTreeModelInfo modelInfo)
        {
            if (_models == null) {
                return false;
            }

            if (modelInfo._position.X >= m_startX && modelInfo._position.X < m_endX) {
                if (modelInfo._position.Z >= m_startY && modelInfo._position.Z < m_endY) {
                    // it belongs to this instance or a child

                    if (children != null)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (children[i] != null)
                            {
                                if (children[i].AddModel(modelInfo))
                                    return true;
                            }
                        }
                    }
                    // up to us to store it
                    if (modelInfo._position.Y == 0) {
                        modelInfo._position.Y = GetHeightAt(modelInfo._position.X, modelInfo._position.Z);
                    }
                    modelInfo._node = this;
                    _models.Add(modelInfo);
                    return true;
                }
            }
            return false;
        }
Esempio n. 3
0
 public Player(Game game)
     : base(game)
 {
     _playerModel = new QuadTreeModelInfo(game.Content.Load<Model>("Content\\BabyBeholder"), position, 1.0f, Vector3.Zero);
     _playerCamera = new PlayerCamera();
 }
Esempio n. 4
0
 /// <summary>
 /// Lets the QuadTree know of the new position of a model
 /// </summary>
 /// <param name="modelInfo">ModelInfo object returned from AddModel</param>
 /// <param name="position">where to put the model</param>
 public void UpdateModelPosition(QuadTreeModelInfo modelInfo, Vector3 position)
 {
     if (_valid && _root != null) {
         if (modelInfo != null) {
             if (modelInfo._node != null) {
                 modelInfo._node.RemoveModel(modelInfo);
             }
             modelInfo._position = position;
             _root.AddModel(modelInfo);
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Removes a model and it's associated data from the terrain
 /// Returns the Model that was contained in the QuadTreeModelInfo,
 /// or null if modelInfo is null or contains a null Model reference.
 /// </summary>
 /// <param name="modelInfo">A QuadtreeModelInfo object returned from AddModel()</param>
 public Model RemoveModel(QuadTreeModelInfo modelInfo)
 {
     if (modelInfo != null) {
         if (modelInfo._node != null) {
             modelInfo._node.RemoveModel(modelInfo);
         }
         return modelInfo._model;
     }
     return null;
 }
Esempio n. 6
0
 /// <summary>
 /// Add a model to the terrain.  
 /// Returns null if not on terrain or QuadTree not created.
 /// </summary>
 /// <param name="model">Model to add</param>
 /// <param name="position">where to put the model</param>
 /// <param name="scale">scaling</param>
 /// <param name="rotation">orientation, rotation about the Y/Up axis</param>
 public QuadTreeModelInfo AddModel(Model model, Vector3 position, float scale, Vector3 rotation)
 {
     if (_valid && _root != null) {
         QuadTreeModelInfo modelInfo = new QuadTreeModelInfo(model, position, scale, rotation);
         if (_root.AddModel(modelInfo)) //position, scale, rotationY, model);
             return modelInfo;
     }
     return null;
 }