示例#1
0
        /// <summary>
        /// Constructor of LoadModel class.
        /// Create <paramref name="Model"/> at <paramref name="Position"/ >  with <paramref name="Scale"/> and <paramref name="Rotation"/>
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Position"></param>
        /// <param name="Rotation"></param>
        /// <param name="Scale"></param>
        /// <param name="graphicsDevice"></param>
        public LoadModel(Model Model, Vector3 Position, Vector3 Rotation,
            Vector3 Scale, GraphicsDevice graphicsDevice, LightsAndShadows.Light light)
        {
            // Console.WriteLine(Position);
            this.baseWorld = Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotation.X) * Matrix.CreateRotationX(Rotation.Y) * Matrix.CreateRotationX(Rotation.Z) * Matrix.CreateTranslation(Position);

            shadowCasters = new List<ShadowCasterObject>();
            this.Model = Model;
            modelTransforms = new Matrix[Model.Bones.Count];
            Model.CopyAbsoluteBoneTransformsTo(modelTransforms);

            this.Position = Position;
            this.Rotation = Rotation;
            this.playerTarget = Vector3.Zero;
            this.Scale = Scale;
            this.graphicsDevice = graphicsDevice;
            this.light = light;
            buildBoundingSphere();
            CreateBoudingBox();

            foreach (ModelMesh mesh in Model.Meshes)
            {
                if (!mesh.Name.Contains("Bounding"))
                    foreach (ModelMeshPart meshpart in mesh.MeshParts)
                {

                     ShadowCasterObject shad = new ShadowCasterObject(
                                                    //meshpart.VertexDeclaration,
                                                    meshpart.VertexBuffer,
                                                    meshpart.VertexOffset,
                                                    //meshpart.VertexStride,
                                                    meshpart.IndexBuffer,
                                                    //meshpart.BaseVertex,
                                                    meshpart.NumVertices,
                                                    meshpart.StartIndex,
                                                    meshpart.PrimitiveCount,
                                                    modelTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position));
                     this.shadowCasters.Add(shad);
                }
            }
        }
示例#2
0
        //Animated model constructor
        public LoadModel(Model Model, Vector3 Position, Vector3 Rotation,
            Vector3 Scale, GraphicsDevice GraphicsDevice,
            ContentManager Content, LightsAndShadows.Light light)
        {
            this.baseWorld = Matrix.CreateScale(Scale) * Matrix.CreateRotationX(Rotation.X)
            *Matrix.CreateRotationY(Rotation.Y)*
            Matrix.CreateRotationZ(Rotation.Z)*
            Matrix.CreateTranslation(Position);
            shadowCasters = new List<ShadowCasterObject>();
            //Console.WriteLine(Position);
            this.Model = Model;
            this.graphicsDevice = GraphicsDevice;
            this.content = Content;
            this.Position = Position;
            this.playerTarget = Vector3.Zero;
            this.Rotation = Rotation;
            this.Scale = Scale;
            this.light = light;
            modelTransforms = new Matrix[Model.Bones.Count];
            Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
            SkinningData skinningData = Model.Tag as SkinningData;
            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");
            this.skinningData = Model.Tag as SkinningData;
            Player = new AnimationPlayer(skinningData);
            buildBoundingSphereAnimated();

            foreach (ModelMesh mesh in Model.Meshes)
            {
                if (!mesh.Name.Contains("Bounding"))
                    foreach (ModelMeshPart meshpart in mesh.MeshParts)
                    {

                        ShadowCasterObject shad = new ShadowCasterObject(
                            //meshpart.VertexDeclaration,
                                                       meshpart.VertexBuffer,
                                                       meshpart.VertexOffset,
                            //meshpart.VertexStride,
                                                       meshpart.IndexBuffer,
                            //meshpart.BaseVertex,
                                                       meshpart.NumVertices,
                                                       meshpart.StartIndex,
                                                       meshpart.PrimitiveCount,
                                                       modelTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position));
                        this.shadowCasters.Add(shad);
                    }
            }
        }