Esempio n. 1
0
        /// <summary>
        /// Chaining method for adding an obstacle to this Section.
        /// It initializes bounding boxes and stores in Collidable Obstacles.
        /// </summary>
        /// <param name="obstacleEntity">The entity containing the obstacle</param>
        /// <param name="useSubBoundingBoxes">true to use the bounding boxes of the sub-meshes</param>
        /// <returns></returns>
        public Section AddObstacleEntity(Entity obstacleEntity, bool useSubBoundingBoxes)
        {
            // Attach it in ModelEntity
            RootEntity.AddChild(obstacleEntity);

            // Get and add bb to CollidableObstacles
            var modelComponent = obstacleEntity.Get <ModelComponent>();

            var collidableObstacle = new Obstacle {
                Entity = obstacleEntity
            };

            if (useSubBoundingBoxes)
            {
                // Use bounding boxes from parts of the obstacle.
                foreach (var mesh in modelComponent.Model.Meshes)
                {
                    collidableObstacle.BoundingBoxes.Add(mesh.BoundingBox);
                }
            }
            else
            {
                // Use bounding box of the whole model
                collidableObstacle.BoundingBoxes.Add(modelComponent.Model.BoundingBox);
            }

            CollidableObstacles.Add(collidableObstacle);

            return(this);
        }
Esempio n. 2
0
        public Section AddBackgroundEntity(Entity backgroundEntity)
        {
            // Attach  it in ModelEntity
            RootEntity.AddChild(backgroundEntity);

            // Get length via its bounding box
            var modelComponent = backgroundEntity.Get <ModelComponent>().Model;
            var boundingBox    = modelComponent.BoundingBox;

            Length += boundingBox.Maximum.Z - boundingBox.Minimum.Z;

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Chaining method for adding an obstacle to this Section.
        /// It initializes bounding boxes and stores in Collidable Obstacles.
        /// </summary>
        /// <param name="obstacleEntity">The entity containing the obstacle</param>
        /// <param name="useSubBoundingBoxes">true to use the bounding boxes of the sub-meshes</param>
        /// <returns></returns>
        public Section AddObstacleEntity(Entity obstacleEntity, bool useSubBoundingBoxes)
        {
            // Attach it in ModelEntity
            RootEntity.AddChild(obstacleEntity);

            // Get and add bb to CollidableObstacles
            var modelComponent = obstacleEntity.Get <ModelComponent>();

            var collidableObstacle = new Obstacle {
                Entity = obstacleEntity
            };

            if (useSubBoundingBoxes)
            {
                // Use bounding boxes from parts of the obstacle.
                foreach (var mesh in modelComponent.Model.Meshes)
                {
                    var boundingBox = mesh.BoundingBox;
                    var nodeIndex   = mesh.NodeIndex;
                    while (nodeIndex >= 0)
                    {
                        var node      = modelComponent.Model.Skeleton.Nodes[nodeIndex];
                        var transform = node.Transform;
                        var matrix    = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, transform.Scale, Vector3.Zero, transform.Rotation, transform.Position);

                        Vector3.TransformNormal(ref boundingBox.Minimum, ref matrix, out boundingBox.Minimum);
                        Vector3.TransformNormal(ref boundingBox.Maximum, ref matrix, out boundingBox.Maximum);

                        nodeIndex = node.ParentIndex;
                    }

                    collidableObstacle.BoundingBoxes.Add(boundingBox);
                }
            }
            else
            {
                // Use bounding box of the whole model
                collidableObstacle.BoundingBoxes.Add(modelComponent.Model.BoundingBox);
            }

            CollidableObstacles.Add(collidableObstacle);

            return(this);
        }