Пример #1
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            this.gridCellSize = 1.8f;
            if (BunnyModel != null)
            {
                this.ObjectModel = BunnyModel;
            }

            base.LoadContent();

            if (BunnyModel == null)
            {
                BunnyModel = this.ObjectModel;
            }

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.ANIMATEDMODEL, "AnimatedModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.ANIMATEDMODEL;
            this.DefaultTechnique = "AnimatedModelTechnique";
            this.skinningData     = (SkinningData)this.ObjectModel.Tag;

            // currentClip = skinningData.AnimationClips[animations[animationIndex]];
            this.AnimationPlayer.StartClip();

            // Loading Bunny State Machines
            this.AnimationStateMachine = new BunnyAnimationStateMachine(this);
            this.MonsterStateMachine   = new BunnyStateMachine(this, this.PatrolPointLeft, this.PatrolPointRight);
        }
Пример #2
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            GddModel gddModel = ModelManager.LoadModel(this.modelName, this.Game, this.ScaleMatrix * this.Rotation);

            this.ObjectModel   = gddModel.Model;
            this.ModelTextures = gddModel.Textures;

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.ANIMATEDMODEL, "Effects\\AnimatedModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.ANIMATEDMODEL;
            this.DefaultTechnique = "AnimatedModelTechnique";
            this.AnimationPlayer  = new ModelAnimationPlayer(this.ObjectModel.Tag as SkinningData);

            this.skinningData = (SkinningData)this.ObjectModel.Tag;

            this.AnimationPlayer.SetClip((this.ObjectModel.Tag as SkinningData).AnimationClips.Values.First());
            this.AnimationPlayer.StartClip();
            this.AnimationPlayer.StepClip();

            this.currentPhysicsVertices =
                this.AnimationPlayer.CurrentClip.vertices[(int)this.ModelDirection][this.AnimationPlayer.CurrentKeyframe];

            this.PhysicsVertices = this.currentPhysicsVertices;

            this.LoadCommonContent();

            this.PhysicsBody.Mass                    = 70.0f;
            this.PhysicsBody.MomentOfInertia         = float.MaxValue;
            this.PhysicsGeometry.FrictionCoefficient = 10.0f;
            this.PhysicsBody.IsStatic                = false;
        }
Пример #3
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            gridCellSize = 1.8f;
            base.LoadContent();

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.ANIMATEDMODEL, "AnimatedModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.ANIMATEDMODEL;
            this.DefaultTechnique = "AnimatedModelTechnique";

            HeroGeometry = PhysicsGeometry;
        }
Пример #4
0
        /// <summary>
        /// The draw physics vertices.
        /// </summary>
        public virtual void DrawPhysicsVertices()
        {
            if (Globals.displayState == DISPLAY_STATE.BOTH || Globals.displayState == DISPLAY_STATE.TWO_DIM)
            {
                // draw the 2d representation of the model
                ShaderManager.AddEffect(ShaderManager.EFFECT_ID.SIMPLE, "SimpleEffect", this.Game);

                VertexPositionColor[] verticesPC;

                verticesPC = new VertexPositionColor[this.PhysicsGeometry.WorldVertices.Count + 1];
                for (int i = 0; i < this.PhysicsGeometry.WorldVertices.Count; i++)
                {
                    verticesPC[i] =
                        new VertexPositionColor(
                            new Vector3(this.PhysicsGeometry.WorldVertices[i], SceneManager.Z_POSITION), Color.Green);
                }

                verticesPC[this.PhysicsGeometry.WorldVertices.Count] =
                    new VertexPositionColor(
                        new Vector3(this.PhysicsGeometry.WorldVertices[0], SceneManager.Z_POSITION), Color.Green);

                var vd = new VertexDeclaration(this.Game.GraphicsDevice, VertexPositionColor.VertexElements);
                var VB = new VertexBuffer(
                    this.Game.GraphicsDevice,
                    VertexPositionColor.SizeInBytes * (this.PhysicsGeometry.WorldVertices.Count + 1),
                    BufferUsage.None);
                VB.SetData(verticesPC);

                ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.SIMPLE);

                ShaderManager.SetValue("WVP", this.scene.Camera.View * this.scene.Camera.Perspective);

                ShaderManager.SetValue("Color", Color.Black.ToVector4());

                ShaderManager.SetCurrentTechnique("SimpleTechnique");
                ShaderManager.GetCurrentEffectGraphicsDevice().VertexDeclaration = vd;
                ShaderManager.Begin();
                foreach (EffectPass pass in ShaderManager.GetEffectPasses())
                {
                    pass.Begin();
                    ShaderManager.GetCurrentEffectGraphicsDevice().Vertices[0].SetSource(
                        VB, 0, VertexPositionColor.SizeInBytes);
                    ShaderManager.GetCurrentEffectGraphicsDevice().DrawPrimitives(
                        PrimitiveType.LineStrip, 0, this.PhysicsGeometry.WorldVertices.Count);
                    pass.End();
                }

                ShaderManager.End();
            }
        }
Пример #5
0
        /// <summary>
        /// The add scene.
        /// </summary>
        /// <param name="scene">
        /// The scene.
        /// </param>
        public static void AddScene(Scene scene)
        {
            scene.Visible = false;

            scenes.Add(scene);

            if (scene.TopMost && vd == null)
            {
                // set up the vertices and add the effect
                overlayVertexArray = new VertexPositionColor[4];

                overlayVertexArray[0] =
                    new VertexPositionColor(
                        new Vector3(
                            -game.GraphicsDevice.Viewport.Width / 2.0f,
                            -game.GraphicsDevice.Viewport.Height / 2.0f,
                            0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[1] =
                    new VertexPositionColor(
                        new Vector3(
                            -game.GraphicsDevice.Viewport.Width / 2.0f, game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[2] =
                    new VertexPositionColor(
                        new Vector3(
                            game.GraphicsDevice.Viewport.Width / 2.0f, -game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);
                overlayVertexArray[3] =
                    new VertexPositionColor(
                        new Vector3(
                            game.GraphicsDevice.Viewport.Width / 2.0f, game.GraphicsDevice.Viewport.Height / 2.0f, 0.0f),
                        Color.TransparentBlack);

                vd = new VertexDeclaration(game.GraphicsDevice, VertexPositionColor.VertexElements);

                vb = new VertexBuffer(game.GraphicsDevice, VertexPositionColor.SizeInBytes * 4, BufferUsage.None);
                vb.SetData(overlayVertexArray);

                Vector4 overlayColor = Color.Black.ToVector4();
                overlayColor.W = 0.85f;

                ShaderManager.AddEffect(ShaderManager.EFFECT_ID.OVERLAY, "overlay", game);
                ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.OVERLAY);
                ShaderManager.SetValue("OverlayColor", overlayColor);
                ShaderManager.CommitChanges();
            }
        }
Пример #6
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            this.gridCellSize = 1.8f;

            base.LoadContent();
            this.PhysicsBody.IsStatic = true;

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.ANIMATEDMODEL, "AnimatedModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.ANIMATEDMODEL;
            this.DefaultTechnique = "AnimatedModelTechnique";
            this.skinningData     = (SkinningData)this.ObjectModel.Tag;

            // currentClip = skinningData.AnimationClips[animations[animationIndex]];
            this.AnimationPlayer.StartClip();

            // Loading Bunny State Machines
            this.AnimationStateMachine = new FlowerAnimationStateMachine(this);
            this.MonsterStateMachine   = new FlowerStateMachine(this);
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Background"/> class.
        /// </summary>
        /// <param name="s">
        /// The s.
        /// </param>
        public Background(Scene s)
        {
            this.scene = s;
            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.BACKGROUND, "Background", this.scene.Game);

            // TODO: Integrate into Level Editor
            this.Backgrounds = new[]
            {
                new BackgroundLayer(s)
                {
                    Filename = "Levels/clouds", ScrollSpeed = 0.5f, WidthBias = 1 / 10.0f
                },
                new BackgroundLayer(s)
                {
                    Filename = "Levels/mountain", ScrollSpeed = 5.0f, WidthBias = 1 / 20.0f
                },
                new BackgroundLayer(s)
                {
                    Filename = "Levels/hills", ScrollSpeed = 30.0f, WidthBias = 1 / 30.0f
                }
            };
        }
Пример #8
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            this.offset = Vector2.Zero;
            GddModel gddModel = ModelManager.LoadModel(this.modelName, this.Game, this.ScaleMatrix * Matrix.CreateFromYawPitchRoll(this.YawRotation, 0.0f, 0.0f));

            this.ObjectModel = gddModel.Model;
            this.ModelTextures.Clear();
            this.ModelTextures.AddRange(gddModel.Textures);

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.STATICMODEL, "Effects\\StaticModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.STATICMODEL;
            this.DefaultTechnique = "StaticModelTechnique";

            if (this.GeometryType == GeometryType.Polygon)
            {
                this.PhysicsVertices = new Vertices(gddModel.Vertices.Select(v => new Vector2(v.X, v.Y)).ToArray());
                this.physicsVertices.Rotate(-this.RollRotation);
                this.mass = gddModel.Mass * 100.0f;
            }

            this.LoadCommonContent();
            this.PhysicsBody.IsStatic = true;
        }
Пример #9
0
        private static Texture2D RenderToTarget(Model model, ModelAnimationPlayer player, Microsoft.Xna.Framework.Game game, Matrix world, out Texture2D Sillouette)
        {
            DepthStencilBuffer old = ShadowMapManager.SetupShadowMap(game.GraphicsDevice, ref renderTarget, ref depthBuffer);

            BoundingSphere bs = new BoundingSphere();

            bool first = true;

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (first)
                {
                    bs    = mesh.BoundingSphere;
                    first = false;
                }
                else
                {
                    bs = BoundingSphere.CreateMerged(bs, mesh.BoundingSphere);
                }
            }

            bs.Center.X = bs.Center.Z;
            bs.Radius  *= 1.5f;

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.PHYSICS, "PhysicsRenderer", game);
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.PHYSICS);
            ShaderManager.SetValue("World", world);

            Matrix m = Matrix.Identity;

            m.M33 = 0;
            m.M43 = 0.5f;
            ShaderManager.SetValue("Projection", m);


            Matrix view;

            view = Matrix.CreateTranslation(-bs.Center) * Matrix.CreateScale(1 / bs.Radius, 1 / bs.Radius, 1);

            ShaderManager.SetValue("Projection", m);
            ShaderManager.SetValue("View", view);
            ShaderManager.SetValue("usingBones", player != null);

            if (player != null)
            {
                ShaderManager.SetValue("Bones", player.GetSkinTransforms());
            }

            ShaderManager.CommitChanges();
            List <Effect> effects = new List <Effect>();

            game.GraphicsDevice.Clear(Color.Black);

            foreach (ModelMesh mesh in model.Meshes)
            {
                effects.Clear();

                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    effects.Add(part.Effect);
                    part.Effect = ShaderManager.GetCurrentEffect();
                }
                mesh.Draw();
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    mesh.MeshParts[i].Effect = effects[i];
                }
            }

            ShadowMapManager.ResetGraphicsDevice(game.GraphicsDevice, old);

            Color[] textureColors = new Color[(int)(TextureSize.X * TextureSize.Y)];
            renderTarget.GetTexture().GetData <Color>(textureColors);

            Sillouette = new Texture2D(game.GraphicsDevice, (int)TextureSize.X, (int)TextureSize.Y);
            Sillouette.SetData <Color>(textureColors);
            return(renderTarget.GetTexture());
        }
Пример #10
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            // base.LoadContent();
            this.ObjectModel = this.Game.Content.Load <Model>(this.modelName);

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.STATICMODEL, "Effects\\StaticModel", this.Game);
            this.DefaultEffectID  = ShaderManager.EFFECT_ID.STATICMODEL;
            this.DefaultTechnique = "StaticModelTechnique";

            foreach (Effect effect in this.ObjectModel.Meshes.SelectMany(mesh => mesh.Effects))
            {
                if (effect.Parameters["Texture"] != null)
                {
                    this.ModelTextures.Add(effect.Parameters["Texture"].GetValueTexture2D());
                }
                else if (effect.Parameters["BasicTexture"] != null)
                {
                    this.ModelTextures.Add(effect.Parameters["BasicTexture"].GetValueTexture2D());
                }
            }

            var modelBuffer = new List <Vector3>();

            int sizeofVertex = GetSizeOfMesh(this.ObjectModel);

            Vector2[] temp;
            this.groundBodies     = new List <Body>();
            this.groundGeometries = new List <Physics.GeomDC>();
            Vertices vertices;
            int      index = 0;

            foreach (ModelMesh mesh in this.ObjectModel.Meshes)
            {
                var meshBuffer  = new MyStruct[mesh.VertexBuffer.SizeInBytes / sizeofVertex];
                var indexBuffer = new short[mesh.IndexBuffer.SizeInBytes / sizeof(short)];
                mesh.VertexBuffer.GetData(meshBuffer);

                // modelBuffer.AddRange(meshBuffer.Select(v => new Vector3(v.Position.Z, v.Position.Y, v.Position.X)));
                mesh.IndexBuffer.GetData(indexBuffer);

                for (int i = 0; i < indexBuffer.Length; i += 6)
                {
                    if (Math.Abs(meshBuffer[indexBuffer[i]].Position.X - meshBuffer[indexBuffer[i + 1]].Position.X) <
                        0.05f &&
                        Math.Abs(meshBuffer[indexBuffer[i + 1]].Position.X - meshBuffer[indexBuffer[i + 2]].Position.X) <
                        0.05f)
                    {
                        temp = new[]
                        {
                            new Vector2(meshBuffer[indexBuffer[i]].Position.Z * this.Scale.X, meshBuffer[indexBuffer[i]].Position.Y * this.Scale.Y),
                            new Vector2(
                                meshBuffer[indexBuffer[i + 1]].Position.Z * this.Scale.X, meshBuffer[indexBuffer[i + 1]].Position.Y * this.Scale.Y),
                            new Vector2(
                                meshBuffer[indexBuffer[i + 2]].Position.Z * this.Scale.X, meshBuffer[indexBuffer[i + 2]].Position.Y * this.Scale.Y),
                            new Vector2(
                                meshBuffer[indexBuffer[i + 4]].Position.Z * this.Scale.X, meshBuffer[indexBuffer[i + 4]].Position.Y * this.Scale.Y)
                        };

                        vertices = new Vertices(ref temp);
                        //vertices.SubDivideEdges(0.5f);

                        this.PhysicsBody = BodyFactory.Instance.CreatePolygonBody(
                            this.scene.PhysicsSimulator, vertices, 1000);
                        this.PhysicsGeometry = new Physics.GeomDC(this, GeomFactory.Instance.CreatePolygonGeom(
                                                                      this.PhysicsBody, vertices, 0.3f));
                        this.scene.PhysicsSimulator.Add(this.PhysicsGeometry);

                        this.PhysicsGeometry.FrictionCoefficient = 4.0f;

                        this.PhysicsGeometry.CollisionCategories = CollisionCategory.Cat1;
                        this.PhysicsGeometry.CollidesWith        = CollisionCategory.All & ~CollisionCategory.Cat1;

                        this.offset               = this.PhysicsBody.Position;
                        this.OffsetMatrix         = Matrix.CreateTranslation(new Vector3(this.offset, 0.0f));
                        this.InverseOffsetMatrix  = Matrix.CreateTranslation(new Vector3(-this.offset, 0.0f));
                        this.PhysicsBody.Position = this.Position2D + this.offset;

                        this.PhysicsBody.IsStatic = true;

                        this.groundGeometries.Add(new Physics.GeomDC(this, this.PhysicsGeometry));
                        this.groundBodies.Add(this.PhysicsBody);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// The load content.
        /// </summary>
        protected override void LoadContent()
        {
            this.HeaderFont    = this.Game.Content.Load <SpriteFont>("Font//TutorialHeader");
            this.BodyFont      = this.Game.Content.Load <SpriteFont>("Font//TutorialBody");
            this.DialogTexture = this.Game.Content.Load <Texture2D>("Textures\\DialogTexture");

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.TEXTURE, "TextureEffect", this.Game);

            // create the texture that will be shown
            var renderTarget = new RenderTarget2D(
                this.Game.GraphicsDevice,
                512,
                (int)(512 * (this.TextBoxSize.Y / this.TextBoxSize.X)),
                1,
                SurfaceFormat.Color);
            var depthBuffer = new DepthStencilBuffer(
                this.Game.GraphicsDevice,
                512,
                (int)(512 * (this.TextBoxSize.Y / this.TextBoxSize.X)),
                DepthFormat.Depth16);

            DepthStencilBuffer old = ShadowMapManager.SetupShadowMap(
                this.Game.GraphicsDevice, ref renderTarget, ref depthBuffer, Color.TransparentWhite);

            var spriteBatch = (SpriteBatch)this.scene.Game.Services.GetService(typeof(SpriteBatch));

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

            spriteBatch.Draw(
                this.DialogTexture,
                new Rectangle(0, 0, 512, (int)(512 * (this.TextBoxSize.Y / this.TextBoxSize.X))),
                Color.White);

            string header = this.HeaderText.Replace("\\n", "\n");

            spriteBatch.DrawString(
                this.HeaderFont,
                header,
                new Vector2(renderTarget.Width / 2.0f, (renderTarget.Height / 10.0f) + 30),
                Color.Black,
                0.0f,
                this.HeaderFont.MeasureString(header) / 2.0f,
                1.0f,
                SpriteEffects.None,
                1.0f);
            string body    = this.BodyText.Replace("\\n", "\n");
            var    textPos = new Vector2(renderTarget.Width / 2.0f, renderTarget.Height / 10.0f) +
                             new Vector2(
                this.BodyFont.MeasureString(body).X / -2.0f, 2 * this.HeaderFont.MeasureString(header).Y);

            spriteBatch.DrawString(
                this.BodyFont,
                body,
                textPos,
                Color.Black,
                0.0f,
                Vector2.Zero,
                1.0f,
                SpriteEffects.None,
                1.0f);
            spriteBatch.End();

            ShadowMapManager.ResetGraphicsDevice(this.Game.GraphicsDevice, old);
            this.TextTexture = renderTarget.GetTexture();

            var halfTextBoxSizeHeight = new Vector3(0.0f, this.TextBoxSize.Y / 2.0f, 0.0f);
            var halfTextBoxSizeWidth  = new Vector3(this.TextBoxSize.X / 2.0f, 0.0f, 0.0f);

            this.textSprite = new[]
            {
                new TextureSprite(-halfTextBoxSizeWidth - halfTextBoxSizeHeight, new Vector2(0.0f, 1.0f)),
                new TextureSprite(-halfTextBoxSizeWidth + halfTextBoxSizeHeight, Vector2.Zero),
                new TextureSprite(halfTextBoxSizeWidth - halfTextBoxSizeHeight, new Vector2(1.0f, 1.0f)),
                new TextureSprite(halfTextBoxSizeWidth + halfTextBoxSizeHeight, new Vector2(1.0f, 0.0f)),
            };

            this.PhysicsBody = BodyFactory.Instance.CreateRectangleBody(
                halfTextBoxSizeWidth.X * 2, halfTextBoxSizeHeight.Y * 2, 1.0f);
            this.PhysicsGeometry = new Physics.GeomDC(this, GeomFactory.Instance.CreateRectangleGeom(
                                                          this.PhysicsBody, halfTextBoxSizeWidth.X * 2, halfTextBoxSizeHeight.Y * 2));
            this.aabb = this.PhysicsGeometry.AABB;
        }