コード例 #1
0
        protected override void LoadContent()
        {
            base.LoadContent();

            font = Content.Load<SpriteFont>("consolas.ft");
            lineVertex = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
        }
コード例 #2
0
 protected override void DefaultDrawOverride(Game game)
 {
     if (_imageTexture != null)
     {
         PrimitiveBatch.DrawImage(_imageTexture, null, Bounds);
     }
 }
コード例 #3
0
ファイル: Water.cs プロジェクト: Zalrioth/BitSmith
        public Water(GraphicsDevice device, Texture2D particleTexture)
        {
            pb = new PrimitiveBatch(device);
            this.particleTexture = particleTexture;
            spriteBatch = new SpriteBatch(device);
            metaballTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            particlesTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            drawTarget = new RenderTarget2D(device, device.Viewport.Width, device.Viewport.Height);
            alphaTest = new AlphaTestEffect(device);
            alphaTest.ReferenceAlpha = 175;

            var view = device.Viewport;
            alphaTest.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                Matrix.CreateOrthographicOffCenter(0, view.Width, view.Height, 0, 0, 1);

            for (int i = 0; i < columns.Length; i++)
            {
                columns[i] = new WaterColumn()
                {
                    Height = 240,
                    TargetHeight = 240,
                    Speed = 0
                };
            }
        }
コード例 #4
0
        public void Draw(GraphicsDevice device)
        {
            if (material == null)
            {
                Warm(device);
            }

            material.Projection = proj;
            material.View       = view;
            material.World      = Matrix.Identity;
            material.CurrentTechnique.Passes[0].Apply();

            PrimitiveBatch instance = PrimitiveBatch.GetInstance(device);

            instance.Begin(Primitive.Line);

            instance.SetColor(color);
            for (int p = 1; p < points.Length; p++)
            {
                instance.AddVertex(points[p - 1]);
                instance.AddVertex(points[p - 0]);
            }

            instance.AddVertex(points[points.Length - 1]);
            instance.AddVertex(points[0]);

            instance.End();
        }
コード例 #5
0
 public static void DrawLine<TEffect>(
     this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch,
     Color color, Vector3 p1, Vector3 p2)
         where TEffect : Effect, IEffectMatrices
             => primitiveBatch.DrawLine(
                 new VertexPositionColor(p1, color),
                 new VertexPositionColor(p2, color));
コード例 #6
0
        public static void TraceCircle<TEffect>(
            this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch,
            Color color,
            Vector2 position,
            Single radius,
            Int32 segments = 15)
                where TEffect : Effect, IEffectMatrices
        {
            Single step = MathHelper.TwoPi / segments;
            Single angle = 0;
            Vector2 start;
            Vector2 end = new Vector2(radius, 0);

            for(var i=0; i< segments; i++)
            {
                angle += step;
                start = end;

                end = new Vector2(
                    x: (Single)Math.Cos(angle) * radius, 
                    y: (Single)Math.Sin(angle) * radius);

                primitiveBatch.DrawLine(
                    color: color, 
                    p1: position + start, 
                    p2: position + end);
            }
        }
コード例 #7
0
 protected override void LoadContent()
 {
     _primitiveBatch   = new PrimitiveBatch(GraphicsDevice);
     _primitiveDrawing = new PrimitiveDrawing(_primitiveBatch);
     _localProjection  = Matrix.CreateOrthographicOffCenter(0f, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
     _localView        = Matrix.Identity;
 }
コード例 #8
0
 public SelectedItemsDisplay(GraphicsDevice device)
 {
     _primitiveBatch          = new PrimitiveBatch(device);
     _selectedJoints          = new List <Joint>();
     _selectedGameObjects     = new List <GameObject>();
     _selectedGameObjectParts = new List <GameObjectPart>();
 }
コード例 #9
0
        public void Draw3D(PrimitiveBatch primitiveBatch, Matrix world, Matrix projection, Matrix view, Vector3 where)
        {
            // the sun is made from 4 lines in a circle.
            primitiveBatch.Begin(PrimitiveType.LineList, world, projection, view);

            // draw the vertical and horizontal lines
            primitiveBatch.AddVertex(where + new Vector3(0, LIGHT_SIZE, 0), Color.White);
            primitiveBatch.AddVertex(where + new Vector3(0, -LIGHT_SIZE, 0), Color.White);

            primitiveBatch.AddVertex(where + new Vector3(LIGHT_SIZE, 0, 0), Color.White);
            primitiveBatch.AddVertex(where + new Vector3(-LIGHT_SIZE, 0, 0), Color.White);

            // to know where to draw the diagonal lines, we need to use trig.
            // cosine of pi / 4 tells us what the x coordinate of a circle's radius is
            // at 45 degrees. the y coordinate normally would come from sin, but sin and
            // cos 45 are the same, so we can reuse cos for both x and y.
            float sunSizeDiagonal = (float)Math.Cos(MathHelper.PiOver4);

            // since that trig tells us the x and y for a unit circle, which has a
            // radius of 1, we need scale that result by the sun's radius.
            sunSizeDiagonal *= LIGHT_SIZE;

            primitiveBatch.AddVertex(
                where + new Vector3(-sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray);
            primitiveBatch.AddVertex(
                where + new Vector3(sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray);

            primitiveBatch.AddVertex(
                where + new Vector3(sunSizeDiagonal, sunSizeDiagonal, 0), Color.Gray);
            primitiveBatch.AddVertex(
                where + new Vector3(-sunSizeDiagonal, -sunSizeDiagonal, 0), Color.Gray);

            primitiveBatch.End();
        }
コード例 #10
0
ファイル: BasicShapes.cs プロジェクト: Cyberbanan/voxeliq
        public static void DrawSolidPolygon(PrimitiveBatch primitiveBatch, Vector2[] vertices, int count, Color color, bool outline)
        {
            if (!primitiveBatch.IsReady())
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");

            if (count == 2)
            {
                DrawPolygon(primitiveBatch, vertices, count, color);
                return;
            }

            Color colorFill = color * (outline ? 0.5f : 1.0f);

            for (int i = 1; i < count - 1; i++)
            {
                primitiveBatch.AddVertex(vertices[0], colorFill, PrimitiveType.TriangleList);
                primitiveBatch.AddVertex(vertices[i], colorFill, PrimitiveType.TriangleList);
                primitiveBatch.AddVertex(vertices[i + 1], colorFill, PrimitiveType.TriangleList);
            }

            if (outline)
            {
                DrawPolygon(primitiveBatch, vertices, count, color);
            }
        }
コード例 #11
0
        private CollisionManager()
        {
            this.currentDrawType = DRAW_TYPE.DRAW_ALL;
            this.bodyGlobalSet = new XboxHashSet<CollisionBody>();
            this.bodyGroupList = new List<CollisionBody>();
            this.bodyGroupHashSet = new XboxHashSet<CollisionBody>();
            this.primitiveBatch = new PrimitiveBatch(Program.GAME.GraphicsDevice);
            font = Program.GAME.Content.Load<SpriteFont>("MenuFont");

            int poolSize = (int)Math.Pow(4, nodeDepth - 2);

            this.nodeArrayPool = new List<QuadTreeNode[]>(poolSize);
            for (int i = 0; i < poolSize; i++)
            {
                QuadTreeNode[] array = new QuadTreeNode[4];
                array[0] = new QuadTreeNode();
                array[1] = new QuadTreeNode();
                array[2] = new QuadTreeNode();
                array[3] = new QuadTreeNode();
                this.nodeArrayPool.Add(array);
            }

            this.bodySetPool = new List<XboxHashSet<CollisionBody>>(poolSize);
            for (int i = 0; i < poolSize; i++)
            {
                this.bodySetPool.Add(new XboxHashSet<CollisionBody>(maxNodeCapacity + 1));
            }
        }
コード例 #12
0
        /// <summary>Loads the graphics resources of the component</summary>
        protected override void LoadContent()
        {
            this.contentManager = new ResourceContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(GraphicsDeviceService),
#if WINDOWS_PHONE
                Resources.Phone7DebugDrawerResources.ResourceManager
#else
                Resources.DebugDrawerResources.ResourceManager
#endif
                );

            // The effect will be managed by our content manager and only needs to be
            // reloaded when the graphics device has been totally shut down or is
            // starting up for the first time.
#if WINDOWS_PHONE
            this.fillEffect = new BasicEffect(GraphicsDevice);
#else
            this.fillEffect = this.contentManager.Load <Effect>("SolidColorEffect");
#endif
            this.drawContext = new EffectDrawContext(this.fillEffect);

            // Create the sprite batch we're using for text rendering
            this.font            = this.contentManager.Load <SpriteFont>("LucidaSpriteFont");
            this.fontSpriteBatch = new SpriteBatch(GraphicsDevice);

            // Create a new vertex buffer and its matching vertex declaration for
            // holding the geometry data of our debug overlays.
            this.batchDrawer = PrimitiveBatch <VertexPositionColor> .GetDefaultBatchDrawer(
                GraphicsDevice
                );
        }
コード例 #13
0
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager c, Microsoft.Xna.Framework.Graphics.GraphicsDevice g)
        {
            base.LoadContent(c, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            balls = new List<Ball>();

            for (int i = 0; i < 50; i++)
            {
                balls.Add(new Ball(new Vector3(i * 2, 2, 2), new Vector3(i + 1, -i, i % 2) * 0.1f, 0.5f));
            }

            planes = new List<Plane>();

            planes.Add(new Plane(Vector3.Right, 0));
            planes.Add(new Plane(Vector3.Up, 0));
            planes.Add(new Plane(new Vector3(0, 0, 1), 0));
            planes.Add(new Plane(Vector3.Left, -10));
            planes.Add(new Plane(Vector3.Down, -10));
            planes.Add(new Plane(new Vector3(0, 0, -1), -10));

            MeshBuilder mb = new MeshBuilder(g);
            sphere = mb.CreateSphere(1f, 10, 10);
        }
コード例 #14
0
        public override void Draw(GameTime gameTime)
        {
            LinkedList <Vector2> screenTitle = MyFont.GetWord(GlobalValues.TitleFontScaleSize, "Splash Screen");
            Vector2 screenTitlePos           = GlobalValues.GetWordCenterPos("Splash Screen", true);

            if (GlobalValues.ValuesInitialized)
            {
                if (spriteBatch != null)
                {
                    spriteBatch.Begin();

                    spriteBatch.Draw(myImage, new Vector2(0, 0));

                    spriteBatch.End();
                }

                if (pb != null)
                {
                    pb.Begin(PrimitiveType.LineList);

                    DrawLander();
                    DrawLanderRocket();
                    DisplayKeys();

                    pb.End();
                }
                else
                {
                    pb = GlobalValues.PrimitiveBatch;
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Draws the console window
        /// </summary>
        /// <param name="spriteBatch">Sprite batch</param>
        /// <param name="primitiveBatch">Primitives batch</param>
        /// <param name="w">Console window width</param>
        /// <param name="h">Console window height</param>
        public void Draw(SpriteBatch spriteBatch, PrimitiveBatch primitiveBatch, int w, int h)
        {
            if (Font == null)
            {
                throw new NullReferenceException("Font was null");
            }

            primitiveBatch.DrawRectangle(0, 0, w, h, new Color(0, 0, 0, 200));
            int lines      = h / Font.YSize;
            int totalLines = DebugLog.SharedInstance.MessagesCount;

            lines = lines > totalLines ? totalLines : lines;
            for (int i = 0; i < lines; i++)
            {
                Color color = Color.White;
                switch (DebugLog.SharedInstance[totalLines - lines + i].Type)
                {
                case DebugMessageType.Info:
                    color = InfoColor;
                    break;

                case DebugMessageType.Warning:
                    color = WarningColor;
                    break;

                case DebugMessageType.Error:
                    color = ErrorColor;
                    break;
                }
                Font.Draw(spriteBatch, DebugLog.SharedInstance[totalLines - lines + i].Message, 0, i * Font.YSize, color);
            }
        }
コード例 #16
0
        public static void DrawTriangles(PrimitiveBatch primitiveBatch, Vector2 position, Vector2[] outVertices, int[] outIndices, Color color, bool outline = true)
        {
            if (!primitiveBatch.IsReady())
            {
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
            }

            //int count = vertices.Length;

            //if (count == 2)
            //{
            //    DrawPolygon(position, vertices, color);
            //    return;
            //}

            Color colorFill = color * (outline ? 0.5f : 1.0f);

            //Vector2[] outVertices;
            //int[] outIndices;
            //Triangulator.Triangulate(vertices, WindingOrder.CounterClockwise, out outVertices, out outIndices);

            //var position = Vector2.Zero;

            for (int i = 0; i < outIndices.Length - 2; i += 3)
            {
                primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i]].X + position.X, outVertices[outIndices[i]].Y + position.Y), colorFill, PrimitiveType.TriangleList);
                primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i + 1]].X + position.X, outVertices[outIndices[i + 1]].Y + position.Y), colorFill, PrimitiveType.TriangleList);
                primitiveBatch.AddVertex(new Vector2(outVertices[outIndices[i + 2]].X + position.X, outVertices[outIndices[i + 2]].Y + position.Y), colorFill, PrimitiveType.TriangleList);
            }

            //if (outline)
            //    DrawPolygon(position, vertices, color);
        }
コード例 #17
0
ファイル: MapViewerPanel.cs プロジェクト: bschwind/Sky-Slider
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            base.LoadContent(content);

            map = new Map(Device, "startPosTest.txt");
            //        map = new Map();
            BlockData.Initialize(Device, content);
            primBatch = new PrimitiveBatch(Device);

            MeshBuilder mb = new MeshBuilder(Device);
            mb.Begin();

            //mb.AddCylinder(1, 1, 50);
            mb.AddSphere(1, 20, 20);
            testMesh = mb.End();

            mNode = new MeshNode(testMesh);
            mNode.SetPivot(new Vector3(0, -1f, 0));
            mNode.SetScl(new Vector3(1, 5, 1));
            MeshNode child = new MeshNode(testMesh);
            child.SetPos(new Vector3(0, 2, 0));
            MeshNode another = new MeshNode(testMesh);
            another.SetPos(new Vector3(0, 2, 0));

            //Mesh sphere = mb.CreateSphere(0.1f, 10, 10);
            //startMarker = new MeshNode(sphere);
            //startMarker.SetPos(map.StartPos);
            //child.AddChild(another);
            //mNode.AddChild(child);
        }
コード例 #18
0
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");
            StaticEditorMode.ContentManager = content;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont  = content.Load <SpriteFont>("Fonts/hudfont");

            primitiveBatch = new PrimitiveBatch(GraphicsDevice);

            Application.Idle += delegate { Update(); };
            Application.Idle += delegate { Invalidate(); };

            Camera = new Camera2D {
                Pos = new Vector2(Width / 2, Height / 2)
            };
            background = content.Load <Texture2D>("Images/ScrollingTexture");

            timer = new Stopwatch();
            timer.Start();

            //if (Microsoft.Xna.Framework.Input.Mouse.WindowHandle != this.Handle)
            //    Microsoft.Xna.Framework.Input.Mouse.WindowHandle = this.Handle;

            randomizer = new Random();
        }
コード例 #19
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            pb = new PrimitiveBatch(GraphicsDevice);
        }
コード例 #20
0
ファイル: Terrain.cs プロジェクト: AidanFairman/LunarLander
        public override void Initialize()
        {
            //graphics = new GraphicsDeviceManager(this);

            pb = new PrimitiveBatch(Game.GraphicsDevice);

            land = LanderTextToVector.GetPoints(String.Format("{0}\\{1}.txt", Game.Content.RootDirectory, terrainName)).ToArray();

            landingPads = LanderTextToVector.GetPoints(String.Format("{0}\\{1}.txt", Game.Content.RootDirectory, padName)).ToArray();

            landColor = Color.White;
            padColor  = Color.ForestGreen;

            int height = Game.GraphicsDevice.Viewport.Height;
            int width  = Game.GraphicsDevice.Viewport.Width;

            xScale = (int)((width / horizontalTerrainParts - 1));
            yScale = 0 - (int)((height * (2.0f / 3.0f)) / verticalTerrainParts);

            for (int i = 0; i < land.Length; ++i)
            {
                land[i].X *= (xScale);
                land[i].Y *= yScale;
                land[i].Y += (height);
            }
            for (int i = 0; i < landingPads.Length; ++i)
            {
                landingPads[i].X *= xScale;
                landingPads[i].Y *= yScale;
                landingPads[i].Y += height;
            }

            base.Initialize();
        }
コード例 #21
0
        public void Draw(PrimitiveBatch batch, Player player)
        {
            batch.DrawRectangle(_base, Color.White, 1);
            var health = new Rectangle(11, 11, 10, (int)player.GillPower);

            batch.DrawFilledRectangle(health, Color.Blue);
        }
コード例 #22
0
        /// <summary>
        /// Initializes the control, creating the ContentManager
        /// and using it to load a SpriteFont
        /// </summary>
        protected override void Initialize()
        {
            //  Initialize,
            contentMan  = new ContentManager(Services, "Content");
            spriteBatch = new SpriteBatch(GraphicsDevice);
            primBatch   = new PrimitiveBatch(GraphicsDevice);
            randomizer  = new Random();
            Camera      = new Camera2D();


            //  hook the mouse to the XNA graphic display control,
            if (Mouse.WindowHandle != this.Handle)
            {
                Mouse.WindowHandle = this.Handle;
            }

            //  Load some textures and fonts,
            debugOverlay = contentMan.Load <Texture2D>("Assets/Images/Basics/BlankPixel");
            crosshair    = contentMan.Load <Texture2D>("Assets/Other/Dev/9pxCrosshair");
            devCharacter = contentMan.Load <Texture2D>("Assets/Other/Dev/devHarland");
            font         = contentMan.Load <SpriteFont>("Assets/Fonts/Debug");

            //  Setup the grid initially
            RefreshGrid();

            //  Set up tick,
            timer          = new Timer();
            timer.Interval = (int)((1.0f / 60f) * 1000);//  Lock to 60fps max.
            timer.Tick    += new EventHandler(tick);
            timer.Start();
            total.Start();
        }
コード例 #23
0
        public override void LoadContent()
        {
            StateManager.game.Window.Title = "Lunar Lander";

            pb = GlobalValues.PrimitiveBatch;

            mapNames = Terrain.LoadMapsNames();
        }
コード例 #24
0
ファイル: FSDebugView.cs プロジェクト: pottaman/Nez
        public override void onAddedToEntity()
        {
            transform.setPosition(new Vector2(-float.MaxValue, -float.MaxValue) * 0.5f);
            _primitiveBatch = new PrimitiveBatch(1000);

            _localProjection = Matrix.CreateOrthographicOffCenter(0f, Core.graphicsDevice.Viewport.Width, Core.graphicsDevice.Viewport.Height, 0f, 0f, 1f);
            _localView       = Matrix.Identity;
        }
コード例 #25
0
ファイル: DemoPanel.cs プロジェクト: bschwind/Physics
        public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
        {
            base.LoadContent(content);

            primBatch = new PrimitiveBatch(Panel.Device);

            setupEngine();
        }
コード例 #26
0
ファイル: GameScreen.cs プロジェクト: patriksvensson/ld29
 public override void Initialize()
 {
     _batch          = new SpriteBatch(_device);
     _primitiveBatch = new PrimitiveBatch(_batch);
     _camera         = new Camera();
     _player         = new Player();
     _healthBar      = new HealthBar();
 }
コード例 #27
0
ファイル: DxRectangle.cs プロジェクト: akimoto-akira/Pulse
 public void DrawBorder(PrimitiveBatch<VertexPositionColor> primitiveBatch, Color color)
 {
     VertexPositionColor p1 = new VertexPositionColor(new Vector3(X, Y + Height, 1.0f), color);
     VertexPositionColor p2 = new VertexPositionColor(new Vector3(X, Y, 1.0f), color);
     VertexPositionColor p3 = new VertexPositionColor(new Vector3(X + Width, Y, 1.0f), color);
     VertexPositionColor p4 = new VertexPositionColor(new Vector3(X + Width, Y + Height, 1.0f), color);
     primitiveBatch.DrawQuad(p1, p2, p3, p4);
 }
コード例 #28
0
        public DebugManager(GameStatePlay playState, Entity player)
        {
            _playState      = playState;
            _player         = player;
            _primitiveBatch = new PrimitiveBatch();

            IMGUIManager.Setup();
        }
コード例 #29
0
ファイル: BasicShapes.cs プロジェクト: Cyberbanan/voxeliq
        public static void DrawSegment(PrimitiveBatch primitiveBatch, Vector2 start, Vector2 end, Color color)
        {
            if (!primitiveBatch.IsReady())
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");

            primitiveBatch.AddVertex(start, color, PrimitiveType.LineList);
            primitiveBatch.AddVertex(end, color, PrimitiveType.LineList);
        }
コード例 #30
0
ファイル: GameScreen.cs プロジェクト: patriksvensson/ld29
 public override void Initialize()
 {
     _batch = new SpriteBatch(_device);
     _primitiveBatch = new PrimitiveBatch(_batch);
     _camera = new Camera();
     _player = new Player();
     _healthBar = new HealthBar();
 }
コード例 #31
0
 public static void TraceTriangle<TEffect>(
     this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch,
     Color color, Vector3 p1, Vector3 p2, Vector3 p3)
         where TEffect : Effect, IEffectMatrices
             => primitiveBatch.TraceTriangle(
                 new VertexPositionColor(p1, color),
                 new VertexPositionColor(p2, color),
                 new VertexPositionColor(p3, color));
コード例 #32
0
 public static void DrawLine<TEffect>(
     this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch,
     Color c1, Single x1, Single y1, Single z1,
     Color c2, Single x2, Single y2, Single z2)
         where TEffect : Effect, IEffectMatrices
             => primitiveBatch.DrawLine(
                 new VertexPositionColor(new Vector3(x1, y1, z1), c1),
                 new VertexPositionColor(new Vector3(x2, y2, z2), c1));
コード例 #33
0
 public Laser(Game game, float xPosition, float yPosition, float trajectory, bool type) : base(game)
 {
     pb          = new PrimitiveBatch(game.GraphicsDevice);
     xInitialPos = xPosition;
     yInitialPos = yPosition;
     playerLaser = type;
     rotation    = trajectory;
 }
コード例 #34
0
 public TrianglesStrip(GraphicsDevice device,PrimitiveBatch primitiveBatch)
 {
     this.device = device;
     this.batch = primitiveBatch;
     state = new RasterizerState();
     state.CullMode = CullMode.CullCounterClockwiseFace;
     state.FillMode = FillMode.WireFrame;
 }
コード例 #35
0
        public static void Init(Game game)
        {
            VoxelRenderer.graphicsDevice = game.GraphicsDevice;
            int maxVertexSize = 1000000;

            batch  = new PrimitiveBatch <VertexPositionColorTextureNormal>(game.GraphicsDevice, maxVertexSize * Utilities.SizeOf <VertexPositionColorTextureNormal>(), maxVertexSize);
            effect = new BasicEffect(game.GraphicsDevice);
        }
コード例 #36
0
        public GridSample()
        {
            // Create a new PrimitiveBatch, which can be used to draw 2D lines and shapes.
            primitiveBatch = new PrimitiveBatch(this);
            Components.Add(primitiveBatch);

            paintDistanceSquared = Scale.LengthSquared();
        }
コード例 #37
0
 public override void Shutdown()
 {
     if (LineBatch != null)
     {
         OwnGraphics.OurPrimitiveManager.RemovePrimitiveBatch(LineBatch);
         LineBatch = null;
     }
 }
コード例 #38
0
 public static void DrawTriangle<TEffect>(
     this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch, 
     Color color, Vector2 p1, Vector2 p2, Vector2 p3, Single y = 0)
         where TEffect : Effect, IEffectMatrices
              => primitiveBatch.DrawTriangle(
                 new VertexPositionColor(new Vector3(p1, y), color),
                 new VertexPositionColor(new Vector3(p2, y), color),
                 new VertexPositionColor(new Vector3(p3, y), color));
コード例 #39
0
ファイル: MeowGame.cs プロジェクト: GrimMaple/meow-engine
 /// <summary>
 /// Create a new window
 /// </summary>
 /// <param name="w">Window width</param>
 /// <param name="h">Window height</param>
 public MeowGame(uint w, uint h) : base(w, h)
 {
     ClearColor     = new Graphics.Color(0, 0, 0);
     renderer       = new Graphics.Renderer();
     renderTarget   = new RenderTarget(renderer);
     primitiveBatch = new PrimitiveBatch(renderTarget);
     spriteBatch    = new SpriteBatch(renderTarget);
 }
コード例 #40
0
        public override void LoadContent(ContentManager c, GraphicsDevice g)
        {
            base.LoadContent(c, g);

            cam = new FirstPersonCamera(0.5f, 5f);
            cam.Pos = new Vector3(5, 1, 10);
            primBatch = new PrimitiveBatch(g);
        }
コード例 #41
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            RectangleF clip;
            RectangleF destRect   = Bounds;
            Rectangle? sourceRect = null;

            if (HasClip(out clip))
            {
                RectangleF inter = RectangleF.Empty;
                inter.Left   = Math.Max(clip.Left, destRect.Left);
                inter.Top    = Math.Max(clip.Top, destRect.Top);
                inter.Right  = Math.Min(clip.Right, destRect.Right);
                inter.Bottom = Math.Min(clip.Bottom, destRect.Bottom);

                int leftClip      = (int)(inter.Left - DrawPosition.X);
                int rightClip     = (int)(inter.Right - (DrawPosition.X + Width));
                int topClip       = (int)(inter.Top - DrawPosition.Y);
                int bottomClip    = (int)(inter.Bottom - (DrawPosition.Y + Height));
                int clippedWidth  = rightClip - leftClip;
                int clippedHeight = bottomClip - topClip;

                Rectangle source = Rectangle.Empty;
                source.X      = leftClip;
                source.Y      = topClip;
                source.Width  = (int)Width + clippedWidth;
                source.Height = (int)Height + clippedHeight;
                sourceRect    = source;

                destRect.X     += leftClip;
                destRect.Y     += topClip;
                destRect.Width  = Math.Max(destRect.Width + clippedWidth, 0);
                destRect.Height = Math.Max(destRect.Height + clippedHeight, 0);

                if (UIManager.DrawDebug)
                {
                    PrimitiveBatch.Begin();
                    PRect rect = new PRect(clip, 1);
                    rect.Color = Color.Yellow;
                    rect.Draw();
                    PrimitiveBatch.End();

                    PrimitiveBatch.Begin();
                    rect       = new PRect(inter, 1);
                    rect.Color = Color.Magenta;
                    rect.Draw();
                    PrimitiveBatch.End();
                }

                //int rC = (int)(  inter.Right - ( DrawPosition.X + Width ) - location.X + location.X);
                //int lC = (int)( location.X + inter.Left - DrawPosition.X - location.X );
                //int bC = (int)( location.Y + inter.Bottom - ( DrawPosition.Y + Height ) - location.Y );
                //int tC = (int)( location.Y + inter.Top - DrawPosition.Y - location.Y );
            }

            spriteBatch.Draw(texture, destRect, sourceRect, Color, 0f, Vector2.Zero, SpriteEffect, LayerDepth);
        }
コード例 #42
0
 public static void DrawLine<TEffect>(
     this PrimitiveBatch<VertexPositionColor, TEffect> primitiveBatch, 
     Color c1, Vector2 p1, 
     Color c2, Vector2 p2,
     Single y = 0)
         where TEffect : Effect, IEffectMatrices
             => primitiveBatch.DrawLine(
                 new VertexPositionColor(new Vector3(p1, y), c1),
                 new VertexPositionColor(new Vector3(p2, y), c2));
コード例 #43
0
ファイル: DebugGraph.cs プロジェクト: HaKDMoDz/4DBlockEngine
        public void AttachGraphics(PrimitiveBatch primitiveBatch, SpriteBatch spriteBatch, SpriteFont spriteFont)
        {
            m_primitiveBatch = primitiveBatch;
            m_spriteBatch = spriteBatch;
            m_spriteFont = spriteFont;

            Initialize();
            LoadContent();
        }
コード例 #44
0
ファイル: Rocks.cs プロジェクト: boba2000fett/Asteroids
 public Rocks(float rockRotation, int rockSize, float xPosition, float yPosition, int type, Game game) : base(game)
 {
     pb          = new PrimitiveBatch(game.GraphicsDevice);
     xInitialPos = xPosition;
     yInitialPos = yPosition;
     typeOfRock  = type;
     rotation    = rockRotation;
     size        = rockSize;
 }
コード例 #45
0
ファイル: MazeEngine.cs プロジェクト: m3Lith/ktu-maze
 protected override void LoadContent()
 {
     _mainPrimitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
     _mainBasicEffect = new BasicEffect(GraphicsDevice)
     {
         VertexColorEnabled = true,
         TextureEnabled = false,
         LightingEnabled = false
     };
     base.LoadContent();
 }
コード例 #46
0
ファイル: Water.cs プロジェクト: AlexanderGurinov/WaterGame
        public Water(Game game)
        {
            this.game = game;

            var graphicsService = (IGraphicsDeviceService) game.Services.GetService(typeof (IGraphicsDeviceService));

            var waterSurfacePointCount = (graphicsService.GraphicsDevice.Viewport.Width / surfaceSegmentLength) + 1;

            surface = new WaterPoint[waterSurfacePointCount];

            primitiveBatch = new PrimitiveBatch(graphicsService.GraphicsDevice);
        }
コード例 #47
0
ファイル: RobotDemo.cs プロジェクト: bschwind/Graphics-Demos
        //A scenegraph is composed of SceneNodes
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new FirstPersonCamera(0.5f, 5f);        //0.5f is the turn speed for the camera, and 5f is the translational speed
            cam.Pos = new Vector3(3, 3, 13);              //Move our camera to the point (3, 3, 13)
            primBatch = new PrimitiveBatch(g);            //Initialize our PrimitiveBatch

            //Define the objects in our scene
            Mesh sphere, cylinder, box;                   //Define the meshes we will use for the robot arm
                                                          //A mesh holds a list of vertices, and a list of indices which represent triangles

            MeshNode arm, elbow, forearm, wrist, hand;    //Define all the parts of the robot arm we will use

            MeshBuilder mb = new MeshBuilder(g);          //MeshBuilder is a helper class for generating 3D geometry
                                                          //It has some built in functions to create primitives, as well as
                                                          //functions to create your own arbitrary meshes

            //Genererate our geometry
            //All geometry created is centered around the origin in its local coordinate system
            sphere = mb.CreateSphere(0.5f, 15, 15);       //Create a sphere mesh, with radius 0.5 and with 15 subdivisions
            cylinder = mb.CreateCylinder(0.3f, 2.0f, 15); //Create a cylinder with radius 0.3, a height of 2, and 15 subdivisions
            box = mb.CreateBox(0.8f, 1.4f, 0.1f);         //Create a box with width 0.8, height of 1.4, and depth of 0.1

            shoulder = new MeshNode(sphere);              //Assign the sphere mesh to our shoulder node

            arm = new MeshNode(cylinder);                 //Assign the cylinder mesh to our arm node
            arm.SetPos(new Vector3(0, -1, 0));            //Translate the arm down 1 on the y axis

            elbow = new MeshNode(sphere);                 //Assign a sphere to our elbow node
            elbow.SetPos(new Vector3(0, -2, 0));          //Translate the elbow down 2 on the y axis

            forearm = new MeshNode(cylinder);             //Assign a cylinder to our forearm node
            forearm.SetPos(new Vector3(0, -1, 0));        //Translate the forearm down 1 on the y axis

            wrist = new MeshNode(sphere);                 //Assign a sphere for the wrist node
            wrist.SetPos(new Vector3(0, -2, 0));          //Translate the wrist down 2 on the y axis

            hand = new MeshNode(box);                     //Assign the box to the hand node
            hand.SetPos(new Vector3(0, -0.7f, 0));        //Translate the hand down 0.7 (half the height of the box) on the y axis

            shoulder.AddChild(arm);                       //The shoulder is the root of this scene, in our case. It is the parent
            shoulder.AddChild(elbow);                     //of both the arm and the elbow

            elbow.AddChild(forearm);                      //The elbow is the parent of the forearm and wrist
            elbow.AddChild(wrist);

            wrist.AddChild(hand);                         //The wrist is the parent of the hand

            shoulder.SetPos(new Vector3(0, 5, 0));        //This call effectively translates the entire arm up 5 on the y axis
        }
コード例 #48
0
        public static void DrawDebugData(GraphicsDevice device, PrimitiveBatch primBatch)
        {
            projection = Matrix.CreateOrthographicOffCenter(0f, device.Viewport.Width / MetreInPixels,
                                                         device.Viewport.Height / MetreInPixels, 0f, 0f,
                                                         1f);

            Matrix view = Matrix.CreateTranslation(new Vector3((ToMetres(-Camera.Offset)), 0f))
                * Matrix.CreateTranslation(new Vector3(ToMetres(-GameRoot.ScreenCentre), 0f))
                * Matrix.CreateScale(Camera.ZoomAmount, Camera.ZoomAmount, 0)
                * Matrix.CreateTranslation(new Vector3(ToMetres(GameRoot.ScreenCentre), 0f));

            debug.RenderDebugData(ref projection, ref view);
        }
コード例 #49
0
 /// <summary>Initializes a new instance of the <see cref="TrianglesStrip" /> class.</summary>
 /// <param name="device">The device.</param>
 /// <param name="primitiveBatch">The primitive batch.</param>
 public TrianglesStrip(GraphicsDevice device, PrimitiveBatch primitiveBatch)
 {
     this.IsFilled = true;
     this.Color = Color.White;
     this.point = new List<Vector2>();
     this.device = device;
     this.batch = primitiveBatch;
     this.state = new RasterizerState
                      {
                          CullMode = CullMode.CullCounterClockwiseFace,
                          FillMode = FillMode.WireFrame
                      };
 }
コード例 #50
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            primBatch = new PrimitiveBatch(Device);
            cam = new FirstPersonCamera(0.5f, 10);
            cam.Pos = new Vector3(3, 3, 13);

            MeshBuilder mb = new MeshBuilder(g);
            sphere = mb.CreateSphere(1f, 10, 10);

            setupEngine();
        }
コード例 #51
0
ファイル: BasicShapes.cs プロジェクト: Cyberbanan/voxeliq
        public static void DrawPolygon(PrimitiveBatch primitiveBatch, Vector2[] vertices, int count, Color color)
        {
            if (!primitiveBatch.IsReady())
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");

            for (int i = 0; i < count - 1; i++)
            {
                primitiveBatch.AddVertex(vertices[i], color, PrimitiveType.LineList);
                primitiveBatch.AddVertex(vertices[i + 1], color, PrimitiveType.LineList);
            }

            primitiveBatch.AddVertex(vertices[count - 1], color, PrimitiveType.LineList);
            primitiveBatch.AddVertex(vertices[0], color, PrimitiveType.LineList);
        }
コード例 #52
0
        public RadarRenderSystem(Rectangle radarBounds, Rectangle scanBounds)
            : base(typeof(Body))
        {
            _RadarBounds = radarBounds;
            _RadarCenter = new Vector2(radarBounds.X + radarBounds.Width / 2f, radarBounds.Y + radarBounds.Height / 2f);
            _ScanBounds = scanBounds;

            _Projection = Matrix.CreateOrthographicOffCenter(0, ScreenHelper.GraphicsDevice.Viewport.Width, ScreenHelper.GraphicsDevice.Viewport.Height,
                0f, 0f, 1);
            _View = Matrix.Identity;

            _PrimBatch = new PrimitiveBatch(ScreenHelper.GraphicsDevice);
            _SpriteBatch = new SpriteBatch(ScreenHelper.GraphicsDevice);
        }
コード例 #53
0
ファイル: World.cs プロジェクト: Eamnon/Emergence
        public int Draw(GameTime gameTime, PrimitiveBatch primitiveBatch)
        {
            for (int i = 0; i < symets.Count; i++)
            {
                symets[i].Draw(primitiveBatch);
            }

            //if (drawOverlays)
            //{
            //    shape1HitOverlay.Draw(primitiveBatch);
            //    shape2HitOverlay.Draw(primitiveBatch);
            //}

            return 1;
        }
コード例 #54
0
ファイル: GameWorld.cs プロジェクト: chrishaukap/GameDev
        public GameWorldCore(GraphicsDeviceManager g, ContentManager c, Game1 game)
        {
            mContent = c;
            mGraphics = g;
            mGame = game;
            mPrimitiveBatch = new PrimitiveBatch(Camera, g.GraphicsDevice);
            mSpriteBatch = new SpriteBatch(mGraphics.GraphicsDevice);
            mPathfinder = new Pathfinder(g, this);
            mAgents = new List<Agent>();
            mCraters = new List<Crater>();
            mCones = new List<Cone>();
            mRandom = new Random();

            InitializeStartingAgents();
        }
コード例 #55
0
        protected override void Draw(Matrix view, Matrix Projection, RenderHelper render, PrimitiveBatch batch)
        {
            if (fill == false)
            {
                render.PushRasterizerState(state);
            }

            batch.Begin(PrimitiveType.TriangleList,view,Projection);
            foreach (var item in point)
            {
                batch.AddVertex(item, color);
            }
            batch.End();

            render.PopRasterizerState();
        }
コード例 #56
0
ファイル: ExampleGame.cs プロジェクト: jpgdev/JPEngine
        protected override void Initialize()
        {
            Engine.Initialize(graphics, this);
            Engine.Window.Width = 1280;
            Engine.Window.Height = 720;
            Engine.Managers.Add(typeof(ScriptConsole), new ScriptConsole(new ConsoleOptions(Content.Load<SpriteFont>("Fonts/ConsoleFont"))
            {
                Width = GraphicsDevice.Viewport.Width
            }));

            Engine.Window.IsMouseVisible = true;

            _primitiveBatch = new PrimitiveBatch(Engine.Window.GraphicsDevice);

            base.Initialize();
        }
コード例 #57
0
ファイル: GraphManager.cs プロジェクト: Cyberbanan/voxeliq
        protected override void LoadContent()
        {
            // init the drawing related objects.
            _primitiveBatch = new PrimitiveBatch(this.GraphicsDevice, 1000);
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _spriteFont = this._assetManager.Verdana;
            _localProjection = Matrix.CreateOrthographicOffCenter(0f, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
            _localView = Matrix.Identity;           
            
            // attach the drawing objects to the graph modules.
            foreach (var graph in this._graphs)
            {
                graph.AttachGraphics(this._primitiveBatch, this._spriteBatch, this._spriteFont, this._localProjection, this._localView);
            }

            base.LoadContent();
        }
コード例 #58
0
ファイル: MiniTriRenderer.cs プロジェクト: numo16/SharpDX
        /// <summary>
        /// Initializes a new instance of the <see cref="MiniTriRenderer" /> class.
        /// </summary>
        protected override void LoadContent()
        {
            // Creates a basic effect
            Utilities.Dispose(ref basicEffect);
            basicEffect = new BasicEffect(GraphicsDevice)
                              {
                                  VertexColorEnabled = true,
                                  View = Matrix.Identity,
                                  Projection = Matrix.Identity,
                                  World = Matrix.Identity
                              };

            // Creates primitive bag
            Utilities.Dispose(ref primitiveBatch);
            primitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);

            Window.AllowUserResizing = true;
        }
コード例 #59
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new FirstPersonCamera(0.5f, 5f);
            cam.Pos = new Vector3(5, 1, 10);
            primBatch = new PrimitiveBatch(g);

            //Set up our triangle
            a = new Vector3(4, 1, 5);
            b = new Vector3(6, 1.5f, 3);
            c = new Vector3(6, 1, 5);

            triangleCenter = (a + b + c) / 3f;

            n = Vector3.Normalize(Vector3.Cross(c - a, b - a));
        }
コード例 #60
0
        public override void LoadContent(ContentManager content, GraphicsDevice g)
        {
            base.LoadContent(content, g);

            //Set up our camera and primitive renderer
            cam = new FirstPersonCamera(0.5f, 5f);
            cam.Pos = new Vector3(5, 1, 10);
            primBatch = new PrimitiveBatch(g);

            animation = Animation.Parse("Content/MotionCaptures/BriskWalk1_All.tsv");

            spheres = new List<MeshNode>();
            MeshBuilder mb = new MeshBuilder(Device);

            for (int i = 0; i < animation.GetNumMarkers(); i++)
            {
                spheres.Add(new MeshNode(mb.CreateSphere(0.06f, 10, 10)));
            }
        }