コード例 #1
0
        private void DrawSkinnedModel(Model model, SkinnedAnimationPlayer skinnedAnimationPlayer, RootAnimationPlayer rootAnimationPlayer)
        {
            Matrix[] boneTransforms = null;
            if (skinnedAnimationPlayer != null)
            {
                boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
            }

            Matrix rootTransform = Matrix.Identity;

            if (rootAnimationPlayer != null)
            {
                rootTransform = rootAnimationPlayer.GetCurrentTransform();
            }

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (SkinnedEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Projection = projection;
                    effect.View       = view;
                    if (boneTransforms != null)
                    {
                        effect.SetBoneTransforms(boneTransforms);
                    }
                    effect.World         = rootTransform * skinnedWorld;
                    effect.SpecularColor = Vector3.Zero;
                }

                mesh.Draw();
            }
        }
コード例 #2
0
        private void DrawRigidModel(Model model, RigidAnimationPlayer rigidAnimationPlayer, RootAnimationPlayer rootAnimationPlayer)
        {
            Matrix[] boneTransforms = null;
            if (rigidAnimationPlayer != null)
            {
                boneTransforms = rigidAnimationPlayer.GetBoneTransforms();
            }

            Matrix rootTransform = Matrix.Identity;

            if (rootAnimationPlayer != null)
            {
                rootTransform = rootAnimationPlayer.GetCurrentTransform();
            }

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Projection = projection;
                    effect.View       = view;
                    if (boneTransforms != null)
                    {
                        effect.World = boneTransforms[mesh.ParentBone.Index] * rootTransform * rigidWorld;
                    }
                    else
                    {
                        effect.World = rootTransform * rigidWorld;
                    }
                }

                mesh.Draw();
            }
        }
コード例 #3
0
        /// <summary>
        /// Render car model with this seperate method because we
        /// render it in 2 steps, first the solid stuff, then the alpha glass.
        /// We also rotate the wheels around :)
        /// </summary>
        /// <param name="carNumber">Car type number (0, 1 or 2) for the car
        /// texture</param>
        /// <param name="carColor">Car color we are currently using.</param>
        /// <param name="shadowCarMode">In the shadow car mode we render
        /// everything (including wheels and glass) with a special ShadowCar
        /// shader, that is very transparent. Used for the shadow car when
        /// playing that shows how we drove the last time.</param>
        /// <param name="renderMatrix">Render matrix for the car</param>
        public void RenderCar(bool renderCyclist, Color carColor,
                              Matrix renderMatrix)
        {
            //renderMatrix = Matrix.CreateTranslation(renderMatrix.Translation + Vector3.UnitZ * 5);
            // Multiply object matrix by render matrix, result is used multiple
            // times here.
            renderMatrix = objectMatrix * renderMatrix;


            Matrix[] boneTransforms = null;
            if (skinnedPlayer != null)
            {
                boneTransforms = skinnedPlayer.GetSkinTransforms();
            }

            Matrix rootTransform = Matrix.Identity;

            if (skinnedRootPlayer != null)
            {
                rootTransform = skinnedRootPlayer.GetCurrentTransform();
            }


            if (renderCyclist)
            {
                foreach (ModelMesh mesh in skinnedModel.Meshes)
                {
                    //mesh.MeshParts[0].
                    //skinned.Parameters["diffuseTexture"].SetValue();


                    foreach (Effect effect in mesh.Effects)
                    {
                        //effect.Parameters["diffuseTexture"].SetValue(effect);
                        effect.Parameters["viewProj"].SetValue(BaseGame.ViewProjectionMatrix);
                        effect.Parameters["world"].SetValue(rootTransform * renderMatrix);
                        effect.Parameters["Bones"].SetValue(boneTransforms);
                        effect.CommitChanges();

                        //effect.EnableDefaultLighting();
                        //effect.Projection = BaseGame.ProjectionMatrix;
                        //effect.View = BaseGame.ViewMatrix;
                        //if (boneTransforms != null)
                        //effect.SetBoneTransforms(boneTransforms);
                        //effect.World = rootTransform * renderMatrix;
                        //effect.SpecularColor = Vector3.Zero;
                    }

                    mesh.Draw();
                }
            }

            boneTransforms = null;
            if (rigidPlayer != null)
            {
                boneTransforms = rigidPlayer.GetBoneTransforms();
            }

            rootTransform = Matrix.Identity;
            if (rigidRootPlayer != null)
            {
                rootTransform = rigidRootPlayer.GetCurrentTransform();
            }

            foreach (ModelMesh mesh in rigidModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = Color.Lerp(Color.White, carColor, 0.5f).ToVector3();
                    effect.Projection   = BaseGame.ProjectionMatrix;
                    effect.View         = BaseGame.ViewMatrix;
                    if (boneTransforms != null)
                    {
                        effect.World = boneTransforms[mesh.ParentBone.Index] * rootTransform * renderMatrix;
                    }
                    else
                    {
                        effect.World = rootTransform * renderMatrix;
                    }
                    effect.SpecularPower = 64;
                }

                mesh.Draw();
            }
        }