当前位置: 首页>>代码示例>>C#>>正文


C# Viewport.Project方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Viewport.Project方法的典型用法代码示例。如果您正苦于以下问题:C# Viewport.Project方法的具体用法?C# Viewport.Project怎么用?C# Viewport.Project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Graphics.Viewport的用法示例。


在下文中一共展示了Viewport.Project方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Butterfly

 public Butterfly(Vector3 Position, float rotation, Viewport ViewPort, Matrix View, Matrix Projection, ButterflyColors color)
 {
     world = Matrix.CreateFromAxisAngle(Vector3.Right, -1 * (float)(Math.PI / 2f)) * Matrix.CreateTranslation(Position);
     Vector3 ScreenProjection = ViewPort.Project(Position, Projection, View, Matrix.CreateScale(0.1f) * Matrix.CreateFromAxisAngle(Vector3.Right, -1 * (float)(Math.PI / 2f)) * Matrix.CreateTranslation(Position));
     hitbox = new Hitbox(new Rectangle((int)(ScreenProjection.X - padX), (int)(ScreenProjection.Y - padY), 2 * padX, 2 * padY));
     viewPort = ViewPort;
     projection = Projection;
     view = View;
     hitbox.Entered += new Hitbox.EnteredEventHandler(hitbox_Entered);
     hitbox.Exited += new Hitbox.ExitedEventHandler(hitbox_Exited);
     timeSelected = new Stopwatch();
     myColor = color;
     hidden = false;
     position = Position;
     startPosition = Position * 20;
     msOffset = rand.Next(0, 500);
     wanderDirection = new Vector2();
     tether = Vector2.Transform(new Vector2(Position.X, Position.Y), Matrix.CreateScale(0.1f));
 }
开发者ID:rocketeer13,项目名称:KinderKinect,代码行数:19,代码来源:Butterfly.cs

示例2: Draw

        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            Vector3 horizV;
            Vector3 horiz;
            float horizHeight;

            if (selectionMode == 1)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (!cupTracks[i].HasLoaded) continue;

                    ScreenManager.GraphicsDevice.SetRenderTarget(cupTrackRT[i]);

                    ScreenManager.GraphicsDevice.Clear(cupTracks[i].SkyColor);

                    int nextpos = (trackPos[i] + 1);
                    if (nextpos >= cupTracks[i].TrackSegments.Count) nextpos = nextpos - cupTracks[i].TrackSegments.Count;
                    Camera.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (193f/108f), 0.001f, 100f);
                    Camera.Position = cupTracks[i].TrackSegments[trackPos[i]].Position + new Vector3(0, 0.5f, 0);
                    Camera.LookAt(cupTracks[i].TrackSegments[nextpos].Position + new Vector3(0, 0.5f, 0), 0f);
                    drawEffect.View = Camera.viewMatrix;
                    drawEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 16f/9f, 0.001f, 100f);
                    drawAlphaEffect.View = Camera.viewMatrix;
                    drawAlphaEffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 16f / 9f, 0.001f, 100f);

                    cupTrackPM[i].Update(gameTime, new Vector2(((1280 * 4) / MathHelper.TwoPi) * Camera.Yaw, 0f));
                    Viewport testVP = new Viewport(0, 0, 193, 108);
                    horizV = new Vector3(0, 0f, -100);
                    horiz = testVP.Project(horizV, Camera.projectionMatrix, Camera.ViewMatrixUpDownOnly(), Camera.worldMatrix);
                    horizHeight = horiz.Y - (25f * cupTrackPM[i].Scale);
                    ScreenManager.SpriteBatch.Begin();
                    ScreenManager.SpriteBatch.Draw(texList["blank"], new Rectangle(cupTrackRT[i].Width / 2, (int)(horizHeight), cupTrackRT[i].Width * 2, (cupTrackRT[i].Height - (int)(horizHeight)) + 400), null, cupTracks[i].GroundColor, 0f, new Vector2(0.5f, 0), SpriteEffects.None, 1);
                    ScreenManager.SpriteBatch.End();
                    ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateScale(new Vector3(cupTrackPM[i].Scale, cupTrackPM[i].Scale, 1f)) * Matrix.CreateTranslation(new Vector3(cupTrackRT[i].Width / 2, horizHeight, 0f)));
                    cupTrackPM[i].Draw(ScreenManager.SpriteBatch);
                    ScreenManager.SpriteBatch.End();

                    ScreenManager.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                    ScreenManager.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                    ScreenManager.GraphicsDevice.BlendState = BlendState.Opaque;
                    ScreenManager.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

                    cupTracks[i].DrawBatches(ScreenManager.GraphicsDevice, drawEffect, drawAlphaEffect);

            #if !WINDOWS_PHONE
                    ScreenManager.GraphicsDevice.SetRenderTarget(null);
            #else
                    ScreenManager.GraphicsDevice.SetRenderTarget(Psuedo3DRacer.renderTarget);

            #endif
                }

            }

            Camera.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, ScreenManager.Viewport.AspectRatio, 0.001f, 100f);
            Camera.Position = new Vector3(3f, 0.2f, 16f);
            Camera.LookAt(new Vector3(0f, 0.5f, 25f) + lookAtOffset, 0f);

            drawEffect.View = Camera.viewMatrix;
            drawEffect.Projection = Camera.projectionMatrix;
            drawAlphaEffect.View = Camera.viewMatrix;
            drawAlphaEffect.Projection = Camera.projectionMatrix;

            ScreenManager.GraphicsDevice.Clear(Track.SkyColor);
            horizV = new Vector3(0, 0f, -200);
            horiz = ScreenManager.Viewport.Project(horizV, Camera.projectionMatrix, Camera.ViewMatrixUpDownOnly(), Camera.worldMatrix);
            horizHeight = horiz.Y - (25 * Parallax.Scale);
            ScreenManager.SpriteBatch.Begin();
            ScreenManager.SpriteBatch.Draw(texList["blank"], new Rectangle(ScreenManager.Viewport.Width / 2, (int)horizHeight, ScreenManager.Viewport.Width * 2, (ScreenManager.Viewport.Height - (int)horizHeight) + 400), null, Track.GroundColor, 0f, new Vector2(0.5f, 0), SpriteEffects.None, 1);
            ScreenManager.SpriteBatch.End();
            ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Matrix.CreateScale(new Vector3(Parallax.Scale, Parallax.Scale,1f)) * Matrix.CreateTranslation(new Vector3(ScreenManager.Viewport.Width / 2, horizHeight, 0f)));
            Parallax.Draw(ScreenManager.SpriteBatch);
            ScreenManager.SpriteBatch.End();

            ScreenManager.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            ScreenManager.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            ScreenManager.GraphicsDevice.BlendState = BlendState.Opaque;
            ScreenManager.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

            if(Track.HasLoaded) Track.DrawBatches(ScreenManager.GraphicsDevice, drawEffect, drawAlphaEffect);

            ScreenManager.FadeBackBufferToBlack(0.5f);

            spriteBatch.Begin();
            spriteBatch.Draw(texList["banner-top"], bannerTop1Pos, null, Color.White, 0f, new Vector2(texList["banner-top"].Width / 2, 0f), 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(texList["banner-bottom"], bannerBottom1Pos, null, Color.White, 0f, new Vector2(texList["banner-bottom"].Width / 2, 0f), 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(texList["banner-top"], bannerTop2Pos, null, Color.White, 0f, new Vector2(texList["banner-top"].Width / 2, 0f), 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(texList["banner-bottom"], bannerBottom2Pos, null, Color.White, 0f, new Vector2(texList["banner-bottom"].Width / 2, 0f), 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(texList["paintcar"], bannerBottom1Pos - new Vector2(0, ((bannerBottom1Pos.Y - (bannerTop1Pos.Y + texList["banner-top"].Height)) / 2) - 1f), null, Color.White * paintCarAlpha, 0f, new Vector2(texList["paintcar"].Width, texList["paintcar"].Height)/2, 1f, SpriteEffects.None, 1);
            spriteBatch.Draw(texList["selectcup"], bannerBottom2Pos - new Vector2(0, ((bannerBottom2Pos.Y - (bannerTop2Pos.Y + texList["banner-top"].Height)) / 2) - 1f), null, Color.White * selectCupAlpha, 0f, new Vector2(texList["selectcup"].Width, texList["selectcup"].Height) / 2, 1f, SpriteEffects.None, 1);

            spriteBatch.Draw(texList["car-spot"], SpotPos, null, Color.White, 0f, new Vector2(texList["car-spot"].Width , texList["car-spot"].Height)/2, 1f, SpriteEffects.None, 1);
//.........这里部分代码省略.........
开发者ID:GarethIW,项目名称:Psuedo3DRacer,代码行数:101,代码来源:SelectionScreen.cs

示例3: drawSpawnBar

            private void drawSpawnBar(Vector3 spawnPoint, float zoom, Viewport viewport)
            {
                Vector3 projection = viewport.Project(spawnPoint, RenderingDevice.Camera.Projection,
                    RenderingDevice.Camera.View, RenderingDevice.Camera.World);
                float baseZoom = 100;
                float scale = baseZoom / zoom; // baseZoom / zoom gets us a scale that increases when zoom is low; that is; zoomed in.
                float offset = 15;
                Vector2 screenCoords = new Vector2(projection.X, projection.Y);

                screenCoords.X += offset * RenderingDevice.TextureScaleFactor.X;
                screenCoords.Y -= offset * RenderingDevice.TextureScaleFactor.Y;

                outerSpawnBar.X = innerSpawnBar.X = (int)(screenCoords.X + texOffset * RenderingDevice.TextureScaleFactor.X * scale);
                outerSpawnBar.Y = innerSpawnBar.Y = (int)(screenCoords.Y + texOffset * RenderingDevice.TextureScaleFactor.Y * scale);

                RenderingDevice.SpriteBatch.Draw(Resources.EmptyTex, outerSpawnBar, null, outerBarColor, 0, Vector2.Zero, SpriteEffects.None, 0);
                if(remaining > 0)
                    RenderingDevice.SpriteBatch.Draw(Resources.EmptyTex, innerSpawnBar, null, innerBarColor, 0, Vector2.Zero, SpriteEffects.None, 0);
                RenderingDevice.SpriteBatch.Draw(barTex, screenCoords, null, Color.White, 0, Vector2.Zero, RenderingDevice.TextureScaleFactor * scale, SpriteEffects.None, 0);
            }
开发者ID:snoozbuster,项目名称:accelerated-delivery,代码行数:20,代码来源:Level.cs

示例4: Run

        public static void Run()
        {
            var left = -1;
            var right = 1;
            var bottom = -1;
            var top = 1;
            
            var near = 5.0f;
            var far = near + 30.0f;
            var xdiv = (right - left) / (far - near);
            var ydiv = (top - bottom) / (far - near);

            var world = Matrix.Identity;
            var view = Matrix.Identity;
            var proj = Matrix.CreatePerspectiveOffCenter(left, right, bottom, top, near, far);

            var width = 2;
            var height = 2;

            var port = new Viewport(left, bottom, width, height);

            // From MSDN et. al.
            //
            // projection space refers to the space after applying projection transformation from 
            // view space. After the projection transformation, visible content has x and y coordinates
            // ranging from -1 to 1, and z coordinates ranging from 0 to 1.
            //
            // Positive Z comes out of the screen, so negative near and far is into the screen.
            //
            // The viewport then mirrors Y so it goes down in screen space.
            Doing(v => port.Project(v, proj, view, world)).With(-1, -1, -near).ShouldBe(-1, 1, 0)
                                                          .With( 1, -1, -near).ShouldBe(1, 1, 0)
                                                          .With(-1, 1, -near).ShouldBe(-1, -1, 0)
                                                          .With(1, 1, -near).ShouldBe(1, -1, 0)
                                                          .With( 0, 0, -near).ShouldBe(0, 0, 0)
                                                          .With(0, 0, -far).ShouldBe(0, 0, 1);
            
            // Test project is inverse of unproject
            Doing(v => port.Unproject(v, proj, view, world)).With(-1, -1, 1).ShouldBe(-1 / near * far, 1 / near * far, -far);
            Doing(v => port.Project(v, proj, view, world)).With(-1 / near * far, 1 / near * far, -far).ShouldBe(-1, -1, 1);

            Doing(v => port.Project(v, proj, view, world)).With(-1 / near * far, -1 / near * far, -far).ShouldBe(-1, 1, 1)
                                                          .With(1 / near * far, 1 / near * far, -far).ShouldBe(1, -1, 1)
                                                          .With(1 / near * far, -1 / near * far, -far).ShouldBe(1, 1, 1);

            // Similar verification but now with values that are typical of usage.
            top = 10;
            left = -5;
            bottom = 0;
            right = 5;

            near = 1.0f;
            far = near + 100.0f;
            
            world = Matrix.Identity;
            view = Matrix.Identity;
            proj = Matrix.CreatePerspectiveOffCenter(left, right, bottom, top, near, far);

            width = 640;
            height = 480;
            port = new Viewport(0, 0, width, height);

            Doing(v => port.Project(v, proj, view, world))

                // Corners of the screen at near plane.
                .With(left, top, -near).ShouldBe(0, 0, 0)
                .With(right, top, -near).ShouldBe(width, 0, 0)
                .With(left, bottom, -near).ShouldBe(0, height, 0)
                .With(right, bottom, -near).ShouldBe(width, height, 0)

                // Center of the screen.
                .With(0, 0, -near).ShouldBe(width / 2, height, 0)
                .With(0, 0, -far).ShouldBe(width / 2, height, 1);

            Doing(v => port.Unproject(v, proj, view, world)).With(0, 0, 0).ShouldBe(left, top, -near)
                                                            .With(width, 0, 0).ShouldBe(right, top, -near)
                                                            .With(0, height, 0).ShouldBe(left, bottom, -near)
                                                            .With(width, height, 0).ShouldBe(right, bottom, -near);
        }
开发者ID:JaapSuter,项目名称:Pentacorn,代码行数:79,代码来源:CoordinateSystemAssumptions.cs

示例5: ProjectRayToScreenSpace

        public static void ProjectRayToScreenSpace(Ray ray, Viewport viewport, Matrix viewTransform, Matrix projectionTransform,
            out Vector2 rayPosition,
            out Vector2 rayDirection)
        {
            Vector3 screenPosition1 = viewport.Project(ray.Position, projectionTransform, viewTransform, Matrix.Identity);
            Vector3 screenPosition2 = viewport.Project(ray.Position + ray.Direction, projectionTransform, viewTransform, Matrix.Identity);

            Vector3 direction = screenPosition2 - screenPosition1;
            rayPosition = new Vector2(screenPosition1.X, screenPosition1.Y);
            rayDirection = new Vector2(direction.X, direction.Y);
        }
开发者ID:thormme,项目名称:Chimera,代码行数:11,代码来源:Utils.cs

示例6: ProjectTest

        public void ProjectTest()
        {
            Viewport viewport = new Viewport(0, 0, 640, 480);
              PerspectiveProjection projection = new PerspectiveProjection();
              projection.SetFieldOfView(MathHelper.ToRadians(60), viewport.AspectRatio, 10, 1000);
              Matrix44F view = Matrix44F.CreateLookAt(new Vector3F(0, 0, 0), new Vector3F(0, 0, -1), Vector3F.Up);

              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(320, 240, 0), viewport.Project(new Vector3F(0, 0, -10), projection, view)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 0), viewport.Project(new Vector3F(projection.Left, projection.Top, -10), projection, view)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(640, 0, 0), viewport.Project(new Vector3F(projection.Right, projection.Top, -10), projection, view)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 480, 0), viewport.Project(new Vector3F(projection.Left, projection.Bottom, -10), projection, view)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(640, 480, 0), viewport.Project(new Vector3F(projection.Right, projection.Bottom, -10), projection, view)));

              Vector3[] farCorners = new Vector3[4];
              GraphicsHelper.GetFrustumFarCorners(projection, farCorners);
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(320, 240, 1), viewport.Project(new Vector3F(0, 0, -1000), projection, view)));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 0, 1), viewport.Project((Vector3F)farCorners[0], projection, view), 1e-4f));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(640, 0, 1), viewport.Project((Vector3F)farCorners[1], projection, view), 1e-4f));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(0, 480, 1), viewport.Project((Vector3F)farCorners[2], projection, view), 1e-4f));
              Assert.IsTrue(Vector3F.AreNumericallyEqual(new Vector3F(640, 480, 1), viewport.Project((Vector3F)farCorners[3], projection, view), 1e-4f));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:21,代码来源:GraphicsHelperTest2.cs

示例7: Render

        public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            if(camera == null)
            {
                return;
            }

            Vector3 screenCoord = viewport.Project(WorldPosition, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);
            if(viewport.Bounds.Contains((int) screenCoord.X, (int) screenCoord.Y) && screenCoord.Z > 0 && Image != null)
            {
                batch.Draw(Image.Image, new Vector2(screenCoord.X, screenCoord.Y) + Offset, Image.SourceRect, Tint, Rotation, new Vector2(Image.SourceRect.Width / 2.0f, Image.SourceRect.Height / 2.0f), Scale, Effects, 0.0f);
            }
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:13,代码来源:SpriteDrawCommand.cs

示例8: Render

        public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            Vector2 extents = Font.MeasureString(Text);
            Vector3 unprojected = viewport.Project(Position, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);

            unprojected.X = Math.Min(Math.Max(extents.X * 0.5f, unprojected.X), viewport.Width - extents.X * 0.5f) ;
            unprojected.Y = Math.Min(Math.Max(extents.Y * 0.5f, unprojected.Y), viewport.Height - extents.Y * 0.5f);

            batch.DrawString(Font, Text, new Vector2(unprojected.X + 1, unprojected.Y) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X - 1, unprojected.Y) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y + 1) - extents / 2.0f, StrokeColor);
            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y - 1) - extents / 2.0f, StrokeColor);

            batch.DrawString(Font, Text, new Vector2(unprojected.X, unprojected.Y) - extents / 2.0f, TextColor);

            base.Render(batch, camera, viewport);
        }
开发者ID:careid,项目名称:myheartisinthework,代码行数:18,代码来源:Drawer2D.cs

示例9: RenderSunMoon

        public void RenderSunMoon(DwarfTime time, GraphicsDevice device, Camera camera, Viewport viewPort, float scale)
        {
            Matrix rot = Matrix.CreateRotationZ(-(CosTime + 0.5f * (float) Math.PI));
            SunPosition = new Vector3(1000, 100, 0);
            Vector3 moonPosition = new Vector3(-1000, 100, 0);
            SunPosition = Vector3.Transform(SunPosition, rot);
            moonPosition = Vector3.Transform(moonPosition, rot);
            SunPosition += camera.Position;
            moonPosition += camera.Position;

            Vector3 cameraFrameSun = Vector3.Transform(SunPosition, camera.ViewMatrix * camera.ProjectionMatrix);
            Vector3 cameraFramMoon = Vector3.Transform(moonPosition, camera.ViewMatrix * camera.ProjectionMatrix);

            Vector3 unProjectSun = viewPort.Project(SunPosition, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);
            Vector3 unProjectMoon = viewPort.Project(moonPosition, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);

            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity);

            if(unProjectSun.Z > 0 && cameraFrameSun.Z > 0)
            {
                DwarfGame.SpriteBatch.Draw(SunTexture, new Vector2(unProjectSun.X - SunTexture.Width / 2 * scale, unProjectSun.Y - SunTexture.Height / 2 * scale), null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0.0f);
            }
            if(unProjectMoon.Z > 0 && cameraFramMoon.Z > 0)
            {
                DwarfGame.SpriteBatch.Draw(MoonTexture, new Vector2(unProjectMoon.X - SunTexture.Width / 2 * scale, unProjectMoon.Y - SunTexture.Height / 2 * scale), null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0.0f);
            }
            DwarfGame.SpriteBatch.End();

            Vector3 sunDir = (camera.Position - SunPosition);
            sunDir.Normalize();
            SunlightDir = sunDir;
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:32,代码来源:SkyRenderer.cs

示例10: GetScreenCoordinates

 public Vector3 GetScreenCoordinates(Vector3 point)
 {
     // todo: retrieve viewport
     Viewport v = new Viewport(0, 0, 1024, 768);
     return v.Project(point, ProjectionMatrix, viewMatrix, Matrix.Identity);
 }
开发者ID:EmielBon,项目名称:nintendo-ds-framework,代码行数:6,代码来源:Camera.cs

示例11: Render

        public override void Render(SpriteBatch batch, Camera camera, Viewport viewport)
        {
            if(batch == null || camera == null)
            {
                return;
            }

            Vector2 extents = Datastructures.SafeMeasure(Font, Text);

            Vector3 unprojected = viewport.Project(Position, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);

            if (unprojected.Z < 0)
            {
                return;
            }

            Rectangle rect = new Rectangle((int) (unprojected.X - extents.X / 2.0f - StrokeWeight), (int) (unprojected.Y - extents.Y / 2.0f - StrokeWeight),
                (int) (extents.X + StrokeWeight + 5), (int) (extents.Y + StrokeWeight + 5));

            Drawer2D.FillRect(batch, rect, FillColor);
            Drawer2D.DrawRect(batch, rect, RectStrokeColor, StrokeWeight);
            Drawer2D.SafeDraw(batch, Text, Font, StrokeColor, new Vector2(unprojected.X + 1, unprojected.Y) - extents / 2.0f, Vector2.Zero);
            Drawer2D.SafeDraw(batch, Text, Font, StrokeColor, new Vector2(unprojected.X - 1, unprojected.Y) - extents / 2.0f, Vector2.Zero);

            Drawer2D.SafeDraw(batch, Text, Font, StrokeColor, new Vector2(unprojected.X, unprojected.Y + 1) - extents / 2.0f, Vector2.Zero);
            Drawer2D.SafeDraw(batch, Text, Font, StrokeColor, new Vector2(unprojected.X, unprojected.Y - 1) - extents / 2.0f, Vector2.Zero);

            Drawer2D.SafeDraw(batch, Text, Font, TextColor, new Vector2(unprojected.X, unprojected.Y) - extents / 2.0f, Vector2.Zero);
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:29,代码来源:TextBoxDrawCommand.cs

示例12: PreRender

        public override void PreRender(DwarfTime time, SpriteBatch sprites)
        {
            if(!HomeSet)
            {
                HomePosition = PlayState.Camera.Target;
                HomeSet = true;
            }

            if(IsVisible && !IsMinimized && GUI.RootComponent.IsVisible)
            {
                Viewport originalViewport = PlayState.GraphicsDevice.Viewport;
                Camera.Update(time, PlayState.ChunkManager);
                Camera.Target = PlayState.Camera.Target + Vector3.Up * 50;
                Camera.Phi = -(float) Math.PI * 0.5f;
                Camera.Theta = PlayState.Camera.Theta;
                Camera.UpdateProjectionMatrix();

                PlayState.GraphicsDevice.SetRenderTarget(RenderTarget);
                PlayState.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);
                PlayState.DefaultShader.Parameters["xView"].SetValue(Camera.ViewMatrix);
                PlayState.DefaultShader.Parameters["xEnableFog"].SetValue(0);

                PlayState.DefaultShader.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);
                PlayState.DefaultShader.CurrentTechnique = PlayState.DefaultShader.Techniques["Textured_colorscale"];

                PlayState.GraphicsDevice.BlendState = BlendState.AlphaBlend;

                PlayState.ChunkManager.RenderAll(Camera, time, PlayState.GraphicsDevice, PlayState.DefaultShader, Matrix.Identity, ColorMap);
                PlayState.WaterRenderer.DrawWaterFlat(PlayState.GraphicsDevice, Camera.ViewMatrix, Camera.ProjectionMatrix, PlayState.DefaultShader, PlayState.ChunkManager);

                PlayState.GraphicsDevice.Textures[0] = null;
                PlayState.GraphicsDevice.Indices = null;
                PlayState.GraphicsDevice.SetVertexBuffer(null);
                PlayState.DefaultShader.Parameters["xEnableFog"].SetValue(1);

                DwarfGame.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, RasterizerState.CullNone);
                Viewport viewPort = new Viewport(RenderTarget.Bounds);
                foreach(MinimapIcon icon in PlayState.ComponentManager.RootComponent.GetChildrenOfTypeRecursive<MinimapIcon>())
                {

                    if (!icon.Parent.IsVisible)
                    {
                        continue;
                    }

                   Vector3 screenPos = viewPort.Project(icon.GlobalTransform.Translation, Camera.ProjectionMatrix, Camera.ViewMatrix, Matrix.Identity);

                    if(RenderTarget.Bounds.Contains((int) screenPos.X, (int) screenPos.Y))
                    {
                        sprites.Draw(icon.Icon.Image, new Vector2(screenPos.X, screenPos.Y), icon.Icon.SourceRect, Color.White, 0.0f, new Vector2(icon.Icon.SourceRect.Width / 2.0f, icon.Icon.SourceRect.Height / 2.0f), icon.IconScale, SpriteEffects.None, 0);
                    }
                }

                sprites.End();
                PlayState.GraphicsDevice.BlendState = BlendState.AlphaBlend;
                PlayState.GraphicsDevice.DepthStencilState = DepthStencilState.None;
                PlayState.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
                PlayState.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
                PlayState.GraphicsDevice.SetRenderTarget(null);

            }

            base.PreRender(time, sprites);
        }
开发者ID:scorvi,项目名称:dwarfcorp,代码行数:64,代码来源:Minimap.cs

示例13: updateLifeBarsMonsters

 //Updates the life bar texture
 public void updateLifeBarsMonsters(int i,int percentage, Vector3 position, Camera cam, Viewport viewport)
 {
     Vector3 posi = viewport.Project(position, cam.projection, cam.view, Matrix.Identity);
     Vector2 pos = new Vector2(posi.X, posi.Y) + new Vector2(-40 ,-40);
     //pos = new Vector2(0, 0);
     if (percentage == 100)
         monstersLife[i].Update(ref life100, pos);
     if (percentage == 75)
         monstersLife[i].Update(ref life75, pos);
     if (percentage == 50)
         monstersLife[i].Update(ref life50, pos);
     if (percentage == 25)
         monstersLife[i].Update(ref life25, pos);
 }
开发者ID:er1,项目名称:c376p1,代码行数:15,代码来源:SpriteManager.cs


注:本文中的Microsoft.Xna.Framework.Graphics.Viewport.Project方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。