示例#1
0
        /// <summary>
        /// Get the bounding sphere of the model
        /// </summary>
        public BoundingBox GetBoundingBox(Model model, Matrix location, float scale)
        {
            BoundingSphere sphere = new BoundingSphere();

            //Get the bounding Sphere of the tank
            foreach (ModelMesh mesh in model.Meshes)
            {
                if (sphere.Radius == 0)
                {
                    sphere = mesh.BoundingSphere;
                }
                else
                {
                    sphere = BoundingSphere.CreateMerged(sphere, mesh.BoundingSphere);
                }
            }
            // world.
            Vector3 Position = new Vector3(location.M41, location.M42, location.M43);

            sphere.Center = Position;
            sphere.Radius = scale;
            BoundingBox box = BoundingBox.CreateFromSphere(sphere);

            return(box);
        }
示例#2
0
        public void initialise()
        {
            foreach (ModelMesh mesh in _carModel.Meshes)
            {
                _boundingSphere = BoundingSphere.CreateMerged(_boundingSphere, mesh.BoundingSphere);
            }

            _physicsManager = new PhysicsManager();

            _position      = new Vector3((150 * 2), 0, (200 * 2));
            _rotation      = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), MathHelper.PiOver2);
            _we            = 0;
            _tractionForce = 0;
            _dragForce     = 0;
            _cDrag         = 0;
            _rollingForce  = 0;

            _steeringAngle  = 0;
            _steeringRadius = 0;

            _throttlePosition = 0;
            _brakingPosition  = 0;
            _velocity         = Vector3.Zero;
            _force            = Vector3.Zero;
            _engineState      = ON;
            _currentGear      = "Neutral";
            _currentRPM       = 1000;
        }
        public BoundingSphere MergeModelSpheres(Model model, TransformComponent transform)
        {
            var sphere = new BoundingSphere();

            foreach (var mesh in model.Meshes)
            {
                if (sphere.Radius == 0)
                {
                    sphere = mesh.BoundingSphere;
                }
                else
                {
                    sphere = BoundingSphere.
                             CreateMerged(sphere, mesh.BoundingSphere);
                }
            }
            sphere.Center = transform.Position;

            if (transform.Scale.X > transform.Scale.Y && transform.Scale.X > transform.Scale.Z)
            {
                sphere.Radius *= transform.Scale.X;
            }
            else if (transform.Scale.Y > transform.Scale.X && transform.Scale.Y > transform.Scale.Z)
            {
                sphere.Radius *= transform.Scale.Y;
            }
            else
            {
                sphere.Radius *= transform.Scale.Z;
            }

            return(sphere);
        }
示例#4
0
文件: Ball.cs 项目: DrGengar/Volamus
        public void LoadContent(Wind _wind)
        {
            effect = GameStateManager.Instance.Content.Load <Effect>("Effects/shader");

            model       = GameStateManager.Instance.Content.Load <Model>("Models/BeachBall");
            ballTexture = GameStateManager.Instance.Content.Load <Texture2D>("Textures/BeachBallTexture");
            ballShadow  = GameStateManager.Instance.Content.Load <Texture2D>("Images/BallShadow");

            //BoundingSphere erstellen
            boundingSphere = new BoundingSphere();

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (boundingSphere.Radius == 0)
                {
                    boundingSphere = mesh.BoundingSphere;
                }
                else
                {
                    boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
                }
            }

            boundingSphere.Radius *= 1.0f;
            originalRadius         = boundingSphere.Radius;

            boundingSphere.Center = position;

            wind = _wind;

            Initialize();
        }
 public static BoundingSphere MergeWith(
     this BoundingSphere first,
     BoundingSphere second
     )
 {
     return(BoundingSphere.CreateMerged(first, second));
 }
示例#6
0
        protected override void LoadContent()
        {
            ContentData.viewPort = GraphicsDevice.Viewport;

            spriteBatch              = new SpriteBatch(GraphicsDevice);
            contentData.gameFont     = Content.Load <SpriteFont>("interface");
            contentData.menuFont     = Content.Load <SpriteFont>("menu");
            contentData.menuHelpFont = Content.Load <SpriteFont>("menuHelp");

            spriteBatch        = new SpriteBatch(GraphicsDevice);
            contentData.logo   = Content.Load <Texture2D>("logo");
            contentData.menu   = Content.Load <Song>("Battlestar Galactica Opening");
            contentData.inGame = Content.Load <Song>("All Along The Watchtower");

            // Projectiles and fx
            contentData.explosion   = Content.Load <Texture2D>("explosion_animation");
            contentData.laser       = Content.Load <Texture2D>("laser");
            contentData.energyCells = Content.Load <Texture2D>("energy_cells");
            contentData.gameOver    = Content.Load <Texture2D>("game_over");

            // Scrolling background
            contentData.space     = Content.Load <Texture2D>("space");
            contentData.spaceDust = Content.Load <Texture2D>("space_dust");

            // 3d models
            contentData.viperMarkII = Content.Load <Model>("Viper_Mk_II");
            BoundingSphere boundingSphere = new BoundingSphere();

            foreach (var mesh in contentData.viperMarkII.Meshes)
            {
                foreach (BasicEffect fx in mesh.Effects)
                {
                    fx.EnableDefaultLighting();
                    fx.SpecularColor     = Color.White.ToVector3();
                    fx.DiffuseColor      = Color.Gray.ToVector3();
                    fx.AmbientLightColor = Color.White.ToVector3();
                }
                boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
            }
            ContentData.viperMarkIIBoundingRadius = boundingSphere.Radius;

            contentData.raider = Content.Load <Model>("Cylon_Raider");
            boundingSphere     = new BoundingSphere();
            foreach (var mesh in contentData.raider.Meshes)
            {
                foreach (BasicEffect fx in mesh.Effects)
                {
                    fx.EnableDefaultLighting();
                    fx.SpecularColor     = Color.Gray.ToVector3();
                    fx.DiffuseColor      = Color.Gray.ToVector3();
                    fx.AmbientLightColor = Color.White.ToVector3();
                }
                boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
            }
            ContentData.raiderBoundingRadius = boundingSphere.Radius;

            // Initialize menu background music
            MediaPlayer.Volume = 1.0f;
            MediaPlayer.Play(contentData.menu);
        }
示例#7
0
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            spriteFont  = Content.Load <SpriteFont>("gameFont");

            string[] modelNames = new[]
            {
                @"Tank",
                @"75Cathedral-model",
                @"Jane_solid_3ds",
                @"Primitives\Cube",
                @"Primitives\Cylinder",
                @"Primitives\Plane",
                @"Primitives\Sphere",
                @"Primitives\Teapot",
                @"Primitives\Torus",
                @"Primitives\Combined",
            };
            _models = new Model[modelNames.Length];
            _modelBoundingSpheres = new BoundingSphere[modelNames.Length];
            for (int i = 0; i < modelNames.Length; ++i)
            {
                _models[i] = Content.Load <Model>(modelNames[i]);

                BoundingSphere boundingSphere = new BoundingSphere();
                foreach (ModelMesh mesh in _models[i].Meshes)
                {
                    boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
                }
                _modelBoundingSpheres[i] = boundingSphere;
            }
        }
示例#8
0
        private void SetBoundingBox()
        {
            BoundingSphere mergedSphere = new BoundingSphere();

            BoundingSphere[] boundingSpheres;
            int index     = 0;
            int meshCount = model.Meshes.Count;

            boundingSpheres = new BoundingSphere[meshCount];
            foreach (ModelMesh mesh in model.Meshes)
            {
                boundingSpheres[index++] = mesh.BoundingSphere;
            }

            mergedSphere = boundingSpheres[0];
            if ((meshCount) > 1)
            {
                index = 1;
                do
                {
                    mergedSphere = BoundingSphere.CreateMerged(mergedSphere,
                                                               boundingSpheres[index]);
                    index++;
                } while (index < meshCount);
            }

            mergedSphere.Center = position;
        }
示例#9
0
        private ModelMeshContent ProcessMesh(MeshContent mesh, ModelBoneContent parent, ContentProcessorContext context)
        {
            var bounds       = new BoundingSphere();
            var parts        = new List <ModelMeshPartContent>();
            var vertexBuffer = new VertexBufferContent();
            var indexBuffer  = new IndexCollection();

            var startVertex = 0;

            foreach (var geometry in mesh.Geometry)
            {
                var vertices    = geometry.Vertices;
                var vertexCount = vertices.VertexCount;
                var geomBuffer  = geometry.Vertices.CreateVertexBuffer();
                vertexBuffer.Write(vertexBuffer.VertexData.Length, 1, geomBuffer.VertexData);

                var startIndex = indexBuffer.Count;
                indexBuffer.AddRange(geometry.Indices);

                var partContent = new ModelMeshPartContent(vertexBuffer, indexBuffer, startVertex, vertexCount, startIndex, geometry.Indices.Count / 3);
                partContent.Material = geometry.Material;
                parts.Add(partContent);

                // Update mesh bounding box
                bounds = BoundingSphere.CreateMerged(bounds, BoundingSphere.CreateFromPoints(geometry.Vertices.Positions));

                // Geoms are supposed to all have the same decl, so just steal one of these
                vertexBuffer.VertexDeclaration = geomBuffer.VertexDeclaration;

                startVertex += vertexCount;
            }

            return(new ModelMeshContent(mesh.Name, mesh, parent, bounds, parts));
        }
示例#10
0
        protected BoundingSphere MergedBoundingSphere(Model model)
        {
            BoundingSphere mergedSphere = new BoundingSphere();

            BoundingSphere[] boundingSpheres;
            int index     = 0;
            int meshCount = model.Meshes.Count;

            boundingSpheres = new BoundingSphere[meshCount];
            foreach (ModelMesh mesh in model.Meshes)
            {
                boundingSpheres[index++] = mesh.BoundingSphere;
            }

            mergedSphere = boundingSpheres[0];
            if ((model.Meshes.Count) > 1)
            {
                index = 1;
                do
                {
                    mergedSphere = BoundingSphere.CreateMerged(mergedSphere,
                                                               boundingSpheres[index]);
                    index++;
                } while (index < model.Meshes.Count);
            }
            mergedSphere.Center.Y = 0;
            return(mergedSphere);
        }
示例#11
0
        protected override void LoadContent()
        {
            contentManager = new ContentManager(Game.Services, "Content/meshes");
            model          = contentManager.Load <Model>(modelName);
            bones          = new Matrix[model.Bones.Count];
            foreach (ModelMesh mesh in model.Meshes)
            {
                ModelBounds = BoundingSphere.CreateMerged(ModelBounds,
                                                          mesh.BoundingSphere);
            }

            if (enableCelShading)
            {
                //Cel Shading
                celLightingEffect = contentManager.Load <Effect>("Cel");
                GetEffectParameters();
                if (textureName == null)
                {
                    textureName = "2031";
                }
                modelTexture = contentManager.Load <Texture2D>(textureName);

                //Calculate the projection properties first on any
                //load callback.  That way if the window gets resized,
                //the perspective matrix is updated accordingly
                float aspectRatio = (float)GraphicsDevice.Viewport.Width /
                                    (float)GraphicsDevice.Viewport.Height;
                float fov = MathHelper.PiOver4 * aspectRatio * 3 / 4;
                projection = hostScreen.ProjectionMatrix;
            }

            base.LoadContent();
        }
示例#12
0
        private BoundingSphere CalculateBounds(SceneTemplate scene)
        {
            var instance = scene.CreateInstance();

            instance.SetPoseTransforms();

            var bounds = default(BoundingSphere);

            foreach (var d in instance.DrawableReferences)
            {
                var b = _Meshes[d.MeshIndex].BoundingSphere;

                if (d.Transform is Transforms.RigidTransform statXform)
                {
                    b = b.Transform(statXform.WorldMatrix.ToXna());
                }

                if (d.Transform is Transforms.SkinnedTransform skinXform)
                {
                    // this is a bit agressive and probably over-reaching, but with skins you never know the actual bounds
                    // unless you calculate the bounds frame by frame.

                    var bb = b;

                    foreach (var xb in skinXform.SkinMatrices.Select(item => bb.Transform(item.ToXna())))
                    {
                        b = BoundingSphere.CreateMerged(b, xb);
                    }
                }

                bounds = bounds.Radius == 0 ? b : BoundingSphere.CreateMerged(bounds, b);
            }

            return(bounds);
        }
示例#13
0
        /// <summary>
        /// Obtiene el índice de crecimiento al añadir los volúmenes especificados
        /// </summary>
        /// <param name="sphere1">Esfera primera</param>
        /// <param name="sphere2">Esfera segunda</param>
        /// <returns>Devuelve el índice de crecimiento al añadir los volúmenes especificados</returns>
        private float GetGrowth(BoundingSphere sphere1, BoundingSphere sphere2)
        {
            BoundingSphere newSphere = BoundingSphere.CreateMerged(sphere1, sphere2);

            // Se devuelve un valor proporcional al cambio en el área de superficie de la esfera
            return((newSphere.Radius * newSphere.Radius) - (sphere1.Radius * sphere1.Radius));
        }
示例#14
0
        /// <summary>
        /// Construye la jerarquía del nodo actual
        /// </summary>
        /// <param name="northWest">Nodo al noroeste</param>
        /// <param name="northEast">Nodo al noreste</param>
        /// <param name="southWest">Nodo al suroeste</param>
        /// <param name="southEast">Nodo al sureste</param>
        public virtual void Build(SceneryNode northWest, SceneryNode northEast, SceneryNode southWest, SceneryNode southEast)
        {
            northWest.Parent = this;
            northEast.Parent = this;
            southWest.Parent = this;
            southEast.Parent = this;

            Childs.Clear();

            Childs.Add(NodeHeads.NorthWest, northWest);
            Childs.Add(NodeHeads.NorthEast, northEast);
            Childs.Add(NodeHeads.SouthWest, southWest);
            Childs.Add(NodeHeads.SouthEast, southEast);

            BoundingBox northAABB = BoundingBox.CreateMerged(northWest.m_AABB, northEast.m_AABB);
            BoundingBox southAABB = BoundingBox.CreateMerged(southWest.m_AABB, southEast.m_AABB);

            m_AABB = BoundingBox.CreateMerged(northAABB, southAABB);

            BoundingSphere northSPH = BoundingSphere.CreateMerged(northWest.m_SPH, northEast.m_SPH);
            BoundingSphere southSPH = BoundingSphere.CreateMerged(southWest.m_SPH, southEast.m_SPH);

            m_SPH = BoundingSphere.CreateMerged(northSPH, southSPH);

            NodeCenter = Vector3.Divide(m_AABB.Max + m_AABB.Min, 2.0f);
        }
示例#15
0
        public void LoadContent(ContentManager Content)
        {
            // Load the assets for the Earth.
            model            = Content.Load <Model>(@"Models\earth");
            effect           = Content.Load <Effect>(@"Effects\earth");
            dayTexture       = Content.Load <Texture2D>(@"Textures\earth_day_color_spec");
            nightTexture     = Content.Load <Texture2D>(@"Textures\earth_night_color");
            cloudTexture     = Content.Load <Texture2D>(@"Textures\earth_clouds_alpha");
            normalMapTexture = Content.Load <Texture2D>(@"Textures\earth_nrm");

            // Setup material settings for the Earth.
            ambient       = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
            diffuse       = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
            specular      = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
            shininess     = 20.0f;
            cloudStrength = 1.15f;

            // Calculate the bounding sphere of the Earth model and bind the
            // custom Earth effect file to the model.
            foreach (ModelMesh mesh in model.Meshes)
            {
                bounds = BoundingSphere.CreateMerged(bounds, mesh.BoundingSphere);

                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = effect;
                }
            }
        }
示例#16
0
        public Hazard(Vector3 position, float speed, bool alive, bool barrelRollin, float rollRandomMod)
        {
            this.position      = position;
            this.world         = Matrix.CreateTranslation(position);
            this.speed         = speed;
            this.alive         = alive;
            this.yaw           = 0;
            this.pitch         = 0;
            this.roll          = 0;
            this.barrelRollin  = barrelRollin;
            this.rollRandomMod = rollRandomMod;
            this.explosionSize = 0.5f;
            this.observers     = new List <Observer>();
            this.scoreObserver = new ScoreObserver();
            AddObserver(scoreObserver);

            velocity     = Vector3.Forward;
            defaultSpeed = new Vector3(0, 0, speed);

            foreach (ModelMesh mesh in HazardForm.Model.Meshes)
            {
                boundingSphere = BoundingSphere.CreateMerged(this.boundingSphere, mesh.BoundingSphere);
            }

            boundingSphere.Radius *= HazardForm.scale;
        }
示例#17
0
        public Teleporter(Model model, BasicEffect effect, List <BoundingBox> boundingBoxes, float offset)
        {
            this.model         = model;
            this.effect        = effect;
            this.boundingBoxes = boundingBoxes;
            this.offset        = offset;
            isOnPlayer         = true;
            position           = Vector3.Zero;

            transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            sphere           = model.Meshes[0].BoundingSphere;
            sphere.Radius   -= 0.22f;
            sphere.Center.Y += sphereCenterOffset;
            if (model.Meshes.Count > 1)
            {
                foreach (ModelMesh mesh in model.Meshes)
                {
                    sphere = BoundingSphere.CreateMerged(sphere, mesh.BoundingSphere);
                }
            }

            sphere = sphere.Transform(scaleMatrix);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="loader">The loader.</param>
        public CustomModel(GraphicFactory factory, ObjectInformation[] loader)
            : base(factory, loader[0].modelName, false)
        {
            System.Diagnostics.Debug.Assert(loader != null);
            System.Diagnostics.Debug.Assert(loader.Count() != 0);
            BatchInformations    = new BatchInformation[1][];
            BatchInformations[0] = new BatchInformation[loader.Count()];

            TextureInformations    = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[loader.Count()];

            BoundingSphere bs = new BoundingSphere();

            for (int i = 0; i < loader.Count(); i++)
            {
                BatchInformations[0][i]   = loader[i].batchInformation;
                TextureInformations[0][i] = loader[i].textureInformation;

                float   radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformations[0][i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }
            modelRadius = bs.Radius;
        }
示例#19
0
文件: Object3.cs 项目: bburhans/vtank
 /// <summary>
 /// Calculated a single bounding sphere for this model, call whenever the model changes.
 /// </summary>
 private void CalculateBoundingSphere()
 {
     foreach (ModelMesh mesh in model.Meshes)
     {
         BoundingSphere meshBoundingSphere = mesh.BoundingSphere;
         BoundingSphere.CreateMerged(ref bounds, ref meshBoundingSphere, out bounds);
     }
 }
        public void CreateMerged_Contains()
        {
            var a = new BoundingSphere(Vector3.Zero, 5);
            var b = new BoundingSphere(new Vector3(1, 0, 0), 2);
            var m = BoundingSphere.CreateMerged(a, b);

            Assert.AreEqual(a, m);
        }
示例#21
0
 protected void initBoundingSphere()
 {
     foreach (ModelMesh mesh in model.Meshes)
     {
         boundingSphere = BoundingSphere.CreateMerged(boundingSphere, mesh.BoundingSphere);
     }
     boundingSphere = boundingSphere.Transform(world);
 }
        public void CreateMerged_Intersect()
        {
            var a = new BoundingSphere(Vector3.Zero, 5);
            var b = new BoundingSphere(new Vector3(6, 0, 0), 5);
            var m = BoundingSphere.CreateMerged(a, b);

            Assert.AreEqual(ContainmentType.Contains, m.Contains(a));
            Assert.AreEqual(ContainmentType.Contains, m.Contains(b));
        }
示例#23
0
        public override void LoadContent()
        {
            model          = XNAGame.Instance.Content.Load <Model>(modelName);
            worldTransform = Matrix.CreateWorld(Position, Look, Up);

            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingSphere = BoundingSphere.CreateMerged(BoundingSphere, mesh.BoundingSphere);
            }
        }
        public void CreateMerged_Contains2()
        {
            var a = new BoundingSphere(new Vector3(1, 0, 0), 2);
            var b = new BoundingSphere(Vector3.Zero, 5);
            var m = BoundingSphere.CreateMerged(a, b);

            Assert.AreEqual(ContainmentType.Contains, b.Contains(a));
            Assert.AreEqual(ContainmentType.Intersects, a.Contains(b));
            Assert.AreEqual(b, m);
        }
示例#25
0
        static public BoundingSphere GetSceneSphere(this Model model)
        {
            BoundingSphere sceneSphere = new BoundingSphere();

            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingSphere boundingSphere = mesh.BoundingSphere;
                sceneSphere = BoundingSphere.CreateMerged(sceneSphere, boundingSphere);
            }
            return(sceneSphere);
        }
示例#26
0
        private Model model;                                          // Variável para carregar o modelo 3d da nave

        /// <summary>
        /// Construtor que inicializa o modelo da nave
        /// </summary>
        /// <param name="content"></param>
        /// <param name="path"></param>
        public NaveModel(ContentManager content, string path)
        {
            //Load do modelo da nave
            model = content.Load <Model>(path);

            //Criação de Bounding Sphere para a Nave
            foreach (ModelMesh mesh in this.model.Meshes)
            {
                boundingSphere = BoundingSphere.CreateMerged(this.boundingSphere, mesh.BoundingSphere);
            }
        }
示例#27
0
        /// <summary>
        /// Calculate bounding sphere and return results.
        /// This also set internal caching.
        /// </summary>
        /// <returns>Bounding sphere of the node and its children.</returns>
        public virtual BoundingSphere UpdateBoundingSphere()
        {
            // count event
            Utils.CountAndAlert.Count(Utils.CountAndAlert.PredefAlertTypes.HeavyUpdate);

            // if empty skip
            if (Empty)
            {
                _boundingSphereDirty = false;
                LastBoundingSphere   = EmptyBoundingSphere;
                return(EmptyBoundingSphere);
            }

            // make sure transformations are up-to-date
            DoTransformationsUpdateIfNeeded();

            // bounding sphere to return
            BoundingSphere ret = new BoundingSphere();

            // calculate all child nodes bounding spheres
            foreach (Node child in _childNodes)
            {
                // skip invisible nodes
                if (!child.Visible)
                {
                    continue;
                }

                // get bounding sphere
                BoundingSphere currSphere = child.GetBoundingSphere();
                ret = BoundingSphere.CreateMerged(ret, currSphere);
            }

            // apply all entities directly under this node
            foreach (IEntity entity in _childEntities)
            {
                // skip invisible entities
                if (!entity.Visible)
                {
                    continue;
                }

                // get entity bounding sphere
                BoundingSphere currSphere = entity.GetBoundingSphere(this, ref _localTransform, ref _worldTransform);
                ret = BoundingSphere.CreateMerged(ret, currSphere);
            }

            // put into cache
            _boundingSphereDirty = false;
            LastBoundingSphere   = ret;

            // return final bounding sphere
            return(ret);
        }
示例#28
0
        protected BoundingSphere CalcBoundingSphere()
        {
            BoundingSphere sphere = new BoundingSphere();

            for (int iMesh = 0; iMesh < listMeshRenderObj.Count; iMesh++)
            {
                MeshRenderObj meshRenderObj = listMeshRenderObj[iMesh] as MeshRenderObj;
                sphere = BoundingSphere.CreateMerged(sphere, meshRenderObj.BoundingSphere);
            }
            return(sphere);
        }
        /// <summary>
        /// Loads the model.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="BatchInformations">The batch informations.</param>
        /// <param name="TextureInformations">The texture informations.</param>
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            skinnedModel = factory.GetAnimatedModel(Name);
            ModelBuilderHelper.Extract(factory, out BatchInformations, out TextureInformations, skinnedModel.Model, _diffuseName, _bumpName, _specularName, _glowName, isInternal);
            BoundingSphere sphere = new BoundingSphere();

            foreach (var item in skinnedModel.Model.Meshes)
            {
                sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere);
            }
            modelRadius = sphere.Radius;
        }
示例#30
0
 public virtual void UpdateBoundingVolume()
 {
     if (Model != null)
     {
         BoundingSphere = new BoundingSphere();
         foreach (var mesh in Model.Meshes)
         {
             BoundingSphere = BoundingSphere.CreateMerged(mesh.BoundingSphere.Transform(mesh.ParentBone.Transform), BoundingSphere);
         }
         BoundingSphere = BoundingSphere.Transform(Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position));
     }
 }
示例#31
0
 public virtual void UpdateBoundingVolume()
 {
     if (Model != null)
     {
         BoundingSphere = new BoundingSphere();
         foreach (var mesh in Model.Meshes)
         {
             BoundingSphere = BoundingSphere.CreateMerged(mesh.BoundingSphere.Transform(mesh.ParentBone.Transform), BoundingSphere);
         }
         BoundingSphere = BoundingSphere.Transform(Matrix.CreateScale(Scale) * Matrix.CreateTranslation(Position));
     }
 }
示例#32
0
        protected override void LoadContent()
        {
            if (asset != null)
                this.model = Game.Content.Load<Model>("Models/"+asset);

            Matrix[] transforms = new Matrix[this.model.Bones.Count];
            this.model.CopyAbsoluteBoneTransformsTo(transforms);

            BoundingBox = new BoundingBox();
            BoundingSphere = new BoundingSphere();
            for (int m = 0; m < this.model.Meshes.Count; m++)
            {
                ModelMesh mm = this.model.Meshes[m];
                BoundingBox partBox = new BoundingBox();
                for (int p = 0; p < mm.MeshParts.Count; p++)
                {
                    ModelMeshPart part = mm.MeshParts[p];
                    Vector3[] vertices = part.GetVertexElement(VertexElementUsage.Position);
                    partBox = BoundingBox.CreateFromPoints(vertices);
                }
                partBox.Min = Vector3.Transform(partBox.Min, transforms[mm.ParentBone.Index]);
                partBox.Max = Vector3.Transform(partBox.Max, transforms[mm.ParentBone.Index]);
                BoundingBox = partBox;
                BoundingSphere = BoundingSphere.CreateMerged(BoundingSphere, mm.BoundingSphere);
            }

            base.LoadContent();
        }